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

Public Member Functions

 PolygonsGM ()
 
- 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
 
- 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
 

Static Protected Member Functions

static void SetLocation (SkCanvas *canvas, int counter, int lineNum)
 
static void SetColorAndAlpha (SkPaint *paint, SkRandom *rand)
 

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 28 of file polygons.cpp.

Constructor & Destructor Documentation

◆ PolygonsGM()

skiagm::PolygonsGM::PolygonsGM ( )
inline

Definition at line 30 of file polygons.cpp.

30{}

Member Function Documentation

◆ getISize()

SkISize skiagm::PolygonsGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 35 of file polygons.cpp.

35 {
36 int width = kNumPolygons * kCellSize + 40;
37 int height = (kNumJoins * kNumStrokeWidths + kNumExtraStyles) * kCellSize + 40;
38 return SkISize::Make(width, height);
39 }
SkScalar width()
Definition: gm.h:159
SkScalar height()
Definition: gm.h:162
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 33 of file polygons.cpp.

33{ return SkString("polygons"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 104 of file polygons.cpp.

104 {
105 // Stroke widths are:
106 // 0(may use hairline rendering), 10(common case for stroke-style)
107 // 40(>= geometry width/height, make the contour filled in fact)
108 constexpr int kStrokeWidths[] = {0, 10, 40};
109 SkASSERT(kNumStrokeWidths == std::size(kStrokeWidths));
110
111 constexpr SkPaint::Join kJoins[] = {
113 };
114 SkASSERT(kNumJoins == std::size(kJoins));
115
116 int counter = 0;
118 paint.setAntiAlias(true);
119
120 SkRandom rand;
121 // For stroke style painter
123 for (int join = 0; join < kNumJoins; ++join) {
124 for (int width = 0; width < kNumStrokeWidths; ++width) {
125 for (int i = 0; i < fPolygons.size(); ++i) {
126 canvas->save();
127 SetLocation(canvas, counter, fPolygons.size());
128
129 SetColorAndAlpha(&paint, &rand);
130 paint.setStrokeJoin(kJoins[join]);
131 paint.setStrokeWidth(SkIntToScalar(kStrokeWidths[width]));
132
133 canvas->drawPath(fPolygons[i], paint);
134 canvas->restore();
135 ++counter;
136 }
137 }
138 }
139
140 // For stroke-and-fill style painter and fill style painter
141 constexpr SkPaint::Style kStyles[] = {
143 };
144 SkASSERT(kNumExtraStyles == std::size(kStyles));
145
146 paint.setStrokeJoin(SkPaint::kMiter_Join);
147 paint.setStrokeWidth(SkIntToScalar(20));
148 for (int style = 0; style < kNumExtraStyles; ++style) {
149 paint.setStyle(kStyles[style]);
150 for (int i = 0; i < fPolygons.size(); ++i) {
151 canvas->save();
152 SetLocation(canvas, counter, fPolygons.size());
153 SetColorAndAlpha(&paint, &rand);
154 canvas->drawPath(fPolygons[i], paint);
155 canvas->restore();
156 ++counter;
157 }
158 }
159 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition: SkPaint.h:195
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
int size() const
Definition: SkTArray.h:421
static void SetColorAndAlpha(SkPaint *paint, SkRandom *rand)
Definition: polygons.cpp:95
static void SetLocation(SkCanvas *canvas, int counter, int lineNum)
Definition: polygons.cpp:89
const Paint & paint
Definition: color_source.cc:38
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
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ onOnceBeforeDraw()

void skiagm::PolygonsGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 42 of file polygons.cpp.

42 {
43 SkPoint p0[] = {{0, 0}, {60, 0}, {90, 40}}; // triangle
44 SkPoint p1[] = {{0, 0}, {0, 40}, {60, 40}, {40, 0}}; // trapezoid
45 SkPoint p2[] = {{0, 0}, {40, 40}, {80, 40}, {40, 0}}; // diamond
46 SkPoint p3[] = {{10, 0}, {50, 0}, {60, 10}, {60, 30}, {50, 40},
47 {10, 40}, {0, 30}, {0, 10}}; // octagon
48 SkPoint p4[32]; // circle-like polygons with 32-edges.
49 SkPoint p5[] = {{0, 0}, {20, 20}, {0, 40}, {60, 20}}; // concave polygon with 4 edges
50 SkPoint p6[] = {{0, 40}, {0, 30}, {15, 30}, {15, 20}, {30, 20},
51 {30, 10}, {45, 10}, {45, 0}, {60, 0}, {60, 40}}; // stairs-like polygon
52 SkPoint p7[] = {{0, 20}, {20, 20}, {30, 0}, {40, 20}, {60, 20},
53 {45, 30}, {55, 50}, {30, 40}, {5, 50}, {15, 30}}; // five-point stars
54
55 for (size_t i = 0; i < std::size(p4); ++i) {
56 SkScalar angle = 2 * SK_ScalarPI * i / std::size(p4);
57 p4[i].set(20 * SkScalarCos(angle) + 20, 20 * SkScalarSin(angle) + 20);
58 }
59
60 struct Polygons {
61 SkPoint* fPoints;
62 size_t fPointNum;
63 } pgs[] = {
64 { p0, std::size(p0) },
65 { p1, std::size(p1) },
66 { p2, std::size(p2) },
67 { p3, std::size(p3) },
68 { p4, std::size(p4) },
69 { p5, std::size(p5) },
70 { p6, std::size(p6) },
71 { p7, std::size(p7) }
72 };
73
74 SkASSERT(std::size(pgs) == kNumPolygons);
75 for (size_t pgIndex = 0; pgIndex < std::size(pgs); ++pgIndex) {
77 b.moveTo(pgs[pgIndex].fPoints[0].fX,
78 pgs[pgIndex].fPoints[0].fY);
79 for (size_t ptIndex = 1; ptIndex < pgs[pgIndex].fPointNum; ++ptIndex) {
80 b.lineTo(pgs[pgIndex].fPoints[ptIndex].fX,
81 pgs[pgIndex].fPoints[ptIndex].fY);
82 }
83 b.close();
84 fPolygons.push_back(b.detach());
85 }
86 }
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
float SkScalar
Definition: extension.cpp:12
static bool b
void set(float x, float y)
Definition: SkPoint_impl.h:200

◆ SetColorAndAlpha()

static void skiagm::PolygonsGM::SetColorAndAlpha ( SkPaint paint,
SkRandom rand 
)
inlinestaticprotected

Definition at line 95 of file polygons.cpp.

95 {
96 SkColor color = rand->nextU();
97 color |= 0xff000000;
98 paint->setColor(color);
99 if (40 == paint->getStrokeWidth()) {
100 paint->setAlpha(0xA0);
101 }
102 }
uint32_t SkColor
Definition: SkColor.h:37
uint32_t nextU()
Definition: SkRandom.h:42
DlColor color

◆ SetLocation()

static void skiagm::PolygonsGM::SetLocation ( SkCanvas canvas,
int  counter,
int  lineNum 
)
inlinestaticprotected

Definition at line 89 of file polygons.cpp.

89 {
90 SkScalar x = SK_Scalar1 * kCellSize * (counter % lineNum) + 30 + SK_Scalar1 / 4;
91 SkScalar y = SK_Scalar1 * kCellSize * (counter / lineNum) + 30 + 3 * SK_Scalar1 / 4;
92 canvas->translate(x, y);
93 }
#define SK_Scalar1
Definition: SkScalar.h:18
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
double y
double x

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