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

Side by Side Diff: gm/conicpaths.cpp

Issue 815143003: fix conic gm to have fixed wrapping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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 | no next file » | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkTArray.h" 10 #include "SkTArray.h"
11 11
12 namespace skiagm { 12 class ConicPathsGM : public skiagm::GM {
13
14 class ConicPathsGM : public GM {
15 protected: 13 protected:
16 14
17 virtual SkString onShortName() SK_OVERRIDE { 15 SkString onShortName() SK_OVERRIDE {
18 return SkString("conicpaths"); 16 return SkString("conicpaths");
19 } 17 }
20 18
21 virtual SkISize onISize() SK_OVERRIDE { 19 SkISize onISize() SK_OVERRIDE {
22 return SkISize::Make(1000, 1000); 20 return SkISize::Make(950, 1000);
23 } 21 }
24 22
25 virtual void onOnceBeforeDraw() SK_OVERRIDE { 23 void onOnceBeforeDraw() SK_OVERRIDE {
26 { 24 {
25 const SkScalar w = SkScalarSqrt(2)/2;
27 SkPath* conicCirlce = &fPaths.push_back(); 26 SkPath* conicCirlce = &fPaths.push_back();
28 conicCirlce->moveTo(0, -0); 27 conicCirlce->moveTo(0, -0);
29 conicCirlce->conicTo(SkIntToScalar(0), SkIntToScalar(50), 28 conicCirlce->conicTo(0, 50, 50, 50, w);
30 SkIntToScalar(50), SkIntToScalar(50), 29 conicCirlce->rConicTo(50, 0, 50, -50, w);
31 SkScalarHalf(SkScalarSqrt(2))); 30 conicCirlce->rConicTo(0, -50, -50, -50, w);
32 conicCirlce->rConicTo(SkIntToScalar(50), SkIntToScalar(0), 31 conicCirlce->rConicTo(-50, 0, -50, 50, w);
33 SkIntToScalar(50), SkIntToScalar(-50),
34 SkScalarHalf(SkScalarSqrt(2)));
35 conicCirlce->rConicTo(SkIntToScalar(0), SkIntToScalar(-50),
36 SkIntToScalar(-50), SkIntToScalar(-50),
37 SkScalarHalf(SkScalarSqrt(2)));
38 conicCirlce->rConicTo(SkIntToScalar(-50), SkIntToScalar(0),
39 SkIntToScalar(-50), SkIntToScalar(50),
40 SkScalarHalf(SkScalarSqrt(2)));
41 32
42 } 33 }
43 { 34 {
44 SkPath* hyperbola = &fPaths.push_back(); 35 SkPath* hyperbola = &fPaths.push_back();
45 hyperbola->moveTo(0, -0); 36 hyperbola->moveTo(0, -0);
46 hyperbola->conicTo(SkIntToScalar(0), SkIntToScalar(100), 37 hyperbola->conicTo(0, 100, 100, 100, 2);
47 SkIntToScalar(100), SkIntToScalar(100),
48 SkIntToScalar(2));
49 } 38 }
50 { 39 {
51 SkPath* thinHyperbola = &fPaths.push_back(); 40 SkPath* thinHyperbola = &fPaths.push_back();
52 thinHyperbola->moveTo(0, -0); 41 thinHyperbola->moveTo(0, -0);
53 thinHyperbola->conicTo(SkIntToScalar(100), SkIntToScalar(100), 42 thinHyperbola->conicTo(100, 100, 5, 0, 2);
54 SkIntToScalar(5), SkIntToScalar(0),
55 SkIntToScalar(2));
56 } 43 }
57 { 44 {
58 SkPath* veryThinHyperbola = &fPaths.push_back(); 45 SkPath* veryThinHyperbola = &fPaths.push_back();
59 veryThinHyperbola->moveTo(0, -0); 46 veryThinHyperbola->moveTo(0, -0);
60 veryThinHyperbola->conicTo(SkIntToScalar(100), SkIntToScalar(100), 47 veryThinHyperbola->conicTo(100, 100, 1, 0, 2);
61 SkIntToScalar(1), SkIntToScalar(0),
62 SkIntToScalar(2));
63 } 48 }
64 { 49 {
65 SkPath* closedHyperbola = &fPaths.push_back(); 50 SkPath* closedHyperbola = &fPaths.push_back();
66 closedHyperbola->moveTo(0, -0); 51 closedHyperbola->moveTo(0, -0);
67 closedHyperbola->conicTo(SkIntToScalar(100), SkIntToScalar(100), 52 closedHyperbola->conicTo(100, 100, 0, 0, 2);
68 SkIntToScalar(0), SkIntToScalar(0),
69 SkIntToScalar(2));
70 } 53 }
71 { 54 {
72 // using 1 as weight defaults to using quadTo 55 // using 1 as weight defaults to using quadTo
73 SkPath* nearParabola = &fPaths.push_back(); 56 SkPath* nearParabola = &fPaths.push_back();
74 nearParabola->moveTo(0, -0); 57 nearParabola->moveTo(0, -0);
75 nearParabola->conicTo(SkIntToScalar(0), SkIntToScalar(100), 58 nearParabola->conicTo(0, 100, 100, 100, 0.999f);
76 SkIntToScalar(100), SkIntToScalar(100),
77 0.999f);
78 } 59 }
79 { 60 {
80 SkPath* thinEllipse = &fPaths.push_back(); 61 SkPath* thinEllipse = &fPaths.push_back();
81 thinEllipse->moveTo(0, -0); 62 thinEllipse->moveTo(0, -0);
82 thinEllipse->conicTo(SkIntToScalar(100), SkIntToScalar(100), 63 thinEllipse->conicTo(100, 100, 5, 0, SK_ScalarHalf);
83 SkIntToScalar(5), SkIntToScalar(0),
84 SK_ScalarHalf);
85 } 64 }
86 { 65 {
87 SkPath* veryThinEllipse = &fPaths.push_back(); 66 SkPath* veryThinEllipse = &fPaths.push_back();
88 veryThinEllipse->moveTo(0, -0); 67 veryThinEllipse->moveTo(0, -0);
89 veryThinEllipse->conicTo(SkIntToScalar(100), SkIntToScalar(100), 68 veryThinEllipse->conicTo(100, 100, 1, 0, SK_ScalarHalf);
90 SkIntToScalar(1), SkIntToScalar(0),
91 SK_ScalarHalf);
92 } 69 }
93 { 70 {
94 SkPath* closedEllipse = &fPaths.push_back(); 71 SkPath* closedEllipse = &fPaths.push_back();
95 closedEllipse->moveTo(0, -0); 72 closedEllipse->moveTo(0, -0);
96 closedEllipse->conicTo(SkIntToScalar(100), SkIntToScalar(100), 73 closedEllipse->conicTo(100, 100, 0, 0, SK_ScalarHalf);
97 SkIntToScalar(0), SkIntToScalar(0),
98 SK_ScalarHalf);
99 } 74 }
100 } 75 }
101 76
102 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 77 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
103 static const SkAlpha kAlphaValue[] = { 0xFF, 0x40 }; 78 const SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
104
105 enum {
106 kMargin = 15,
107 };
108 int wrapX = canvas->getDeviceSize().fWidth - kMargin;
109 79
110 SkScalar maxH = 0; 80 SkScalar maxH = 0;
111 canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin)); 81 const SkScalar margin = 15;
82 canvas->translate(margin, margin);
112 canvas->save(); 83 canvas->save();
113 84
114 SkScalar x = SkIntToScalar(kMargin); 85 SkScalar x = margin;
86 int counter = 0;
115 for (int p = 0; p < fPaths.count(); ++p) { 87 for (int p = 0; p < fPaths.count(); ++p) {
116 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) { 88 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
117 for (int aa = 0; aa < 2; ++aa) { 89 for (int aa = 0; aa < 2; ++aa) {
118 for (int fh = 0; fh < 2; ++fh) { 90 for (int fh = 0; fh < 2; ++fh) {
119 91
120 const SkRect& bounds = fPaths[p].getBounds(); 92 const SkRect& bounds = fPaths[p].getBounds();
121 93
122 if (x + bounds.width() > wrapX) {
123 canvas->restore();
124 canvas->translate(0, maxH + SkIntToScalar(kMargin));
125 canvas->save();
126 maxH = 0;
127 x = SkIntToScalar(kMargin);
128 }
129
130 SkPaint paint; 94 SkPaint paint;
131 paint.setARGB(kAlphaValue[a], 0, 0, 0); 95 paint.setARGB(kAlphaValue[a], 0, 0, 0);
132 paint.setAntiAlias(SkToBool(aa)); 96 paint.setAntiAlias(SkToBool(aa));
133 if (fh == 1) { 97 if (fh == 1) {
134 paint.setStyle(SkPaint::kStroke_Style); 98 paint.setStyle(SkPaint::kStroke_Style);
135 paint.setStrokeWidth(0); 99 paint.setStrokeWidth(0);
136 } else if (fh == 0) { 100 } else if (fh == 0) {
137 paint.setStyle(SkPaint::kFill_Style); 101 paint.setStyle(SkPaint::kFill_Style);
138 } 102 }
139 canvas->save(); 103 canvas->save();
140 canvas->translate(-bounds.fLeft, -bounds.fTop); 104 canvas->translate(-bounds.fLeft, -bounds.fTop);
141 canvas->drawPath(fPaths[p], paint); 105 canvas->drawPath(fPaths[p], paint);
142 canvas->restore(); 106 canvas->restore();
143 107
144 maxH = SkMaxScalar(maxH, bounds.height()); 108 maxH = SkMaxScalar(maxH, bounds.height());
145 109
146 SkScalar dx = bounds.width() + SkIntToScalar(kMargin); 110 SkScalar dx = bounds.width() + margin;
147 x += dx; 111 x += dx;
148 canvas->translate(dx, 0); 112 canvas->translate(dx, 0);
113
114 if (++counter == 8) {
115 counter = 0;
116
117 canvas->restore();
118 canvas->translate(0, maxH + margin);
119 canvas->save();
120 maxH = 0;
121 x = margin;
122 }
149 } 123 }
150 } 124 }
151 } 125 }
152 } 126 }
153 canvas->restore(); 127 canvas->restore();
154 } 128 }
155 129
156 virtual uint32_t onGetFlags() const SK_OVERRIDE { 130 uint32_t onGetFlags() const SK_OVERRIDE {
157 return kSkipPDF_Flag; 131 return kSkipPDF_Flag;
158 } 132 }
159 133
160 private: 134 private:
161 SkTArray<SkPath> fPaths; 135 SkTArray<SkPath> fPaths;
162 typedef GM INHERITED; 136 typedef skiagm::GM INHERITED;
163 }; 137 };
138 DEF_GM( return SkNEW(ConicPathsGM); )
164 139
165 ////////////////////////////////////////////////////////////////////////////// 140 //////////////////////////////////////////////////////////////////////////////
166 141
167 DEF_GM( return SkNEW(ConicPathsGM); )
168 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698