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" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 9 | #include "SkPath.h" |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 10 | #include "SkRandom.h" |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 11 | #include "SkDashPathEffect.h" |
| 12 | #include "SkParsePath.h" |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 13 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 14 | #define W 400 |
| 15 | #define H 400 |
| 16 | #define N 50 |
| 17 | |
| 18 | static const SkScalar SW = SkIntToScalar(W); |
| 19 | static const SkScalar SH = SkIntToScalar(H); |
| 20 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 21 | static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 22 | SkScalar x = rand.nextUScalar1() * W; |
| 23 | SkScalar y = rand.nextUScalar1() * H; |
| 24 | SkScalar w = rand.nextUScalar1() * (W >> 2); |
| 25 | SkScalar h = rand.nextUScalar1() * (H >> 2); |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 26 | SkScalar hoffset = rand.nextSScalar1(); |
| 27 | SkScalar woffset = rand.nextSScalar1(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 28 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 29 | r->set(x, y, x + w, y + h); |
epoger@google.com | 17b7894 | 2011-08-26 14:40:38 +0000 | [diff] [blame] | 30 | r->offset(-w/2 + woffset, -h/2 + hoffset); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 31 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 32 | paint->setColor(rand.nextU()); |
| 33 | paint->setAlpha(0xFF); |
| 34 | } |
| 35 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 36 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 37 | class StrokesGM : public skiagm::GM { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 38 | public: |
| 39 | StrokesGM() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 40 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 41 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 42 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | SkString onShortName() override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 44 | return SkString("strokes_round"); |
| 45 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 46 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 47 | SkISize onISize() override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 48 | return SkISize::Make(W, H*2); |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 49 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 50 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 51 | void onDraw(SkCanvas* canvas) override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 52 | SkPaint paint; |
| 53 | paint.setStyle(SkPaint::kStroke_Style); |
| 54 | paint.setStrokeWidth(SkIntToScalar(9)/2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 55 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 56 | for (int y = 0; y < 2; y++) { |
| 57 | paint.setAntiAlias(!!y); |
| 58 | SkAutoCanvasRestore acr(canvas, true); |
| 59 | canvas->translate(0, SH * y); |
| 60 | canvas->clipRect(SkRect::MakeLTRB( |
| 61 | SkIntToScalar(2), SkIntToScalar(2) |
| 62 | , SW - SkIntToScalar(2), SH - SkIntToScalar(2) |
| 63 | )); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 64 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 65 | SkRandom rand; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 66 | for (int i = 0; i < N; i++) { |
| 67 | SkRect r; |
| 68 | rnd_rect(&r, &paint, rand); |
| 69 | canvas->drawOval(r, paint); |
| 70 | rnd_rect(&r, &paint, rand); |
| 71 | canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); |
| 72 | rnd_rect(&r, &paint, rand); |
| 73 | } |
| 74 | } |
| 75 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 76 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 77 | private: |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 78 | typedef skiagm::GM INHERITED; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 81 | /* See |
| 82 | https://code.google.com/p/chromium/issues/detail?id=422974 and |
| 83 | http://jsfiddle.net/1xnku3sg/2/ |
| 84 | */ |
| 85 | class ZeroLenStrokesGM : public skiagm::GM { |
| 86 | SkPath fMoveHfPath, fMoveZfPath, fDashedfPath, fRefPath[4]; |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 87 | SkPath fCubicPath, fQuadPath, fLinePath; |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 88 | protected: |
| 89 | void onOnceBeforeDraw() override { |
| 90 | |
| 91 | SkAssertResult(SkParsePath::FromSVGString("M0,0h0M10,0h0M20,0h0", &fMoveHfPath)); |
| 92 | SkAssertResult(SkParsePath::FromSVGString("M0,0zM10,0zM20,0z", &fMoveZfPath)); |
| 93 | SkAssertResult(SkParsePath::FromSVGString("M0,0h25", &fDashedfPath)); |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 94 | SkAssertResult(SkParsePath::FromSVGString("M 0 0 C 0 0 0 0 0 0", &fCubicPath)); |
| 95 | SkAssertResult(SkParsePath::FromSVGString("M 0 0 Q 0 0 0 0", &fQuadPath)); |
| 96 | SkAssertResult(SkParsePath::FromSVGString("M 0 0 L 0 0", &fLinePath)); |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 97 | |
| 98 | for (int i = 0; i < 3; ++i) { |
| 99 | fRefPath[0].addCircle(i * 10.f, 0, 5); |
| 100 | fRefPath[1].addCircle(i * 10.f, 0, 10); |
| 101 | fRefPath[2].addRect(i * 10.f - 4, -2, i * 10.f + 4, 6); |
| 102 | fRefPath[3].addRect(i * 10.f - 10, -10, i * 10.f + 10, 10); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | SkString onShortName() override { |
| 107 | return SkString("zeroPath"); |
| 108 | } |
| 109 | |
| 110 | SkISize onISize() override { |
| 111 | return SkISize::Make(W, H*2); |
| 112 | } |
| 113 | |
| 114 | void onDraw(SkCanvas* canvas) override { |
| 115 | SkPaint fillPaint, strokePaint, dashPaint; |
| 116 | fillPaint.setAntiAlias(true); |
| 117 | strokePaint = fillPaint; |
| 118 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 119 | for (int i = 0; i < 2; ++i) { |
| 120 | fillPaint.setAlpha(255); |
| 121 | strokePaint.setAlpha(255); |
| 122 | strokePaint.setStrokeWidth(i ? 8.f : 10.f); |
| 123 | strokePaint.setStrokeCap(i ? SkPaint::kSquare_Cap : SkPaint::kRound_Cap); |
| 124 | canvas->save(); |
| 125 | canvas->translate(10 + i * 100.f, 10); |
| 126 | canvas->drawPath(fMoveHfPath, strokePaint); |
| 127 | canvas->translate(0, 20); |
| 128 | canvas->drawPath(fMoveZfPath, strokePaint); |
| 129 | dashPaint = strokePaint; |
| 130 | const SkScalar intervals[] = { 0, 10 }; |
| 131 | dashPaint.setPathEffect(SkDashPathEffect::Create(intervals, 2, 0))->unref(); |
| 132 | SkPath fillPath; |
| 133 | dashPaint.getFillPath(fDashedfPath, &fillPath); |
| 134 | canvas->translate(0, 20); |
| 135 | canvas->drawPath(fDashedfPath, dashPaint); |
| 136 | canvas->translate(0, 20); |
| 137 | canvas->drawPath(fRefPath[i * 2], fillPaint); |
| 138 | strokePaint.setStrokeWidth(20); |
| 139 | strokePaint.setAlpha(127); |
| 140 | canvas->translate(0, 50); |
| 141 | canvas->drawPath(fMoveHfPath, strokePaint); |
| 142 | canvas->translate(0, 30); |
| 143 | canvas->drawPath(fMoveZfPath, strokePaint); |
| 144 | canvas->translate(0, 30); |
| 145 | fillPaint.setAlpha(127); |
| 146 | canvas->drawPath(fRefPath[1 + i * 2], fillPaint); |
caryclark | 6651a32 | 2015-09-09 13:20:49 -0700 | [diff] [blame] | 147 | canvas->translate(0, 30); |
| 148 | canvas->drawPath(fCubicPath, strokePaint); |
| 149 | canvas->translate(0, 30); |
| 150 | canvas->drawPath(fQuadPath, strokePaint); |
| 151 | canvas->translate(0, 30); |
| 152 | canvas->drawPath(fLinePath, strokePaint); |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 153 | canvas->restore(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | typedef skiagm::GM INHERITED; |
| 159 | }; |
| 160 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 161 | class Strokes2GM : public skiagm::GM { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 162 | SkPath fPath; |
caryclark | 63c684a | 2015-02-25 09:04:04 -0800 | [diff] [blame] | 163 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 164 | void onOnceBeforeDraw() override { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 165 | SkRandom rand; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 166 | fPath.moveTo(0, 0); |
| 167 | for (int i = 0; i < 13; i++) { |
| 168 | SkScalar x = rand.nextUScalar1() * (W >> 1); |
| 169 | SkScalar y = rand.nextUScalar1() * (H >> 1); |
| 170 | fPath.lineTo(x, y); |
| 171 | } |
| 172 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 173 | |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 174 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 175 | SkString onShortName() override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 176 | return SkString("strokes_poly"); |
| 177 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 178 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 179 | SkISize onISize() override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 180 | return SkISize::Make(W, H*2); |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 181 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 182 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 183 | static void rotate(SkScalar angle, SkScalar px, SkScalar py, SkCanvas* canvas) { |
| 184 | SkMatrix matrix; |
| 185 | matrix.setRotate(angle, px, py); |
| 186 | canvas->concat(matrix); |
| 187 | } |
| 188 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 189 | void onDraw(SkCanvas* canvas) override { |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 190 | canvas->drawColor(SK_ColorWHITE); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 191 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 192 | SkPaint paint; |
| 193 | paint.setStyle(SkPaint::kStroke_Style); |
| 194 | paint.setStrokeWidth(SkIntToScalar(9)/2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 195 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 196 | for (int y = 0; y < 2; y++) { |
| 197 | paint.setAntiAlias(!!y); |
| 198 | SkAutoCanvasRestore acr(canvas, true); |
| 199 | canvas->translate(0, SH * y); |
| 200 | canvas->clipRect(SkRect::MakeLTRB(SkIntToScalar(2), |
| 201 | SkIntToScalar(2), |
| 202 | SW - SkIntToScalar(2), |
| 203 | SH - SkIntToScalar(2))); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 204 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 205 | SkRandom rand; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 206 | for (int i = 0; i < N/2; i++) { |
| 207 | SkRect r; |
| 208 | rnd_rect(&r, &paint, rand); |
| 209 | rotate(SkIntToScalar(15), SW/2, SH/2, canvas); |
| 210 | canvas->drawPath(fPath, paint); |
| 211 | } |
| 212 | } |
| 213 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 214 | |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 215 | private: |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 216 | typedef skiagm::GM INHERITED; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | ////////////////////////////////////////////////////////////////////////////// |
| 220 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 221 | static SkRect inset(const SkRect& r) { |
| 222 | SkRect rr(r); |
| 223 | rr.inset(r.width()/10, r.height()/10); |
| 224 | return rr; |
mike@reedtribe.org | f2c21cd | 2011-06-18 00:15:04 +0000 | [diff] [blame] | 225 | } |
| 226 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 227 | class Strokes3GM : public skiagm::GM { |
| 228 | static void make0(SkPath* path, const SkRect& bounds, SkString* title) { |
| 229 | path->addRect(bounds, SkPath::kCW_Direction); |
| 230 | path->addRect(inset(bounds), SkPath::kCW_Direction); |
| 231 | title->set("CW CW"); |
| 232 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 233 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 234 | static void make1(SkPath* path, const SkRect& bounds, SkString* title) { |
| 235 | path->addRect(bounds, SkPath::kCW_Direction); |
| 236 | path->addRect(inset(bounds), SkPath::kCCW_Direction); |
| 237 | title->set("CW CCW"); |
| 238 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 239 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 240 | static void make2(SkPath* path, const SkRect& bounds, SkString* title) { |
| 241 | path->addOval(bounds, SkPath::kCW_Direction); |
| 242 | path->addOval(inset(bounds), SkPath::kCW_Direction); |
| 243 | title->set("CW CW"); |
| 244 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 245 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 246 | static void make3(SkPath* path, const SkRect& bounds, SkString* title) { |
| 247 | path->addOval(bounds, SkPath::kCW_Direction); |
| 248 | path->addOval(inset(bounds), SkPath::kCCW_Direction); |
| 249 | title->set("CW CCW"); |
| 250 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 251 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 252 | static void make4(SkPath* path, const SkRect& bounds, SkString* title) { |
| 253 | path->addRect(bounds, SkPath::kCW_Direction); |
| 254 | SkRect r = bounds; |
| 255 | r.inset(bounds.width() / 10, -bounds.height() / 10); |
| 256 | path->addOval(r, SkPath::kCW_Direction); |
| 257 | title->set("CW CW"); |
| 258 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 259 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 260 | static void make5(SkPath* path, const SkRect& bounds, SkString* title) { |
| 261 | path->addRect(bounds, SkPath::kCW_Direction); |
| 262 | SkRect r = bounds; |
| 263 | r.inset(bounds.width() / 10, -bounds.height() / 10); |
| 264 | path->addOval(r, SkPath::kCCW_Direction); |
| 265 | title->set("CW CCW"); |
| 266 | } |
| 267 | |
| 268 | public: |
| 269 | Strokes3GM() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 270 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 271 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 272 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 273 | SkString onShortName() override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 274 | return SkString("strokes3"); |
| 275 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 276 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 277 | SkISize onISize() override { |
caryclark | 3760457 | 2015-02-23 06:51:04 -0800 | [diff] [blame] | 278 | return SkISize::Make(1500, 1500); |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 279 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 280 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 281 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 282 | SkPaint origPaint; |
| 283 | origPaint.setAntiAlias(true); |
| 284 | origPaint.setStyle(SkPaint::kStroke_Style); |
| 285 | SkPaint fillPaint(origPaint); |
| 286 | fillPaint.setColor(SK_ColorRED); |
| 287 | SkPaint strokePaint(origPaint); |
caryclark | 1259601 | 2015-07-29 05:27:47 -0700 | [diff] [blame] | 288 | strokePaint.setColor(sk_tool_utils::color_to_565(0xFF4444FF)); |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 289 | |
| 290 | void (*procs[])(SkPath*, const SkRect&, SkString*) = { |
| 291 | make0, make1, make2, make3, make4, make5 |
| 292 | }; |
| 293 | |
caryclark | 3760457 | 2015-02-23 06:51:04 -0800 | [diff] [blame] | 294 | canvas->translate(SkIntToScalar(20), SkIntToScalar(80)); |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 295 | |
| 296 | SkRect bounds = SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)); |
| 297 | SkScalar dx = bounds.width() * 4/3; |
| 298 | SkScalar dy = bounds.height() * 5; |
| 299 | |
| 300 | for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { |
| 301 | SkPath orig; |
| 302 | SkString str; |
| 303 | procs[i](&orig, bounds, &str); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 304 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 305 | canvas->save(); |
| 306 | for (int j = 0; j < 13; ++j) { |
| 307 | strokePaint.setStrokeWidth(SK_Scalar1 * j * j); |
| 308 | canvas->drawPath(orig, strokePaint); |
| 309 | canvas->drawPath(orig, origPaint); |
| 310 | SkPath fill; |
| 311 | strokePaint.getFillPath(orig, &fill); |
| 312 | canvas->drawPath(fill, fillPaint); |
| 313 | canvas->translate(dx + strokePaint.getStrokeWidth(), 0); |
| 314 | } |
| 315 | canvas->restore(); |
| 316 | canvas->translate(0, dy); |
| 317 | } |
| 318 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 319 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 320 | private: |
| 321 | typedef skiagm::GM INHERITED; |
| 322 | }; |
| 323 | |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 324 | class Strokes4GM : public skiagm::GM { |
| 325 | public: |
| 326 | Strokes4GM() {} |
| 327 | |
| 328 | protected: |
| 329 | |
| 330 | SkString onShortName() override { |
| 331 | return SkString("strokes_zoomed"); |
| 332 | } |
| 333 | |
| 334 | SkISize onISize() override { |
| 335 | return SkISize::Make(W, H*2); |
| 336 | } |
| 337 | |
| 338 | void onDraw(SkCanvas* canvas) override { |
| 339 | SkPaint paint; |
| 340 | paint.setStyle(SkPaint::kStroke_Style); |
| 341 | paint.setStrokeWidth(0.055f); |
| 342 | |
| 343 | canvas->scale(1000, 1000); |
| 344 | canvas->drawCircle(0, 2, 1.97f, paint); |
| 345 | } |
| 346 | |
| 347 | private: |
| 348 | typedef skiagm::GM INHERITED; |
| 349 | }; |
| 350 | |
caryclark | 45398df | 2015-08-25 13:19:06 -0700 | [diff] [blame] | 351 | // Test stroking for curves that produce degenerate tangents when t is 0 or 1 (see bug 4191) |
| 352 | class Strokes5GM : public skiagm::GM { |
| 353 | public: |
| 354 | Strokes5GM() {} |
| 355 | |
| 356 | protected: |
| 357 | |
| 358 | SkString onShortName() override { |
| 359 | return SkString("zero_control_stroke"); |
| 360 | } |
| 361 | |
| 362 | SkISize onISize() override { |
| 363 | return SkISize::Make(W, H*2); |
| 364 | } |
| 365 | |
| 366 | void onDraw(SkCanvas* canvas) override { |
| 367 | SkPaint p; |
| 368 | p.setColor(SK_ColorRED); |
| 369 | p.setAntiAlias(true); |
| 370 | p.setStyle(SkPaint::kStroke_Style); |
| 371 | p.setStrokeWidth(40); |
| 372 | p.setStrokeCap(SkPaint::kButt_Cap); |
| 373 | |
| 374 | SkPath path; |
| 375 | path.moveTo(157.474f,111.753f); |
| 376 | path.cubicTo(128.5f,111.5f,35.5f,29.5f,35.5f,29.5f); |
| 377 | canvas->drawPath(path, p); |
| 378 | path.reset(); |
| 379 | path.moveTo(250, 50); |
| 380 | path.quadTo(280, 80, 280, 80); |
| 381 | canvas->drawPath(path, p); |
| 382 | path.reset(); |
| 383 | path.moveTo(150, 50); |
| 384 | path.conicTo(180, 80, 180, 80, 0.707f); |
| 385 | canvas->drawPath(path, p); |
| 386 | |
| 387 | path.reset(); |
| 388 | path.moveTo(157.474f,311.753f); |
| 389 | path.cubicTo(157.474f,311.753f,85.5f,229.5f,35.5f,229.5f); |
| 390 | canvas->drawPath(path, p); |
| 391 | path.reset(); |
| 392 | path.moveTo(280, 250); |
| 393 | path.quadTo(280, 250, 310, 280); |
| 394 | canvas->drawPath(path, p); |
| 395 | path.reset(); |
| 396 | path.moveTo(180, 250); |
| 397 | path.conicTo(180, 250, 210, 280, 0.707f); |
| 398 | canvas->drawPath(path, p); |
| 399 | } |
| 400 | |
| 401 | private: |
| 402 | typedef skiagm::GM INHERITED; |
| 403 | }; |
| 404 | |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 405 | |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 406 | ////////////////////////////////////////////////////////////////////////////// |
| 407 | |
| 408 | static skiagm::GM* F0(void*) { return new StrokesGM; } |
| 409 | static skiagm::GM* F1(void*) { return new Strokes2GM; } |
| 410 | static skiagm::GM* F2(void*) { return new Strokes3GM; } |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 411 | static skiagm::GM* F3(void*) { return new Strokes4GM; } |
caryclark | 45398df | 2015-08-25 13:19:06 -0700 | [diff] [blame] | 412 | static skiagm::GM* F4(void*) { return new Strokes5GM; } |
reed@google.com | 4384fab | 2012-06-05 16:14:23 +0000 | [diff] [blame] | 413 | |
| 414 | static skiagm::GMRegistry R0(F0); |
| 415 | static skiagm::GMRegistry R1(F1); |
| 416 | static skiagm::GMRegistry R2(F2); |
caryclark | 612f70d | 2015-05-19 11:05:37 -0700 | [diff] [blame] | 417 | static skiagm::GMRegistry R3(F3); |
caryclark | 45398df | 2015-08-25 13:19:06 -0700 | [diff] [blame] | 418 | static skiagm::GMRegistry R4(F4); |
caryclark | 5cb00a9 | 2015-08-26 09:04:55 -0700 | [diff] [blame] | 419 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 420 | DEF_GM( return new ZeroLenStrokesGM; ) |