blob: 3cda2c656dbc19a3c07ab126af06363054be7fa4 [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"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000010#include "SkGradientShader.h"
11
12namespace skiagm {
13
14struct GradData {
15 int fCount;
16 const SkColor* fColors;
17 const SkScalar* fPos;
18};
19
mtkleindbfd7ab2016-09-01 11:24:54 -070020constexpr SkColor gColors[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000021 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
22};
mtkleindbfd7ab2016-09-01 11:24:54 -070023constexpr SkScalar gPos0[] = { 0, SK_Scalar1 };
24constexpr SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
25constexpr SkScalar gPos2[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000026 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
27};
28
mtkleindbfd7ab2016-09-01 11:24:54 -070029constexpr SkScalar gPosClamp[] = {0.0f, 0.0f, 1.0f, 1.0f};
30constexpr SkColor gColorClamp[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000031 SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorBLUE
32};
33
mtkleindbfd7ab2016-09-01 11:24:54 -070034constexpr GradData gGradData[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000035 { 2, gColors, gPos0 },
36 { 2, gColors, gPos1 },
37 { 5, gColors, gPos2 },
38 { 4, gColorClamp, gPosClamp }
39};
40
reed1a9b9642016-03-13 14:13:58 -070041static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
42 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000043 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -070044 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
45 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000046 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
47 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -070048 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
49 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000050}
51
reed1a9b9642016-03-13 14:13:58 -070052static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000053 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000054 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -070055 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
56 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000057 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
58 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -070059 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
60 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000061}
62
reed1a9b9642016-03-13 14:13:58 -070063static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data,
64 SkShader::TileMode tm, const SkMatrix& localMatrix) {
65 SkPoint center0, center1;
66 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
67 SkScalarAve(pts[0].fY, pts[1].fY));
68 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
69 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
70 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
71 center0, (pts[1].fX - pts[0].fX) / 2,
72 data.fColors, data.fPos, data.fCount, tm,
73 0, &localMatrix);
74}
75
76static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
77 SkShader::TileMode tm, const SkMatrix& localMatrix) {
78 SkPoint center0, center1;
79 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
80 SkScalarAve(pts[0].fY, pts[1].fY));
81 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
82 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
83 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
84 center1, (pts[1].fX - pts[0].fX) / 7,
85 data.fColors, data.fPos, data.fCount, tm,
86 0, &localMatrix);
87}
88
89static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +000090 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +000091 SkPoint center0, center1;
92 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
93 SkScalarAve(pts[0].fY, pts[1].fY));
94 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
95 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
reed1a9b9642016-03-13 14:13:58 -070096 return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
97 center0, (pts[1].fX - pts[0].fX) / 2,
98 data.fColors, data.fPos, data.fCount, tm,
99 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000100}
101
reed1a9b9642016-03-13 14:13:58 -0700102static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
103 SkShader::TileMode tm, const SkMatrix& localMatrix) {
104 SkPoint center0, center1;
105 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
106 SkScalarAve(pts[0].fY, pts[1].fY));
107 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
108 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
109 return SkGradientShader::MakeTwoPointConical(center1, 0.f,
110 center0, (pts[1].fX - pts[0].fX) / 2,
111 data.fColors, data.fPos, data.fCount, tm,
112 0, &localMatrix);
113}
114
115static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
116 SkShader::TileMode tm, const SkMatrix& localMatrix) {
117 SkPoint center0, center1;
118 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
119 SkScalarAve(pts[0].fY, pts[1].fY));
120 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
121 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
122 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
123 center0, 0.f,
124 data.fColors, data.fPos, data.fCount, tm,
125 0, &localMatrix);
126}
127
128static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000129 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000130 SkPoint center0, center1;
131 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
132 SkScalarAve(pts[0].fY, pts[1].fY));
133 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
134 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
reed1a9b9642016-03-13 14:13:58 -0700135 return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].fX - pts[0].fX) / 2,
136 data.fColors, data.fPos, data.fCount, tm,
137 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000138}
139
reed1a9b9642016-03-13 14:13:58 -0700140static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
141 SkShader::TileMode tm,
142 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000143 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000144 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700145 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000146 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
147 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -0700148 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1,
149 data.fColors, data.fPos,
150 data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000151}
152
reed1a9b9642016-03-13 14:13:58 -0700153static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
154 SkShader::TileMode tm,
155 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000156 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000157 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700158 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000159 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
160 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
reed1a9b9642016-03-13 14:13:58 -0700161 return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
162 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000163}
164
reed1a9b9642016-03-13 14:13:58 -0700165static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
166 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000167 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700168 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
169 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000170 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
171 SkScalarAve(pts[0].fY, pts[1].fY));
172 center0.set(center1.fX + radius1, center1.fY);
reed1a9b9642016-03-13 14:13:58 -0700173 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
174 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000175}
176
reed1a9b9642016-03-13 14:13:58 -0700177static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
178 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000179 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700180 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
181 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000182 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
183 SkScalarAve(pts[0].fY, pts[1].fY));
184 center0.set(center1.fX, center1.fY + radius1);
reed1a9b9642016-03-13 14:13:58 -0700185 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
186 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000187}
egdaniel8405ef92014-06-09 11:57:28 -0700188
reed1a9b9642016-03-13 14:13:58 -0700189static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
190 SkShader::TileMode tm,
191 const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000192 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000193 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700194 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000195 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
196 SkScalarAve(pts[0].fY, pts[1].fY));
197 center0.set(center1.fX + radius1, center1.fY);
reed1a9b9642016-03-13 14:13:58 -0700198 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
199 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000200}
201
reed1a9b9642016-03-13 14:13:58 -0700202static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
203 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000204 SkPoint center0, center1;
commit-bot@chromium.org80894672014-04-22 21:24:22 +0000205 SkScalar radius0 = 0.f;
reed80ea19c2015-05-12 10:37:34 -0700206 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000207 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
208 SkScalarAve(pts[0].fY, pts[1].fY));
209 center0.set(center1.fX, center1.fY + radius1);
reed1a9b9642016-03-13 14:13:58 -0700210 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
211 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000212}
213
reed1a9b9642016-03-13 14:13:58 -0700214static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
215 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000216 SkPoint center0, center1;
reed80ea19c2015-05-12 10:37:34 -0700217 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
218 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000219 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
220 SkScalarAve(pts[0].fY, pts[1].fY));
221 center0.set(center1.fX - radius1 + radius0, center1.fY);
reed1a9b9642016-03-13 14:13:58 -0700222 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
223 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000224}
225
reed1a9b9642016-03-13 14:13:58 -0700226static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
227 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, center1.fY + radius1 - radius0);
reed1a9b9642016-03-13 14:13:58 -0700234 return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
235 data.fPos, data.fCount, tm, 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000236}
237
reed1a9b9642016-03-13 14:13:58 -0700238static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000239 SkShader::TileMode tm, const SkMatrix& localMatrix) {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000240 SkPoint center0, center1;
241 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
242 SkScalarAve(pts[0].fY, pts[1].fY));
243 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
244 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
reed1a9b9642016-03-13 14:13:58 -0700245 return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000246 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000247 data.fColors, data.fPos, data.fCount, tm,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000248 0, &localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000249}
250
reed1a9b9642016-03-13 14:13:58 -0700251typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
252 SkShader::TileMode tm, const SkMatrix& localMatrix);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000253
mtkleindbfd7ab2016-09-01 11:24:54 -0700254constexpr GradMaker gGradMakersOutside[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000255 Make2ConicalOutside, Make2ConicalOutsideFlip,
256 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside
257};
258
mtkleindbfd7ab2016-09-01 11:24:54 -0700259constexpr GradMaker gGradMakersInside[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000260 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
261 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
262};
263
mtkleindbfd7ab2016-09-01 11:24:54 -0700264constexpr GradMaker gGradMakersEdgeCases[] = {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000265 Make2ConicalEdgeX, Make2ConicalEdgeY,
266 Make2ConicalZeroRadEdgeX, Make2ConicalZeroRadEdgeY,
267 Make2ConicalTouchX, Make2ConicalTouchY,
268 Make2ConicalInsideSmallRad
269};
270
271
mtkleindbfd7ab2016-09-01 11:24:54 -0700272constexpr struct {
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000273 const GradMaker* fMaker;
274 const int fCount;
275 const char* fName;
276} gGradCases[] = {
277 { gGradMakersOutside, SK_ARRAY_COUNT(gGradMakersOutside), "outside" },
278 { gGradMakersInside, SK_ARRAY_COUNT(gGradMakersInside), "inside" },
279 { gGradMakersEdgeCases, SK_ARRAY_COUNT(gGradMakersEdgeCases), "edge" },
280};
281
282enum GradCaseType { // these must match the order in gGradCases
283 kOutside_GradCaseType,
284 kInside_GradCaseType,
285 kEdge_GradCaseType,
286};
287
288///////////////////////////////////////////////////////////////////////////////
289
290class ConicalGradientsGM : public GM {
291public:
Florin Malita26249e02017-06-27 13:38:26 -0400292 ConicalGradientsGM(GradCaseType gradCaseType, bool dither,
293 SkShader::TileMode mode = SkShader::kClamp_TileMode)
fmalita063675b2015-10-12 10:41:48 -0700294 : fGradCaseType(gradCaseType)
Florin Malita26249e02017-06-27 13:38:26 -0400295 , fDither(dither)
296 , fMode(mode) {
caryclark65cdba62015-06-15 06:51:08 -0700297 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
fmalita063675b2015-10-12 10:41:48 -0700298 fName.printf("gradients_2pt_conical_%s%s", gGradCases[gradCaseType].fName,
299 fDither ? "" : "_nodither");
Florin Malita26249e02017-06-27 13:38:26 -0400300 switch (mode) {
301 case SkShader::kRepeat_TileMode:
302 fName.appendf("_repeat");
303 break;
304 case SkShader::kMirror_TileMode:
305 fName.appendf("_mirror");
306 break;
307 default:
308 break;
309 }
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000310 }
311
312protected:
313 SkString onShortName() {
314 return fName;
315 }
316
317 virtual SkISize onISize() { return SkISize::Make(840, 815); }
318
319 virtual void onDraw(SkCanvas* canvas) {
320
321 SkPoint pts[2] = {
322 { 0, 0 },
323 { SkIntToScalar(100), SkIntToScalar(100) }
324 };
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000325 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
326 SkPaint paint;
327 paint.setAntiAlias(true);
fmalita063675b2015-10-12 10:41:48 -0700328 paint.setDither(fDither);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000329
330 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
331
332 const GradMaker* gradMaker = gGradCases[fGradCaseType].fMaker;
333 const int count = gGradCases[fGradCaseType].fCount;
334
335 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
336 canvas->save();
337 for (int j = 0; j < count; j++) {
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000338 SkMatrix scale = SkMatrix::I();
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000339
340 if (i == 3) { // if the clamp case
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000341 scale.setScale(0.5f, 0.5f);
342 scale.postTranslate(25.f, 25.f);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000343 }
344
Florin Malita26249e02017-06-27 13:38:26 -0400345 paint.setShader(gradMaker[j](pts, gGradData[i], fMode, scale));
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000346 canvas->drawRect(r, paint);
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000347 canvas->translate(0, SkIntToScalar(120));
348 }
349 canvas->restore();
350 canvas->translate(SkIntToScalar(120), 0);
351 }
352 }
353
354private:
355 typedef GM INHERITED;
356
357 GradCaseType fGradCaseType;
358 SkString fName;
fmalita063675b2015-10-12 10:41:48 -0700359 bool fDither;
Florin Malita26249e02017-06-27 13:38:26 -0400360 SkShader::TileMode fMode;
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000361};
362///////////////////////////////////////////////////////////////////////////////
363
fmalita063675b2015-10-12 10:41:48 -0700364DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true); )
365DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true); )
366DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true); )
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000367
Florin Malita26249e02017-06-27 13:38:26 -0400368DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true, SkShader::kRepeat_TileMode); )
369DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true, SkShader::kRepeat_TileMode); )
370DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true, SkShader::kRepeat_TileMode); )
371
372DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, true, SkShader::kMirror_TileMode); )
373DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, true, SkShader::kMirror_TileMode); )
374DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, true, SkShader::kMirror_TileMode); )
375
fmalita063675b2015-10-12 10:41:48 -0700376DEF_GM( return new ConicalGradientsGM(kInside_GradCaseType, false); )
377DEF_GM( return new ConicalGradientsGM(kOutside_GradCaseType, false); )
378DEF_GM( return new ConicalGradientsGM(kEdge_GradCaseType, false); )
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000379
commit-bot@chromium.orgc8379d72014-04-22 20:56:37 +0000380}