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, SK_ColorBLACK, | 19 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
20 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 20 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
21 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 21 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
22 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 22 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
23 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 23 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
24 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 24 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
25 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 25 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
26 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 26 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
27 }; | 27 }; |
28 | 28 |
29 //static const SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 }; | 29 //constexpr SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 }; |
30 | 30 |
31 static const GradData gGradData[] = { | 31 constexpr GradData gGradData[] = { |
32 { 40, gColors, nullptr }, | 32 { 40, gColors, nullptr }, |
33 // { 2, gColors, gPos }, | 33 // { 2, gColors, gPos }, |
34 // { 2, gCol2, nullptr }, | 34 // { 2, gCol2, nullptr }, |
35 }; | 35 }; |
36 | 36 |
37 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { | 37 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { |
38 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun
t, tm); | 38 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun
t, tm); |
39 } | 39 } |
40 | 40 |
41 static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { | 41 static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { |
42 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY,
pts[1].fY) }; | 42 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY,
pts[1].fY) }; |
43 return SkGradientShader::MakeRadial(pt, pt.fX, data.fColors, data.fPos, data
.fCount, tm); | 43 return SkGradientShader::MakeRadial(pt, pt.fX, data.fColors, data.fPos, data
.fCount, tm); |
44 } | 44 } |
45 | 45 |
46 static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkS
hader::TileMode) { | 46 static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkS
hader::TileMode) { |
47 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY,
pts[1].fY) }; | 47 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY,
pts[1].fY) }; |
48 return SkGradientShader::MakeSweep(pt.fX, pt.fY, data.fColors, data.fPos, da
ta.fCount); | 48 return SkGradientShader::MakeSweep(pt.fX, pt.fY, data.fColors, data.fPos, da
ta.fCount); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkSh
ader::TileMode); | 52 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkSh
ader::TileMode); |
53 | 53 |
54 static const GradMaker gGradMakers[] = { | 54 constexpr GradMaker gGradMakers[] = { |
55 MakeLinear, MakeRadial, MakeSweep, | 55 MakeLinear, MakeRadial, MakeSweep, |
56 }; | 56 }; |
57 | 57 |
58 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
59 | 59 |
60 class GradientsGM : public GM { | 60 class GradientsGM : public GM { |
61 public: | 61 public: |
62 GradientsGM() { | 62 GradientsGM() { |
63 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 63 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
64 } | 64 } |
(...skipping 25 matching lines...) Expand all Loading... |
90 } | 90 } |
91 | 91 |
92 private: | 92 private: |
93 typedef GM INHERITED; | 93 typedef GM INHERITED; |
94 }; | 94 }; |
95 | 95 |
96 /////////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////////// |
97 | 97 |
98 static GM* MyFactory(void*) { return new GradientsGM; } | 98 static GM* MyFactory(void*) { return new GradientsGM; } |
99 static GMRegistry reg(MyFactory); | 99 static GMRegistry reg(MyFactory); |
OLD | NEW |