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

Side by Side Diff: gm/stroke_rect_shader.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/stringart.cpp ('k') | gm/strokedlines.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 2016 Google Inc. 2 * Copyright 2016 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 10
11 namespace skiagm { 11 namespace skiagm {
12 12
13 // Draw stroked rects (both AA and nonAA) with all the types of joins: 13 // Draw stroked rects (both AA and nonAA) with all the types of joins:
14 // bevel, miter, miter-limited-to-bevel, round 14 // bevel, miter, miter-limited-to-bevel, round
15 // and as a hairline. 15 // and as a hairline.
16 DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) { 16 DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) {
17 static constexpr SkRect kRect {0, 0, 100, 100}; 17 constexpr SkRect kRect {0, 0, 100, 100};
18 static constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, k Rect.fBottom}}; 18 constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, kRect.fB ottom}};
19 static constexpr SkColor kColors[] {SK_ColorRED, SK_ColorBLUE}; 19 constexpr SkColor kColors[] {SK_ColorRED, SK_ColorBLUE};
20 SkPaint paint; 20 SkPaint paint;
21 sk_sp<SkShader> shader = SkGradientShader::MakeLinear(kPts, kColors, nullptr , 2, 21 sk_sp<SkShader> shader = SkGradientShader::MakeLinear(kPts, kColors, nullptr , 2,
22 SkShader::kClamp_TileM ode); 22 SkShader::kClamp_TileM ode);
23 paint.setShader(std::move(shader)); 23 paint.setShader(std::move(shader));
24 paint.setStyle(SkPaint::kStroke_Style); 24 paint.setStyle(SkPaint::kStroke_Style);
25 // Do a large initial translate so that local coords disagree with device co ords significantly 25 // Do a large initial translate so that local coords disagree with device co ords significantly
26 // for the first rect drawn. 26 // for the first rect drawn.
27 canvas->translate(kRect.centerX(), kRect.centerY()); 27 canvas->translate(kRect.centerX(), kRect.centerY());
28 static constexpr SkScalar kPad = 20; 28 constexpr SkScalar kPad = 20;
29 for (auto aa : {false, true}) { 29 for (auto aa : {false, true}) {
30 paint.setAntiAlias(aa); 30 paint.setAntiAlias(aa);
31 canvas->save(); 31 canvas->save();
32 32
33 static constexpr SkScalar kStrokeWidth = 10; 33 constexpr SkScalar kStrokeWidth = 10;
34 paint.setStrokeWidth(kStrokeWidth); 34 paint.setStrokeWidth(kStrokeWidth);
35 35
36 paint.setStrokeJoin(SkPaint::kBevel_Join); 36 paint.setStrokeJoin(SkPaint::kBevel_Join);
37 canvas->drawRect(kRect, paint); 37 canvas->drawRect(kRect, paint);
38 canvas->translate(kRect.width() + kPad, 0); 38 canvas->translate(kRect.width() + kPad, 0);
39 39
40 paint.setStrokeJoin(SkPaint::kMiter_Join); 40 paint.setStrokeJoin(SkPaint::kMiter_Join);
41 canvas->drawRect(kRect, paint); 41 canvas->drawRect(kRect, paint);
42 canvas->translate(kRect.width() + kPad, 0); 42 canvas->translate(kRect.width() + kPad, 0);
43 43
44 // This miter limit should effectively produce a bevel join. 44 // This miter limit should effectively produce a bevel join.
45 paint.setStrokeMiter(0.01f); 45 paint.setStrokeMiter(0.01f);
46 canvas->drawRect(kRect, paint); 46 canvas->drawRect(kRect, paint);
47 canvas->translate(kRect.width() + kPad, 0); 47 canvas->translate(kRect.width() + kPad, 0);
48 48
49 paint.setStrokeJoin(SkPaint::kRound_Join); 49 paint.setStrokeJoin(SkPaint::kRound_Join);
50 canvas->drawRect(kRect, paint); 50 canvas->drawRect(kRect, paint);
51 canvas->translate(kRect.width() + kPad, 0); 51 canvas->translate(kRect.width() + kPad, 0);
52 52
53 paint.setStrokeWidth(0); 53 paint.setStrokeWidth(0);
54 canvas->drawRect(kRect, paint); 54 canvas->drawRect(kRect, paint);
55 55
56 canvas->restore(); 56 canvas->restore();
57 canvas->translate(0, kRect.height() + kPad); 57 canvas->translate(0, kRect.height() + kPad);
58 } 58 }
59 } 59 }
60 60
61 } 61 }
OLDNEW
« no previous file with comments | « gm/stringart.cpp ('k') | gm/strokedlines.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698