Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
skiagm::ComplexClipGM Class Reference
Inheritance diagram for skiagm::ComplexClipGM:
skiagm::GM

Public Member Functions

 ComplexClipGM (bool aaclip, bool saveLayer, bool invertDraw)
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 38 of file complexclip.cpp.

Constructor & Destructor Documentation

◆ ComplexClipGM()

skiagm::ComplexClipGM::ComplexClipGM ( bool  aaclip,
bool  saveLayer,
bool  invertDraw 
)
inline

Definition at line 40 of file complexclip.cpp.

41 : fDoAAClip(aaclip)
42 , fDoSaveLayer(saveLayer)
43 , fInvertDraw(invertDraw) {
44 this->setBGColor(0xFFDEDFDE);
45 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ getISize()

SkISize skiagm::ComplexClipGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 57 of file complexclip.cpp.

57{ return SkISize::Make(388, 780); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::ComplexClipGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 48 of file complexclip.cpp.

48 {
49 SkString str;
50 str.printf("complexclip_%s%s%s",
51 fDoAAClip ? "aa" : "bw",
52 fDoSaveLayer ? "_layer" : "",
53 fInvertDraw ? "_invert" : "");
54 return str;
55 }
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534

◆ onDraw()

void skiagm::ComplexClipGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 59 of file complexclip.cpp.

59 {
61 .moveTo(0, 50)
62 .quadTo(0, 0, 50, 0)
63 .lineTo(175, 0)
64 .quadTo(200, 0, 200, 25)
65 .lineTo(200, 150)
66 .quadTo(200, 200, 150, 200)
67 .lineTo(0, 200)
68 .close()
69 .moveTo(50, 50)
70 .lineTo(150, 50)
71 .lineTo(150, 125)
72 .quadTo(150, 150, 125, 150)
73 .lineTo(50, 150)
74 .close()
75 .detach();
76 if (fInvertDraw) {
78 } else {
79 path.setFillType(SkPathFillType::kEvenOdd);
80 }
81 SkPaint pathPaint;
82 pathPaint.setAntiAlias(true);
83 pathPaint.setColor(gPathColor);
84
85 SkPath clipA = SkPath::Polygon({{10, 20}, {165, 22}, {70, 105}, {165, 177}, {-5, 180}}, true);
86
87 SkPath clipB = SkPath::Polygon({{40, 10}, {190, 15}, {195, 190}, {40, 185}, {155, 100}}, true);
88
90
91 constexpr struct {
92 SkClipOp fOp;
93 const char* fName;
94 } gOps[] = { //extra spaces in names for measureText
95 {SkClipOp::kIntersect, "Isect "},
96 {SkClipOp::kDifference, "Diff " },
97 };
98
99 canvas->translate(20, 20);
100 canvas->scale(3 * SK_Scalar1 / 4, 3 * SK_Scalar1 / 4);
101
102 if (fDoSaveLayer) {
103 // We want the layer to appear symmetric relative to actual
104 // device boundaries so we need to "undo" the effect of the
105 // scale and translate
107 4.0f/3.0f * -20,
108 4.0f/3.0f * -20,
109 4.0f/3.0f * (this->getISize().fWidth - 20),
110 4.0f/3.0f * (this->getISize().fHeight - 20));
111
112 bounds.inset(100, 100);
113 SkPaint boundPaint;
114 boundPaint.setColor(SK_ColorRED);
116 canvas->drawRect(bounds, boundPaint);
117 canvas->clipRect(bounds);
118 canvas->saveLayer(&bounds, nullptr);
119 }
120
121 for (int invBits = 0; invBits < 4; ++invBits) {
122 canvas->save();
123 for (size_t op = 0; op < std::size(gOps); ++op) {
124 this->drawHairlines(canvas, path, clipA, clipB);
125
126 bool doInvA = SkToBool(invBits & 1);
127 bool doInvB = SkToBool(invBits & 2);
128 canvas->save();
129 // set clip
132 clipB.setFillType(doInvB ? SkPathFillType::kInverseEvenOdd :
134 canvas->clipPath(clipA, fDoAAClip);
135 canvas->clipPath(clipB, gOps[op].fOp, fDoAAClip);
136
137 // In the inverse case we need to prevent the draw from covering the whole
138 // canvas.
139 if (fInvertDraw) {
140 SkRect rectClip = clipA.getBounds();
141 rectClip.join(path.getBounds());
142 rectClip.join(path.getBounds());
143 rectClip.outset(5, 5);
144 canvas->clipRect(rectClip);
145 }
146
147 // draw path clipped
148 canvas->drawPath(path, pathPaint);
149 canvas->restore();
150
151
153 SkScalar txtX = 45;
154 paint.setColor(gClipAColor);
155 const char* aTxt = doInvA ? "InvA " : "A ";
156 canvas->drawSimpleText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8, txtX, 220, font, paint);
157 txtX += font.measureText(aTxt, strlen(aTxt), SkTextEncoding::kUTF8);
158 paint.setColor(SK_ColorBLACK);
159 canvas->drawSimpleText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8, txtX, 220,
160 font, paint);
161 txtX += font.measureText(gOps[op].fName, strlen(gOps[op].fName), SkTextEncoding::kUTF8);
162 paint.setColor(gClipBColor);
163 const char* bTxt = doInvB ? "InvB " : "B ";
164 canvas->drawSimpleText(bTxt, strlen(bTxt), SkTextEncoding::kUTF8, txtX, 220, font, paint);
165
166 canvas->translate(250,0);
167 }
168 canvas->restore();
169 canvas->translate(0, 250);
170 }
171
172 if (fDoSaveLayer) {
173 canvas->restore();
174 }
175 }
SkClipOp
Definition: SkClipOp.h:13
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SK_Scalar1
Definition: SkScalar.h:18
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
Definition: SkFont.h:35
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkPathBuilder & close()
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & moveTo(SkPoint pt)
SkPathBuilder & quadTo(SkPoint pt1, SkPoint pt2)
Definition: SkPath.h:59
void setFillType(SkPathFillType ft)
Definition: SkPath.h:235
const SkRect & getBounds() const
Definition: SkPath.cpp:430
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.cpp:3614
SkISize getISize() override
Definition: complexclip.cpp:57
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkTypeface > DefaultPortableTypeface()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
constexpr SkColor gPathColor
Definition: complexclip.cpp:34
const char * fName
constexpr SkColor gClipBColor
Definition: complexclip.cpp:36
constexpr SkColor gClipAColor
Definition: complexclip.cpp:35
void outset(float dx, float dy)
Definition: SkRect.h:1077
void join(const SkRect &r)
Definition: SkRect.cpp:126
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

The documentation for this class was generated from the following file: