OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 }; | 28 }; |
29 | 29 |
30 //static const SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 }; | 30 //static const SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 }; |
31 | 31 |
32 static const GradData gGradData[] = { | 32 static const GradData gGradData[] = { |
33 { 40, gColors, NULL }, | 33 { 40, gColors, NULL }, |
34 // { 2, gColors, gPos }, | 34 // { 2, gColors, gPos }, |
35 // { 2, gCol2, NULL }, | 35 // { 2, gCol2, NULL }, |
36 }; | 36 }; |
37 | 37 |
38 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader
::TileMode tm) { | 38 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
39 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo
unt, tm); | 39 SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 40 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
| 41 data.fCount, tm, mapper); |
40 } | 42 } |
41 | 43 |
42 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader
::TileMode tm) { | 44 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
| 45 SkShader::TileMode tm, SkUnitMapper* mapper) { |
43 SkPoint center; | 46 SkPoint center; |
44 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 47 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
45 SkScalarAve(pts[0].fY, pts[1].fY)); | 48 SkScalarAve(pts[0].fY, pts[1].fY)); |
46 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, | 49 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, |
47 data.fPos, data.fCount, tm); | 50 data.fPos, data.fCount, tm, mapper); |
48 } | 51 } |
49 | 52 |
50 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader:
:TileMode) { | 53 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
| 54 SkShader::TileMode, SkUnitMapper* mapper) { |
51 SkPoint center; | 55 SkPoint center; |
52 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 56 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
53 SkScalarAve(pts[0].fY, pts[1].fY)); | 57 SkScalarAve(pts[0].fY, pts[1].fY)); |
54 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat
a.fPos, data.fCount); | 58 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
| 59 data.fPos, data.fCount, mapper); |
55 } | 60 } |
56 | 61 |
57 | 62 |
58 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha
der::TileMode tm); | 63 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
59 | 64 SkShader::TileMode tm, SkUnitMapper* mapper); |
60 static const GradMaker gGradMakers[] = { | 65 static const GradMaker gGradMakers[] = { |
61 MakeLinear, MakeRadial, MakeSweep, | 66 MakeLinear, MakeRadial, MakeSweep, |
62 }; | 67 }; |
63 | 68 |
64 /////////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////////// |
65 | 70 |
66 class GradientsGM : public GM { | 71 class GradientsGM : public GM { |
67 public: | 72 public: |
68 GradientsGM() { | 73 GradientsGM() { |
69 this->setBGColor(0xFFDDDDDD); | 74 this->setBGColor(0xFFDDDDDD); |
(...skipping 13 matching lines...) Expand all Loading... |
83 }; | 88 }; |
84 SkShader::TileMode tm = SkShader::kClamp_TileMode; | 89 SkShader::TileMode tm = SkShader::kClamp_TileMode; |
85 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; | 90 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; |
86 SkPaint paint; | 91 SkPaint paint; |
87 paint.setAntiAlias(true); | 92 paint.setAntiAlias(true); |
88 | 93 |
89 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); | 94 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
90 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { | 95 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
91 canvas->save(); | 96 canvas->save(); |
92 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { | 97 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
93 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm); | 98 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL); |
94 paint.setShader(shader)->unref(); | 99 paint.setShader(shader)->unref(); |
95 canvas->drawRect(r, paint); | 100 canvas->drawRect(r, paint); |
96 canvas->translate(0, SkIntToScalar(120)); | 101 canvas->translate(0, SkIntToScalar(120)); |
97 } | 102 } |
98 canvas->restore(); | 103 canvas->restore(); |
99 canvas->translate(SkIntToScalar(120), 0); | 104 canvas->translate(SkIntToScalar(120), 0); |
100 } | 105 } |
101 } | 106 } |
102 | 107 |
103 private: | 108 private: |
104 typedef GM INHERITED; | 109 typedef GM INHERITED; |
105 }; | 110 }; |
106 | 111 |
107 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
108 | 113 |
109 static GM* MyFactory(void*) { return new GradientsGM; } | 114 static GM* MyFactory(void*) { return new GradientsGM; } |
110 static GMRegistry reg(MyFactory); | 115 static GMRegistry reg(MyFactory); |
OLD | NEW |