Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
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 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 140 of file hairlines.cpp.

140 {
141 constexpr SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
142 constexpr SkScalar kWidths[] = { 0, 0.5f, 1.5f };
143
144 enum {
145 kMargin = 5,
146 };
147 int wrapX = 1250 - kMargin;
148
149 SkScalar maxH = 0;
151 canvas->save();
152
154 for (int p = 0; p < fPaths.size(); ++p) {
155 for (size_t a = 0; a < std::size(kAlphaValue); ++a) {
156 for (int aa = 0; aa < 2; ++aa) {
157 for (size_t w = 0; w < std::size(kWidths); w++) {
158 const SkRect& bounds = fPaths[p].getBounds();
159
160 if (x + bounds.width() > wrapX) {
161 canvas->restore();
162 canvas->translate(0, maxH + SkIntToScalar(kMargin));
163 canvas->save();
164 maxH = 0;
166 }
167
169 paint.setARGB(kAlphaValue[a], 0, 0, 0);
170 paint.setAntiAlias(SkToBool(aa));
172 paint.setStrokeWidth(kWidths[w]);
173
174 canvas->save();
175 canvas->translate(-bounds.fLeft, -bounds.fTop);
176 canvas->drawPath(fPaths[p], paint);
177 canvas->restore();
178
179 maxH = std::max(maxH, bounds.height());
180
182 x += dx;
183 canvas->translate(dx, 0);
184 }
185 }
186 }
187 }
188 canvas->restore();
189 }
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
@ kMargin
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
int size() const
Definition SkTArray.h:416
const Paint & paint
float SkScalar
Definition extension.cpp:12
struct MyStruct a[10]
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
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 enum {
35 kNumAngles = 15,
36 kRadius = 40,
37 };
38 for (int i = 0; i < kNumAngles; ++i) {
39 SkScalar angle = SK_ScalarPI * SkIntToScalar(i) / kNumAngles;
40 SkScalar x = kRadius * SkScalarCos(angle);
41 SkScalar y = kRadius * SkScalarSin(angle);
42 lineAngles.moveTo(x, y).lineTo(-x, -y);
43 }
44 fPaths.push_back(lineAngles.detach());
45 }
46
47 fPaths.push_back(SkPathBuilder().moveTo(0, -10)
48 .quadTo(100, 100, -10, 0)
49 .detach());
50
51 fPaths.push_back(SkPathBuilder().moveTo(0, -5)
52 .quadTo(100, 100, -5, 0)
53 .detach());
54
55 fPaths.push_back(SkPathBuilder().moveTo(0, -2)
56 .quadTo(100, 100, -2, 0)
57 .detach());
58
59 fPaths.push_back(SkPathBuilder().moveTo(0, -1)
60 .quadTo(100, 100, -2 + 306.0f / 4, 75)
61 .detach());
62
63 fPaths.push_back(SkPathBuilder().moveTo(0, -1)
64 .quadTo(100, 100, -1, 0)
65 .detach());
66
67 fPaths.push_back(SkPathBuilder().moveTo(0, -0)
68 .quadTo(100, 100, 0, 0)
69 .detach());
70
71 fPaths.push_back(SkPathBuilder().moveTo(0, -0)
72 .quadTo(100, 100, 75, 75)
73 .detach());
74
75 // Two problem cases for gpu hairline renderer found by shapeops testing. These used
76 // to assert that the computed bounding box didn't contain all the vertices.
77
78 fPaths.push_back(SkPathBuilder().moveTo(4, 6)
79 .cubicTo(5, 6, 5, 4, 4, 0)
80 .close()
81 .detach());
82
83 fPaths.push_back(SkPathBuilder().moveTo(5, 1)
84 .lineTo( 4.32787323f, 1.67212653f)
85 .cubicTo(2.75223875f, 3.24776125f,
86 3.00581908f, 4.51236057f,
87 3.7580452f, 4.37367964f)
88 .cubicTo(4.66472578f, 3.888381f,
89 5.f, 2.875f,
90 5.f, 1.f)
91 .close()
92 .detach());
93
94 // Three paths that show the same bug (missing end caps)
95
96 fPaths.push_back(SkPathBuilder().moveTo(6.5f,5.5f)
97 .lineTo(3.5f,0.5f)
98 .moveTo(0.5f,5.5f)
99 .lineTo(3.5f,0.5f)
100 .detach());
101
102 // An X (crbug.com/137317)
103 fPaths.push_back(SkPathBuilder().moveTo(1, 1)
104 .lineTo(6, 6)
105 .moveTo(1, 6)
106 .lineTo(6, 1)
107 .detach());
108
109 // A right angle (crbug.com/137465 and crbug.com/256776)
110 fPaths.push_back(SkPathBuilder().moveTo(5.5f, 5.5f)
111 .lineTo(5.5f, 0.5f)
112 .lineTo(0.5f, 0.5f)
113 .detach());
114
115 {
116 // Arc example to test imperfect truncation bug (crbug.com/295626)
117 constexpr SkScalar kRad = SkIntToScalar(2000);
118 constexpr SkScalar kStartAngle = 262.59717f;
119 constexpr SkScalar kSweepAngle = SkScalarHalf(17.188717f);
120
121 SkPathBuilder bug;
122
123 // Add a circular arc
124 SkRect circle = SkRect::MakeLTRB(-kRad, -kRad, kRad, kRad);
125 bug.addArc(circle, kStartAngle, kSweepAngle);
126
127 // Now add the chord that should cap the circular arc
128 SkPoint p0 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle)),
129 kRad * SkScalarSin(SkDegreesToRadians(kStartAngle)) };
130
131 SkPoint p1 = { kRad * SkScalarCos(SkDegreesToRadians(kStartAngle + kSweepAngle)),
132 kRad * SkScalarSin(SkDegreesToRadians(kStartAngle + kSweepAngle)) };
133
134 bug.moveTo(p0);
135 bug.lineTo(p1);
136 fPaths.push_back(bug.detach());
137 }
138 }
#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: