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

Side by Side Diff: gm/bleed.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/bitmaprect.cpp ('k') | gm/blurcircles.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 2013 Google Inc. 2 * Copyright 2013 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 "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 scanline[x] = outerRingColor; 100 scanline[x] = outerRingColor;
101 } 101 }
102 result->fBitmap.setImmutable(); 102 result->fBitmap.setImmutable();
103 result->fRect.set(2, 2, width - 2, height - 2); 103 result->fRect.set(2, 2, width - 2, height - 2);
104 return true; 104 return true;
105 } 105 }
106 106
107 /** Create a black and white checked bitmap with 2 1-pixel rings around the outs ide edge. 107 /** Create a black and white checked bitmap with 2 1-pixel rings around the outs ide edge.
108 The inner ring is red and the outer ring is blue. */ 108 The inner ring is red and the outer ring is blue. */
109 static bool make_ringed_color_bitmap(TestPixels* result, int width, int height) { 109 static bool make_ringed_color_bitmap(TestPixels* result, int width, int height) {
110 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); 110 const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE);
111 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); 111 const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
112 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); 112 const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK);
113 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); 113 const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE);
114 return make_ringed_bitmap<SkPMColor>(result, width, height, kN32_SkColorType , 114 return make_ringed_bitmap<SkPMColor>(result, width, height, kN32_SkColorType ,
115 kPremul_SkAlphaType, kBlue, kRed, kBlac k, kWhite); 115 kPremul_SkAlphaType, kBlue, kRed, kBlac k, kWhite);
116 } 116 }
117 117
118 /** Makes a alpha bitmap with 1 wide rect/ring of 0s, an inset of 1s, and the in terior is a 2x2 118 /** Makes a alpha bitmap with 1 wide rect/ring of 0s, an inset of 1s, and the in terior is a 2x2
119 checker board of 3/4 and 1/2. The inner checkers are large enough to fill th e interior with 119 checker board of 3/4 and 1/2. The inner checkers are large enough to fill th e interior with
120 the 2x2 checker grid. */ 120 the 2x2 checker grid. */
121 static bool make_ringed_alpha_bitmap(TestPixels* result, int width, int height) { 121 static bool make_ringed_alpha_bitmap(TestPixels* result, int width, int height) {
122 static const uint8_t kZero = 0x00; 122 constexpr uint8_t kZero = 0x00;
123 static const uint8_t kHalf = 0x80; 123 constexpr uint8_t kHalf = 0x80;
124 static const uint8_t k3Q = 0xC0; 124 constexpr uint8_t k3Q = 0xC0;
125 static const uint8_t kOne = 0xFF; 125 constexpr uint8_t kOne = 0xFF;
126 return make_ringed_bitmap<uint8_t>(result, width, height, kAlpha_8_SkColorTy pe, 126 return make_ringed_bitmap<uint8_t>(result, width, height, kAlpha_8_SkColorTy pe,
127 kPremul_SkAlphaType, kZero, kOne, k3Q, kH alf); 127 kPremul_SkAlphaType, kZero, kOne, k3Q, kH alf);
128 } 128 }
129 129
130 /** Helper to reuse above functions to produce images rather than bmps */ 130 /** Helper to reuse above functions to produce images rather than bmps */
131 static void bmp_to_image(TestPixels* result) { 131 static void bmp_to_image(TestPixels* result) {
132 SkASSERT(TestPixels::kBitmap == result->fType); 132 SkASSERT(TestPixels::kBitmap == result->fType);
133 result->fImage = SkImage::MakeFromBitmap(result->fBitmap); 133 result->fImage = SkImage::MakeFromBitmap(result->fBitmap);
134 SkASSERT(result->fImage); 134 SkASSERT(result->fImage);
135 result->fType = TestPixels::kImage; 135 result->fType = TestPixels::kImage;
(...skipping 12 matching lines...) Expand all
148 /** Alpha image case. */ 148 /** Alpha image case. */
149 bool make_ringed_alpha_image(TestPixels* result, int width, int height) { 149 bool make_ringed_alpha_image(TestPixels* result, int width, int height) {
150 if (make_ringed_alpha_bitmap(result, width, height)) { 150 if (make_ringed_alpha_bitmap(result, width, height)) {
151 bmp_to_image(result); 151 bmp_to_image(result);
152 return true; 152 return true;
153 } 153 }
154 return false; 154 return false;
155 } 155 }
156 156
157 static sk_sp<SkShader> make_shader() { 157 static sk_sp<SkShader> make_shader() {
158 static const SkPoint pts[] = { {0, 0}, {20, 20} }; 158 constexpr SkPoint pts[] = { {0, 0}, {20, 20} };
159 static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW }; 159 constexpr SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW };
160 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kMirr or_TileMode); 160 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kMirr or_TileMode);
161 } 161 }
162 162
163 static sk_sp<SkShader> make_null_shader() { return nullptr; } 163 static sk_sp<SkShader> make_null_shader() { return nullptr; }
164 164
165 enum BleedTest { 165 enum BleedTest {
166 kUseBitmap_BleedTest, 166 kUseBitmap_BleedTest,
167 kUseImage_BleedTest, 167 kUseImage_BleedTest,
168 kUseAlphaBitmap_BleedTest, 168 kUseAlphaBitmap_BleedTest,
169 kUseAlphaImage_BleedTest, 169 kUseAlphaImage_BleedTest,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 void onDraw(SkCanvas* canvas) override { 315 void onDraw(SkCanvas* canvas) override {
316 fShader = gBleedRec[fBT].fShaderMaker(); 316 fShader = gBleedRec[fBT].fShaderMaker();
317 317
318 canvas->clear(SK_ColorGRAY); 318 canvas->clear(SK_ColorGRAY);
319 SkTDArray<SkMatrix> matrices; 319 SkTDArray<SkMatrix> matrices;
320 // Draw with identity 320 // Draw with identity
321 *matrices.append() = SkMatrix::I(); 321 *matrices.append() = SkMatrix::I();
322 322
323 // Draw with rotation and scale down in x, up in y. 323 // Draw with rotation and scale down in x, up in y.
324 SkMatrix m; 324 SkMatrix m;
325 static const SkScalar kBottom = SkIntToScalar(kRow4Y + kBlockSize + kBlo ckSpacing); 325 constexpr SkScalar kBottom = SkIntToScalar(kRow4Y + kBlockSize + kBlockS pacing);
326 m.setTranslate(0, kBottom); 326 m.setTranslate(0, kBottom);
327 m.preRotate(15.f, 0, kBottom + kBlockSpacing); 327 m.preRotate(15.f, 0, kBottom + kBlockSpacing);
328 m.preScale(0.71f, 1.22f); 328 m.preScale(0.71f, 1.22f);
329 *matrices.append() = m; 329 *matrices.append() = m;
330 330
331 // Align the next set with the middle of the previous in y, translated t o the right in x. 331 // Align the next set with the middle of the previous in y, translated t o the right in x.
332 SkPoint corners[] = {{0, 0}, { 0, kBottom }, { kWidth, kBottom }, {kWidt h, 0} }; 332 SkPoint corners[] = {{0, 0}, { 0, kBottom }, { kWidth, kBottom }, {kWidt h, 0} };
333 matrices[matrices.count()-1].mapPoints(corners, 4); 333 matrices[matrices.count()-1].mapPoints(corners, 4);
334 SkScalar y = (corners[0].fY + corners[1].fY + corners[2].fY + corners[3] .fY) / 4; 334 SkScalar y = (corners[0].fY + corners[1].fY + corners[2].fY + corners[3] .fY) / 4;
335 SkScalar x = SkTMax(SkTMax(corners[0].fX, corners[1].fX), 335 SkScalar x = SkTMax(SkTMax(corners[0].fX, corners[1].fX),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 400 }
401 } 401 }
402 402
403 #if SK_SUPPORT_GPU 403 #if SK_SUPPORT_GPU
404 void modifyGrContextOptions(GrContextOptions* options) override { 404 void modifyGrContextOptions(GrContextOptions* options) override {
405 options->fMaxTileSizeOverride = kMaxTileSize; 405 options->fMaxTileSizeOverride = kMaxTileSize;
406 } 406 }
407 #endif 407 #endif
408 408
409 private: 409 private:
410 static const int kBlockSize = 70; 410 static constexpr int kBlockSize = 70;
411 static const int kBlockSpacing = 12; 411 static constexpr int kBlockSpacing = 12;
412 412
413 static const int kCol0X = kBlockSpacing; 413 static constexpr int kCol0X = kBlockSpacing;
414 static const int kCol1X = 2*kBlockSpacing + kBlockSize; 414 static constexpr int kCol1X = 2*kBlockSpacing + kBlockSize;
415 static const int kCol2X = 3*kBlockSpacing + 2*kBlockSize; 415 static constexpr int kCol2X = 3*kBlockSpacing + 2*kBlockSize;
416 static const int kCol3X = 4*kBlockSpacing + 3*kBlockSize; 416 static constexpr int kCol3X = 4*kBlockSpacing + 3*kBlockSize;
417 static const int kCol4X = 5*kBlockSpacing + 4*kBlockSize; 417 static constexpr int kCol4X = 5*kBlockSpacing + 4*kBlockSize;
418 static const int kCol5X = 6*kBlockSpacing + 5*kBlockSize; 418 static constexpr int kCol5X = 6*kBlockSpacing + 5*kBlockSize;
419 static const int kWidth = 7*kBlockSpacing + 6*kBlockSize; 419 static constexpr int kWidth = 7*kBlockSpacing + 6*kBlockSize;
420 420
421 static const int kRow0Y = kBlockSpacing; 421 static constexpr int kRow0Y = kBlockSpacing;
422 static const int kRow1Y = 2*kBlockSpacing + kBlockSize; 422 static constexpr int kRow1Y = 2*kBlockSpacing + kBlockSize;
423 static const int kRow2Y = 3*kBlockSpacing + 2*kBlockSize; 423 static constexpr int kRow2Y = 3*kBlockSpacing + 2*kBlockSize;
424 static const int kRow3Y = 4*kBlockSpacing + 3*kBlockSize; 424 static constexpr int kRow3Y = 4*kBlockSpacing + 3*kBlockSize;
425 static const int kRow4Y = 5*kBlockSpacing + 4*kBlockSize; 425 static constexpr int kRow4Y = 5*kBlockSpacing + 4*kBlockSize;
426 426
427 static const int kSmallSize = 6; 427 static constexpr int kSmallSize = 6;
428 static const int kMaxTileSize = 32; 428 static constexpr int kMaxTileSize = 32;
429 429
430 TestPixels fBigTestPixels; 430 TestPixels fBigTestPixels;
431 TestPixels fSmallTestPixels; 431 TestPixels fSmallTestPixels;
432 432
433 sk_sp<SkShader> fShader; 433 sk_sp<SkShader> fShader;
434 434
435 const BleedTest fBT; 435 const BleedTest fBT;
436 436
437 typedef GM INHERITED; 437 typedef GM INHERITED;
438 }; 438 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // now blow up the 1 pixel result 504 // now blow up the 1 pixel result
505 canvas->drawImageRect(surf->makeImageSnapshot(), SkRect::MakeWH(100, 100), nullptr); 505 canvas->drawImageRect(surf->makeImageSnapshot(), SkRect::MakeWH(100, 100), nullptr);
506 canvas->translate(120, 0); 506 canvas->translate(120, 0);
507 } 507 }
508 canvas->restore(); 508 canvas->restore();
509 canvas->translate(0, 120); 509 canvas->translate(0, 120);
510 } 510 }
511 } 511 }
512 512
513 513
OLDNEW
« no previous file with comments | « gm/bitmaprect.cpp ('k') | gm/blurcircles.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698