OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 static const GradData gGradData[] = { | 33 static const GradData gGradData[] = { |
34 { 2, gColors, gPos0 }, | 34 { 2, gColors, gPos0 }, |
35 { 2, gColors, gPos1 }, | 35 { 2, gColors, gPos1 }, |
36 { 5, gColors, gPos2 }, | 36 { 5, gColors, gPos2 }, |
37 { 4, gColorClamp, gPosClamp } | 37 { 4, gColorClamp, gPosClamp } |
38 }; | 38 }; |
39 | 39 |
40 static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data, | 40 static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data, |
41 SkShader::TileMode tm, const SkMatrix& loca
lMatrix) { | 41 SkShader::TileMode tm, const SkMatrix& loca
lMatrix) { |
42 SkPoint center0, center1; | 42 SkPoint center0, center1; |
43 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); | 43 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
44 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 44 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
47 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 47 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
48 center1, radius1, | 48 center1, radius1, |
49 data.fColors, data.fPos, | 49 data.fColors, data.fPos, |
50 data.fCount, tm, 0, &localMat
rix); | 50 data.fCount, tm, 0, &localMat
rix); |
51 } | 51 } |
52 | 52 |
53 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d
ata, | 53 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d
ata, |
54 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 54 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
55 SkPoint center0, center1; | 55 SkPoint center0, center1; |
56 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); | 56 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; |
57 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 57 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
58 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 58 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
60 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 60 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
61 center0, radius0, | 61 center0, radius0, |
62 data.fColors, data.fPos, | 62 data.fColors, data.fPos, |
63 data.fCount, tm, 0, &localMat
rix); | 63 data.fCount, tm, 0, &localMat
rix); |
64 } | 64 } |
65 | 65 |
66 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data, | 66 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data, |
67 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 67 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return SkGradientShader::CreateTwoPointConical(center0, 0.f, | 138 return SkGradientShader::CreateTwoPointConical(center0, 0.f, |
139 center0, (pts[1].fX - pts[0].
fX) / 2, | 139 center0, (pts[1].fX - pts[0].
fX) / 2, |
140 data.fColors, data.fPos, data
.fCount, tm, | 140 data.fColors, data.fPos, data
.fCount, tm, |
141 0, &localMatrix); | 141 0, &localMatrix); |
142 } | 142 } |
143 | 143 |
144 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData
& data, | 144 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData
& data, |
145 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 145 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
146 SkPoint center0, center1; | 146 SkPoint center0, center1; |
147 SkScalar radius0 = 0.f; | 147 SkScalar radius0 = 0.f; |
148 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 148 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
151 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 151 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
152 center1, radius1, | 152 center1, radius1, |
153 data.fColors, data.fPos, | 153 data.fColors, data.fPos, |
154 data.fCount, tm, 0, &localMat
rix); | 154 data.fCount, tm, 0, &localMat
rix); |
155 } | 155 } |
156 | 156 |
157 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad
Data& data, | 157 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad
Data& data, |
158 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 158 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
159 SkPoint center0, center1; | 159 SkPoint center0, center1; |
160 SkScalar radius0 = 0.f; | 160 SkScalar radius0 = 0.f; |
161 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 161 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
164 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 164 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
165 center0, radius0, | 165 center0, radius0, |
166 data.fColors, data.fPos, | 166 data.fColors, data.fPos, |
167 data.fCount, tm, 0, &localMat
rix); | 167 data.fCount, tm, 0, &localMat
rix); |
168 } | 168 } |
169 | 169 |
170 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, | 170 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, |
171 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 171 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
172 SkPoint center0, center1; | 172 SkPoint center0, center1; |
173 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 173 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
174 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 174 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
176 SkScalarAve(pts[0].fY, pts[1].fY)); | 176 SkScalarAve(pts[0].fY, pts[1].fY)); |
177 center0.set(center1.fX + radius1, center1.fY); | 177 center0.set(center1.fX + radius1, center1.fY); |
178 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 178 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
179 center1, radius1, | 179 center1, radius1, |
180 data.fColors, data.fPos, | 180 data.fColors, data.fPos, |
181 data.fCount, tm, 0, &localMat
rix); | 181 data.fCount, tm, 0, &localMat
rix); |
182 } | 182 } |
183 | 183 |
184 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, | 184 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, |
185 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 185 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
186 SkPoint center0, center1; | 186 SkPoint center0, center1; |
187 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 187 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
188 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 188 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
190 SkScalarAve(pts[0].fY, pts[1].fY)); | 190 SkScalarAve(pts[0].fY, pts[1].fY)); |
191 center0.set(center1.fX, center1.fY + radius1); | 191 center0.set(center1.fX, center1.fY + radius1); |
192 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 192 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
193 center1, radius1, | 193 center1, radius1, |
194 data.fColors, data.fPos, | 194 data.fColors, data.fPos, |
195 data.fCount, tm, 0, &localMat
rix); | 195 data.fCount, tm, 0, &localMat
rix); |
196 } | 196 } |
197 | 197 |
198 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData&
data, | 198 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData&
data, |
199 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 199 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
200 SkPoint center0, center1; | 200 SkPoint center0, center1; |
201 SkScalar radius0 = 0.f; | 201 SkScalar radius0 = 0.f; |
202 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 202 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
203 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 203 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
204 SkScalarAve(pts[0].fY, pts[1].fY)); | 204 SkScalarAve(pts[0].fY, pts[1].fY)); |
205 center0.set(center1.fX + radius1, center1.fY); | 205 center0.set(center1.fX + radius1, center1.fY); |
206 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 206 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
207 center1, radius1, | 207 center1, radius1, |
208 data.fColors, data.fPos, | 208 data.fColors, data.fPos, |
209 data.fCount, tm, 0, &localMat
rix); | 209 data.fCount, tm, 0, &localMat
rix); |
210 } | 210 } |
211 | 211 |
212 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData&
data, | 212 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData&
data, |
213 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 213 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
214 SkPoint center0, center1; | 214 SkPoint center0, center1; |
215 SkScalar radius0 = 0.f; | 215 SkScalar radius0 = 0.f; |
216 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 216 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
217 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 217 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
218 SkScalarAve(pts[0].fY, pts[1].fY)); | 218 SkScalarAve(pts[0].fY, pts[1].fY)); |
219 center0.set(center1.fX, center1.fY + radius1); | 219 center0.set(center1.fX, center1.fY + radius1); |
220 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 220 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
221 center1, radius1, | 221 center1, radius1, |
222 data.fColors, data.fPos, | 222 data.fColors, data.fPos, |
223 data.fCount, tm, 0, &localMat
rix); | 223 data.fCount, tm, 0, &localMat
rix); |
224 } | 224 } |
225 | 225 |
226 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, | 226 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, |
227 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 227 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
228 SkPoint center0, center1; | 228 SkPoint center0, center1; |
229 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 229 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
230 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 230 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
231 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 231 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
232 SkScalarAve(pts[0].fY, pts[1].fY)); | 232 SkScalarAve(pts[0].fY, pts[1].fY)); |
233 center0.set(center1.fX - radius1 + radius0, center1.fY); | 233 center0.set(center1.fX - radius1 + radius0, center1.fY); |
234 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 234 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
235 center1, radius1, | 235 center1, radius1, |
236 data.fColors, data.fPos, | 236 data.fColors, data.fPos, |
237 data.fCount, tm, 0, &localMat
rix); | 237 data.fCount, tm, 0, &localMat
rix); |
238 } | 238 } |
239 | 239 |
240 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, | 240 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, |
241 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 241 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
242 SkPoint center0, center1; | 242 SkPoint center0, center1; |
243 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); | 243 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7; |
244 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 244 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; |
245 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), | 245 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), |
246 SkScalarAve(pts[0].fY, pts[1].fY)); | 246 SkScalarAve(pts[0].fY, pts[1].fY)); |
247 center0.set(center1.fX, center1.fY + radius1 - radius0); | 247 center0.set(center1.fX, center1.fY + radius1 - radius0); |
248 return SkGradientShader::CreateTwoPointConical(center0, radius0, | 248 return SkGradientShader::CreateTwoPointConical(center0, radius0, |
249 center1, radius1, | 249 center1, radius1, |
250 data.fColors, data.fPos, | 250 data.fColors, data.fPos, |
251 data.fCount, tm, 0, &localMat
rix); | 251 data.fCount, tm, 0, &localMat
rix); |
252 } | 252 } |
253 | 253 |
254 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData
& data, | 254 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData
& data, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 365 |
366 static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseTyp
e); } | 366 static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseTyp
e); } |
367 static GMRegistry reg1(MyFactory1); | 367 static GMRegistry reg1(MyFactory1); |
368 | 368 |
369 static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseTy
pe); } | 369 static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseTy
pe); } |
370 static GMRegistry reg2(MyFactory2); | 370 static GMRegistry reg2(MyFactory2); |
371 | 371 |
372 static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType)
; } | 372 static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType)
; } |
373 static GMRegistry reg3(MyFactory3); | 373 static GMRegistry reg3(MyFactory3); |
374 } | 374 } |
OLD | NEW |