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

Side by Side Diff: gm/gradients_2pt_conical.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/gradients.cpp ('k') | gm/gradients_no_texture.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 2014 Google Inc. 2 * Copyright 2014 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 "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 10
11 namespace skiagm { 11 namespace skiagm {
12 12
13 struct GradData { 13 struct GradData {
14 int fCount; 14 int fCount;
15 const SkColor* fColors; 15 const SkColor* fColors;
16 const SkScalar* fPos; 16 const SkScalar* fPos;
17 }; 17 };
18 18
19 static const SkColor gColors[] = { 19 constexpr SkColor gColors[] = {
20 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK 20 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
21 }; 21 };
22 static const SkScalar gPos0[] = { 0, SK_Scalar1 }; 22 constexpr SkScalar gPos0[] = { 0, SK_Scalar1 };
23 static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 }; 23 constexpr SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
24 static const SkScalar gPos2[] = { 24 constexpr SkScalar gPos2[] = {
25 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1 25 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
26 }; 26 };
27 27
28 static const SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f}; 28 constexpr SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f};
29 static const SkColor gColorClamp[] = { 29 constexpr SkColor gColorClamp[] = {
30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE 30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
31 }; 31 };
32 32
33 static const GradData gGradData[] = { 33 constexpr GradData gGradData[] = {
34 { 2, gColors, gPos0 }, 34 { 2, gColors, gPos0 },
35 { 2, gColors, gPos1 }, 35 { 2, gColors, gPos1 },
36 { 5, gColors, gPos2 }, 36 { 5, gColors, gPos2 },
37 { 4, gColorClamp, gPosClamp } 37 { 4, gColorClamp, gPosClamp }
38 }; 38 };
39 39
40 static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data, 40 static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
41 SkShader::TileMode tm, const SkMatrix & localMatrix) { 41 SkShader::TileMode tm, const SkMatrix & localMatrix) {
42 SkPoint center0, center1; 42 SkPoint center0, center1;
43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; 43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 243 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
244 return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f , 244 return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f ,
245 center0, (pts[1].fX - pts[0]. fX) / 2, 245 center0, (pts[1].fX - pts[0]. fX) / 2,
246 data.fColors, data.fPos, data .fCount, tm, 246 data.fColors, data.fPos, data .fCount, tm,
247 0, &localMatrix); 247 0, &localMatrix);
248 } 248 }
249 249
250 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, 250 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
251 SkShader::TileMode tm, const SkMatrix& loca lMatrix); 251 SkShader::TileMode tm, const SkMatrix& loca lMatrix);
252 252
253 static const GradMaker gGradMakersOutside[] = { 253 constexpr GradMaker gGradMakersOutside[] = {
254 Make2ConicalOutside, Make2ConicalOutsideFlip, 254 Make2ConicalOutside, Make2ConicalOutsideFlip,
255 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside 255 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside
256 }; 256 };
257 257
258 static const GradMaker gGradMakersInside[] = { 258 constexpr GradMaker gGradMakersInside[] = {
259 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, 259 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
260 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, 260 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
261 }; 261 };
262 262
263 static const GradMaker gGradMakersEdgeCases[] = { 263 constexpr GradMaker gGradMakersEdgeCases[] = {
264 Make2ConicalEdgeX, Make2ConicalEdgeY, 264 Make2ConicalEdgeX, Make2ConicalEdgeY,
265 Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY, 265 Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY,
266 Make2ConicalTouchX, Make2ConicalTouchY, 266 Make2ConicalTouchX, Make2ConicalTouchY,
267 Make2ConicalInsideSmallRad 267 Make2ConicalInsideSmallRad
268 }; 268 };
269 269
270 270
271 static const struct { 271 constexpr struct {
272 const GradMaker* fMaker; 272 const GradMaker* fMaker;
273 const int fCount; 273 const int fCount;
274 const char* fName; 274 const char* fName;
275 } gGradCases[] = { 275 } gGradCases[] = {
276 { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" } , 276 { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" } ,
277 { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" }, 277 { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" },
278 { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" }, 278 { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" },
279 }; 279 };
280 280
281 enum GradCaseType { // these must match the order in gGradCases 281 enum GradCaseType { // these must match the order in gGradCases
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); ) 351 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); )
352 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); ) 352 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); )
353 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); ) 353 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); )
354 354
355 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); ) 355 DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); )
356 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); ) 356 DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); )
357 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); ) 357 DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); )
358 358
359 } 359 }
OLDNEW
« no previous file with comments | « gm/gradients.cpp ('k') | gm/gradients_no_texture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698