OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| 11 #include "SkDashPathEffect.h" |
| 12 #include "SkParsePath.h" |
11 | 13 |
12 #define W 400 | 14 #define W 400 |
13 #define H 400 | 15 #define H 400 |
14 #define N 50 | 16 #define N 50 |
15 | 17 |
16 static const SkScalar SW = SkIntToScalar(W); | 18 static const SkScalar SW = SkIntToScalar(W); |
17 static const SkScalar SH = SkIntToScalar(H); | 19 static const SkScalar SH = SkIntToScalar(H); |
18 | 20 |
19 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { | 21 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { |
20 SkScalar x = rand.nextUScalar1() * W; | 22 SkScalar x = rand.nextUScalar1() * W; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); | 71 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); |
70 rnd_rect(&r, &paint, rand); | 72 rnd_rect(&r, &paint, rand); |
71 } | 73 } |
72 } | 74 } |
73 } | 75 } |
74 | 76 |
75 private: | 77 private: |
76 typedef skiagm::GM INHERITED; | 78 typedef skiagm::GM INHERITED; |
77 }; | 79 }; |
78 | 80 |
| 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, fRef2Path; |
| 87 protected: |
| 88 void onOnceBeforeDraw() override { |
| 89 |
| 90 SkAssertResult(SkParsePath::FromSVGString("M0,0h0M10,0h0M20,0h0", &fMove
HfPath)); |
| 91 SkAssertResult(SkParsePath::FromSVGString("M0,0zM10,0zM20,0z", &fMoveZfP
ath)); |
| 92 SkAssertResult(SkParsePath::FromSVGString("M0,0h25", &fDashedfPath)); |
| 93 |
| 94 fRefPath.addCircle(0, 0, 5); |
| 95 fRefPath.addCircle(10, 0, 5); |
| 96 fRefPath.addCircle(20, 0, 5); |
| 97 |
| 98 fRef2Path.addCircle(0, 0, 10); |
| 99 fRef2Path.addCircle(10, 0, 10); |
| 100 fRef2Path.addCircle(20, 0, 10); |
| 101 } |
| 102 |
| 103 SkString onShortName() override { |
| 104 return SkString("zeroPath"); |
| 105 } |
| 106 |
| 107 SkISize onISize() override { |
| 108 return SkISize::Make(W, H*2); |
| 109 } |
| 110 |
| 111 void onDraw(SkCanvas* canvas) override { |
| 112 SkPaint fillPaint, strokePaint, dashPaint; |
| 113 fillPaint.setAntiAlias(true); |
| 114 strokePaint = fillPaint; |
| 115 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 116 strokePaint.setStrokeWidth(10); |
| 117 strokePaint.setStrokeCap(SkPaint::kRound_Cap); |
| 118 canvas->save(); |
| 119 canvas->translate(10, 10); |
| 120 canvas->drawPath(fMoveHfPath, strokePaint); |
| 121 canvas->translate(0, 20); |
| 122 canvas->drawPath(fMoveZfPath, strokePaint); |
| 123 dashPaint = strokePaint; |
| 124 const SkScalar intervals[] = { 0, 10 }; |
| 125 dashPaint.setPathEffect(SkDashPathEffect::Create(intervals, 2, 0))->unre
f(); |
| 126 SkPath fillPath; |
| 127 dashPaint.getFillPath(fDashedfPath, &fillPath); |
| 128 canvas->translate(0, 20); |
| 129 canvas->drawPath(fDashedfPath, dashPaint); |
| 130 canvas->translate(0, 20); |
| 131 canvas->drawPath(fRefPath, fillPaint); |
| 132 strokePaint.setStrokeWidth(20); |
| 133 strokePaint.setAlpha(127); |
| 134 canvas->translate(0, 50); |
| 135 canvas->drawPath(fMoveHfPath, strokePaint); |
| 136 canvas->translate(0, 30); |
| 137 canvas->drawPath(fMoveZfPath, strokePaint); |
| 138 canvas->translate(0, 30); |
| 139 fillPaint.setAlpha(127); |
| 140 canvas->drawPath(fRef2Path, fillPaint); |
| 141 canvas->restore(); |
| 142 } |
| 143 |
| 144 private: |
| 145 typedef skiagm::GM INHERITED; |
| 146 }; |
| 147 |
79 class Strokes2GM : public skiagm::GM { | 148 class Strokes2GM : public skiagm::GM { |
80 SkPath fPath; | 149 SkPath fPath; |
81 protected: | 150 protected: |
82 void onOnceBeforeDraw() override { | 151 void onOnceBeforeDraw() override { |
83 SkRandom rand; | 152 SkRandom rand; |
84 fPath.moveTo(0, 0); | 153 fPath.moveTo(0, 0); |
85 for (int i = 0; i < 13; i++) { | 154 for (int i = 0; i < 13; i++) { |
86 SkScalar x = rand.nextUScalar1() * (W >> 1); | 155 SkScalar x = rand.nextUScalar1() * (W >> 1); |
87 SkScalar y = rand.nextUScalar1() * (H >> 1); | 156 SkScalar y = rand.nextUScalar1() * (H >> 1); |
88 fPath.lineTo(x, y); | 157 fPath.lineTo(x, y); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 340 |
272 static skiagm::GM* F0(void*) { return new StrokesGM; } | 341 static skiagm::GM* F0(void*) { return new StrokesGM; } |
273 static skiagm::GM* F1(void*) { return new Strokes2GM; } | 342 static skiagm::GM* F1(void*) { return new Strokes2GM; } |
274 static skiagm::GM* F2(void*) { return new Strokes3GM; } | 343 static skiagm::GM* F2(void*) { return new Strokes3GM; } |
275 static skiagm::GM* F3(void*) { return new Strokes4GM; } | 344 static skiagm::GM* F3(void*) { return new Strokes4GM; } |
276 | 345 |
277 static skiagm::GMRegistry R0(F0); | 346 static skiagm::GMRegistry R0(F0); |
278 static skiagm::GMRegistry R1(F1); | 347 static skiagm::GMRegistry R1(F1); |
279 static skiagm::GMRegistry R2(F2); | 348 static skiagm::GMRegistry R2(F2); |
280 static skiagm::GMRegistry R3(F3); | 349 static skiagm::GMRegistry R3(F3); |
| 350 |
| 351 DEF_GM(return SkNEW(ZeroLenStrokesGM);) |
OLD | NEW |