blob: 81549e30f82d652582b75ccb614be21f65ce64bc [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
mtkleindbfd7ab2016-09-01 11:24:54 -070019constexpr SkColor gColors[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000020 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
21};
mtkleindbfd7ab2016-09-01 11:24:54 -070022constexpr SkScalar gPos0[] = { 0, SK_Scalar1 };
23constexpr SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
24constexpr SkScalar gPos2[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000025 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
26};
27
mtkleindbfd7ab2016-09-01 11:24:54 -070028constexpr SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f};
29constexpr SkColor gColorClamp[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000030 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
31};
32
mtkleindbfd7ab2016-09-01 11:24:54 -070033constexpr GradData gGradData[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000034 { 2, gColors, gPos0 },
35 { 2, gColors, gPos1 },
36 { 5, gColors, gPos2 },
37 { 4, gColorClamp, gPosClamp }
38};
39
reed1a9b9642016-03-13 14:13:58 -070040static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
41 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);
reed1a9b9642016-03-13 14:13:58 -070047 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
48 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000049}
50
Yuqian Li81d9f0d2017-12-13 15:47:26 -050051static sk_sp<SkShader> Make2ConicalOutsideStrip(const SkPoint pts[2], const GradData& data,
52 SkShader::TileMode tm, const SkMatrix& localMatrix) {
53 SkPoint center0, center1;
54 SkScalar radius = (pts[1].fX - pts[0].fX) / 3;
55 center0.set(pts[0].fX, pts[0].fY);
56 center1.set(pts[1].fX, pts[1].fY);
57 return SkGradientShader::MakeTwoPointConical(center0, radius, center1, radius, data.fColors,
58 data.fPos, data.fCount, tm, 0, &localMatrix);
59}
60
reed1a9b9642016-03-13 14:13:58 -070061static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000062 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000063 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -070064 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
65 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000066 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
67 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -070068 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
69 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000070}
71
reed1a9b9642016-03-13 14:13:58 -070072static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data,
73 SkShader::TileMode tm, const SkMatrix& localMatrix) {
74 SkPoint center0, center1;
75 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
76 SkScalarAve(pts[0].fY, pts[1].fY));
77 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
78 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
79 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
80 center0, (pts[1].fX - pts[0].fX) / 2,
81 data.fColors, data.fPos, data.fCount, tm,
82 0, &localMatrix);
83}
84
85static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
86 SkShader::TileMode tm, const SkMatrix& localMatrix) {
87 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));
92 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
93 center1, (pts[1].fX - pts[0].fX) / 7,
94 data.fColors, data.fPos, data.fCount, tm,
95 0, &localMatrix);
96}
97
98static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000099 SkShader::TileMode tm, const SkMatrix& localMatrix) {
Yuqian Li650dd902018-03-19 14:23:48 -0400100 SkPoint center0;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000101 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
102 SkScalarAve(pts[0].fY, pts[1].fY));
reed1a9b9642016-03-13 14:13:58 -0700103 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
104 center0, (pts[1].fX - pts[0].fX) / 2,
105 data.fColors, data.fPos, data.fCount, tm,
106 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000107}
108
Yuqian Li650dd902018-03-19 14:23:48 -0400109static sk_sp<SkShader> Make2ConicalInsideCenterReversed(const SkPoint pts[2], const GradData& data,
110 SkShader::TileMode tm, const SkMatrix& localMatrix) {
111 SkPoint center0;
112 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
113 SkScalarAve(pts[0].fY, pts[1].fY));
114 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
115 center0, (pts[1].fX - pts[0].fX) / 7,
116 data.fColors, data.fPos, data.fCount, tm,
117 0, &localMatrix);
118}
119
reed1a9b9642016-03-13 14:13:58 -0700120static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
121 SkShader::TileMode tm, const SkMatrix& localMatrix) {
122 SkPoint center0, center1;
123 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
124 SkScalarAve(pts[0].fY, pts[1].fY));
125 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
126 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
127 return SkGradientShader::MakeTwoPointConical(center1, 0.f,
128 center0, (pts[1].fX - pts[0].fX) / 2,
129 data.fColors, data.fPos, data.fCount, tm,
130 0, &localMatrix);
131}
132
133static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
134 SkShader::TileMode tm, const SkMatrix& localMatrix) {
135 SkPoint center0, center1;
136 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
137 SkScalarAve(pts[0].fY, pts[1].fY));
138 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
139 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
140 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
141 center0, 0.f,
142 data.fColors, data.fPos, data.fCount, tm,
143 0, &localMatrix);
144}
145
146static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000147 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000148 SkPoint center0, center1;
149 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
150 SkScalarAve(pts[0].fY, pts[1].fY));
151 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
152 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
reed1a9b9642016-03-13 14:13:58 -0700153 return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].fX - pts[0].fX) / 2,
154 data.fColors, data.fPos, data.fCount, tm,
155 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000156}
157
reed1a9b9642016-03-13 14:13:58 -0700158static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
159 SkShader::TileMode tm,
160 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000161 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000162 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700163 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000164 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
165 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -0700166 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1,
167 data.fColors, data.fPos,
168 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000169}
170
reed1a9b9642016-03-13 14:13:58 -0700171static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
172 SkShader::TileMode tm,
173 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000174 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000175 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700176 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000177 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
178 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -0700179 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
180 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000181}
182
reed1a9b9642016-03-13 14:13:58 -0700183static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
184 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000185 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700186 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
187 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000188 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
189 SkScalarAve(pts[0].fY, pts[1].fY));
190 center0.set(center1.fX + radius1, center1.fY);
reed1a9b9642016-03-13 14:13:58 -0700191 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
192 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000193}
194
reed1a9b9642016-03-13 14:13:58 -0700195static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
196 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000197 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700198 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
199 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000200 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
201 SkScalarAve(pts[0].fY, pts[1].fY));
202 center0.set(center1.fX, center1.fY + radius1);
reed1a9b9642016-03-13 14:13:58 -0700203 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
204 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000205}
egdaniel8405ef92014-06-09 11:57:28 -0700206
reed1a9b9642016-03-13 14:13:58 -0700207static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
208 SkShader::TileMode tm,
209 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000210 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000211 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700212 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000213 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
214 SkScalarAve(pts[0].fY, pts[1].fY));
215 center0.set(center1.fX + radius1, center1.fY);
reed1a9b9642016-03-13 14:13:58 -0700216 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
217 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000218}
219
reed1a9b9642016-03-13 14:13:58 -0700220static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
221 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000222 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000223 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700224 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000225 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
226 SkScalarAve(pts[0].fY, pts[1].fY));
227 center0.set(center1.fX, center1.fY + radius1);
reed1a9b9642016-03-13 14:13:58 -0700228 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
229 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000230}
231
reed1a9b9642016-03-13 14:13:58 -0700232static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
233 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000234 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700235 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
236 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000237 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
238 SkScalarAve(pts[0].fY, pts[1].fY));
239 center0.set(center1.fX - radius1 + radius0, center1.fY);
reed1a9b9642016-03-13 14:13:58 -0700240 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
241 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000242}
243
reed1a9b9642016-03-13 14:13:58 -0700244static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
245 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000246 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700247 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
248 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000249 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
250 SkScalarAve(pts[0].fY, pts[1].fY));
251 center0.set(center1.fX, center1.fY + radius1 - radius0);
reed1a9b9642016-03-13 14:13:58 -0700252 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
253 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000254}
255
reed1a9b9642016-03-13 14:13:58 -0700256static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000257 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000258 SkPoint center0, center1;
259 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
260 SkScalarAve(pts[0].fY, pts[1].fY));
261 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
262 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
reed1a9b9642016-03-13 14:13:58 -0700263 return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000264 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000265 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000266 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000267}
268
reed1a9b9642016-03-13 14:13:58 -0700269typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
270 SkShader::TileMode tm, const SkMatrix& localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000271
mtkleindbfd7ab2016-09-01 11:24:54 -0700272constexpr GradMaker gGradMakersOutside[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000273 Make2ConicalOutside, Make2ConicalOutsideFlip,
Yuqian Li81d9f0d2017-12-13 15:47:26 -0500274 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside,
275 Make2ConicalOutsideStrip
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000276};
277
mtkleindbfd7ab2016-09-01 11:24:54 -0700278constexpr GradMaker gGradMakersInside[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000279 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
280 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
Yuqian Li650dd902018-03-19 14:23:48 -0400281 Make2ConicalInsideCenterReversed
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000282};
283
mtkleindbfd7ab2016-09-01 11:24:54 -0700284constexpr GradMaker gGradMakersEdgeCases[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000285 Make2ConicalEdgeX, Make2ConicalEdgeY,
286 Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY,
287 Make2ConicalTouchX, Make2ConicalTouchY,
288 Make2ConicalInsideSmallRad
289};
290
291
mtkleindbfd7ab2016-09-01 11:24:54 -0700292constexpr struct {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000293 const GradMaker* fMaker;
294 const int fCount;
295 const char* fName;
296} gGradCases[] = {
297 { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" },
298 { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" },
299 { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" },
300};
301
302enum GradCaseType { // these must match the order in gGradCases
303 kOutside_GradCaseType,
304 kInside_GradCaseType,
305 kEdge_GradCaseType,
306};
307
308///////////////////////////////////////////////////////////////////////////////
309
310class ConicalGradientsGM : public GM {
311public:
Florin Malita26249e02017-06-27 13:38:26 -0400312 ConicalGradientsGM(GradCaseType gradCaseType, bool dither,
313 SkShader::TileMode mode = SkShader::kClamp_TileMode)
fmalita063675b2015-10-12 10:41:48 -0700314 : fGradCaseType(gradCaseType)
Florin Malita26249e02017-06-27 13:38:26 -0400315 , fDither(dither)
316 , fMode(mode) {
Mike Kleind46dce32018-08-16 10:17:03 -0400317 this->setBGColor(0xFFDDDDDD);
fmalita063675b2015-10-12 10:41:48 -0700318 fName.printf("gradients_2pt_conical_%s%s", gGradCases[gradCaseType].fName,
319 fDither ? "" : "_nodither");
Florin Malita26249e02017-06-27 13:38:26 -0400320 switch (mode) {
321 case SkShader::kRepeat_TileMode:
322 fName.appendf("_repeat");
323 break;
324 case SkShader::kMirror_TileMode:
325 fName.appendf("_mirror");
326 break;
327 default:
328 break;
329 }
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000330 }
331
332protected:
333 SkString onShortName() {
334 return fName;
335 }
336
337 virtual SkISize onISize() { return SkISize::Make(840, 815); }
338
339 virtual void onDraw(SkCanvas* canvas) {
340
341 SkPoint pts[2] = {
342 { 0, 0 },
343 { SkIntToScalar(100), SkIntToScalar(100) }
344 };
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000345 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
346 SkPaint paint;
347 paint.setAntiAlias(true);
fmalita063675b2015-10-12 10:41:48 -0700348 paint.setDither(fDither);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000349
350 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
351
352 const GradMaker* gradMaker = gGradCases[fGradCaseType].fMaker;
353 const int count = gGradCases[fGradCaseType].fCount;
354
355 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
356 canvas->save();
357 for (int j = 0; j < count; j++) {
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000358 SkMatrix scale = SkMatrix::I();
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000359
360 if (i == 3) { // if the clamp case
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000361 scale.setScale(0.5f, 0.5f);
362 scale.postTranslate(25.f, 25.f);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000363 }
364
Florin Malita26249e02017-06-27 13:38:26 -0400365 paint.setShader(gradMaker[j](pts, gGradData[i], fMode, scale));
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000366 canvas->drawRect(r, paint);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000367 canvas->translate(0, SkIntToScalar(120));
368 }
369 canvas->restore();
370 canvas->translate(SkIntToScalar(120), 0);
371 }
372 }
373
374private:
375 typedef GM INHERITED;
376
377 GradCaseType fGradCaseType;
378 SkString fName;
fmalita063675b2015-10-12 10:41:48 -0700379 bool fDither;
Florin Malita26249e02017-06-27 13:38:26 -0400380 SkShader::TileMode fMode;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000381};
382///////////////////////////////////////////////////////////////////////////////
383
fmalita063675b2015-10-12 10:41:48 -0700384DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); )
385DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); )
386DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); )
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000387
Florin Malita26249e02017-06-27 13:38:26 -0400388DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true, SkShader::kRepeat_TileMode); )
389DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true, SkShader::kRepeat_TileMode); )
390DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true, SkShader::kRepeat_TileMode); )
391
392DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true, SkShader::kMirror_TileMode); )
393DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true, SkShader::kMirror_TileMode); )
394DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true, SkShader::kMirror_TileMode); )
395
fmalita063675b2015-10-12 10:41:48 -0700396DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); )
397DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); )
398DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); )
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000399
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000400}