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

Side by Side Diff: gm/drawminibitmaprect.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/drawlooper.cpp ('k') | gm/dstreadshuffle.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 2015 Google Inc. 2 * Copyright 2015 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 "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 SkCanvas* canvas = surface->getCanvas(); 23 SkCanvas* canvas = surface->getCanvas();
24 24
25 const SkScalar wScalar = SkIntToScalar(w); 25 const SkScalar wScalar = SkIntToScalar(w);
26 const SkScalar hScalar = SkIntToScalar(h); 26 const SkScalar hScalar = SkIntToScalar(h);
27 27
28 const SkPoint pt = { wScalar / 2, hScalar / 2 }; 28 const SkPoint pt = { wScalar / 2, hScalar / 2 };
29 29
30 const SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar); 30 const SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar);
31 31
32 static const SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW, 32 constexpr SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW,
33 SK_ColorGREEN, SK_ColorMAGENTA, 33 SK_ColorGREEN, SK_ColorMAGENTA,
34 SK_ColorBLUE, SK_ColorCYAN, 34 SK_ColorBLUE, SK_ColorCYAN,
35 SK_ColorRED}; 35 SK_ColorRED};
36 36
37 static const SkScalar pos[] = {0, 37 constexpr SkScalar pos[] = {0,
38 SK_Scalar1 / 6, 38 SK_Scalar1 / 6,
39 2 * SK_Scalar1 / 6, 39 2 * SK_Scalar1 / 6,
40 3 * SK_Scalar1 / 6, 40 3 * SK_Scalar1 / 6,
41 4 * SK_Scalar1 / 6, 41 4 * SK_Scalar1 / 6,
42 5 * SK_Scalar1 / 6, 42 5 * SK_Scalar1 / 6,
43 SK_Scalar1}; 43 SK_Scalar1};
44 44
45 SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(pos)); 45 SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(pos));
46 SkPaint paint; 46 SkPaint paint;
47 SkRect rect = SkRect::MakeWH(wScalar, hScalar); 47 SkRect rect = SkRect::MakeWH(wScalar, hScalar);
48 SkMatrix mat = SkMatrix::I(); 48 SkMatrix mat = SkMatrix::I();
49 for (int i = 0; i < 4; ++i) { 49 for (int i = 0; i < 4; ++i) {
50 paint.setShader(SkGradientShader::MakeRadial( 50 paint.setShader(SkGradientShader::MakeRadial(
51 pt, radius, 51 pt, radius,
52 colors, pos, 52 colors, pos,
53 SK_ARRAY_COUNT(colors), 53 SK_ARRAY_COUNT(colors),
54 SkShader::kRepeat_TileMode, 54 SkShader::kRepeat_TileMode,
55 0, &mat)); 55 0, &mat));
56 canvas->drawRect(rect, paint); 56 canvas->drawRect(rect, paint);
57 rect.inset(wScalar / 8, hScalar / 8); 57 rect.inset(wScalar / 8, hScalar / 8);
58 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); 58 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
59 } 59 }
60 return surface->makeImageSnapshot(); 60 return surface->makeImageSnapshot();
61 } 61 }
62 62
63 static const int gSize = 1024; 63 constexpr int gSize = 1024;
64 static const int gSurfaceSize = 2048; 64 constexpr int gSurfaceSize = 2048;
65 65
66 // This GM calls drawImageRect several times using the same texture. This is 66 // This GM calls drawImageRect several times using the same texture. This is
67 // intended to exercise batching of these calls. 67 // intended to exercise batching of these calls.
68 class DrawMiniBitmapRectGM : public skiagm::GM { 68 class DrawMiniBitmapRectGM : public skiagm::GM {
69 public: 69 public:
70 DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) { 70 DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) {
71 fName.set("drawminibitmaprect"); 71 fName.set("drawminibitmaprect");
72 if (fAA) { 72 if (fAA) {
73 fName.appendf("_aa"); 73 fName.appendf("_aa");
74 } 74 }
75 } 75 }
76 76
77 protected: 77 protected:
78 SkString onShortName() override { return fName; } 78 SkString onShortName() override { return fName; }
79 79
80 SkISize onISize() override { return SkISize::Make(gSize, gSize); } 80 SkISize onISize() override { return SkISize::Make(gSize, gSize); }
81 81
82 void onDraw(SkCanvas* canvas) override { 82 void onDraw(SkCanvas* canvas) override {
83 if (nullptr == fImage) { 83 if (nullptr == fImage) {
84 fImage = makebm(canvas, gSurfaceSize, gSurfaceSize); 84 fImage = makebm(canvas, gSurfaceSize, gSurfaceSize);
85 } 85 }
86 86
87 const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; 87 const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
88 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2); 88 const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2);
89 89
90 static const int kPadX = 30; 90 constexpr int kPadX = 30;
91 static const int kPadY = 40; 91 constexpr int kPadY = 40;
92 92
93 int rowCount = 0; 93 int rowCount = 0;
94 canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY)); 94 canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY));
95 canvas->save(); 95 canvas->save();
96 SkRandom random; 96 SkRandom random;
97 97
98 SkPaint paint; 98 SkPaint paint;
99 paint.setAntiAlias(fAA); 99 paint.setAntiAlias(fAA);
100 for (int w = 1; w <= kMaxSrcRectSize; w *= 3) { 100 for (int w = 1; w <= kMaxSrcRectSize; w *= 3) {
101 for (int h = 1; h <= kMaxSrcRectSize; h *= 3) { 101 for (int h = 1; h <= kMaxSrcRectSize; h *= 3) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 private: 134 private:
135 bool fAA; 135 bool fAA;
136 sk_sp<SkImage> fImage; 136 sk_sp<SkImage> fImage;
137 SkString fName; 137 SkString fName;
138 138
139 typedef skiagm::GM INHERITED; 139 typedef skiagm::GM INHERITED;
140 }; 140 };
141 141
142 DEF_GM( return new DrawMiniBitmapRectGM(true); ) 142 DEF_GM( return new DrawMiniBitmapRectGM(true); )
143 DEF_GM( return new DrawMiniBitmapRectGM(false); ) 143 DEF_GM( return new DrawMiniBitmapRectGM(false); )
OLDNEW
« no previous file with comments | « gm/drawlooper.cpp ('k') | gm/dstreadshuffle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698