OLD | NEW |
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 #include "gm.h" | 7 #include "gm.h" |
8 #include "SkGradientShader.h" | 8 #include "SkGradientShader.h" |
9 | 9 |
10 using namespace skiagm; | 10 using namespace skiagm; |
11 | 11 |
12 struct GradData { | 12 struct GradData { |
13 int fCount; | 13 int fCount; |
14 const SkColor* fColors; | 14 const SkColor* fColors; |
15 const SkScalar* fPos; | 15 const SkScalar* fPos; |
16 }; | 16 }; |
17 | 17 |
18 static const SkColor gColors[] = { | 18 constexpr SkColor gColors[] = { |
19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, | 19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, |
20 }; | 20 }; |
21 | 21 |
22 static const GradData gGradData[] = { | 22 constexpr GradData gGradData[] = { |
23 { 1, gColors, nullptr }, | 23 { 1, gColors, nullptr }, |
24 { 2, gColors, nullptr }, | 24 { 2, gColors, nullptr }, |
25 { 3, gColors, nullptr }, | 25 { 3, gColors, nullptr }, |
26 { 4, gColors, nullptr }, | 26 { 4, gColors, nullptr }, |
27 }; | 27 }; |
28 | 28 |
29 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { | 29 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { |
30 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun
t, tm); | 30 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun
t, tm); |
31 } | 31 } |
32 | 32 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 64 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
65 return SkGradientShader::MakeTwoPointConical(center1, radius1, | 65 return SkGradientShader::MakeTwoPointConical(center1, radius1, |
66 center0, radius0, | 66 center0, radius0, |
67 data.fColors, data.fPos, | 67 data.fColors, data.fPos, |
68 data.fCount, tm); | 68 data.fCount, tm); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm); | 72 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm); |
73 | 73 |
74 static const GradMaker gGradMakers[] = { | 74 constexpr GradMaker gGradMakers[] = { |
75 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical, | 75 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical, |
76 }; | 76 }; |
77 | 77 |
78 /////////////////////////////////////////////////////////////////////////////// | 78 /////////////////////////////////////////////////////////////////////////////// |
79 | 79 |
80 class GradientsNoTextureGM : public GM { | 80 class GradientsNoTextureGM : public GM { |
81 public: | 81 public: |
82 GradientsNoTextureGM(bool dither) : fDither(dither) { | 82 GradientsNoTextureGM(bool dither) : fDither(dither) { |
83 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 83 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
84 } | 84 } |
85 | 85 |
86 protected: | 86 protected: |
87 | 87 |
88 SkString onShortName() override { | 88 SkString onShortName() override { |
89 return SkString(fDither ? "gradients_no_texture" : "gradients_no_texture
_nodither"); | 89 return SkString(fDither ? "gradients_no_texture" : "gradients_no_texture
_nodither"); |
90 } | 90 } |
91 | 91 |
92 SkISize onISize() override { return SkISize::Make(640, 615); } | 92 SkISize onISize() override { return SkISize::Make(640, 615); } |
93 | 93 |
94 void onDraw(SkCanvas* canvas) override { | 94 void onDraw(SkCanvas* canvas) override { |
95 static const SkPoint kPts[2] = { { 0, 0 }, | 95 constexpr SkPoint kPts[2] = { { 0, 0 }, |
96 { SkIntToScalar(50), SkIntToScalar(50)
} }; | 96 { SkIntToScalar(50), SkIntToScalar(50)
} }; |
97 static const SkShader::TileMode kTM = SkShader::kClamp_TileMode; | 97 constexpr SkShader::TileMode kTM = SkShader::kClamp_TileMode; |
98 SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) }; | 98 SkRect kRect = { 0, 0, SkIntToScalar(50), SkIntToScalar(50) }; |
99 SkPaint paint; | 99 SkPaint paint; |
100 paint.setAntiAlias(true); | 100 paint.setAntiAlias(true); |
101 paint.setDither(fDither); | 101 paint.setDither(fDither); |
102 | 102 |
103 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); | 103 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
104 static const uint8_t kAlphas[] = { 0xff, 0x40 }; | 104 constexpr uint8_t kAlphas[] = { 0xff, 0x40 }; |
105 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) { | 105 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphas); ++a) { |
106 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) { | 106 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) { |
107 canvas->save(); | 107 canvas->save(); |
108 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) { | 108 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) { |
109 paint.setShader(gGradMakers[j](kPts, gGradData[i], kTM)); | 109 paint.setShader(gGradMakers[j](kPts, gGradData[i], kTM)); |
110 paint.setAlpha(kAlphas[a]); | 110 paint.setAlpha(kAlphas[a]); |
111 canvas->drawRect(kRect, paint); | 111 canvas->drawRect(kRect, paint); |
112 canvas->translate(0, SkIntToScalar(kRect.height() + 20)); | 112 canvas->translate(0, SkIntToScalar(kRect.height() + 20)); |
113 } | 113 } |
114 canvas->restore(); | 114 canvas->restore(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 typedef GM INHERITED; | 275 typedef GM INHERITED; |
276 }; | 276 }; |
277 | 277 |
278 /////////////////////////////////////////////////////////////////////////////// | 278 /////////////////////////////////////////////////////////////////////////////// |
279 | 279 |
280 DEF_GM(return new GradientsNoTextureGM(true);) | 280 DEF_GM(return new GradientsNoTextureGM(true);) |
281 DEF_GM(return new GradientsNoTextureGM(false);) | 281 DEF_GM(return new GradientsNoTextureGM(false);) |
282 DEF_GM(return new GradientsManyColorsGM(true);) | 282 DEF_GM(return new GradientsManyColorsGM(true);) |
283 DEF_GM(return new GradientsManyColorsGM(false);) | 283 DEF_GM(return new GradientsManyColorsGM(false);) |
OLD | NEW |