blob: dece66ed8b2aa6ab2c29f40a15da229ff92694d8 [file] [log] [blame]
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +00001
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +00002/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "gm.h"
9#include "SkGradientShader.h"
10
11namespace skiagm {
12
13struct GradData {
14 int fCount;
15 const SkColor* fColors;
16 const SkScalar* fPos;
17};
18
19static const SkColor gColors[] = {
20 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
21};
22static const SkScalar gPos0[] = { 0, SK_Scalar1 };
23static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
24static const SkScalar gPos2[] = {
25 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
26};
27
28static const SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f};
29static const SkColor gColorClamp[] = {
30 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
31};
32
33static const GradData gGradData[] = {
34 { 2, gColors, gPos0 },
35 { 2, gColors, gPos1 },
36 { 5, gColors, gPos2 },
37 { 4, gColorClamp, gPosClamp }
38};
39
40static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000041 SkShader::TileMode tm, SkUnitMapper* mapper,
42 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000043 SkPoint center0, center1;
44 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
45 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
46 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
47 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
48 return SkGradientShader::CreateTwoPointConical(center0, radius0,
49 center1, radius1,
50 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000051 data.fCount, tm, mapper,
52 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000053}
54
55static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000056 SkShader::TileMode tm, SkUnitMapper* mapper,
57 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000058 SkPoint center0, center1;
59 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
60 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
61 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
62 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
63 return SkGradientShader::CreateTwoPointConical(center1, radius1,
64 center0, radius0,
65 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000066 data.fCount, tm, mapper,
67 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000068}
69
70static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000071 SkShader::TileMode tm, SkUnitMapper* mapper,
72 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000073 SkPoint center0, center1;
74 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
75 SkScalarAve(pts[0].fY, pts[1].fY));
76 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
77 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000078 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
79 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000080 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000081 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000082}
83
84static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000085 SkShader::TileMode tm, SkUnitMapper* mapper,
86 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000087 SkPoint center0, center1;
88 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
89 SkScalarAve(pts[0].fY, pts[1].fY));
90 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
91 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000092 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
93 center1, (pts[1].fX - pts[0].fX) / 7,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000094 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000095 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000096}
97
98static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +000099 SkShader::TileMode tm, SkUnitMapper* mapper,
100 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000101 SkPoint center0, center1;
102 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
103 SkScalarAve(pts[0].fY, pts[1].fY));
104 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
105 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000106 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
107 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000108 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000109 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000110}
111
112static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000113 SkShader::TileMode tm, SkUnitMapper* mapper,
114 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000115 SkPoint center0, center1;
116 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
117 SkScalarAve(pts[0].fY, pts[1].fY));
118 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
119 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000120 return SkGradientShader::CreateTwoPointConical(center1, 0.f,
121 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000122 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000123 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000124}
125
126static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000127 SkShader::TileMode tm, SkUnitMapper* mapper,
128 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000129 SkPoint center0, center1;
130 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
131 SkScalarAve(pts[0].fY, pts[1].fY));
132 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
133 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000134 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
135 center0, 0.f,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000136 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000137 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000138}
139
140static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000141 SkShader::TileMode tm, SkUnitMapper* mapper,
142 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000143 SkPoint center0, center1;
144 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
145 SkScalarAve(pts[0].fY, pts[1].fY));
146 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
147 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000148 return SkGradientShader::CreateTwoPointConical(center0, 0.f,
149 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000150 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000151 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000152}
153
154static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000155 SkShader::TileMode tm, SkUnitMapper* mapper,
156 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000157 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000158 SkScalar radius0 = 0.f;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000159 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
160 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
161 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
162 return SkGradientShader::CreateTwoPointConical(center0, radius0,
163 center1, radius1,
164 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000165 data.fCount, tm, mapper,
166 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000167}
168
169static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000170 SkShader::TileMode tm, SkUnitMapper* mapper,
171 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000172 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000173 SkScalar radius0 = 0.f;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000174 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
175 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
176 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
177 return SkGradientShader::CreateTwoPointConical(center1, radius1,
178 center0, radius0,
179 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000180 data.fCount, tm, mapper,
181 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000182}
183
184static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000185 SkShader::TileMode tm, SkUnitMapper* mapper,
186 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000187 SkPoint center0, center1;
188 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
189 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
190 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
191 SkScalarAve(pts[0].fY, pts[1].fY));
192 center0.set(center1.fX + radius1, center1.fY);
193 return SkGradientShader::CreateTwoPointConical(center0, radius0,
194 center1, radius1,
195 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000196 data.fCount, tm, mapper,
197 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000198}
199
200static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000201 SkShader::TileMode tm, SkUnitMapper* mapper,
202 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000203 SkPoint center0, center1;
204 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
205 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
206 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
207 SkScalarAve(pts[0].fY, pts[1].fY));
208 center0.set(center1.fX, center1.fY + radius1);
209 return SkGradientShader::CreateTwoPointConical(center0, radius0,
210 center1, radius1,
211 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000212 data.fCount, tm, mapper,
213 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000214}
215static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000216 SkShader::TileMode tm, SkUnitMapper* mapper,
217 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000218 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000219 SkScalar radius0 = 0.f;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000220 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
221 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
222 SkScalarAve(pts[0].fY, pts[1].fY));
223 center0.set(center1.fX + radius1, center1.fY);
224 return SkGradientShader::CreateTwoPointConical(center0, radius0,
225 center1, radius1,
226 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000227 data.fCount, tm, mapper,
228 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000229}
230
231static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000232 SkShader::TileMode tm, SkUnitMapper* mapper,
233 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000234 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000235 SkScalar radius0 = 0.f;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000236 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
237 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
238 SkScalarAve(pts[0].fY, pts[1].fY));
239 center0.set(center1.fX, center1.fY + radius1);
240 return SkGradientShader::CreateTwoPointConical(center0, radius0,
241 center1, radius1,
242 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000243 data.fCount, tm, mapper,
244 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000245}
246
247static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000248 SkShader::TileMode tm, SkUnitMapper* mapper,
249 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000250 SkPoint center0, center1;
251 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
252 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
253 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
254 SkScalarAve(pts[0].fY, pts[1].fY));
255 center0.set(center1.fX - radius1 + radius0, center1.fY);
256 return SkGradientShader::CreateTwoPointConical(center0, radius0,
257 center1, radius1,
258 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000259 data.fCount, tm, mapper,
260 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000261}
262
263static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000264 SkShader::TileMode tm, SkUnitMapper* mapper,
265 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000266 SkPoint center0, center1;
267 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
268 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
269 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
270 SkScalarAve(pts[0].fY, pts[1].fY));
271 center0.set(center1.fX, center1.fY + radius1 - radius0);
272 return SkGradientShader::CreateTwoPointConical(center0, radius0,
273 center1, radius1,
274 data.fColors, data.fPos,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000275 data.fCount, tm, mapper,
276 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000277}
278
279static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000280 SkShader::TileMode tm, SkUnitMapper* mapper,
281 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000282 SkPoint center0, center1;
283 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
284 SkScalarAve(pts[0].fY, pts[1].fY));
285 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
286 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000287 return SkGradientShader::CreateTwoPointConical(center0, 0.0000000000000000001f,
288 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000289 data.fColors, data.fPos, data.fCount, tm, mapper,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000290 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000291}
292
293typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000294 SkShader::TileMode tm, SkUnitMapper* mapper,
295 const SkMatrix& localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000296
297static const GradMaker gGradMakersOutside[] = {
298 Make2ConicalOutside, Make2ConicalOutsideFlip,
299 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside
300};
301
302static const GradMaker gGradMakersInside[] = {
303 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
304 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
305};
306
307static const GradMaker gGradMakersEdgeCases[] = {
308 Make2ConicalEdgeX, Make2ConicalEdgeY,
309 Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY,
310 Make2ConicalTouchX, Make2ConicalTouchY,
311 Make2ConicalInsideSmallRad
312};
313
314
315static const struct {
316 const GradMaker* fMaker;
317 const int fCount;
318 const char* fName;
319} gGradCases[] = {
320 { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" },
321 { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" },
322 { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" },
323};
324
325enum GradCaseType { // these must match the order in gGradCases
326 kOutside_GradCaseType,
327 kInside_GradCaseType,
328 kEdge_GradCaseType,
329};
330
331///////////////////////////////////////////////////////////////////////////////
332
333class ConicalGradientsGM : public GM {
334public:
335 ConicalGradientsGM(GradCaseType gradCaseType) {
336 this->setBGColor(0xFFDDDDDD);
337 fName.printf("gradients_2pt_conical_%s", gGradCases[gradCaseType].fName);
338 fGradCaseType = gradCaseType;
339 }
340
341protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +0000342 virtual uint32_t onGetFlags() const SK_OVERRIDE {
343 if (fGradCaseType != kInside_GradCaseType) {
344 return kSkipTiled_Flag;
345 }
346 return 0;
347 }
348
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000349 SkString onShortName() {
350 return fName;
351 }
352
353 virtual SkISize onISize() { return SkISize::Make(840, 815); }
354
355 virtual void onDraw(SkCanvas* canvas) {
356
357 SkPoint pts[2] = {
358 { 0, 0 },
359 { SkIntToScalar(100), SkIntToScalar(100) }
360 };
361 SkShader::TileMode tm = SkShader::kClamp_TileMode;
362 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
363 SkPaint paint;
364 paint.setAntiAlias(true);
365
366 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
367
368 const GradMaker* gradMaker = gGradCases[fGradCaseType].fMaker;
369 const int count = gGradCases[fGradCaseType].fCount;
370
371 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
372 canvas->save();
373 for (int j = 0; j < count; j++) {
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000374 SkMatrix scale = SkMatrix::I();
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000375
376 if (i == 3) { // if the clamp case
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000377 scale.setScale(0.5f, 0.5f);
378 scale.postTranslate(25.f, 25.f);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000379 }
380
commit-bot@chromium.orge2b193c2014-05-16 13:49:08 +0000381 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, NULL, scale);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000382 paint.setShader(shader);
383 canvas->drawRect(r, paint);
384 shader->unref();
385 canvas->translate(0, SkIntToScalar(120));
386 }
387 canvas->restore();
388 canvas->translate(SkIntToScalar(120), 0);
389 }
390 }
391
392private:
393 typedef GM INHERITED;
394
395 GradCaseType fGradCaseType;
396 SkString fName;
397};
398///////////////////////////////////////////////////////////////////////////////
399
400static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseType); }
401static GMRegistry reg1(MyFactory1);
402
403static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseType); }
404static GMRegistry reg2(MyFactory2);
405
406static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType); }
407static GMRegistry reg3(MyFactory3);
408}