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

Side by Side Diff: gm/shadertext3.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/shadertext2.cpp ('k') | gm/shadowmaps.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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
11 11
12 namespace skiagm { 12 namespace skiagm {
13 13
14 static void makebm(SkBitmap* bm, int w, int h) { 14 static void makebm(SkBitmap* bm, int w, int h) {
15 bm->allocN32Pixels(w, h); 15 bm->allocN32Pixels(w, h);
16 bm->eraseColor(SK_ColorTRANSPARENT); 16 bm->eraseColor(SK_ColorTRANSPARENT);
17 17
18 SkCanvas canvas(*bm); 18 SkCanvas canvas(*bm);
19 SkScalar s = SkIntToScalar(SkMin32(w, h)); 19 SkScalar s = SkIntToScalar(SkMin32(w, h));
20 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; 20 const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
21 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } }; 21 const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } };
22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 22 const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
23 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; 23 const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
24 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 }; 24 const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 };
25 25
26 26
27 SkPaint paint; 27 SkPaint paint;
28 28
29 paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos, 29 paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode)); 30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
31 canvas.drawPaint(paint); 31 canvas.drawPaint(paint);
32 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos, 32 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode)); 33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
34 canvas.drawPaint(paint); 34 canvas.drawPaint(paint);
35 } 35 }
36 36
37 /////////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////////
38 38
39 struct LabeledMatrix { 39 struct LabeledMatrix {
40 SkMatrix fMatrix; 40 SkMatrix fMatrix;
41 const char* fLabel; 41 const char* fLabel;
42 }; 42 };
43 43
44 static const char kText[] = "B"; 44 constexpr char kText[] = "B";
45 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; 45 constexpr int kTextLen = SK_ARRAY_COUNT(kText) - 1;
46 static const int kPointSize = 300; 46 constexpr int kPointSize = 300;
47 47
48 class ShaderText3GM : public GM { 48 class ShaderText3GM : public GM {
49 public: 49 public:
50 ShaderText3GM() { 50 ShaderText3GM() {
51 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); 51 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
52 } 52 }
53 53
54 protected: 54 protected:
55 55
56 SkString onShortName() override { 56 SkString onShortName() override {
(...skipping 19 matching lines...) Expand all
76 sk_tool_utils::set_portable_typeface(&outlinePaint); 76 sk_tool_utils::set_portable_typeface(&outlinePaint);
77 outlinePaint.setTextSize(SkIntToScalar(kPointSize)); 77 outlinePaint.setTextSize(SkIntToScalar(kPointSize));
78 outlinePaint.setStyle(SkPaint::kStroke_Style); 78 outlinePaint.setStyle(SkPaint::kStroke_Style);
79 outlinePaint.setStrokeWidth(0.f); 79 outlinePaint.setStrokeWidth(0.f);
80 80
81 canvas->translate(15.f, 15.f); 81 canvas->translate(15.f, 15.f);
82 82
83 // draw glyphs scaled up 83 // draw glyphs scaled up
84 canvas->scale(2.f, 2.f); 84 canvas->scale(2.f, 2.f);
85 85
86 static const SkShader::TileMode kTileModes[] = { 86 constexpr SkShader::TileMode kTileModes[] = {
87 SkShader::kRepeat_TileMode, 87 SkShader::kRepeat_TileMode,
88 SkShader::kMirror_TileMode, 88 SkShader::kMirror_TileMode,
89 }; 89 };
90 90
91 // position the baseline of the first run 91 // position the baseline of the first run
92 canvas->translate(0.f, 0.75f * kPointSize); 92 canvas->translate(0.f, 0.75f * kPointSize);
93 93
94 canvas->save(); 94 canvas->save();
95 int i = 0; 95 int i = 0;
96 for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) { 96 for (size_t tm0 = 0; tm0 < SK_ARRAY_COUNT(kTileModes); ++tm0) {
(...skipping 29 matching lines...) Expand all
126 private: 126 private:
127 SkBitmap fBmp; 127 SkBitmap fBmp;
128 typedef GM INHERITED; 128 typedef GM INHERITED;
129 }; 129 };
130 130
131 /////////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////////
132 132
133 static GM* MyFactory(void*) { return new ShaderText3GM; } 133 static GM* MyFactory(void*) { return new ShaderText3GM; }
134 static GMRegistry reg(MyFactory); 134 static GMRegistry reg(MyFactory);
135 } 135 }
OLDNEW
« no previous file with comments | « gm/shadertext2.cpp ('k') | gm/shadowmaps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698