Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(955)

Side by Side Diff: gm/strokes.cpp

Issue 1309753002: experiment with zero-length round capped line segments (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add overall documentation with paint caps Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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[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:
148 typedef skiagm::GM INHERITED;
149 };
150
79 class Strokes2GM : public skiagm::GM { 151 class Strokes2GM : public skiagm::GM {
80 SkPath fPath; 152 SkPath fPath;
81 protected: 153 protected:
82 void onOnceBeforeDraw() override { 154 void onOnceBeforeDraw() override {
83 SkRandom rand; 155 SkRandom rand;
84 fPath.moveTo(0, 0); 156 fPath.moveTo(0, 0);
85 for (int i = 0; i < 13; i++) { 157 for (int i = 0; i < 13; i++) {
86 SkScalar x = rand.nextUScalar1() * (W >> 1); 158 SkScalar x = rand.nextUScalar1() * (W >> 1);
87 SkScalar y = rand.nextUScalar1() * (H >> 1); 159 SkScalar y = rand.nextUScalar1() * (H >> 1);
88 fPath.lineTo(x, y); 160 fPath.lineTo(x, y);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 343
272 static skiagm::GM* F0(void*) { return new StrokesGM; } 344 static skiagm::GM* F0(void*) { return new StrokesGM; }
273 static skiagm::GM* F1(void*) { return new Strokes2GM; } 345 static skiagm::GM* F1(void*) { return new Strokes2GM; }
274 static skiagm::GM* F2(void*) { return new Strokes3GM; } 346 static skiagm::GM* F2(void*) { return new Strokes3GM; }
275 static skiagm::GM* F3(void*) { return new Strokes4GM; } 347 static skiagm::GM* F3(void*) { return new Strokes4GM; }
276 348
277 static skiagm::GMRegistry R0(F0); 349 static skiagm::GMRegistry R0(F0);
278 static skiagm::GMRegistry R1(F1); 350 static skiagm::GMRegistry R1(F1);
279 static skiagm::GMRegistry R2(F2); 351 static skiagm::GMRegistry R2(F2);
280 static skiagm::GMRegistry R3(F3); 352 static skiagm::GMRegistry R3(F3);
353
354 DEF_GM(return SkNEW(ZeroLenStrokesGM);)
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698