OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 namespace skiagm { | 10 namespace skiagm { |
11 | 11 |
12 static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate) { | 12 static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate, |
| 13 const SkMatrix& localMatrix) { |
13 SkPoint pts[2] = { {0, 0}, {width, height}}; | 14 SkPoint pts[2] = { {0, 0}, {width, height}}; |
14 SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN}; | 15 SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN}; |
15 if (alternate) { | 16 if (alternate) { |
16 pts[1].fY = 0; | 17 pts[1].fY = 0; |
17 colors[0] = SK_ColorBLUE; | 18 colors[0] = SK_ColorBLUE; |
18 colors[1] = SK_ColorYELLOW; | 19 colors[1] = SK_ColorYELLOW; |
19 } | 20 } |
20 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, | 21 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, |
21 SkShader::kClamp_TileMode, NULL); | 22 SkShader::kClamp_TileMode, NULL, 0, &loc
alMatrix); |
22 } | 23 } |
23 | 24 |
24 /////////////////////////////////////////////////////////////////////////////// | 25 /////////////////////////////////////////////////////////////////////////////// |
25 | 26 |
26 class ShaderBoundsGM : public GM { | 27 class ShaderBoundsGM : public GM { |
27 public: | 28 public: |
28 typedef SkShader* (*ShaderGenFunc)(SkScalar width, SkScalar height, | 29 typedef SkShader* (*ShaderGenFunc)(SkScalar width, SkScalar height, |
29 bool alternate); | 30 bool alternate, const SkMatrix& localMatr
ix); |
30 ShaderBoundsGM(ShaderGenFunc maker, const SkString& name) | 31 ShaderBoundsGM(ShaderGenFunc maker, const SkString& name) |
31 : fShaderMaker(maker), | 32 : fShaderMaker(maker), |
32 fName(name) { | 33 fName(name) { |
33 } | 34 } |
34 | 35 |
35 protected: | 36 protected: |
36 SkString onShortName() { | 37 SkString onShortName() { |
37 return fName; | 38 return fName; |
38 } | 39 } |
39 | 40 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 canvas->drawRect(r, paint); | 74 canvas->drawRect(r, paint); |
74 } | 75 } |
75 | 76 |
76 SkShader* MakeShader(int width, int height, bool background) { | 77 SkShader* MakeShader(int width, int height, bool background) { |
77 SkScalar scale = 0.5f; | 78 SkScalar scale = 0.5f; |
78 if (background) { | 79 if (background) { |
79 scale = 0.6f; | 80 scale = 0.6f; |
80 } | 81 } |
81 SkScalar shaderWidth = SkScalarDiv(SkIntToScalar(width), scale); | 82 SkScalar shaderWidth = SkScalarDiv(SkIntToScalar(width), scale); |
82 SkScalar shaderHeight = SkScalarDiv(SkIntToScalar(height), scale); | 83 SkScalar shaderHeight = SkScalarDiv(SkIntToScalar(height), scale); |
83 SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background); | |
84 SkMatrix shaderScale; | 84 SkMatrix shaderScale; |
85 shaderScale.setScale(scale, scale); | 85 shaderScale.setScale(scale, scale); |
86 shader->setLocalMatrix(shaderScale); | 86 SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background, s
haderScale); |
87 return shader; | 87 return shader; |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 typedef GM INHERITED; | 91 typedef GM INHERITED; |
92 | 92 |
93 ShaderGenFunc fShaderMaker; | 93 ShaderGenFunc fShaderMaker; |
94 SkString fName; | 94 SkString fName; |
95 | 95 |
96 SkShader* MakeShader(bool background); | 96 SkShader* MakeShader(bool background); |
97 }; | 97 }; |
98 | 98 |
99 /////////////////////////////////////////////////////////////////////////////// | 99 /////////////////////////////////////////////////////////////////////////////// |
100 | 100 |
101 static GM* MyFactory(void*) { | 101 static GM* MyFactory(void*) { |
102 return new ShaderBoundsGM(MakeLinear, SkString("shaderbounds_linear")); | 102 return new ShaderBoundsGM(MakeLinear, SkString("shaderbounds_linear")); |
103 } | 103 } |
104 static GMRegistry reg(MyFactory); | 104 static GMRegistry reg(MyFactory); |
105 | 105 |
106 } | 106 } |
OLD | NEW |