blob: e7dd4782440b4371964cfa0a5151b1d54fb3fe10 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * 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.
6 */
bungemand3ebb482015-08-05 13:57:49 -07007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
Mike Reedcfb130c2020-08-03 11:02:20 -040012#include "include/core/SkPathBuilder.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkRect.h"
14#include "include/core/SkScalar.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
17#include "include/core/SkTypes.h"
reed@google.comc2807002011-04-11 13:57:04 +000018
Mike Reedd16d6542020-08-22 15:08:27 -040019namespace {
20struct PathDY {
21 SkPath path;
22 SkScalar dy;
23};
John Stiles32153852020-08-23 18:30:07 -040024}
reed@google.comc2807002011-04-11 13:57:04 +000025
Mike Reedd16d6542020-08-22 15:08:27 -040026typedef PathDY (*MakePathProc)();
27
28static PathDY make_frame() {
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000029 SkRect r = { SkIntToScalar(10), SkIntToScalar(10),
30 SkIntToScalar(630), SkIntToScalar(470) };
Mike Reedd16d6542020-08-22 15:08:27 -040031 SkPath path = SkPath::RRect(SkRRect::MakeRectXY(r, 15, 15));
reed@google.comc2807002011-04-11 13:57:04 +000032 SkPaint paint;
33 paint.setStyle(SkPaint::kStroke_Style);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000034 paint.setStrokeWidth(SkIntToScalar(5));
Mike Reedd16d6542020-08-22 15:08:27 -040035 paint.getFillPath(path, &path);
36 return {path, 15};
reed@google.comc2807002011-04-11 13:57:04 +000037}
38
Mike Reedd16d6542020-08-22 15:08:27 -040039static PathDY make_triangle() {
mtkleindbfd7ab2016-09-01 11:24:54 -070040 constexpr int gCoord[] = {
reed@google.comc2807002011-04-11 13:57:04 +000041 10, 20, 15, 5, 30, 30
42 };
Mike Reedd16d6542020-08-22 15:08:27 -040043 return {
44 SkPathBuilder().moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]))
45 .lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]))
46 .lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]))
47 .close()
48 .offset(10, 0)
49 .detach(),
50 30
51 };
reed@google.comc2807002011-04-11 13:57:04 +000052}
53
Mike Reedd16d6542020-08-22 15:08:27 -040054static PathDY make_rect() {
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000055 SkRect r = { SkIntToScalar(10), SkIntToScalar(10),
56 SkIntToScalar(30), SkIntToScalar(30) };
Mike Reedd16d6542020-08-22 15:08:27 -040057 return {
58 SkPathBuilder().addRect(r).offset(10, 0).detach(),
59 30
60 };
reed@google.comc2807002011-04-11 13:57:04 +000061}
62
Mike Reedd16d6542020-08-22 15:08:27 -040063static PathDY make_oval() {
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000064 SkRect r = { SkIntToScalar(10), SkIntToScalar(10),
65 SkIntToScalar(30), SkIntToScalar(30) };
Mike Reedd16d6542020-08-22 15:08:27 -040066 return {
67 SkPathBuilder().addOval(r).offset(10, 0).detach(),
68 30
69 };
reed@google.comc2807002011-04-11 13:57:04 +000070}
71
Mike Reedd16d6542020-08-22 15:08:27 -040072static PathDY make_sawtooth(int teeth) {
reed@google.comc2807002011-04-11 13:57:04 +000073 SkScalar x = SkIntToScalar(20);
74 SkScalar y = SkIntToScalar(20);
75 const SkScalar x0 = x;
Jim Van Verthecdb6862016-12-13 18:17:47 -050076 const SkScalar dx = SkIntToScalar(5);
77 const SkScalar dy = SkIntToScalar(10);
rmistry@google.comd6176b02012-08-23 18:14:13 +000078
Mike Reedd16d6542020-08-22 15:08:27 -040079 SkPathBuilder builder;
80 builder.moveTo(x, y);
Jim Van Verthecdb6862016-12-13 18:17:47 -050081 for (int i = 0; i < teeth; i++) {
reed@google.comc2807002011-04-11 13:57:04 +000082 x += dx;
Mike Reedd16d6542020-08-22 15:08:27 -040083 builder.lineTo(x, y - dy);
reed@google.comc2807002011-04-11 13:57:04 +000084 x += dx;
Mike Reedd16d6542020-08-22 15:08:27 -040085 builder.lineTo(x, y + dy);
reed@google.comc2807002011-04-11 13:57:04 +000086 }
Mike Reedd16d6542020-08-22 15:08:27 -040087 builder.lineTo(x, y + (2 * dy));
88 builder.lineTo(x0, y + (2 * dy));
89 builder.close();
90
91 return {builder.detach(), 30};
reed@google.comc2807002011-04-11 13:57:04 +000092}
93
Mike Reedd16d6542020-08-22 15:08:27 -040094static PathDY make_sawtooth_3() { return make_sawtooth(3); }
95static PathDY make_sawtooth_32() { return make_sawtooth(32); }
Jim Van Verthecdb6862016-12-13 18:17:47 -050096
Mike Reedd16d6542020-08-22 15:08:27 -040097static PathDY make_house() {
98 SkPathBuilder builder;
99 builder.addPolygon({
100 {21, 23},
101 {21, 11.534f},
102 {22.327f, 12.741f},
103 {23.673f, 11.261f},
104 {12, 0.648f},
105 {8, 4.285f},
106 {8, 2},
107 {4, 2},
108 {4, 7.921f},
109 {0.327f, 11.26f},
110 {1.673f, 12.74f},
111 {3, 11.534f},
112 {3, 23},
113 {11, 23},
114 {11, 18},
115 {13, 18},
116 {13, 23},
117 {21, 23}}, true)
118 .polylineTo({
119 {9, 16},
120 {9, 21},
121 {5, 21},
122 {5, 9.715f},
123 {12, 3.351f},
124 {19, 9.715f},
125 {19, 21},
126 {15, 21},
127 {15, 16},
128 {9, 16}})
129 .close()
130 .offset(20, 0);
131 return {builder.detach(), 30};
Jim Van Verthecdb6862016-12-13 18:17:47 -0500132}
133
Mike Reedd16d6542020-08-22 15:08:27 -0400134static PathDY make_star(int n) {
reed@google.comc2807002011-04-11 13:57:04 +0000135 const SkScalar c = SkIntToScalar(45);
136 const SkScalar r = SkIntToScalar(20);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000137
reed@google.comc2807002011-04-11 13:57:04 +0000138 SkScalar rad = -SK_ScalarPI / 2;
139 const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000140
Mike Reedd16d6542020-08-22 15:08:27 -0400141 SkPathBuilder builder;
142 builder.moveTo(c, c - r);
reed@google.comc2807002011-04-11 13:57:04 +0000143 for (int i = 1; i < n; i++) {
144 rad += drad;
Mike Reedd16d6542020-08-22 15:08:27 -0400145 builder.lineTo(c + SkScalarCos(rad) * r, c + SkScalarSin(rad) * r);
reed@google.comc2807002011-04-11 13:57:04 +0000146 }
Mike Reedd16d6542020-08-22 15:08:27 -0400147 builder.close();
148
149 return {builder.detach(), r * 2 * 6 / 5};
reed@google.comc2807002011-04-11 13:57:04 +0000150}
151
Mike Reedd16d6542020-08-22 15:08:27 -0400152static PathDY make_star_5() { return make_star(5); }
153static PathDY make_star_13() { return make_star(13); }
reed@google.comc2807002011-04-11 13:57:04 +0000154
vandebo@chromium.org683001c2012-05-09 17:17:51 +0000155// We don't expect any output from this path.
Mike Reedd16d6542020-08-22 15:08:27 -0400156static PathDY make_line() {
157 return {
158 SkPathBuilder().moveTo(30, 30)
159 .lineTo(120, 40)
160 .close()
161 .moveTo(150, 30)
162 .lineTo(150, 30)
163 .lineTo(300, 40)
164 .close()
165 .detach(),
166 40
167 };
vandebo@chromium.org683001c2012-05-09 17:17:51 +0000168}
169
Mike Reed92f6eb12020-08-25 11:48:41 -0400170static SkPath make_info() {
171 SkPathBuilder path;
172 path.moveTo(24, 4);
173 path.cubicTo(12.94999980926514f, 4,
174 4, 12.94999980926514f,
175 4, 24);
176 path.cubicTo(4, 35.04999923706055f,
177 12.94999980926514f, 44,
178 24, 44);
179 path.cubicTo(35.04999923706055f, 44,
180 44, 35.04999923706055f,
181 44, 24);
182 path.cubicTo(44, 12.95000076293945f,
183 35.04999923706055f, 4,
184 24, 4);
185 path.close();
186 path.moveTo(26, 34);
187 path.lineTo(22, 34);
188 path.lineTo(22, 22);
189 path.lineTo(26, 22);
190 path.lineTo(26, 34);
191 path.close();
192 path.moveTo(26, 18);
193 path.lineTo(22, 18);
194 path.lineTo(22, 14);
195 path.lineTo(26, 14);
196 path.lineTo(26, 18);
197 path.close();
198 return path.detach();
Jim Van Verthf9e678d2017-02-15 15:46:52 -0500199}
Jim Van Verth77047542017-01-11 14:17:00 -0500200
Mike Reed92f6eb12020-08-25 11:48:41 -0400201static SkPath make_accessibility() {
202 SkPathBuilder path;
203 path.moveTo(12, 2);
204 path.cubicTo(13.10000038146973f, 2,
205 14, 2.900000095367432f,
206 14, 4);
207 path.cubicTo(14, 5.099999904632568f,
208 13.10000038146973f, 6,
209 12, 6);
210 path.cubicTo(10.89999961853027f, 6,
211 10, 5.099999904632568f,
212 10, 4);
213 path.cubicTo(10, 2.900000095367432f,
214 10.89999961853027f, 2,
215 12, 2);
216 path.close();
217 path.moveTo(21, 9);
218 path.lineTo(15, 9);
219 path.lineTo(15, 22);
220 path.lineTo(13, 22);
221 path.lineTo(13, 16);
222 path.lineTo(11, 16);
223 path.lineTo(11, 22);
224 path.lineTo(9, 22);
225 path.lineTo(9, 9);
226 path.lineTo(3, 9);
227 path.lineTo(3, 7);
228 path.lineTo(21, 7);
229 path.lineTo(21, 9);
230 path.close();
231 return path.detach();
Jim Van Verth77047542017-01-11 14:17:00 -0500232}
233
Jim Van Verth33632d82017-02-28 10:24:39 -0500234// test case for http://crbug.com/695196
Mike Reed92f6eb12020-08-25 11:48:41 -0400235static SkPath make_visualizer() {
236 SkPathBuilder path;
237 path.moveTo(1.9520f, 2.0000f);
238 path.conicTo(1.5573f, 1.9992f, 1.2782f, 2.2782f, 0.9235f);
239 path.conicTo(0.9992f, 2.5573f, 1.0000f, 2.9520f, 0.9235f);
240 path.lineTo(1.0000f, 5.4300f);
241 path.lineTo(17.0000f, 5.4300f);
242 path.lineTo(17.0000f, 2.9520f);
243 path.conicTo(17.0008f, 2.5573f, 16.7218f, 2.2782f, 0.9235f);
244 path.conicTo(16.4427f, 1.9992f, 16.0480f, 2.0000f, 0.9235f);
245 path.lineTo(1.9520f, 2.0000f);
246 path.close();
247 path.moveTo(2.7140f, 3.1430f);
248 path.conicTo(3.0547f, 3.1287f, 3.2292f, 3.4216f, 0.8590f);
249 path.conicTo(3.4038f, 3.7145f, 3.2292f, 4.0074f, 0.8590f);
250 path.conicTo(3.0547f, 4.3003f, 2.7140f, 4.2860f, 0.8590f);
251 path.conicTo(2.1659f, 4.2631f, 2.1659f, 3.7145f, 0.7217f);
252 path.conicTo(2.1659f, 3.1659f, 2.7140f, 3.1430f, 0.7217f);
253 path.lineTo(2.7140f, 3.1430f);
254 path.close();
255 path.moveTo(5.0000f, 3.1430f);
256 path.conicTo(5.3407f, 3.1287f, 5.5152f, 3.4216f, 0.8590f);
257 path.conicTo(5.6898f, 3.7145f, 5.5152f, 4.0074f, 0.8590f);
258 path.conicTo(5.3407f, 4.3003f, 5.0000f, 4.2860f, 0.8590f);
259 path.conicTo(4.4519f, 4.2631f, 4.4519f, 3.7145f, 0.7217f);
260 path.conicTo(4.4519f, 3.1659f, 5.0000f, 3.1430f, 0.7217f);
261 path.lineTo(5.0000f, 3.1430f);
262 path.close();
263 path.moveTo(7.2860f, 3.1430f);
264 path.conicTo(7.6267f, 3.1287f, 7.8012f, 3.4216f, 0.8590f);
265 path.conicTo(7.9758f, 3.7145f, 7.8012f, 4.0074f, 0.8590f);
266 path.conicTo(7.6267f, 4.3003f, 7.2860f, 4.2860f, 0.8590f);
267 path.conicTo(6.7379f, 4.2631f, 6.7379f, 3.7145f, 0.7217f);
268 path.conicTo(6.7379f, 3.1659f, 7.2860f, 3.1430f, 0.7217f);
269 path.close();
270 path.moveTo(1.0000f, 6.1900f);
271 path.lineTo(1.0000f, 14.3810f);
272 path.conicTo(0.9992f, 14.7757f, 1.2782f, 15.0548f, 0.9235f);
273 path.conicTo(1.5573f, 15.3338f, 1.9520f, 15.3330f, 0.9235f);
274 path.lineTo(16.0480f, 15.3330f);
275 path.conicTo(16.4427f, 15.3338f, 16.7218f, 15.0548f, 0.9235f);
276 path.conicTo(17.0008f, 14.7757f, 17.0000f, 14.3810f, 0.9235f);
277 path.lineTo(17.0000f, 6.1910f);
278 path.lineTo(1.0000f, 6.1910f);
279 path.lineTo(1.0000f, 6.1900f);
280 path.close();
281 return path.detach();
Jim Van Verth33632d82017-02-28 10:24:39 -0500282}
283
mtkleindbfd7ab2016-09-01 11:24:54 -0700284constexpr MakePathProc gProcs[] = {
reed@google.comc2807002011-04-11 13:57:04 +0000285 make_frame,
286 make_triangle,
287 make_rect,
288 make_oval,
Jim Van Verthecdb6862016-12-13 18:17:47 -0500289 make_sawtooth_32,
reed@google.comc2807002011-04-11 13:57:04 +0000290 make_star_5,
vandebo@chromium.org683001c2012-05-09 17:17:51 +0000291 make_star_13,
292 make_line,
Jim Van Verthecdb6862016-12-13 18:17:47 -0500293 make_house,
294 make_sawtooth_3,
reed@google.comc2807002011-04-11 13:57:04 +0000295};
296
297#define N SK_ARRAY_COUNT(gProcs)
298
reed@google.com5ee64912012-06-11 17:30:33 +0000299class PathFillGM : public skiagm::GM {
reed@google.comc2807002011-04-11 13:57:04 +0000300 SkPath fPath[N];
301 SkScalar fDY[N];
Jim Van Verth77047542017-01-11 14:17:00 -0500302 SkPath fInfoPath;
Jim Van Verthf9e678d2017-02-15 15:46:52 -0500303 SkPath fAccessibilityPath;
Jim Van Verth33632d82017-02-28 10:24:39 -0500304 SkPath fVisualizerPath;
caryclark88c748a2015-02-18 10:56:00 -0800305protected:
mtklein36352bf2015-03-25 18:17:31 -0700306 void onOnceBeforeDraw() override {
reed@google.comc2807002011-04-11 13:57:04 +0000307 for (size_t i = 0; i < N; i++) {
Mike Reedd16d6542020-08-22 15:08:27 -0400308 auto [path, dy] = gProcs[i]();
309 fPath[i] = path;
310 fDY[i] = dy;
reed@google.comc2807002011-04-11 13:57:04 +0000311 }
Jim Van Verth77047542017-01-11 14:17:00 -0500312
Mike Reed92f6eb12020-08-25 11:48:41 -0400313 fInfoPath = make_info();
314 fAccessibilityPath = make_accessibility();
315 fVisualizerPath = make_visualizer();
reed@google.comc2807002011-04-11 13:57:04 +0000316 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000317
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +0000318
mtklein36352bf2015-03-25 18:17:31 -0700319 SkString onShortName() override {
reed@google.comc2807002011-04-11 13:57:04 +0000320 return SkString("pathfill");
321 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000322
mtklein36352bf2015-03-25 18:17:31 -0700323 SkISize onISize() override {
reed@google.com5ee64912012-06-11 17:30:33 +0000324 return SkISize::Make(640, 480);
reed@google.comc2807002011-04-11 13:57:04 +0000325 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000326
mtklein36352bf2015-03-25 18:17:31 -0700327 void onDraw(SkCanvas* canvas) override {
reed@google.comc2807002011-04-11 13:57:04 +0000328 SkPaint paint;
329 paint.setAntiAlias(true);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000330
reed@google.comc2807002011-04-11 13:57:04 +0000331 for (size_t i = 0; i < N; i++) {
332 canvas->drawPath(fPath[i], paint);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +0000333 canvas->translate(SkIntToScalar(0), fDY[i]);
reed@google.comc2807002011-04-11 13:57:04 +0000334 }
Jim Van Verth77047542017-01-11 14:17:00 -0500335
Jim Van Verthf9e678d2017-02-15 15:46:52 -0500336 canvas->save();
Jim Van Verth77047542017-01-11 14:17:00 -0500337 canvas->scale(0.300000011920929f, 0.300000011920929f);
338 canvas->translate(50, 50);
339 canvas->drawPath(fInfoPath, paint);
Jim Van Verthf9e678d2017-02-15 15:46:52 -0500340 canvas->restore();
341
342 canvas->scale(2, 2);
343 canvas->translate(5, 15);
344 canvas->drawPath(fAccessibilityPath, paint);
Jim Van Verth33632d82017-02-28 10:24:39 -0500345
346 canvas->scale(0.5f, 0.5f);
347 canvas->translate(5, 50);
348 canvas->drawPath(fVisualizerPath, paint);
reed@google.comc2807002011-04-11 13:57:04 +0000349 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000350
reed@google.comc2807002011-04-11 13:57:04 +0000351private:
John Stiles7571f9e2020-09-02 22:42:33 -0400352 using INHERITED = skiagm::GM;
reed@google.com5ee64912012-06-11 17:30:33 +0000353};
354
355// test inverse-fill w/ a clip that completely excludes the geometry
356class PathInverseFillGM : public skiagm::GM {
357 SkPath fPath[N];
358 SkScalar fDY[N];
caryclark88c748a2015-02-18 10:56:00 -0800359protected:
mtklein36352bf2015-03-25 18:17:31 -0700360 void onOnceBeforeDraw() override {
reed@google.com5ee64912012-06-11 17:30:33 +0000361 for (size_t i = 0; i < N; i++) {
Mike Reedd16d6542020-08-22 15:08:27 -0400362 auto [path, dy] = gProcs[i]();
363 fPath[i] = path;
364 fDY[i] = dy;
reed@google.com5ee64912012-06-11 17:30:33 +0000365 }
366 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000367
mtklein36352bf2015-03-25 18:17:31 -0700368 SkString onShortName() override {
reed@google.com5ee64912012-06-11 17:30:33 +0000369 return SkString("pathinvfill");
370 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000371
mtklein36352bf2015-03-25 18:17:31 -0700372 SkISize onISize() override {
reed@google.com5ee64912012-06-11 17:30:33 +0000373 return SkISize::Make(450, 220);
374 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000375
reed@google.com5ee64912012-06-11 17:30:33 +0000376 static void show(SkCanvas* canvas, const SkPath& path, const SkPaint& paint,
377 const SkRect* clip, SkScalar top, const SkScalar bottom) {
378 canvas->save();
379 if (clip) {
380 SkRect r = *clip;
381 r.fTop = top;
382 r.fBottom = bottom;
383 canvas->clipRect(r);
384 }
385 canvas->drawPath(path, paint);
386 canvas->restore();
387 }
388
mtklein36352bf2015-03-25 18:17:31 -0700389 void onDraw(SkCanvas* canvas) override {
Mike Reed92f6eb12020-08-25 11:48:41 -0400390 SkPath path = SkPathBuilder().addCircle(50, 50, 40)
391 .toggleInverseFillType()
392 .detach();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000393
Mike Reed92f6eb12020-08-25 11:48:41 -0400394 SkRect clipR = {0, 0, 100, 200};
reed@google.com5ee64912012-06-11 17:30:33 +0000395
Mike Reed92f6eb12020-08-25 11:48:41 -0400396 canvas->translate(10, 10);
reed@google.com5ee64912012-06-11 17:30:33 +0000397
398 for (int doclip = 0; doclip <= 1; ++doclip) {
399 for (int aa = 0; aa <= 1; ++aa) {
400 SkPaint paint;
401 paint.setAntiAlias(SkToBool(aa));
402
403 canvas->save();
404 canvas->clipRect(clipR);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000405
halcanary96fcdcc2015-08-27 07:41:13 -0700406 const SkRect* clipPtr = doclip ? &clipR : nullptr;
reed@google.com5ee64912012-06-11 17:30:33 +0000407
408 show(canvas, path, paint, clipPtr, clipR.fTop, clipR.centerY());
409 show(canvas, path, paint, clipPtr, clipR.centerY(), clipR.fBottom);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000410
reed@google.com5ee64912012-06-11 17:30:33 +0000411 canvas->restore();
412 canvas->translate(SkIntToScalar(110), 0);
413 }
414 }
415 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000416
reed@google.com5ee64912012-06-11 17:30:33 +0000417private:
John Stiles7571f9e2020-09-02 22:42:33 -0400418 using INHERITED = skiagm::GM;
reed@google.comc2807002011-04-11 13:57:04 +0000419};
420
caryclarke3e8c722016-03-01 09:42:03 -0800421DEF_SIMPLE_GM(rotatedcubicpath, canvas, 200, 200) {
422 SkPaint p;
423 p.setAntiAlias(true);
424 p.setStyle(SkPaint::kFill_Style);
425
426 canvas->translate(50, 50);
427 SkPath path;
428 path.moveTo(48,-23);
429 path.cubicTo(48,-29.5, 6,-30, 6,-30);
430 path.cubicTo(6,-30, 2,0, 2,0);
431 path.cubicTo(2,0, 44,-21.5, 48,-23);
432 path.close();
433
434 p.setColor(SK_ColorBLUE);
435 canvas->drawPath(path, p);
436
437 // Rotated path, which is not antialiased on GPU
438 p.setColor(SK_ColorRED);
439 canvas->rotate(90);
440 canvas->drawPath(path, p);
441}
442
reed@google.comc2807002011-04-11 13:57:04 +0000443///////////////////////////////////////////////////////////////////////////////
444
scroggo96f16e82015-12-10 13:31:59 -0800445DEF_GM( return new PathFillGM; )
446DEF_GM( return new PathInverseFillGM; )
Cary Clark8540e112018-04-11 14:30:27 -0400447
Cary Clark4eb6f7a2018-04-17 13:34:37 -0400448DEF_SIMPLE_GM(bug7792, canvas, 800, 800) {
Cary Clark8540e112018-04-11 14:30:27 -0400449 // from skbug.com/7792 bug description
450 SkPaint p;
451 SkPath path;
452 path.moveTo(10, 10);
453 path.moveTo(75, 75);
454 path.lineTo(150, 75);
455 path.lineTo(150, 150);
456 path.lineTo(75, 150);
457 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400458 // from skbug.com/7792#c3
Cary Clark8540e112018-04-11 14:30:27 -0400459 canvas->translate(200, 0);
460 path.reset();
461 path.moveTo(75, 50);
462 path.moveTo(100, 75);
463 path.lineTo(150, 75);
464 path.lineTo(150, 150);
465 path.lineTo(75, 150);
466 path.lineTo(75, 50);
467 path.close();
468 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400469 // from skbug.com/7792#c9
Cary Clark8540e112018-04-11 14:30:27 -0400470 canvas->translate(200, 0);
471 path.reset();
472 path.moveTo(10, 10);
473 path.moveTo(75, 75);
474 path.lineTo(150, 75);
475 path.lineTo(150, 150);
476 path.lineTo(75, 150);
477 path.close();
478 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400479 // from skbug.com/7792#c11
Cary Clark8540e112018-04-11 14:30:27 -0400480 canvas->translate(-200 * 2, 200);
481 path.reset();
482 path.moveTo(75, 150);
483 path.lineTo(75, 75);
484 path.lineTo(150, 75);
485 path.lineTo(150, 150);
486 path.lineTo(75, 150);
487 path.moveTo(75, 150);
488 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400489 // from skbug.com/7792#c14
Cary Clark8540e112018-04-11 14:30:27 -0400490 canvas->translate(200, 0);
491 path.reset();
492 path.moveTo(250, 75);
493 path.moveTo(250, 75);
494 path.moveTo(250, 75);
495 path.moveTo(100, 75);
496 path.lineTo(150, 75);
497 path.lineTo(150, 150);
498 path.lineTo(75, 150);
499 path.lineTo(75, 75);
500 path.close();
501 path.lineTo(0, 0);
502 path.close();
503 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400504 // from skbug.com/7792#c15
Cary Clark8540e112018-04-11 14:30:27 -0400505 canvas->translate(200, 0);
506 path.reset();
507 path.moveTo(75, 75);
508 path.lineTo(150, 75);
509 path.lineTo(150, 150);
510 path.lineTo(75, 150);
511 path.moveTo(250, 75);
512 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400513 // from skbug.com/7792#c17
Cary Clark31608c02018-04-12 10:29:46 -0400514 canvas->translate(-200 * 2, 200);
515 path.reset();
516 path.moveTo(75, 10);
517 path.moveTo(75, 75);
518 path.lineTo(150, 75);
519 path.lineTo(150, 150);
520 path.lineTo(75, 150);
521 path.lineTo(75, 10);
522 path.close();
523 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400524 // from skbug.com/7792#c19
Cary Clark88ba9712018-04-12 14:00:24 -0400525 canvas->translate(200, 0);
526 path.reset();
527 path.moveTo(75, 75);
528 path.lineTo(75, 75);
529 path.lineTo(75, 75);
530 path.lineTo(75, 75);
531 path.lineTo(150, 75);
532 path.lineTo(150, 150);
533 path.lineTo(75, 150);
534 path.close();
535 path.moveTo(10, 10);
536 path.lineTo(30, 10);
537 path.lineTo(10, 30);
538 canvas->drawPath(path, p);
Cary Clarkd4228472018-04-13 07:07:04 -0400539 // from skbug.com/7792#c23
540 canvas->translate(200, 0);
541 path.reset();
542 path.moveTo(75, 75);
543 path.lineTo(75, 75);
544 path.moveTo(75, 75);
545 path.lineTo(75, 75);
546 path.lineTo(150, 75);
547 path.lineTo(150, 150);
548 path.lineTo(75, 150);
549 path.close();
550 canvas->drawPath(path, p);
Cary Clark48c464a2018-04-16 12:06:07 -0400551 // from skbug.com/7792#c29
552 canvas->translate(-200 * 2, 200);
553 path.reset();
554 path.moveTo(75, 75);
555 path.lineTo(150, 75);
556 path.lineTo(150, 150);
557 path.lineTo(75, 150);
558 path.lineTo(75, 250);
559 path.moveTo(75, 75);
560 path.close();
561 canvas->drawPath(path, p);
Cary Clarka7651562018-04-17 09:30:14 -0400562 // from skbug.com/7792#c31
563 canvas->translate(200, 0);
564 path.reset();
565 path.moveTo(75, 75);
566 path.lineTo(150, 75);
567 path.lineTo(150, 150);
568 path.lineTo(75, 150);
569 path.lineTo(75, 10);
570 path.moveTo(75, 75);
571 path.close();
572 canvas->drawPath(path, p);
Cary Clark1cd60982018-04-17 11:53:34 -0400573 // from skbug.com/7792#c36
574 canvas->translate(200, 0);
575 path.reset();
576 path.moveTo(75, 75);
577 path.lineTo(150, 75);
578 path.lineTo(150, 150);
579 path.lineTo(10, 150);
580 path.moveTo(75, 75);
581 path.lineTo(75, 75);
582 canvas->drawPath(path, p);
Cary Clark4eb6f7a2018-04-17 13:34:37 -0400583 // from skbug.com/7792#c39
584 canvas->translate(200, -200 * 3);
585 path.reset();
586 path.moveTo(150, 75);
587 path.lineTo(150, 150);
588 path.lineTo(75, 150);
589 path.lineTo(75, 100);
590 canvas->drawPath(path, p);
Cary Clarkb120e922018-04-18 12:25:08 -0400591 // from zero_length_paths_aa
592 canvas->translate(0, 200);
593 path.reset();
594 path.moveTo(150, 100);
595 path.lineTo(150, 100);
596 path.lineTo(150, 150);
597 path.lineTo(75, 150);
598 path.lineTo(75, 100);
599 path.lineTo(75, 75);
600 path.lineTo(150, 75);
601 path.close();
602 canvas->drawPath(path, p);
Cary Clarkdbc59ba2018-04-19 07:37:29 -0400603 // from skbug.com/7792#c41
604 canvas->translate(0, 200);
605 path.reset();
606 path.moveTo(75, 75);
607 path.lineTo(150, 75);
608 path.lineTo(150, 150);
609 path.lineTo(140, 150);
610 path.lineTo(140, 75);
611 path.moveTo(75, 75);
612 path.close();
613 canvas->drawPath(path, p);
614 // from skbug.com/7792#c53
615 canvas->translate(0, 200);
616 path.reset();
617 path.moveTo(75, 75);
618 path.lineTo(150, 75);
619 path.lineTo(150, 150);
620 path.lineTo(140, 150);
621 path.lineTo(140, 75);
622 path.moveTo(75, 75);
623 path.close();
624 canvas->drawPath(path, p);
Cary Clark8540e112018-04-11 14:30:27 -0400625}
Mike Reed1ae3e752020-04-26 17:20:22 -0400626
627#include "include/core/SkSurface.h"
628
629DEF_SIMPLE_GM(path_stroke_clip_crbug1070835, canvas, 25, 50) {
630 SkCanvas* orig = canvas;
631 auto surf = SkSurface::MakeRasterN32Premul(25, 25);
632 canvas = surf->getCanvas();
633
634 SkPaint p;
635 p.setColor(SK_ColorRED);
636 p.setAntiAlias(true);
637 p.setStyle(SkPaint::kStroke_Style);
638 p.setStrokeWidth(2);
639
640 canvas->scale(4.16666651f/2, 4.16666651f/2);
641
642 SkPath path;
643
644 SkPoint pts[] = {
645 {11, 12},
646 {11, 18.0751324f},
647 {6.07513189f, 23},
648 {-4.80825292E-7f, 23},
649 {-6.07513332f, 23},
650 {-11, 18.0751324f},
651 {-11, 11.999999f},
652 {-10.999999f, 5.92486763f},
653 {-6.07513189f, 1},
654 {1.31173692E-7f, 1},
655 {6.07513141f, 1},
656 {10.9999981f, 5.92486572f},
657 {11, 11.9999971f},
658 };
659 path.moveTo(pts[0]).cubicTo(pts[1], pts[2], pts[3])
660 .cubicTo(pts[4], pts[5], pts[6])
661 .cubicTo(pts[7], pts[8], pts[9])
662 .cubicTo(pts[10],pts[11],pts[12]);
663
664 canvas->drawPath(path, p);
665
Mike Reedb746b1f2021-01-06 08:43:51 -0500666 surf->draw(orig, 0, 0);
Mike Reed1ae3e752020-04-26 17:20:22 -0400667}
Mike Reed3c411f52020-04-28 15:17:48 -0400668
669DEF_SIMPLE_GM(path_arcto_skbug_9077, canvas, 200, 200) {
670 SkPaint p;
671 p.setColor(SK_ColorRED);
672 p.setAntiAlias(true);
673 p.setStyle(SkPaint::kStroke_Style);
674 p.setStrokeWidth(2);
675
Mike Reedcfb130c2020-08-03 11:02:20 -0400676 SkPathBuilder path;
Mike Reed3c411f52020-04-28 15:17:48 -0400677 SkPoint pts[] = { {20, 20}, {100, 20}, {100, 60}, {130, 150}, {180, 160} };
678 SkScalar radius = 60;
679 path.moveTo(pts[0]);
680 path.lineTo(pts[1]);
681 path.lineTo(pts[2]);
682 path.close();
683 path.arcTo(pts[3], pts[4], radius);
Mike Reedcfb130c2020-08-03 11:02:20 -0400684 canvas->drawPath(path.detach(), p);
Mike Reed3c411f52020-04-28 15:17:48 -0400685}
Michael Ludwig3e8ff3e2021-04-23 15:47:14 -0400686
687DEF_SIMPLE_GM(path_skbug_11859, canvas, 512, 512) {
688 SkPaint paint;
689 paint.setColor(SK_ColorRED);
690 paint.setAntiAlias(true);
691
692 SkPath path;
693 path.moveTo(258, -2);
694 path.lineTo(258, 258);
695 path.lineTo(237, 258);
696 path.lineTo(240, -2);
697 path.lineTo(258, -2);
698 path.moveTo(-2, -2);
699 path.lineTo(240, -2);
700 path.lineTo(238, 131);
701 path.lineTo(-2, 131);
702 path.lineTo(-2, -2);
703
704 canvas->scale(2, 2);
705 canvas->drawPath(path, paint);
706}
Michael Ludwig4e9d5e22021-05-11 10:00:12 -0400707
708DEF_SIMPLE_GM(path_skbug_11886, canvas, 256, 256) {
709 SkPoint m = {0.f, 770.f};
710 SkPath path;
711 path.moveTo(m);
712 path.cubicTo(m + SkPoint{0.f, 1.f}, m + SkPoint{20.f, -750.f}, m + SkPoint{83.f, -746.f});
713 SkPaint paint;
714 paint.setAntiAlias(true);
715 canvas->drawPath(path, paint);
716}