blob: 39ebb4a1f9ec540d19639e8a3d605486db360638 [file] [log] [blame]
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +00007
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +00008#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.org83f23d82014-05-22 12:27:41 +000041 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000042 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -070043 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
44 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000045 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
47 return SkGradientShader::CreateTwoPointConical(center0, radius0,
48 center1, radius1,
49 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000050 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000051}
52
53static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000054 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000055 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -070056 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
57 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000058 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
60 return SkGradientShader::CreateTwoPointConical(center1, radius1,
61 center0, radius0,
62 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000063 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000064}
65
66static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000067 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000068 SkPoint center0, center1;
69 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
70 SkScalarAve(pts[0].fY, pts[1].fY));
71 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
72 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000073 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
74 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000075 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000076 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000077}
78
79static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000080 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000081 SkPoint center0, center1;
82 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
83 SkScalarAve(pts[0].fY, pts[1].fY));
84 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
85 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000086 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
87 center1, (pts[1].fX - pts[0].fX) / 7,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000088 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000089 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000090}
91
92static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000093 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000094 SkPoint center0, center1;
95 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
96 SkScalarAve(pts[0].fY, pts[1].fY));
97 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
98 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000099 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
100 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000101 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000102 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000103}
104
105static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000106 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000107 SkPoint center0, center1;
108 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
109 SkScalarAve(pts[0].fY, pts[1].fY));
110 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
111 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000112 return SkGradientShader::CreateTwoPointConical(center1, 0.f,
113 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000114 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000115 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000116}
117
118static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000119 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000120 SkPoint center0, center1;
121 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
122 SkScalarAve(pts[0].fY, pts[1].fY));
123 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
124 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000125 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
126 center0, 0.f,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000127 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000128 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000129}
130
131static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000132 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000133 SkPoint center0, center1;
134 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
135 SkScalarAve(pts[0].fY, pts[1].fY));
136 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
137 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000138 return SkGradientShader::CreateTwoPointConical(center0, 0.f,
139 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000140 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000141 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000142}
143
144static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000145 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000146 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000147 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700148 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
151 return SkGradientShader::CreateTwoPointConical(center0, radius0,
152 center1, radius1,
153 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000154 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000155}
156
157static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000158 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000159 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000160 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700161 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
164 return SkGradientShader::CreateTwoPointConical(center1, radius1,
165 center0, radius0,
166 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000167 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000168}
169
170static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000171 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000172 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700173 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
174 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
176 SkScalarAve(pts[0].fY, pts[1].fY));
177 center0.set(center1.fX + radius1, center1.fY);
178 return SkGradientShader::CreateTwoPointConical(center0, radius0,
179 center1, radius1,
180 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000181 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000182}
183
184static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000185 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000186 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700187 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
188 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
190 SkScalarAve(pts[0].fY, pts[1].fY));
191 center0.set(center1.fX, center1.fY + radius1);
192 return SkGradientShader::CreateTwoPointConical(center0, radius0,
193 center1, radius1,
194 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000195 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000196}
egdaniel8405ef92014-06-09 11:57:28 -0700197
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000198static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000199 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000200 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000201 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700202 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000203 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
204 SkScalarAve(pts[0].fY, pts[1].fY));
205 center0.set(center1.fX + radius1, center1.fY);
206 return SkGradientShader::CreateTwoPointConical(center0, radius0,
207 center1, radius1,
208 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000209 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000210}
211
212static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000213 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000214 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000215 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700216 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000217 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
218 SkScalarAve(pts[0].fY, pts[1].fY));
219 center0.set(center1.fX, center1.fY + radius1);
220 return SkGradientShader::CreateTwoPointConical(center0, radius0,
221 center1, radius1,
222 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000223 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000224}
225
226static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000227 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000228 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700229 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
230 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000231 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
232 SkScalarAve(pts[0].fY, pts[1].fY));
233 center0.set(center1.fX - radius1 + radius0, center1.fY);
234 return SkGradientShader::CreateTwoPointConical(center0, radius0,
235 center1, radius1,
236 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000237 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000238}
239
240static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000241 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000242 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700243 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
244 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000245 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
246 SkScalarAve(pts[0].fY, pts[1].fY));
247 center0.set(center1.fX, center1.fY + radius1 - radius0);
248 return SkGradientShader::CreateTwoPointConical(center0, radius0,
249 center1, radius1,
250 data.fColors, data.fPos,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000251 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000252}
253
254static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000255 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000256 SkPoint center0, center1;
257 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
258 SkScalarAve(pts[0].fY, pts[1].fY));
259 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
260 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000261 return SkGradientShader::CreateTwoPointConical(center0, 0.0000000000000000001f,
262 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000263 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000264 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000265}
266
267typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000268 SkShader::TileMode tm, const SkMatrix& localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000269
270static const GradMaker gGradMakersOutside[] = {
271 Make2ConicalOutside, Make2ConicalOutsideFlip,
272 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside
273};
274
275static const GradMaker gGradMakersInside[] = {
276 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
277 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
278};
279
280static const GradMaker gGradMakersEdgeCases[] = {
281 Make2ConicalEdgeX, Make2ConicalEdgeY,
282 Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY,
283 Make2ConicalTouchX, Make2ConicalTouchY,
284 Make2ConicalInsideSmallRad
285};
286
287
288static const struct {
289 const GradMaker* fMaker;
290 const int fCount;
291 const char* fName;
292} gGradCases[] = {
293 { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" },
294 { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" },
295 { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" },
296};
297
298enum GradCaseType { // these must match the order in gGradCases
299 kOutside_GradCaseType,
300 kInside_GradCaseType,
301 kEdge_GradCaseType,
302};
303
304///////////////////////////////////////////////////////////////////////////////
305
306class ConicalGradientsGM : public GM {
307public:
fmalita063675b2015-10-12 10:41:48 -0700308 ConicalGradientsGM(GradCaseType gradCaseType, bool dither)
309 : fGradCaseType(gradCaseType)
310 , fDither(dither) {
caryclark65cdba62015-06-15 06:51:08 -0700311 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
fmalita063675b2015-10-12 10:41:48 -0700312 fName.printf("gradients_2pt_conical_%s%s", gGradCases[gradCaseType].fName,
313 fDither ? "" : "_nodither");
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000314 }
315
316protected:
317 SkString onShortName() {
318 return fName;
319 }
320
321 virtual SkISize onISize() { return SkISize::Make(840, 815); }
322
323 virtual void onDraw(SkCanvas* canvas) {
324
325 SkPoint pts[2] = {
326 { 0, 0 },
327 { SkIntToScalar(100), SkIntToScalar(100) }
328 };
329 SkShader::TileMode tm = SkShader::kClamp_TileMode;
330 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
331 SkPaint paint;
332 paint.setAntiAlias(true);
fmalita063675b2015-10-12 10:41:48 -0700333 paint.setDither(fDither);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000334
335 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
336
337 const GradMaker* gradMaker = gGradCases[fGradCaseType].fMaker;
338 const int count = gGradCases[fGradCaseType].fCount;
339
340 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
341 canvas->save();
342 for (int j = 0; j < count; j++) {
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000343 SkMatrix scale = SkMatrix::I();
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000344
345 if (i == 3) { // if the clamp case
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000346 scale.setScale(0.5f, 0.5f);
347 scale.postTranslate(25.f, 25.f);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000348 }
349
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000350 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000351 paint.setShader(shader);
352 canvas->drawRect(r, paint);
353 shader->unref();
354 canvas->translate(0, SkIntToScalar(120));
355 }
356 canvas->restore();
357 canvas->translate(SkIntToScalar(120), 0);
358 }
359 }
360
361private:
362 typedef GM INHERITED;
363
364 GradCaseType fGradCaseType;
365 SkString fName;
fmalita063675b2015-10-12 10:41:48 -0700366 bool fDither;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000367};
368///////////////////////////////////////////////////////////////////////////////
369
fmalita063675b2015-10-12 10:41:48 -0700370DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); )
371DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); )
372DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); )
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000373
fmalita063675b2015-10-12 10:41:48 -0700374DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); )
375DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); )
376DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); )
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000377
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000378}