mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 10 | #include "SkPath.h" |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 11 | #include "SkRandom.h" |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 12 | #include "SkDashPathEffect.h" |
| 13 | #include "SkParsePath.h" |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 14 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 15 | #define W 400 |
| 16 | #define H 400 |
| 17 | #define N 50 |
| 18 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 19 | constexpr SkScalar SW = SkIntToScalar(W); |
| 20 | constexpr SkScalar SH = SkIntToScalar(H); |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 21 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 22 | static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 23 | 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.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 27 | SkScalar hoffset = rand.nextSScalar1(); |
| 28 | SkScalar woffset = rand.nextSScalar1(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 29 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 30 | r->set(x, y, x + w, y + h); |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 31 | r->offset(-w/2 + woffset, -h/2 + hoffset); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 32 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 33 | paint->setColor(rand.nextU()); |
| 34 | paint->setAlpha(0xFF); |
| 35 | } |
| 36 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 37 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 38 | class StrokesGM : public skiagm::GM { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 39 | public: |
| 40 | StrokesGM() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 41 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 42 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 43 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 44 | SkString onShortName() override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 45 | return SkString("strokes_round"); |
| 46 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 48 | SkISize onISize() override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 49 | return SkISize::Make(W, H*2); |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 50 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 51 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 52 | void onDraw(SkCanvas* canvas) override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 53 | SkPaint paint; |
| 54 | paint.setStyle(SkPaint::kStroke_Style); |
| 55 | paint.setStrokeWidth(SkIntToScalar(9)/2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 56 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 57 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 65 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 66 | SkRandom rand; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 67 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 77 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 78 | private: |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 79 | typedef skiagm::GM INHERITED; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 82 | /* See |
| 83 | https://code.google.com/p/chromium/issues/detail?id=422974 and |
| 84 | http://jsfiddle.net/1xnku3sg/2/ |
| 85 | */ |
| 86 | class ZeroLenStrokesGM : public skiagm::GM { |
| 87 | SkPath fMoveHfPath, fMoveZfPath, fDashedfPath, fRefPath[4]; |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 88 | SkPath fCubicPath, fQuadPath, fLinePath; |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 89 | protected: |
| 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)); |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 95 | 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)); |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 98 | |
| 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 }; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 132 | dashPaint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0)); |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 133 | 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); |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 148 | 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); |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 154 | canvas->restore(); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | private: |
| 159 | typedef skiagm::GM INHERITED; |
| 160 | }; |
| 161 | |
caryclark | 950305e | 2015-10-26 08:17:04 -0700 | [diff] [blame] | 162 | class 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 | } |
| 193 | private: |
| 194 | typedef skiagm::GM INHERITED; |
| 195 | }; |
| 196 | |
caryclark | b775e91 | 2015-11-30 13:47:11 -0800 | [diff] [blame] | 197 | DEF_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 | } |
caryclark | 950305e | 2015-10-26 08:17:04 -0700 | [diff] [blame] | 213 | |
caryclark | 57eecc1 | 2015-12-08 04:29:45 -0800 | [diff] [blame] | 214 | DEF_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 | |
caryclark | 40b7d3b | 2015-12-22 06:13:33 -0800 | [diff] [blame] | 240 | DEF_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}, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 247 | {105.738571f,13.126318f}, |
caryclark | 40b7d3b | 2015-12-22 06:13:33 -0800 | [diff] [blame] | 248 | {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.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 272 | class Strokes2GM : public skiagm::GM { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 273 | SkPath fPath; |
caryclark | 63c684a | 2015-02-25 09:04:04 -0800 | [diff] [blame] | 274 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 275 | void onOnceBeforeDraw() override { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 276 | SkRandom rand; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 277 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 284 | |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 285 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 286 | SkString onShortName() override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 287 | return SkString("strokes_poly"); |
| 288 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 289 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 290 | SkISize onISize() override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 291 | return SkISize::Make(W, H*2); |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 292 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 293 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 294 | void onDraw(SkCanvas* canvas) override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 295 | canvas->drawColor(SK_ColorWHITE); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 296 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 297 | SkPaint paint; |
| 298 | paint.setStyle(SkPaint::kStroke_Style); |
| 299 | paint.setStrokeWidth(SkIntToScalar(9)/2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 300 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 301 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 309 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 310 | SkRandom rand; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 311 | for (int i = 0; i < N/2; i++) { |
| 312 | SkRect r; |
| 313 | rnd_rect(&r, &paint, rand); |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 314 | canvas->rotate(SkIntToScalar(15), SW/2, SH/2); |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 315 | canvas->drawPath(fPath, paint); |
| 316 | } |
| 317 | } |
| 318 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 319 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 320 | private: |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 321 | typedef skiagm::GM INHERITED; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | ////////////////////////////////////////////////////////////////////////////// |
| 325 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 326 | static SkRect inset(const SkRect& r) { |
| 327 | SkRect rr(r); |
| 328 | rr.inset(r.width()/10, r.height()/10); |
| 329 | return rr; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 330 | } |
| 331 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 332 | class 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 338 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 339 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 344 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 345 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 350 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 351 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 356 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 357 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 364 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 365 | 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 | |
| 373 | public: |
| 374 | Strokes3GM() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 375 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 376 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 377 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 378 | SkString onShortName() override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 379 | return SkString("strokes3"); |
| 380 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 381 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 382 | SkISize onISize() override { |
caryclark | 3760457 | 2015-02-23 06:51:04 -0800 | [diff] [blame] | 383 | return SkISize::Make(1500, 1500); |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 384 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 385 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 386 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 387 | 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); |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 393 | strokePaint.setColor(sk_tool_utils::color_to_565(0xFF4444FF)); |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 394 | |
| 395 | void (*procs[])(SkPath*, const SkRect&, SkString*) = { |
| 396 | make0, make1, make2, make3, make4, make5 |
| 397 | }; |
| 398 | |
caryclark | 3760457 | 2015-02-23 06:51:04 -0800 | [diff] [blame] | 399 | canvas->translate(SkIntToScalar(20), SkIntToScalar(80)); |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 400 | |
| 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 409 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 410 | 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 424 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 425 | private: |
| 426 | typedef skiagm::GM INHERITED; |
| 427 | }; |
| 428 | |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 429 | class Strokes4GM : public skiagm::GM { |
| 430 | public: |
| 431 | Strokes4GM() {} |
| 432 | |
| 433 | protected: |
| 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); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 447 | |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 448 | canvas->scale(1000, 1000); |
| 449 | canvas->drawCircle(0, 2, 1.97f, paint); |
| 450 | } |
| 451 | |
| 452 | private: |
| 453 | typedef skiagm::GM INHERITED; |
| 454 | }; |
| 455 | |
caryclark | 45398df | 2015-08-25 13:19:06 -0700 | [diff] [blame] | 456 | // Test stroking for curves that produce degenerate tangents when t is 0 or 1 (see bug 4191) |
| 457 | class Strokes5GM : public skiagm::GM { |
| 458 | public: |
| 459 | Strokes5GM() {} |
| 460 | |
| 461 | protected: |
| 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 | |
| 506 | private: |
| 507 | typedef skiagm::GM INHERITED; |
| 508 | }; |
| 509 | |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 510 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 511 | ////////////////////////////////////////////////////////////////////////////// |
| 512 | |
scroggo | 96f16e8 | 2015-12-10 13:31:59 -0800 | [diff] [blame] | 513 | DEF_GM( return new StrokesGM; ) |
| 514 | DEF_GM( return new Strokes2GM; ) |
| 515 | DEF_GM( return new Strokes3GM; ) |
| 516 | DEF_GM( return new Strokes4GM; ) |
| 517 | DEF_GM( return new Strokes5GM; ) |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 518 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 519 | DEF_GM( return new ZeroLenStrokesGM; ) |
caryclark | 950305e | 2015-10-26 08:17:04 -0700 | [diff] [blame] | 520 | DEF_GM( return new TeenyStrokesGM; ) |