Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
complexclip3.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
12#include "include/core/SkFont.h"
15#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
21#include "tools/ToolUtils.h"
23
24#include <utility>
25
26namespace skiagm {
27
29
30class ComplexClip3GM : public GM {
31public:
32 ComplexClip3GM(bool doSimpleClipFirst)
33 : fDoSimpleClipFirst(doSimpleClipFirst) {
34 this->setBGColor(0xFFDDDDDD);
35 }
36
37protected:
38 SkString getName() const override {
39 SkString str;
40 str.printf("complexclip3_%s", fDoSimpleClipFirst ? "simple" : "complex");
41 return str;
42 }
43
44 SkISize getISize() override { return SkISize::Make(400, 950); }
45
46 void onDraw(SkCanvas* canvas) override {
47 SkPath clipSimple = SkPath::Circle(70, 50, 20);
48
49 SkRect r1 = { 10, 20, 70, 80 };
50 SkPath clipComplex = SkPathBuilder().moveTo(40, 50)
51 .arcTo(r1, 30, 300, false)
52 .close()
53 .detach();
54
55 SkPath* firstClip = &clipSimple;
56 SkPath* secondClip = &clipComplex;
57 if (!fDoSimpleClipFirst) {
58 std::swap(firstClip, secondClip);
59 }
60
62 paint.setAntiAlias(true);
63
65
66 constexpr struct {
67 SkClipOp fOp;
68 const char* fName;
69 } gOps[] = {
72 };
73
74 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
75 canvas->scale(3 * SK_Scalar1 / 4, 3 * SK_Scalar1 / 4);
76
77 SkPaint pathPaint;
78 pathPaint.setAntiAlias(true);
79 pathPaint.setColor(gPathColor);
80
81 for (int invA = 0; invA < 2; ++invA) {
82 for (int aaBits = 0; aaBits < 4; ++aaBits) {
83 canvas->save();
84 for (size_t op = 0; op < std::size(gOps); ++op) {
85 for (int invB = 0; invB < 2; ++invB) {
86 bool doAAA = SkToBool(aaBits & 1);
87 bool doAAB = SkToBool(aaBits & 2);
88 bool doInvA = SkToBool(invA);
89 bool doInvB = SkToBool(invB);
90 canvas->save();
91 // set clip
94 secondClip->setFillType(doInvB ? SkPathFillType::kInverseEvenOdd :
96 canvas->clipPath(*firstClip, doAAA);
97 canvas->clipPath(*secondClip, gOps[op].fOp, doAAB);
98
99 // draw rect clipped
100 SkRect r = { 0, 0, 100, 100 };
101 canvas->drawRect(r, pathPaint);
102 canvas->restore();
103
104
105 SkScalar txtX = SkIntToScalar(10);
106 paint.setColor(SK_ColorBLACK);
107 SkString str;
108 str.printf("%s%s %s %s%s", doAAA ? "A" : "B",
109 doInvA ? "I" : "N",
110 gOps[op].fName,
111 doAAB ? "A" : "B",
112 doInvB ? "I" : "N");
113
114 canvas->drawString(str.c_str(), txtX, SkIntToScalar(130), font, paint);
115 if (doInvB) {
116 canvas->translate(SkIntToScalar(150),0);
117 } else {
118 canvas->translate(SkIntToScalar(120),0);
119 }
120 }
121 }
122 canvas->restore();
123 canvas->translate(0, SkIntToScalar(150));
124 }
125 }
126 }
127
128private:
129 bool fDoSimpleClipFirst;
130
131 using INHERITED = GM;
132};
133
134//////////////////////////////////////////////////////////////////////////////
135
136// Simple clip first
137DEF_GM( return new ComplexClip3GM(true); )
138// Complex clip first
139DEF_GM( return new ComplexClip3GM(false); )
140} // namespace skiagm
SkClipOp
Definition SkClipOp.h:13
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
#define SK_Scalar1
Definition SkScalar.h:18
#define SkIntToScalar(x)
Definition SkScalar.h:57
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
void drawRect(const SkRect &rect, const SkPaint &paint)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
int save()
Definition SkCanvas.cpp:451
void scale(SkScalar sx, SkScalar sy)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
SkPathBuilder & close()
SkPathBuilder & arcTo(const SkRect &oval, SkScalar startAngleDeg, SkScalar sweepAngleDeg, bool forceMoveTo)
SkPathBuilder & moveTo(SkPoint pt)
void setFillType(SkPathFillType ft)
Definition SkPath.h:235
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:3530
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * c_str() const
Definition SkString.h:133
ComplexClip3GM(bool doSimpleClipFirst)
SkString getName() const override
void onDraw(SkCanvas *canvas) override
SkISize getISize() override
void setBGColor(SkColor)
Definition gm.cpp:159
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
sk_sp< SkTypeface > DefaultPortableTypeface()
constexpr SkColor gPathColor
const char * fName
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20