Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Protected Member Functions | List of all members
skiagm::HairlinesGM Class Reference
Inheritance diagram for skiagm::HairlinesGM:
skiagm::GM

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
 

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
 
- 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
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 25 of file hairlines.cpp.

Member Function Documentation

◆ getISize()

SkISize skiagm::HairlinesGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 29 of file hairlines.cpp.

29{ return SkISize::Make(1250, 1250); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 27 of file hairlines.cpp.

27{ return SkString("hairlines"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 139 of file hairlines.cpp.

139 {
140 constexpr SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
141 constexpr SkScalar kWidths[] = { 0, 0.5f, 1.5f };
142
143 enum {
144 kMargin = 5,
145 };
146 int wrapX = 1250 - kMargin;
147
148 SkScalar maxH = 0;
150 canvas->save();
151
153 for (int p = 0; p < fPaths.size(); ++p) {
154 for (size_t a = 0; a < std::size(kAlphaValue); ++a) {
155 for (int aa = 0; aa < 2; ++aa) {
156 for (size_t w = 0; w < std::size(kWidths); w++) {
157 const SkRect& bounds = fPaths[p].getBounds();
158
159 if (x + bounds.width() > wrapX) {
160 canvas->restore();
161 canvas->translate(0, maxH + SkIntToScalar(kMargin));
162 canvas->save();
163 maxH = 0;
165 }
166
168 paint.setARGB(kAlphaValue[a], 0, 0, 0);
169 paint.setAntiAlias(SkToBool(aa));
171 paint.setStrokeWidth(kWidths[w]);
172
173 canvas->save();
174 canvas->translate(-bounds.fLeft, -bounds.fTop);
175 canvas->drawPath(fPaths[p], paint);
176 canvas->restore();
177
178 maxH = std::max(maxH, bounds.height());
179
181 x += dx;
182 canvas->translate(dx, 0);
183 }
184 }
185 }
186 }
187 canvas->restore();
188 }
uint8_t SkAlpha
Definition: SkColor.h:26
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
constexpr int kMargin
Definition: aaxfermodes.cpp:31
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
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
int size() const
Definition: SkTArray.h:421
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
struct MyStruct a[10]
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
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 const SkScalar kWidths[]
SkScalar w

◆ onOnceBeforeDraw()

void skiagm::HairlinesGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 31 of file hairlines.cpp.

31 {
32 {
33 SkPathBuilder lineAngles;
34 constexpr int kNumAngles = 15;
35 constexpr int kRadius = 40;
36
37 for (int i = 0; i < kNumAngles; ++i) {
38 SkScalar angle = SK_ScalarPI * SkIntToScalar(i) / kNumAngles;
39 SkScalar x = kRadius * SkScalarCos(angle);
40 SkScalar y = kRadius * SkScalarSin(angle);
41 lineAngles.moveTo(x, y).lineTo(-x, -y);
42 }
43 fPaths.push_back(lineAngles.detach());
44 }
45
46 fPaths.push_back(SkPathBuilder().moveTo(0, -10)
47 .quadTo(100, 100, -10, 0)
48 .detach());
49
50 fPaths.push_back(SkPathBuilder().moveTo(0, -5)
51 .quadTo(100, 100, -5, 0)
52 .detach());
53
54 fPaths.push_back(SkPathBuilder().moveTo(0, -2)
55 .quadTo(100, 100, -2, 0)
56 .detach());
57
58 fPaths.push_back(SkPathBuilder().moveTo(0, -1)
59 .quadTo(100, 100, -2 + 306.0f / 4, 75)
60 .detach());
61
62 fPaths.push_back(SkPathBuilder().moveTo(0, -1)
63 .quadTo(100, 100, -1, 0)
64 .detach());
65
66 fPaths.push_back(SkPathBuilder().moveTo(0, -0)
67 .quadTo(100, 100, 0, 0)
68 .detach());
69
70 fPaths.push_back(SkPathBuilder().moveTo(0, -0)
71 .quadTo(100, 100, 75, 75)
72 .detach());
73
74 // Two problem cases for gpu hairline renderer found by shapeops testing. These used
75 // to assert that the computed bounding box didn't contain all the vertices.
76
77 fPaths.push_back(SkPathBuilder().moveTo(4, 6)
78 .cubicTo(5, 6, 5, 4, 4, 0)
79 .close()
80 .detach());
81
82 fPaths.push_back(SkPathBuilder().moveTo(5, 1)
83 .lineTo( 4.32787323f, 1.67212653f)
84 .cubicTo(2.75223875f, 3.24776125f,
85 3.00581908f, 4.51236057f,
86 3.7580452f, 4.37367964f)
87 .cubicTo(4.66472578f, 3.888381f,
88 5.f, 2.875f,
89 5.f, 1.f)
90 .close()
91 .detach());
92
93 // Three paths that show the same bug (missing end caps)
94
95 fPaths.push_back(SkPathBuilder().moveTo(6.5f,5.5f)
96 .lineTo(3.5f,0.5f)
97 .moveTo(0.5f,5.5f)
98 .lineTo(3.5f,0.5f)
99 .detach());
100
101 // An X (crbug.com/137317)
102 fPaths.push_back(SkPathBuilder().moveTo(1, 1)
103 .lineTo(6, 6)
104 .moveTo(1, 6)
105 .lineTo(6, 1)
106 .detach());
107
108 // A right angle (crbug.com/137465 and crbug.com/256776)
109 fPaths.push_back(SkPathBuilder().moveTo(5.5f, 5.5f)
110 .lineTo(5.5f, 0.5f)
111 .lineTo(0.5f, 0.5f)
112 .detach());
113
114 {
115 // Arc example to test imperfect truncation bug (crbug.com/295626)
116 constexpr SkScalar kRad = SkIntToScalar(2000);
117 constexpr SkScalar kStartAngle = 262.59717f;
118 constexpr SkScalar kSweepAngle = SkScalarHalf(17.188717f);
119
120 SkPathBuilder bug;
121
122 // Add a circular arc
123 SkRect circle = SkRect::MakeLTRB(-kRad, -kRad, kRad, kRad);
124 bug.addArc(circle, kStartAngle, kSweepAngle);
125
126 // Now add the chord that should cap the circular arc
127 SkPoint p0 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle)),
128 kRad * SkScalarSin(SkDegreesToRadians(kStartAngle)) };
129
130 SkPoint p1 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle + kSweepAngle)),
131 kRad * SkScalarSin(SkDegreesToRadians(kStartAngle + kSweepAngle)) };
132
133 bug.moveTo(p0);
134 bug.lineTo(p1);
135 fPaths.push_back(bug.detach());
136 }
137 }
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarHalf(a)
Definition: SkScalar.h:75
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
SkPathBuilder & lineTo(SkPoint pt)
SkPathBuilder & addArc(const SkRect &oval, SkScalar startAngleDeg, SkScalar sweepAngleDeg)
SkPathBuilder & moveTo(SkPoint pt)
double y
constexpr int kRadius
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: