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

Side by Side Diff: gm/circulararcs.cpp

Issue 2300623005: Replace a lot of 'static const' with 'constexpr' or 'const'. (Closed)
Patch Set: small msvc concession Created 4 years, 3 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 | « gm/bmpfilterqualityrepeat.cpp ('k') | gm/clippedbitmapshaders.cpp » ('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 2016 Google Inc. 2 * Copyright 2016 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 <functional> 8 #include <functional>
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDashPathEffect.h" 10 #include "SkDashPathEffect.h"
11 #include "gm.h" 11 #include "gm.h"
12 12
13 static constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f , 270.f}; 13 constexpr SkScalar kStarts[] = {0.f, 10.f, 30.f, 45.f, 90.f, 165.f, 180.f, 270.f };
14 static constexpr SkScalar kSweeps[] = {1.f, 45.f, 90.f, 130.f, 180.f, 184.f, 300 .f, 355.f}; 14 constexpr SkScalar kSweeps[] = {1.f, 45.f, 90.f, 130.f, 180.f, 184.f, 300.f, 355 .f};
15 static constexpr SkScalar kDiameter = 40.f; 15 constexpr SkScalar kDiameter = 40.f;
16 static constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter}; 16 constexpr SkRect kRect = {0.f, 0.f, kDiameter, kDiameter};
17 static constexpr int kW = 1000; 17 constexpr int kW = 1000;
18 static constexpr int kH = 1000; 18 constexpr int kH = 1000;
19 static constexpr SkScalar kPad = 20.f; 19 constexpr SkScalar kPad = 20.f;
20 20
21 void draw_arcs(SkCanvas* canvas, std::function<void(SkPaint*)> configureStyle) { 21 void draw_arcs(SkCanvas* canvas, std::function<void(SkPaint*)> configureStyle) {
22 // Draws grid of arcs with different start/sweep angles in red and their com plement arcs in 22 // Draws grid of arcs with different start/sweep angles in red and their com plement arcs in
23 // blue. 23 // blue.
24 auto drawGrid = [canvas, &configureStyle] (SkScalar x, SkScalar y, bool useC enter, bool aa) { 24 auto drawGrid = [canvas, &configureStyle] (SkScalar x, SkScalar y, bool useC enter, bool aa) {
25 SkPaint p0; 25 SkPaint p0;
26 p0.setColor(SK_ColorRED); 26 p0.setColor(SK_ColorRED);
27 p0.setAntiAlias(aa); 27 p0.setAntiAlias(aa);
28 // Set a reasonable stroke width that configureStyle can override. 28 // Set a reasonable stroke width that configureStyle can override.
29 p0.setStrokeWidth(15.f); 29 p0.setStrokeWidth(15.f);
(...skipping 13 matching lines...) Expand all
43 canvas->drawArc(kRect, start, sweep, useCenter, p0); 43 canvas->drawArc(kRect, start, sweep, useCenter, p0);
44 canvas->drawArc(kRect, start, -(360.f - sweep), useCenter, p1); 44 canvas->drawArc(kRect, start, -(360.f - sweep), useCenter, p1);
45 canvas->translate(kRect.width() + kPad, 0.f); 45 canvas->translate(kRect.width() + kPad, 0.f);
46 } 46 }
47 canvas->restore(); 47 canvas->restore();
48 canvas->translate(0, kRect.height() + kPad); 48 canvas->translate(0, kRect.height() + kPad);
49 } 49 }
50 canvas->restore(); 50 canvas->restore();
51 }; 51 };
52 // Draw a grids for combo of enabling/disabling aa and using center. 52 // Draw a grids for combo of enabling/disabling aa and using center.
53 static constexpr SkScalar kGridW = kW / 2.f; 53 constexpr SkScalar kGridW = kW / 2.f;
54 static constexpr SkScalar kGridH = kH / 2.f; 54 constexpr SkScalar kGridH = kH / 2.f;
55 drawGrid(0.f , 0.f , false, false); 55 drawGrid(0.f , 0.f , false, false);
56 drawGrid(kGridW, 0.f , true , false); 56 drawGrid(kGridW, 0.f , true , false);
57 drawGrid(0.f , kGridH, false, true ); 57 drawGrid(0.f , kGridH, false, true );
58 drawGrid(kGridW, kGridH, true , true ); 58 drawGrid(kGridW, kGridH, true , true );
59 // Draw separators between the grids. 59 // Draw separators between the grids.
60 SkPaint linePaint; 60 SkPaint linePaint;
61 linePaint.setAntiAlias(true); 61 linePaint.setAntiAlias(true);
62 linePaint.setColor(SK_ColorBLACK); 62 linePaint.setColor(SK_ColorBLACK);
63 canvas->drawLine(kGridW, 0.f , kGridW, SkIntToScalar(kH), lineP aint); 63 canvas->drawLine(kGridW, 0.f , kGridW, SkIntToScalar(kH), lineP aint);
64 canvas->drawLine(0.f , kGridH, SkIntToScalar(kW), kGridH, lineP aint); 64 canvas->drawLine(0.f , kGridH, SkIntToScalar(kW), kGridH, lineP aint);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 DEF_ARC_GM(stroke_and_fill_round) { 122 DEF_ARC_GM(stroke_and_fill_round) {
123 auto setStroke = [] (SkPaint* p) { 123 auto setStroke = [] (SkPaint* p) {
124 p->setStyle(SkPaint::kStrokeAndFill_Style); 124 p->setStyle(SkPaint::kStrokeAndFill_Style);
125 p->setStrokeCap(SkPaint::kRound_Cap); 125 p->setStrokeCap(SkPaint::kRound_Cap);
126 }; 126 };
127 draw_arcs(canvas, setStroke); 127 draw_arcs(canvas, setStroke);
128 } 128 }
129 129
130 DEF_SIMPLE_GM(circular_arcs_weird, canvas, 1000, 400) { 130 DEF_SIMPLE_GM(circular_arcs_weird, canvas, 1000, 400) {
131 static constexpr SkScalar kS = 50; 131 constexpr SkScalar kS = 50;
132 struct Arc { 132 struct Arc {
133 SkRect fOval; 133 SkRect fOval;
134 SkScalar fStart; 134 SkScalar fStart;
135 SkScalar fSweep; 135 SkScalar fSweep;
136 }; 136 };
137 static const Arc noDrawArcs[] = { 137 const Arc noDrawArcs[] = {
138 // no sweep 138 // no sweep
139 {SkRect::MakeWH(kS, kS), 0, 0}, 139 {SkRect::MakeWH(kS, kS), 0, 0},
140 // empty rect in x 140 // empty rect in x
141 {SkRect::MakeWH(-kS, kS), 0, 90}, 141 {SkRect::MakeWH(-kS, kS), 0, 90},
142 // empty rect in y 142 // empty rect in y
143 {SkRect::MakeWH(kS, -kS), 0, 90}, 143 {SkRect::MakeWH(kS, -kS), 0, 90},
144 // empty rect in x and y 144 // empty rect in x and y
145 {SkRect::MakeWH( 0, 0), 0, 90}, 145 {SkRect::MakeWH( 0, 0), 0, 90},
146 }; 146 };
147 static const Arc arcs[] = { 147 const Arc arcs[] = {
148 // large start 148 // large start
149 {SkRect::MakeWH(kS, kS), 810.f, 90.f}, 149 {SkRect::MakeWH(kS, kS), 810.f, 90.f},
150 // large negative start 150 // large negative start
151 {SkRect::MakeWH(kS, kS), -810.f, 90.f}, 151 {SkRect::MakeWH(kS, kS), -810.f, 90.f},
152 // exactly 360 sweep 152 // exactly 360 sweep
153 {SkRect::MakeWH(kS, kS), 0.f, 360.f}, 153 {SkRect::MakeWH(kS, kS), 0.f, 360.f},
154 // exactly -360 sweep 154 // exactly -360 sweep
155 {SkRect::MakeWH(kS, kS), 0.f, -360.f}, 155 {SkRect::MakeWH(kS, kS), 0.f, -360.f},
156 // exactly 540 sweep 156 // exactly 540 sweep
157 {SkRect::MakeWH(kS, kS), 0.f, 540.f}, 157 {SkRect::MakeWH(kS, kS), 0.f, 540.f},
(...skipping 10 matching lines...) Expand all
168 paints.back().setStrokeWidth(kS / 6.f); 168 paints.back().setStrokeWidth(kS / 6.f);
169 // hairline 169 // hairline
170 paints.push_back().setStyle(SkPaint::kStroke_Style); 170 paints.push_back().setStyle(SkPaint::kStroke_Style);
171 paints.back().setStrokeWidth(0.f); 171 paints.back().setStrokeWidth(0.f);
172 // stroke and fill 172 // stroke and fill
173 paints.push_back().setStyle(SkPaint::kStrokeAndFill_Style); 173 paints.push_back().setStyle(SkPaint::kStrokeAndFill_Style);
174 paints.back().setStrokeWidth(kS / 6.f); 174 paints.back().setStrokeWidth(kS / 6.f);
175 // dash effect 175 // dash effect
176 paints.push_back().setStyle(SkPaint::kStroke_Style); 176 paints.push_back().setStyle(SkPaint::kStroke_Style);
177 paints.back().setStrokeWidth(kS / 6.f); 177 paints.back().setStrokeWidth(kS / 6.f);
178 static constexpr SkScalar kDashIntervals[] = {kS / 15, 2 * kS / 15}; 178 constexpr SkScalar kDashIntervals[] = {kS / 15, 2 * kS / 15};
179 paints.back().setPathEffect(SkDashPathEffect::Make(kDashIntervals, 2, 0.f)); 179 paints.back().setPathEffect(SkDashPathEffect::Make(kDashIntervals, 2, 0.f));
180 180
181 canvas->translate(kPad, kPad); 181 canvas->translate(kPad, kPad);
182 // This loop should draw nothing. 182 // This loop should draw nothing.
183 for (auto arc : noDrawArcs) { 183 for (auto arc : noDrawArcs) {
184 for (auto paint : paints) { 184 for (auto paint : paints) {
185 paint.setAntiAlias(true); 185 paint.setAntiAlias(true);
186 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, false, paint); 186 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, false, paint);
187 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, true, paint); 187 canvas->drawArc(arc.fOval, arc.fStart, arc.fSweep, true, paint);
188 } 188 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 p0.setColor(SK_ColorRED); 226 p0.setColor(SK_ColorRED);
227 p0.setStrokeWidth(15.f); 227 p0.setStrokeWidth(15.f);
228 p0.setStyle(SkPaint::kStroke_Style); 228 p0.setStyle(SkPaint::kStroke_Style);
229 p0.setAlpha(100); 229 p0.setAlpha(100);
230 canvas->translate(20, 0); 230 canvas->translate(20, 0);
231 canvas->drawPath(path, p0); 231 canvas->drawPath(path, p0);
232 232
233 SkRect kRect = { 60, 0, 100, 40}; 233 SkRect kRect = { 60, 0, 100, 40};
234 canvas->drawArc(kRect, 45, 90, true, p0); 234 canvas->drawArc(kRect, 45, 90, true, p0);
235 } 235 }
OLDNEW
« no previous file with comments | « gm/bmpfilterqualityrepeat.cpp ('k') | gm/clippedbitmapshaders.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698