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

Public Member Functions

 ConvexPolyClip ()
 
- 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 onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
bool runAsBench () const 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

This GM tests convex polygon clips.

Definition at line 94 of file convexpolyclip.cpp.

Constructor & Destructor Documentation

◆ ConvexPolyClip()

skiagm::ConvexPolyClip::ConvexPolyClip ( )
inline

Definition at line 96 of file convexpolyclip.cpp.

96 {
97 this->setBGColor(0xFFFFFFFF);
98 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ getISize()

SkISize skiagm::ConvexPolyClip::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 103 of file convexpolyclip.cpp.

103 {
104 // When benchmarking the saveLayer set of draws is skipped.
105 int w = 435;
106 if (kBench_Mode != this->getMode()) {
107 w *= 2;
108 }
109 return SkISize::Make(w, 540);
110 }
@ kBench_Mode
Definition: gm.h:121
Mode getMode() const
Definition: gm.h:125
SkScalar w
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 101 of file convexpolyclip.cpp.

101{ return SkString("convex_poly_clip"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 155 of file convexpolyclip.cpp.

155 {
156 SkScalar y = 0;
157 constexpr SkScalar kMargin = 10.f;
158
159 SkPaint bgPaint;
160 bgPaint.setAlpha(0x15);
161 SkISize size = canvas->getBaseLayerSize();
162 canvas->drawImageRect(fImg, SkRect::MakeIWH(size.fWidth, size.fHeight),
163 SkSamplingOptions(), &bgPaint);
164
165 constexpr char kTxt[] = "Clip Me!";
167 SkScalar textW = font.measureText(kTxt, std::size(kTxt)-1, SkTextEncoding::kUTF8);
168 SkPaint txtPaint;
169 txtPaint.setColor(SK_ColorDKGRAY);
170
171 SkScalar startX = 0;
172 int testLayers = kBench_Mode != this->getMode();
173 for (int doLayer = 0; doLayer <= testLayers; ++doLayer) {
174 for (const Clip& clip : fClips) {
175 SkScalar x = startX;
176 for (int aa = 0; aa < 2; ++aa) {
177 if (doLayer) {
180 bounds.outset(2, 2);
181 bounds.offset(x, y);
182 canvas->saveLayer(&bounds, nullptr);
183 } else {
184 canvas->save();
185 }
186 canvas->translate(x, y);
187 clip.setOnCanvas(canvas, SkClipOp::kIntersect, SkToBool(aa));
188 canvas->drawImage(fImg, 0, 0);
189 canvas->restore();
190 x += fImg->width() + kMargin;
191 }
192 for (int aa = 0; aa < 2; ++aa) {
193
194 SkPaint clipOutlinePaint;
195 clipOutlinePaint.setAntiAlias(true);
196 clipOutlinePaint.setColor(0x50505050);
197 clipOutlinePaint.setStyle(SkPaint::kStroke_Style);
198 clipOutlinePaint.setStrokeWidth(0);
199
200 if (doLayer) {
203 bounds.outset(2, 2);
204 bounds.offset(x, y);
205 canvas->saveLayer(&bounds, nullptr);
206 } else {
207 canvas->save();
208 }
209 canvas->translate(x, y);
210 SkPath closedClipPath = clip.asClosedPath();
211 canvas->drawPath(closedClipPath, clipOutlinePaint);
212 clip.setOnCanvas(canvas, SkClipOp::kIntersect, SkToBool(aa));
213 canvas->scale(1.f, 1.8f);
214 canvas->drawSimpleText(kTxt, std::size(kTxt)-1, SkTextEncoding::kUTF8,
215 0, 1.5f * font.getSize(), font, txtPaint);
216 canvas->restore();
217 x += textW + 2 * kMargin;
218 }
219 y += fImg->height() + kMargin;
220 }
221 y = 0;
222 startX += 2 * fImg->width() + SkScalarCeilToInt(2 * textW) + 6 * kMargin;
223 }
224 }
constexpr SkColor SK_ColorDKGRAY
Definition: SkColor.h:108
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:36
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
constexpr int kMargin
Definition: aaxfermodes.cpp:31
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
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
virtual SkISize getBaseLayerSize() const
Definition: SkCanvas.cpp:369
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
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
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
Definition: SkFont.h:35
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
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
void setAlpha(U8CPU a)
Definition: SkPaint.h:279
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
const SkRect & getBounds() const
Definition: SkPath.cpp:430
float SkScalar
Definition: extension.cpp:12
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkTypeface > DefaultPortableTypeface()
Clip
Definition: layer.h:53
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.
Definition: SkSize.h:16
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623

◆ onOnceBeforeDraw()

void skiagm::ConvexPolyClip::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 112 of file convexpolyclip.cpp.

112 {
113 // On < c++17, emplace_back() returns a void :(
114 auto emplace_back = [](std::vector<Clip>& clips) -> Clip& {
115 clips.emplace_back();
116 return clips.back();
117 };
118
119 emplace_back(fClips).setPath(SkPath::Polygon({
120 { 5.f, 5.f},
121 {100.f, 20.f},
122 { 15.f, 100.f},
123 }, false));
124
125 SkPathBuilder hexagon;
126 constexpr SkScalar kRadius = 45.f;
127 const SkPoint center = { kRadius, kRadius };
128 for (int i = 0; i < 6; ++i) {
129 SkScalar angle = 2 * SK_ScalarPI * i / 6;
130 SkPoint point = { SkScalarCos(angle), SkScalarSin(angle) };
131 point.scale(kRadius);
132 point = center + point;
133 if (0 == i) {
134 hexagon.moveTo(point);
135 } else {
136 hexagon.lineTo(point);
137 }
138 }
139 emplace_back(fClips).setPath(hexagon.snapshot());
140
141 SkMatrix scaleM;
142 scaleM.setScale(1.1f, 0.4f, kRadius, kRadius);
143 emplace_back(fClips).setPath(hexagon.detach().makeTransform(scaleM));
144
145 emplace_back(fClips).setRect(SkRect::MakeXYWH(8.3f, 11.6f, 78.2f, 72.6f));
146
147 SkRect rect = SkRect::MakeLTRB(10.f, 12.f, 80.f, 86.f);
148 SkMatrix rotM;
149 rotM.setRotate(23.f, rect.centerX(), rect.centerY());
150 emplace_back(fClips).setPath(SkPath::Rect(rect).makeTransform(rotM));
151
152 fImg = make_img(100, 100);
153 }
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & moveTo(SkPoint pt)
SkPath snapshot() const
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition: SkPath.cpp:3586
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.cpp:3614
SkPath makeTransform(const SkMatrix &m, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.h:1400
static sk_sp< SkImage > make_img(int w, int h)
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
constexpr int kRadius
void scale(float scale, SkPoint *dst) const
Definition: SkPoint.cpp:17
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ runAsBench()

bool skiagm::ConvexPolyClip::runAsBench ( ) const
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 226 of file convexpolyclip.cpp.

226{ return true; }

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