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

Side by Side Diff: gm/gradients.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/gradient_matrix.cpp ('k') | gm/gradients_2pt_conical.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 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 "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 #include "SkLinearGradient.h" 10 #include "SkLinearGradient.h"
11 11
12 namespace skiagm { 12 namespace skiagm {
13 13
14 struct GradData { 14 struct GradData {
15 int fCount; 15 int fCount;
16 const SkColor* fColors; 16 const SkColor* fColors;
17 const SkScalar* fPos; 17 const SkScalar* fPos;
18 }; 18 };
19 19
20 static const SkColor gColors[] = { 20 constexpr SkColor gColors[] = {
21 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK 21 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
22 }; 22 };
23 static const SkScalar gPos0[] = { 0, SK_Scalar1 }; 23 constexpr SkScalar gPos0[] = { 0, SK_Scalar1 };
24 static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 }; 24 constexpr SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
25 static const SkScalar gPos2[] = { 25 constexpr SkScalar gPos2[] = {
26 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1 26 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
27 }; 27 };
28 28
29 static const SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f}; 29 constexpr SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f};
30 static const SkColor gColorClamp[] = { 30 constexpr SkColor gColorClamp[] = {
31 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE 31 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
32 }; 32 };
33 33
34 static const GradData gGradData[] = { 34 constexpr GradData gGradData[] = {
35 { 2, gColors, nullptr }, 35 { 2, gColors, nullptr },
36 { 2, gColors, gPos0 }, 36 { 2, gColors, gPos0 },
37 { 2, gColors, gPos1 }, 37 { 2, gColors, gPos1 },
38 { 5, gColors, nullptr }, 38 { 5, gColors, nullptr },
39 { 5, gColors, gPos2 }, 39 { 5, gColors, gPos2 },
40 { 4, gColorClamp, gPosClamp } 40 { 4, gColorClamp, gPosClamp }
41 }; 41 };
42 42
43 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, 43 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data,
44 SkShader::TileMode tm, const SkMatrix& localMa trix) { 44 SkShader::TileMode tm, const SkMatrix& localMa trix) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; 84 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
87 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radi us0, 87 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radi us0,
88 data.fColors, data.fPos, 88 data.fColors, data.fPos,
89 data.fCount, tm, 0, &localMatri x); 89 data.fCount, tm, 0, &localMatri x);
90 } 90 }
91 91
92 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, 92 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
93 SkShader::TileMode tm, const SkMatrix& loca lMatrix); 93 SkShader::TileMode tm, const SkMatrix& loca lMatrix);
94 static const GradMaker gGradMakers[] = { 94 constexpr GradMaker gGradMakers[] = {
95 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical 95 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical
96 }; 96 };
97 97
98 /////////////////////////////////////////////////////////////////////////////// 98 ///////////////////////////////////////////////////////////////////////////////
99 99
100 class GradientsGM : public GM { 100 class GradientsGM : public GM {
101 public: 101 public:
102 GradientsGM(bool dither) : fDither(dither) { 102 GradientsGM(bool dither) : fDither(dither) {
103 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); 103 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
104 } 104 }
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 canvas->drawRect(SkRect::MakeXYWH(0, 0, 500, 500), p); 786 canvas->drawRect(SkRect::MakeXYWH(0, 0, 500, 500), p);
787 } 787 }
788 788
789 DEF_SIMPLE_GM(gradient_many_stops, canvas, 500, 500) { 789 DEF_SIMPLE_GM(gradient_many_stops, canvas, 500, 500) {
790 draw_many_stops(canvas, 0); 790 draw_many_stops(canvas, 0);
791 } 791 }
792 792
793 DEF_SIMPLE_GM(gradient_many_stops_4f, canvas, 500, 500) { 793 DEF_SIMPLE_GM(gradient_many_stops_4f, canvas, 500, 500) {
794 draw_many_stops(canvas, SkLinearGradient::kForce4fContext_PrivateFlag); 794 draw_many_stops(canvas, SkLinearGradient::kForce4fContext_PrivateFlag);
795 } 795 }
OLDNEW
« no previous file with comments | « gm/gradient_matrix.cpp ('k') | gm/gradients_2pt_conical.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698