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

Side by Side Diff: gm/polygons.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/pixelsnap.cpp ('k') | gm/quadpaths.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 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 "SkPath.h" 10 #include "SkPath.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 paint->setColor(color); 91 paint->setColor(color);
92 if (40 == paint->getStrokeWidth()) { 92 if (40 == paint->getStrokeWidth()) {
93 paint->setAlpha(0xA0); 93 paint->setAlpha(0xA0);
94 } 94 }
95 } 95 }
96 96
97 void onDraw(SkCanvas* canvas) override { 97 void onDraw(SkCanvas* canvas) override {
98 // Stroke widths are: 98 // Stroke widths are:
99 // 0(may use hairline rendering), 10(common case for stroke-style) 99 // 0(may use hairline rendering), 10(common case for stroke-style)
100 // 40(>= geometry width/height, make the contour filled in fact) 100 // 40(>= geometry width/height, make the contour filled in fact)
101 static const int kStrokeWidths[] = {0, 10, 40}; 101 constexpr int kStrokeWidths[] = {0, 10, 40};
102 SkASSERT(kNumStrokeWidths == SK_ARRAY_COUNT(kStrokeWidths)); 102 SkASSERT(kNumStrokeWidths == SK_ARRAY_COUNT(kStrokeWidths));
103 103
104 static const SkPaint::Join kJoins[] = { 104 constexpr SkPaint::Join kJoins[] = {
105 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join 105 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
106 }; 106 };
107 SkASSERT(kNumJoins == SK_ARRAY_COUNT(kJoins)); 107 SkASSERT(kNumJoins == SK_ARRAY_COUNT(kJoins));
108 108
109 int counter = 0; 109 int counter = 0;
110 SkPaint paint; 110 SkPaint paint;
111 paint.setAntiAlias(true); 111 paint.setAntiAlias(true);
112 112
113 SkRandom rand; 113 SkRandom rand;
114 // For stroke style painter 114 // For stroke style painter
115 paint.setStyle(SkPaint::kStroke_Style); 115 paint.setStyle(SkPaint::kStroke_Style);
116 for (int join = 0; join < kNumJoins; ++join) { 116 for (int join = 0; join < kNumJoins; ++join) {
117 for (int width = 0; width < kNumStrokeWidths; ++width) { 117 for (int width = 0; width < kNumStrokeWidths; ++width) {
118 for (int i = 0; i < fPolygons.count(); ++i) { 118 for (int i = 0; i < fPolygons.count(); ++i) {
119 canvas->save(); 119 canvas->save();
120 SetLocation(canvas, counter, fPolygons.count()); 120 SetLocation(canvas, counter, fPolygons.count());
121 121
122 SetColorAndAlpha(&paint, &rand); 122 SetColorAndAlpha(&paint, &rand);
123 paint.setStrokeJoin(kJoins[join]); 123 paint.setStrokeJoin(kJoins[join]);
124 paint.setStrokeWidth(SkIntToScalar(kStrokeWidths[width])); 124 paint.setStrokeWidth(SkIntToScalar(kStrokeWidths[width]));
125 125
126 canvas->drawPath(fPolygons[i], paint); 126 canvas->drawPath(fPolygons[i], paint);
127 canvas->restore(); 127 canvas->restore();
128 ++counter; 128 ++counter;
129 } 129 }
130 } 130 }
131 } 131 }
132 132
133 // For stroke-and-fill style painter and fill style painter 133 // For stroke-and-fill style painter and fill style painter
134 static const SkPaint::Style kStyles[] = { 134 constexpr SkPaint::Style kStyles[] = {
135 SkPaint::kStrokeAndFill_Style, SkPaint::kFill_Style 135 SkPaint::kStrokeAndFill_Style, SkPaint::kFill_Style
136 }; 136 };
137 SkASSERT(kNumExtraStyles == SK_ARRAY_COUNT(kStyles)); 137 SkASSERT(kNumExtraStyles == SK_ARRAY_COUNT(kStyles));
138 138
139 paint.setStrokeJoin(SkPaint::kMiter_Join); 139 paint.setStrokeJoin(SkPaint::kMiter_Join);
140 paint.setStrokeWidth(SkIntToScalar(20)); 140 paint.setStrokeWidth(SkIntToScalar(20));
141 for (int style = 0; style < kNumExtraStyles; ++style) { 141 for (int style = 0; style < kNumExtraStyles; ++style) {
142 paint.setStyle(kStyles[style]); 142 paint.setStyle(kStyles[style]);
143 for (int i = 0; i < fPolygons.count(); ++i) { 143 for (int i = 0; i < fPolygons.count(); ++i) {
144 canvas->save(); 144 canvas->save();
145 SetLocation(canvas, counter, fPolygons.count()); 145 SetLocation(canvas, counter, fPolygons.count());
146 SetColorAndAlpha(&paint, &rand); 146 SetColorAndAlpha(&paint, &rand);
147 canvas->drawPath(fPolygons[i], paint); 147 canvas->drawPath(fPolygons[i], paint);
148 canvas->restore(); 148 canvas->restore();
149 ++counter; 149 ++counter;
150 } 150 }
151 } 151 }
152 } 152 }
153 153
154 private: 154 private:
155 static const int kNumPolygons = 8; 155 static constexpr int kNumPolygons = 8;
156 static const int kCellSize = 100; 156 static constexpr int kCellSize = 100;
157 static const int kNumExtraStyles = 2; 157 static constexpr int kNumExtraStyles = 2;
158 static const int kNumStrokeWidths = 3; 158 static constexpr int kNumStrokeWidths = 3;
159 static const int kNumJoins = 3; 159 static constexpr int kNumJoins = 3;
160 160
161 SkTArray<SkPath> fPolygons; 161 SkTArray<SkPath> fPolygons;
162 typedef GM INHERITED; 162 typedef GM INHERITED;
163 }; 163 };
164 164
165 ////////////////////////////////////////////////////////////////////////////// 165 //////////////////////////////////////////////////////////////////////////////
166 166
167 DEF_GM(return new PolygonsGM;) 167 DEF_GM(return new PolygonsGM;)
168 168
169 } 169 }
OLDNEW
« no previous file with comments | « gm/pixelsnap.cpp ('k') | gm/quadpaths.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698