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

Side by Side Diff: gm/shadertext2.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/shadertext.cpp ('k') | gm/shadertext3.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 #include "gm.h" 7 #include "gm.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
11 11
12 static void makebm(SkBitmap* bm, int w, int h) { 12 static void makebm(SkBitmap* bm, int w, int h) {
13 bm->allocN32Pixels(w, h); 13 bm->allocN32Pixels(w, h);
14 bm->eraseColor(SK_ColorTRANSPARENT); 14 bm->eraseColor(SK_ColorTRANSPARENT);
15 15
16 SkCanvas canvas(*bm); 16 SkCanvas canvas(*bm);
17 SkScalar s = SkIntToScalar(SkMin32(w, h)); 17 SkScalar s = SkIntToScalar(SkMin32(w, h));
18 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; 18 const SkPoint kPts0[] = { { 0, 0 }, { s, s } };
19 static const SkPoint kPts1[] = { { s, 0 }, { 0, s } }; 19 const SkPoint kPts1[] = { { s, 0 }, { 0, s } };
20 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 20 const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
21 static const SkColor kColors0[] = {0x40FF00FF, 0xF0FFFF00, 0x4000FFFF }; 21 const SkColor kColors0[] = {0x40FF00FF, 0xF0FFFF00, 0x4000FFFF };
22 static const SkColor kColors1[] = {0xF0FF00FF, 0x80FFFF00, 0xF000FFFF }; 22 const SkColor kColors1[] = {0xF0FF00FF, 0x80FFFF00, 0xF000FFFF };
23 23
24 24
25 SkPaint paint; 25 SkPaint paint;
26 26
27 paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos, 27 paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
28 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode)); 28 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
29 canvas.drawPaint(paint); 29 canvas.drawPaint(paint);
30 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos, 30 paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
31 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode)); 31 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
32 canvas.drawPaint(paint); 32 canvas.drawPaint(paint);
33 } 33 }
34 34
35 /////////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////////
36 36
37 struct LabeledMatrix { 37 struct LabeledMatrix {
38 SkMatrix fMatrix; 38 SkMatrix fMatrix;
39 const char* fLabel; 39 const char* fLabel;
40 }; 40 };
41 41
42 DEF_SIMPLE_GM_BG(shadertext2, canvas, 1800, 900, 42 DEF_SIMPLE_GM_BG(shadertext2, canvas, 1800, 900,
43 sk_tool_utils::color_to_565(0xFFDDDDDD)) { 43 sk_tool_utils::color_to_565(0xFFDDDDDD)) {
44 static const char kText[] = "SKIA"; 44 constexpr char kText[] = "SKIA";
45 static const int kTextLen = SK_ARRAY_COUNT(kText) - 1; 45 constexpr int kTextLen = SK_ARRAY_COUNT(kText) - 1;
46 static const int kPointSize = 55; 46 constexpr int kPointSize = 55;
47 47
48 SkTDArray<LabeledMatrix> matrices; 48 SkTDArray<LabeledMatrix> matrices;
49 matrices.append()->fMatrix.reset(); 49 matrices.append()->fMatrix.reset();
50 matrices.top().fLabel = "Identity"; 50 matrices.top().fLabel = "Identity";
51 matrices.append()->fMatrix.setScale(1.2f, 0.8f); 51 matrices.append()->fMatrix.setScale(1.2f, 0.8f);
52 matrices.top().fLabel = "Scale"; 52 matrices.top().fLabel = "Scale";
53 matrices.append()->fMatrix.setRotate(10.f); 53 matrices.append()->fMatrix.setRotate(10.f);
54 matrices.top().fLabel = "Rotate"; 54 matrices.top().fLabel = "Rotate";
55 matrices.append()->fMatrix.reset(); 55 matrices.append()->fMatrix.reset();
56 matrices.top().fMatrix.setPerspX(-0.0015f); 56 matrices.top().fMatrix.setPerspX(-0.0015f);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 SkPaint labelPaint; 98 SkPaint labelPaint;
99 labelPaint.setColor(0xff000000); 99 labelPaint.setColor(0xff000000);
100 labelPaint.setAntiAlias(true); 100 labelPaint.setAntiAlias(true);
101 sk_tool_utils::set_portable_typeface(&labelPaint); 101 sk_tool_utils::set_portable_typeface(&labelPaint);
102 labelPaint.setTextSize(12.f); 102 labelPaint.setTextSize(12.f);
103 103
104 canvas->translate(15.f, 15.f); 104 canvas->translate(15.f, 15.f);
105 canvas->drawBitmap(bmp, 0, 0); 105 canvas->drawBitmap(bmp, 0, 0);
106 canvas->translate(0, bmp.height() + labelPaint.getTextSize() + 15.f); 106 canvas->translate(0, bmp.height() + labelPaint.getTextSize() + 15.f);
107 107
108 static const char kLabelLabel[] = "localM / canvasM"; 108 constexpr char kLabelLabel[] = "localM / canvasM";
109 canvas->drawText(kLabelLabel, strlen(kLabelLabel), 0, 0, labelPaint); 109 canvas->drawText(kLabelLabel, strlen(kLabelLabel), 0, 0, labelPaint);
110 canvas->translate(0, 15.f); 110 canvas->translate(0, 15.f);
111 111
112 canvas->save(); 112 canvas->save();
113 SkScalar maxLabelW = 0; 113 SkScalar maxLabelW = 0;
114 canvas->translate(0, kPadY / 2 + kPointSize); 114 canvas->translate(0, kPadY / 2 + kPointSize);
115 for (int lm = 0; lm < localMatrices.count(); ++lm) { 115 for (int lm = 0; lm < localMatrices.count(); ++lm) {
116 canvas->drawText(matrices[lm].fLabel, strlen(matrices[lm].fLabel), 116 canvas->drawText(matrices[lm].fLabel, strlen(matrices[lm].fLabel),
117 0, labelPaint.getTextSize() - 1, labelPaint); 117 0, labelPaint.getTextSize() - 1, labelPaint);
118 SkScalar labelW = labelPaint.measureText(matrices[lm].fLabel, 118 SkScalar labelW = labelPaint.measureText(matrices[lm].fLabel,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 stroke.setStyle(SkPaint::kStroke_Style); 165 stroke.setStyle(SkPaint::kStroke_Style);
166 canvas->translate(0.f, kPointSize + kPadY); 166 canvas->translate(0.f, kPointSize + kPadY);
167 columnH += kPointSize + kPadY; 167 columnH += kPointSize + kPadY;
168 } 168 }
169 canvas->restore(); 169 canvas->restore();
170 canvas->translate(w + kPadX, 0.f); 170 canvas->translate(w + kPadX, 0.f);
171 } 171 }
172 if (0 == s) { 172 if (0 == s) {
173 canvas->drawLine(0.f, -kPadY, 0.f, columnH + kPadY, outlinePaint ); 173 canvas->drawLine(0.f, -kPadY, 0.f, columnH + kPadY, outlinePaint );
174 canvas->translate(kPadX / 2, 0.f); 174 canvas->translate(kPadX / 2, 0.f);
175 static const char kFillLabel[] = "Filled"; 175 constexpr char kFillLabel[] = "Filled";
176 static const char kStrokeLabel[] = "Stroked"; 176 constexpr char kStrokeLabel[] = "Stroked";
177 SkScalar y = columnH + kPadY / 2; 177 SkScalar y = columnH + kPadY / 2;
178 SkScalar fillX = -outlinePaint.measureText(kFillLabel, strlen(kF illLabel)) - kPadX; 178 SkScalar fillX = -outlinePaint.measureText(kFillLabel, strlen(kF illLabel)) - kPadX;
179 SkScalar strokeX = kPadX; 179 SkScalar strokeX = kPadX;
180 canvas->drawText(kFillLabel, strlen(kFillLabel), fillX, y, label Paint); 180 canvas->drawText(kFillLabel, strlen(kFillLabel), fillX, y, label Paint);
181 canvas->drawText(kStrokeLabel, strlen(kStrokeLabel), strokeX, y, labelPaint); 181 canvas->drawText(kStrokeLabel, strlen(kStrokeLabel), strokeX, y, labelPaint);
182 } 182 }
183 } 183 }
184 } 184 }
OLDNEW
« no previous file with comments | « gm/shadertext.cpp ('k') | gm/shadertext3.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698