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" | |
13 | 11 |
14 #define W 400 | 12 #define W 400 |
15 #define H 400 | 13 #define H 400 |
16 #define N 50 | 14 #define N 50 |
17 | 15 |
18 static const SkScalar SW = SkIntToScalar(W); | 16 static const SkScalar SW = SkIntToScalar(W); |
19 static const SkScalar SH = SkIntToScalar(H); | 17 static const SkScalar SH = SkIntToScalar(H); |
20 | 18 |
21 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { | 19 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { |
22 SkScalar x = rand.nextUScalar1() * W; | 20 SkScalar x = rand.nextUScalar1() * W; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 SkRect r; | 65 SkRect r; |
68 rnd_rect(&r, &paint, rand); | 66 rnd_rect(&r, &paint, rand); |
69 canvas->drawOval(r, paint); | 67 canvas->drawOval(r, paint); |
70 rnd_rect(&r, &paint, rand); | 68 rnd_rect(&r, &paint, rand); |
71 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); | 69 canvas->drawRoundRect(r, r.width()/4, r.height()/4, paint); |
72 rnd_rect(&r, &paint, rand); | 70 rnd_rect(&r, &paint, rand); |
73 } | 71 } |
74 } | 72 } |
75 } | 73 } |
76 | 74 |
77 private: | |
78 typedef skiagm::GM INHERITED; | |
79 }; | |
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[4]; | |
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 for (int i = 0; i < 3; ++i) { | |
95 fRefPath[0].addCircle(i * 10.f, 0, 5); | |
96 fRefPath[1].addCircle(i * 10.f, 0, 10); | |
97 fRefPath[2].addRect(i * 10.f - 4, -2, i * 10.f + 4, 6); | |
98 fRefPath[3].addRect(i * 10.f - 10, -10, i * 10.f + 10, 10); | |
99 } | |
100 } | |
101 | |
102 SkString onShortName() override { | |
103 return SkString("zeroPath"); | |
104 } | |
105 | |
106 SkISize onISize() override { | |
107 return SkISize::Make(W, H*2); | |
108 } | |
109 | |
110 void onDraw(SkCanvas* canvas) override { | |
111 SkPaint fillPaint, strokePaint, dashPaint; | |
112 fillPaint.setAntiAlias(true); | |
113 strokePaint = fillPaint; | |
114 strokePaint.setStyle(SkPaint::kStroke_Style); | |
115 for (int i = 0; i < 2; ++i) { | |
116 fillPaint.setAlpha(255); | |
117 strokePaint.setAlpha(255); | |
118 strokePaint.setStrokeWidth(i ? 8.f : 10.f); | |
119 strokePaint.setStrokeCap(i ? SkPaint::kSquare_Cap : SkPaint::kRound_
Cap); | |
120 canvas->save(); | |
121 canvas->translate(10 + i * 100.f, 10); | |
122 canvas->drawPath(fMoveHfPath, strokePaint); | |
123 canvas->translate(0, 20); | |
124 canvas->drawPath(fMoveZfPath, strokePaint); | |
125 dashPaint = strokePaint; | |
126 const SkScalar intervals[] = { 0, 10 }; | |
127 dashPaint.setPathEffect(SkDashPathEffect::Create(intervals, 2, 0))->
unref(); | |
128 SkPath fillPath; | |
129 dashPaint.getFillPath(fDashedfPath, &fillPath); | |
130 canvas->translate(0, 20); | |
131 canvas->drawPath(fDashedfPath, dashPaint); | |
132 canvas->translate(0, 20); | |
133 canvas->drawPath(fRefPath[i * 2], fillPaint); | |
134 strokePaint.setStrokeWidth(20); | |
135 strokePaint.setAlpha(127); | |
136 canvas->translate(0, 50); | |
137 canvas->drawPath(fMoveHfPath, strokePaint); | |
138 canvas->translate(0, 30); | |
139 canvas->drawPath(fMoveZfPath, strokePaint); | |
140 canvas->translate(0, 30); | |
141 fillPaint.setAlpha(127); | |
142 canvas->drawPath(fRefPath[1 + i * 2], fillPaint); | |
143 canvas->restore(); | |
144 } | |
145 } | |
146 | |
147 private: | 75 private: |
148 typedef skiagm::GM INHERITED; | 76 typedef skiagm::GM INHERITED; |
149 }; | 77 }; |
150 | 78 |
151 class Strokes2GM : public skiagm::GM { | 79 class Strokes2GM : public skiagm::GM { |
152 SkPath fPath; | 80 SkPath fPath; |
153 protected: | 81 protected: |
154 void onOnceBeforeDraw() override { | 82 void onOnceBeforeDraw() override { |
155 SkRandom rand; | 83 SkRandom rand; |
156 fPath.moveTo(0, 0); | 84 fPath.moveTo(0, 0); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 271 |
344 static skiagm::GM* F0(void*) { return new StrokesGM; } | 272 static skiagm::GM* F0(void*) { return new StrokesGM; } |
345 static skiagm::GM* F1(void*) { return new Strokes2GM; } | 273 static skiagm::GM* F1(void*) { return new Strokes2GM; } |
346 static skiagm::GM* F2(void*) { return new Strokes3GM; } | 274 static skiagm::GM* F2(void*) { return new Strokes3GM; } |
347 static skiagm::GM* F3(void*) { return new Strokes4GM; } | 275 static skiagm::GM* F3(void*) { return new Strokes4GM; } |
348 | 276 |
349 static skiagm::GMRegistry R0(F0); | 277 static skiagm::GMRegistry R0(F0); |
350 static skiagm::GMRegistry R1(F1); | 278 static skiagm::GMRegistry R1(F1); |
351 static skiagm::GMRegistry R2(F2); | 279 static skiagm::GMRegistry R2(F2); |
352 static skiagm::GMRegistry R3(F3); | 280 static skiagm::GMRegistry R3(F3); |
353 | |
354 DEF_GM(return SkNEW(ZeroLenStrokesGM);) | |
OLD | NEW |