blob: 7bd31c23f4a864fa88073f8fb8017f9a68bcd09b [file] [log] [blame]
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +00006 */
7
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +00008#include "gm.h"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
bungemand3ebb482015-08-05 13:57:49 -070010#include "SkPath.h"
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000011#include "SkRandom.h"
caryclark5cb00a92015-08-26 09:04:55 -070012#include "SkDashPathEffect.h"
13#include "SkParsePath.h"
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000014
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000015#define W 400
16#define H 400
17#define N 50
18
mtkleindbfd7ab2016-09-01 11:24:54 -070019constexpr SkScalar SW = SkIntToScalar(W);
20constexpr SkScalar SH = SkIntToScalar(H);
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000021
scroggof9d61012014-12-15 12:54:51 -080022static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000023 SkScalar x = rand.nextUScalar1() * W;
24 SkScalar y = rand.nextUScalar1() * H;
25 SkScalar w = rand.nextUScalar1() * (W >> 2);
26 SkScalar h = rand.nextUScalar1() * (H >> 2);
epoger@google.com17b78942011-08-26 14:40:38 +000027 SkScalar hoffset = rand.nextSScalar1();
28 SkScalar woffset = rand.nextSScalar1();
rmistry@google.comae933ce2012-08-23 18:19:56 +000029
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000030 r->set(x, y, x + w, y + h);
epoger@google.com17b78942011-08-26 14:40:38 +000031 r->offset(-w/2 + woffset, -h/2 + hoffset);
rmistry@google.comae933ce2012-08-23 18:19:56 +000032
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000033 paint->setColor(rand.nextU());
34 paint->setAlpha(0xFF);
35}
36
rmistry@google.comae933ce2012-08-23 18:19:56 +000037
reed@google.com4384fab2012-06-05 16:14:23 +000038class StrokesGM : public skiagm::GM {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000039public:
40 StrokesGM() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000041
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000042protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000043
mtklein36352bf2015-03-25 18:17:31 -070044 SkString onShortName() override {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000045 return SkString("strokes_round");
46 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000047
mtklein36352bf2015-03-25 18:17:31 -070048 SkISize onISize() override {
reed@google.com4384fab2012-06-05 16:14:23 +000049 return SkISize::Make(W, H*2);
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000050 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
mtklein36352bf2015-03-25 18:17:31 -070052 void onDraw(SkCanvas* canvas) override {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000053 SkPaint paint;
54 paint.setStyle(SkPaint::kStroke_Style);
55 paint.setStrokeWidth(SkIntToScalar(9)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000056
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000057 for (int y = 0; y < 2; y++) {
58 paint.setAntiAlias(!!y);
59 SkAutoCanvasRestore acr(canvas, true);
60 canvas->translate(0, SH * y);
61 canvas->clipRect(SkRect::MakeLTRB(
62 SkIntToScalar(2), SkIntToScalar(2)
63 , SW - SkIntToScalar(2), SH - SkIntToScalar(2)
64 ));
rmistry@google.comae933ce2012-08-23 18:19:56 +000065
scroggof9d61012014-12-15 12:54:51 -080066 SkRandom rand;
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000067 for (int i = 0; i < N; i++) {
68 SkRect r;
69 rnd_rect(&r, &paint, rand);
70 canvas->drawOval(r, paint);
71 rnd_rect(&r, &paint, rand);
72 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint);
73 rnd_rect(&r, &paint, rand);
74 }
75 }
76 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000077
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000078private:
reed@google.com4384fab2012-06-05 16:14:23 +000079 typedef skiagm::GM INHERITED;
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +000080};
81
caryclark5cb00a92015-08-26 09:04:55 -070082/* See
83 https://code.google.com/p/chromium/issues/detail?id=422974 and
84 http://jsfiddle.net/1xnku3sg/2/
85 */
86class ZeroLenStrokesGM : public skiagm::GM {
87 SkPath fMoveHfPath, fMoveZfPath, fDashedfPath, fRefPath[4];
caryclark6651a322015-09-09 13:20:49 -070088 SkPath fCubicPath, fQuadPath, fLinePath;
caryclark5cb00a92015-08-26 09:04:55 -070089protected:
90 void onOnceBeforeDraw() override {
91
92 SkAssertResult(SkParsePath::FromSVGString("M0,0h0M10,0h0M20,0h0", &fMoveHfPath));
93 SkAssertResult(SkParsePath::FromSVGString("M0,0zM10,0zM20,0z", &fMoveZfPath));
94 SkAssertResult(SkParsePath::FromSVGString("M0,0h25", &fDashedfPath));
caryclark6651a322015-09-09 13:20:49 -070095 SkAssertResult(SkParsePath::FromSVGString("M 0 0 C 0 0 0 0 0 0", &fCubicPath));
96 SkAssertResult(SkParsePath::FromSVGString("M 0 0 Q 0 0 0 0", &fQuadPath));
97 SkAssertResult(SkParsePath::FromSVGString("M 0 0 L 0 0", &fLinePath));
caryclark5cb00a92015-08-26 09:04:55 -070098
99 for (int i = 0; i < 3; ++i) {
100 fRefPath[0].addCircle(i * 10.f, 0, 5);
101 fRefPath[1].addCircle(i * 10.f, 0, 10);
102 fRefPath[2].addRect(i * 10.f - 4, -2, i * 10.f + 4, 6);
103 fRefPath[3].addRect(i * 10.f - 10, -10, i * 10.f + 10, 10);
104 }
105 }
106
107 SkString onShortName() override {
108 return SkString("zeroPath");
109 }
110
111 SkISize onISize() override {
112 return SkISize::Make(W, H*2);
113 }
114
115 void onDraw(SkCanvas* canvas) override {
116 SkPaint fillPaint, strokePaint, dashPaint;
117 fillPaint.setAntiAlias(true);
118 strokePaint = fillPaint;
119 strokePaint.setStyle(SkPaint::kStroke_Style);
120 for (int i = 0; i < 2; ++i) {
121 fillPaint.setAlpha(255);
122 strokePaint.setAlpha(255);
123 strokePaint.setStrokeWidth(i ? 8.f : 10.f);
124 strokePaint.setStrokeCap(i ? SkPaint::kSquare_Cap : SkPaint::kRound_Cap);
125 canvas->save();
126 canvas->translate(10 + i * 100.f, 10);
127 canvas->drawPath(fMoveHfPath, strokePaint);
128 canvas->translate(0, 20);
129 canvas->drawPath(fMoveZfPath, strokePaint);
130 dashPaint = strokePaint;
131 const SkScalar intervals[] = { 0, 10 };
reeda4393342016-03-18 11:22:57 -0700132 dashPaint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
caryclark5cb00a92015-08-26 09:04:55 -0700133 SkPath fillPath;
134 dashPaint.getFillPath(fDashedfPath, &fillPath);
135 canvas->translate(0, 20);
136 canvas->drawPath(fDashedfPath, dashPaint);
137 canvas->translate(0, 20);
138 canvas->drawPath(fRefPath[i * 2], fillPaint);
139 strokePaint.setStrokeWidth(20);
140 strokePaint.setAlpha(127);
141 canvas->translate(0, 50);
142 canvas->drawPath(fMoveHfPath, strokePaint);
143 canvas->translate(0, 30);
144 canvas->drawPath(fMoveZfPath, strokePaint);
145 canvas->translate(0, 30);
146 fillPaint.setAlpha(127);
147 canvas->drawPath(fRefPath[1 + i * 2], fillPaint);
caryclark6651a322015-09-09 13:20:49 -0700148 canvas->translate(0, 30);
149 canvas->drawPath(fCubicPath, strokePaint);
150 canvas->translate(0, 30);
151 canvas->drawPath(fQuadPath, strokePaint);
152 canvas->translate(0, 30);
153 canvas->drawPath(fLinePath, strokePaint);
caryclark5cb00a92015-08-26 09:04:55 -0700154 canvas->restore();
155 }
156 }
157
158private:
159 typedef skiagm::GM INHERITED;
160};
161
caryclark950305e2015-10-26 08:17:04 -0700162class TeenyStrokesGM : public skiagm::GM {
163
164 SkString onShortName() override {
165 return SkString("teenyStrokes");
166 }
167
168 SkISize onISize() override {
169 return SkISize::Make(W, H*2);
170 }
171
172 static void line(SkScalar scale, SkCanvas* canvas, SkColor color) {
173 SkPaint p;
174 p.setAntiAlias(true);
175 p.setStyle(SkPaint::kStroke_Style);
176 p.setColor(color);
177 canvas->translate(50, 0);
178 canvas->save();
179 p.setStrokeWidth(scale * 5);
180 canvas->scale(1 / scale, 1 / scale);
181 canvas->drawLine(20 * scale, 20 * scale, 20 * scale, 100 * scale, p);
182 canvas->drawLine(20 * scale, 20 * scale, 100 * scale, 100 * scale, p);
183 canvas->restore();
184 }
185
186 void onDraw(SkCanvas* canvas) override {
187 line(0.00005f, canvas, SK_ColorBLACK);
188 line(0.000045f, canvas, SK_ColorRED);
189 line(0.0000035f, canvas, SK_ColorGREEN);
190 line(0.000003f, canvas, SK_ColorBLUE);
191 line(0.000002f, canvas, SK_ColorBLACK);
192 }
193private:
194 typedef skiagm::GM INHERITED;
195};
196
caryclarkb775e912015-11-30 13:47:11 -0800197DEF_SIMPLE_GM(CubicStroke, canvas, 384, 384) {
198 SkPaint p;
199 p.setAntiAlias(true);
200 p.setStyle(SkPaint::kStroke_Style);
201 p.setStrokeWidth(1.0720f);
202 SkPath path;
203 path.moveTo(-6000,-6000);
204 path.cubicTo(-3500,5500,-500,5500,2500,-6500);
205 canvas->drawPath(path, p);
206 p.setStrokeWidth(1.0721f);
207 canvas->translate(10, 10);
208 canvas->drawPath(path, p);
209 p.setStrokeWidth(1.0722f);
210 canvas->translate(10, 10);
211 canvas->drawPath(path, p);
212}
caryclark950305e2015-10-26 08:17:04 -0700213
caryclark57eecc12015-12-08 04:29:45 -0800214DEF_SIMPLE_GM(zerolinestroke, canvas, 90, 120) {
215 SkPaint paint;
216 paint.setStyle(SkPaint::kStroke_Style);
217 paint.setStrokeWidth(20);
218 paint.setAntiAlias(true);
219 paint.setStrokeCap(SkPaint::kRound_Cap);
220
221 SkPath path;
222 path.moveTo(30, 90);
223 path.lineTo(30, 90);
224 path.lineTo(60, 90);
225 path.lineTo(60, 90);
226 canvas->drawPath(path, paint);
227
228 path.reset();
229 path.moveTo(30, 30);
230 path.lineTo(60, 30);
231 canvas->drawPath(path, paint);
232
233 path.reset();
234 path.moveTo(30, 60);
235 path.lineTo(30, 60);
236 path.lineTo(60, 60);
237 canvas->drawPath(path, paint);
238}
239
caryclark40b7d3b2015-12-22 06:13:33 -0800240DEF_SIMPLE_GM(quadcap, canvas, 200, 200) {
241 SkPaint p;
242 p.setAntiAlias(true);
243 p.setStyle(SkPaint::kStroke_Style);
244 p.setStrokeWidth(0);
245 SkPath path;
246 SkPoint pts[] = {{105.738571f,13.126318f},
halcanary9d524f22016-03-29 09:03:52 -0700247 {105.738571f,13.126318f},
caryclark40b7d3b2015-12-22 06:13:33 -0800248 {123.753784f,1.f}};
249 SkVector tangent = pts[1] - pts[2];
250 tangent.normalize();
251 SkPoint pts2[3];
252 memcpy(pts2, pts, sizeof(pts));
253 const SkScalar capOutset = SK_ScalarPI / 8;
254 pts2[0].fX += tangent.fX * capOutset;
255 pts2[0].fY += tangent.fY * capOutset;
256 pts2[1].fX += tangent.fX * capOutset;
257 pts2[1].fY += tangent.fY * capOutset;
258 pts2[2].fX += -tangent.fX * capOutset;
259 pts2[2].fY += -tangent.fY * capOutset;
260 path.moveTo(pts2[0]);
261 path.quadTo(pts2[1], pts2[2]);
262 canvas->drawPath(path, p);
263
264 path.reset();
265 path.moveTo(pts[0]);
266 path.quadTo(pts[1], pts[2]);
267 p.setStrokeCap(SkPaint::kRound_Cap);
268 canvas->translate(30, 0);
269 canvas->drawPath(path, p);
270}
271
reed@google.com4384fab2012-06-05 16:14:23 +0000272class Strokes2GM : public skiagm::GM {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000273 SkPath fPath;
caryclark63c684a2015-02-25 09:04:04 -0800274protected:
mtklein36352bf2015-03-25 18:17:31 -0700275 void onOnceBeforeDraw() override {
scroggof9d61012014-12-15 12:54:51 -0800276 SkRandom rand;
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000277 fPath.moveTo(0, 0);
278 for (int i = 0; i < 13; i++) {
279 SkScalar x = rand.nextUScalar1() * (W >> 1);
280 SkScalar y = rand.nextUScalar1() * (H >> 1);
281 fPath.lineTo(x, y);
282 }
283 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000284
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +0000285
mtklein36352bf2015-03-25 18:17:31 -0700286 SkString onShortName() override {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000287 return SkString("strokes_poly");
288 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000289
mtklein36352bf2015-03-25 18:17:31 -0700290 SkISize onISize() override {
reed@google.com4384fab2012-06-05 16:14:23 +0000291 return SkISize::Make(W, H*2);
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000292 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000293
mtklein36352bf2015-03-25 18:17:31 -0700294 void onDraw(SkCanvas* canvas) override {
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000295 canvas->drawColor(SK_ColorWHITE);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000296
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000297 SkPaint paint;
298 paint.setStyle(SkPaint::kStroke_Style);
299 paint.setStrokeWidth(SkIntToScalar(9)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000300
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000301 for (int y = 0; y < 2; y++) {
302 paint.setAntiAlias(!!y);
303 SkAutoCanvasRestore acr(canvas, true);
304 canvas->translate(0, SH * y);
305 canvas->clipRect(SkRect::MakeLTRB(SkIntToScalar(2),
306 SkIntToScalar(2),
307 SW - SkIntToScalar(2),
308 SH - SkIntToScalar(2)));
rmistry@google.comae933ce2012-08-23 18:19:56 +0000309
scroggof9d61012014-12-15 12:54:51 -0800310 SkRandom rand;
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000311 for (int i = 0; i < N/2; i++) {
312 SkRect r;
313 rnd_rect(&r, &paint, rand);
bungeman7438bfc2016-07-12 15:01:19 -0700314 canvas->rotate(SkIntToScalar(15), SW/2, SH/2);
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000315 canvas->drawPath(fPath, paint);
316 }
317 }
318 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000319
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000320private:
reed@google.com4384fab2012-06-05 16:14:23 +0000321 typedef skiagm::GM INHERITED;
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000322};
323
324//////////////////////////////////////////////////////////////////////////////
325
reed@google.com4384fab2012-06-05 16:14:23 +0000326static SkRect inset(const SkRect& r) {
327 SkRect rr(r);
328 rr.inset(r.width()/10, r.height()/10);
329 return rr;
mike@reedtribe.orgf2c21cd2011-06-18 00:15:04 +0000330}
331
reed@google.com4384fab2012-06-05 16:14:23 +0000332class Strokes3GM : public skiagm::GM {
333 static void make0(SkPath* path, const SkRect& bounds, SkString* title) {
334 path->addRect(bounds, SkPath::kCW_Direction);
335 path->addRect(inset(bounds), SkPath::kCW_Direction);
336 title->set("CW CW");
337 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000338
reed@google.com4384fab2012-06-05 16:14:23 +0000339 static void make1(SkPath* path, const SkRect& bounds, SkString* title) {
340 path->addRect(bounds, SkPath::kCW_Direction);
341 path->addRect(inset(bounds), SkPath::kCCW_Direction);
342 title->set("CW CCW");
343 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000344
reed@google.com4384fab2012-06-05 16:14:23 +0000345 static void make2(SkPath* path, const SkRect& bounds, SkString* title) {
346 path->addOval(bounds, SkPath::kCW_Direction);
347 path->addOval(inset(bounds), SkPath::kCW_Direction);
348 title->set("CW CW");
349 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000350
reed@google.com4384fab2012-06-05 16:14:23 +0000351 static void make3(SkPath* path, const SkRect& bounds, SkString* title) {
352 path->addOval(bounds, SkPath::kCW_Direction);
353 path->addOval(inset(bounds), SkPath::kCCW_Direction);
354 title->set("CW CCW");
355 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000356
reed@google.com4384fab2012-06-05 16:14:23 +0000357 static void make4(SkPath* path, const SkRect& bounds, SkString* title) {
358 path->addRect(bounds, SkPath::kCW_Direction);
359 SkRect r = bounds;
360 r.inset(bounds.width() / 10, -bounds.height() / 10);
361 path->addOval(r, SkPath::kCW_Direction);
362 title->set("CW CW");
363 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000364
reed@google.com4384fab2012-06-05 16:14:23 +0000365 static void make5(SkPath* path, const SkRect& bounds, SkString* title) {
366 path->addRect(bounds, SkPath::kCW_Direction);
367 SkRect r = bounds;
368 r.inset(bounds.width() / 10, -bounds.height() / 10);
369 path->addOval(r, SkPath::kCCW_Direction);
370 title->set("CW CCW");
371 }
372
373public:
374 Strokes3GM() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +0000375
reed@google.com4384fab2012-06-05 16:14:23 +0000376protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +0000377
mtklein36352bf2015-03-25 18:17:31 -0700378 SkString onShortName() override {
reed@google.com4384fab2012-06-05 16:14:23 +0000379 return SkString("strokes3");
380 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000381
mtklein36352bf2015-03-25 18:17:31 -0700382 SkISize onISize() override {
caryclark37604572015-02-23 06:51:04 -0800383 return SkISize::Make(1500, 1500);
reed@google.com4384fab2012-06-05 16:14:23 +0000384 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000385
mtklein36352bf2015-03-25 18:17:31 -0700386 void onDraw(SkCanvas* canvas) override {
reed@google.com4384fab2012-06-05 16:14:23 +0000387 SkPaint origPaint;
388 origPaint.setAntiAlias(true);
389 origPaint.setStyle(SkPaint::kStroke_Style);
390 SkPaint fillPaint(origPaint);
391 fillPaint.setColor(SK_ColorRED);
392 SkPaint strokePaint(origPaint);
caryclark12596012015-07-29 05:27:47 -0700393 strokePaint.setColor(sk_tool_utils::color_to_565(0xFF4444FF));
reed@google.com4384fab2012-06-05 16:14:23 +0000394
395 void (*procs[])(SkPath*, const SkRect&, SkString*) = {
396 make0, make1, make2, make3, make4, make5
397 };
398
caryclark37604572015-02-23 06:51:04 -0800399 canvas->translate(SkIntToScalar(20), SkIntToScalar(80));
reed@google.com4384fab2012-06-05 16:14:23 +0000400
401 SkRect bounds = SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50));
402 SkScalar dx = bounds.width() * 4/3;
403 SkScalar dy = bounds.height() * 5;
404
405 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
406 SkPath orig;
407 SkString str;
408 procs[i](&orig, bounds, &str);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000409
reed@google.com4384fab2012-06-05 16:14:23 +0000410 canvas->save();
411 for (int j = 0; j < 13; ++j) {
412 strokePaint.setStrokeWidth(SK_Scalar1 * j * j);
413 canvas->drawPath(orig, strokePaint);
414 canvas->drawPath(orig, origPaint);
415 SkPath fill;
416 strokePaint.getFillPath(orig, &fill);
417 canvas->drawPath(fill, fillPaint);
418 canvas->translate(dx + strokePaint.getStrokeWidth(), 0);
419 }
420 canvas->restore();
421 canvas->translate(0, dy);
422 }
423 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000424
reed@google.com4384fab2012-06-05 16:14:23 +0000425private:
426 typedef skiagm::GM INHERITED;
427};
428
caryclark612f70d2015-05-19 11:05:37 -0700429class Strokes4GM : public skiagm::GM {
430public:
431 Strokes4GM() {}
432
433protected:
434
435 SkString onShortName() override {
436 return SkString("strokes_zoomed");
437 }
438
439 SkISize onISize() override {
440 return SkISize::Make(W, H*2);
441 }
442
443 void onDraw(SkCanvas* canvas) override {
444 SkPaint paint;
445 paint.setStyle(SkPaint::kStroke_Style);
446 paint.setStrokeWidth(0.055f);
halcanary9d524f22016-03-29 09:03:52 -0700447
caryclark612f70d2015-05-19 11:05:37 -0700448 canvas->scale(1000, 1000);
449 canvas->drawCircle(0, 2, 1.97f, paint);
450 }
451
452private:
453 typedef skiagm::GM INHERITED;
454};
455
caryclark45398df2015-08-25 13:19:06 -0700456// Test stroking for curves that produce degenerate tangents when t is 0 or 1 (see bug 4191)
457class Strokes5GM : public skiagm::GM {
458public:
459 Strokes5GM() {}
460
461protected:
462
463 SkString onShortName() override {
464 return SkString("zero_control_stroke");
465 }
466
467 SkISize onISize() override {
468 return SkISize::Make(W, H*2);
469 }
470
471 void onDraw(SkCanvas* canvas) override {
472 SkPaint p;
473 p.setColor(SK_ColorRED);
474 p.setAntiAlias(true);
475 p.setStyle(SkPaint::kStroke_Style);
476 p.setStrokeWidth(40);
477 p.setStrokeCap(SkPaint::kButt_Cap);
478
479 SkPath path;
480 path.moveTo(157.474f,111.753f);
481 path.cubicTo(128.5f,111.5f,35.5f,29.5f,35.5f,29.5f);
482 canvas->drawPath(path, p);
483 path.reset();
484 path.moveTo(250, 50);
485 path.quadTo(280, 80, 280, 80);
486 canvas->drawPath(path, p);
487 path.reset();
488 path.moveTo(150, 50);
489 path.conicTo(180, 80, 180, 80, 0.707f);
490 canvas->drawPath(path, p);
491
492 path.reset();
493 path.moveTo(157.474f,311.753f);
494 path.cubicTo(157.474f,311.753f,85.5f,229.5f,35.5f,229.5f);
495 canvas->drawPath(path, p);
496 path.reset();
497 path.moveTo(280, 250);
498 path.quadTo(280, 250, 310, 280);
499 canvas->drawPath(path, p);
500 path.reset();
501 path.moveTo(180, 250);
502 path.conicTo(180, 250, 210, 280, 0.707f);
503 canvas->drawPath(path, p);
504 }
505
506private:
507 typedef skiagm::GM INHERITED;
508};
509
caryclark612f70d2015-05-19 11:05:37 -0700510
reed@google.com4384fab2012-06-05 16:14:23 +0000511//////////////////////////////////////////////////////////////////////////////
512
scroggo96f16e82015-12-10 13:31:59 -0800513DEF_GM( return new StrokesGM; )
514DEF_GM( return new Strokes2GM; )
515DEF_GM( return new Strokes3GM; )
516DEF_GM( return new Strokes4GM; )
517DEF_GM( return new Strokes5GM; )
caryclark5cb00a92015-08-26 09:04:55 -0700518
halcanary385fe4d2015-08-26 13:07:48 -0700519DEF_GM( return new ZeroLenStrokesGM; )
caryclark950305e2015-10-26 08:17:04 -0700520DEF_GM( return new TeenyStrokesGM; )