OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
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, NULL }, | 34 { 2, gColors, NULL }, |
35 { 2, gColors, gPos0 }, | 35 { 2, gColors, gPos0 }, |
36 { 2, gColors, gPos1 }, | 36 { 2, gColors, gPos1 }, |
37 { 5, gColors, NULL }, | 37 { 5, gColors, NULL }, |
38 { 5, gColors, gPos2 }, | 38 { 5, gColors, gPos2 }, |
39 { 4, gColorClamp, gPosClamp } | 39 { 4, gColorClamp, gPosClamp } |
40 }; | 40 }; |
41 | 41 |
42 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, | 42 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
43 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 43 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 44 const SkMatrix& localMatrix) { |
44 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, | 45 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
45 data.fCount, tm, 0, &localMatrix); | 46 data.fCount, tm, mapper, 0, &localMatr
ix); |
46 } | 47 } |
47 | 48 |
48 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, | 49 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
49 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 50 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 51 const SkMatrix& localMatrix) { |
50 SkPoint center; | 52 SkPoint center; |
51 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 53 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
52 SkScalarAve(pts[0].fY, pts[1].fY)); | 54 SkScalarAve(pts[0].fY, pts[1].fY)); |
53 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, | 55 return SkGradientShader::CreateRadial(center, center.fX, data.fColors, |
54 data.fPos, data.fCount, tm, 0, &localM
atrix); | 56 data.fPos, data.fCount, tm, mapper, 0,
&localMatrix); |
55 } | 57 } |
56 | 58 |
57 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, | 59 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
58 SkShader::TileMode, const SkMatrix& localMatrix) { | 60 SkShader::TileMode, SkUnitMapper* mapper, |
| 61 const SkMatrix& localMatrix) { |
59 SkPoint center; | 62 SkPoint center; |
60 center.set(SkScalarAve(pts[0].fX, pts[1].fX), | 63 center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
61 SkScalarAve(pts[0].fY, pts[1].fY)); | 64 SkScalarAve(pts[0].fY, pts[1].fY)); |
62 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, | 65 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
63 data.fPos, data.fCount, 0, &localMatrix
); | 66 data.fPos, data.fCount, mapper, 0, &loc
alMatrix); |
64 } | 67 } |
65 | 68 |
66 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, | 69 static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, |
67 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 70 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 71 const SkMatrix& localMatrix) { |
68 SkPoint center0, center1; | 72 SkPoint center0, center1; |
69 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), | 73 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
70 SkScalarAve(pts[0].fY, pts[1].fY)); | 74 SkScalarAve(pts[0].fY, pts[1].fY)); |
71 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 75 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
72 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 76 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
73 return SkGradientShader::CreateTwoPointRadial( | 77 return SkGradientShader::CreateTwoPointRadial( |
74 center1, (pts[1].fX - pts[0].f
X) / 7, | 78 center1, (pts[1].fX - pts[0].f
X) / 7, |
75 center0, (pts[1].fX - pts[0].f
X) / 2, | 79 center0, (pts[1].fX - pts[0].f
X) / 2, |
76 data.fColors, data.fPos, data.
fCount, tm, | 80 data.fColors, data.fPos, data.
fCount, tm, mapper, |
77 0, &localMatrix); | 81 0, &localMatrix); |
78 } | 82 } |
79 | 83 |
80 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, | 84 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, |
81 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 85 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 86 const SkMatrix& localMatrix) { |
82 SkPoint center0, center1; | 87 SkPoint center0, center1; |
83 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); | 88 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
84 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); | 89 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 90 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 91 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
87 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 92 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
88 center0, radius0, | 93 center0, radius0, |
89 data.fColors, data.fPos, | 94 data.fColors, data.fPos, |
90 data.fCount, tm, 0, &localMat
rix); | 95 data.fCount, tm, mapper, |
| 96 0, &localMatrix); |
91 } | 97 } |
92 | 98 |
93 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | 99 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
94 SkShader::TileMode tm, const SkMatrix& localMatri
x); | 100 SkShader::TileMode tm, SkUnitMapper* mapper, |
| 101 const SkMatrix& localMatrix); |
95 static const GradMaker gGradMakers[] = { | 102 static const GradMaker gGradMakers[] = { |
96 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical | 103 MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical |
97 }; | 104 }; |
98 | 105 |
99 /////////////////////////////////////////////////////////////////////////////// | 106 /////////////////////////////////////////////////////////////////////////////// |
100 | 107 |
101 class GradientsGM : public GM { | 108 class GradientsGM : public GM { |
102 public: | 109 public: |
103 GradientsGM() { | 110 GradientsGM() { |
104 this->setBGColor(0xFFDDDDDD); | 111 this->setBGColor(0xFFDDDDDD); |
(...skipping 25 matching lines...) Expand all Loading... |
130 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { | 137 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
131 canvas->save(); | 138 canvas->save(); |
132 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { | 139 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
133 SkMatrix scale = SkMatrix::I(); | 140 SkMatrix scale = SkMatrix::I(); |
134 | 141 |
135 if (i == 5) { // if the clamp case | 142 if (i == 5) { // if the clamp case |
136 scale.setScale(0.5f, 0.5f); | 143 scale.setScale(0.5f, 0.5f); |
137 scale.postTranslate(25.f, 25.f); | 144 scale.postTranslate(25.f, 25.f); |
138 } | 145 } |
139 | 146 |
140 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, scale); | 147 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL, s
cale); |
141 | 148 |
142 paint.setShader(shader); | 149 paint.setShader(shader); |
143 canvas->drawRect(r, paint); | 150 canvas->drawRect(r, paint); |
144 shader->unref(); | 151 shader->unref(); |
145 canvas->translate(0, SkIntToScalar(120)); | 152 canvas->translate(0, SkIntToScalar(120)); |
146 } | 153 } |
147 canvas->restore(); | 154 canvas->restore(); |
148 canvas->translate(SkIntToScalar(120), 0); | 155 canvas->translate(SkIntToScalar(120), 0); |
149 } | 156 } |
150 } | 157 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 canvas->save(); | 195 canvas->save(); |
189 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { | 196 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
190 // apply an increasing y perspective as we move to the right | 197 // apply an increasing y perspective as we move to the right |
191 SkMatrix perspective; | 198 SkMatrix perspective; |
192 perspective.setIdentity(); | 199 perspective.setIdentity(); |
193 perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1), | 200 perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1), |
194 SkIntToScalar(500))); | 201 SkIntToScalar(500))); |
195 perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1), | 202 perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1), |
196 SkIntToScalar(10))); | 203 SkIntToScalar(10))); |
197 | 204 |
198 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspec
tive); | 205 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL, p
erspective); |
199 | 206 |
200 paint.setShader(shader); | 207 paint.setShader(shader); |
201 canvas->drawRect(r, paint); | 208 canvas->drawRect(r, paint); |
202 shader->unref(); | 209 shader->unref(); |
203 canvas->translate(0, SkIntToScalar(120)); | 210 canvas->translate(0, SkIntToScalar(120)); |
204 } | 211 } |
205 canvas->restore(); | 212 canvas->restore(); |
206 canvas->translate(SkIntToScalar(120), 0); | 213 canvas->translate(SkIntToScalar(120), 0); |
207 } | 214 } |
208 } | 215 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(300) }; | 320 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(300) }; |
314 SkPaint paint; | 321 SkPaint paint; |
315 paint.setAntiAlias(true); | 322 paint.setAntiAlias(true); |
316 | 323 |
317 SkPoint center; | 324 SkPoint center; |
318 center.iset(0, 300); | 325 center.iset(0, 300); |
319 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); | 326 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
320 SkShader* shader = SkGradientShader::CreateRadial( | 327 SkShader* shader = SkGradientShader::CreateRadial( |
321 SkPoint(center), | 328 SkPoint(center), |
322 SkIntToScalar(200), gColors, NULL, 5, | 329 SkIntToScalar(200), gColors, NULL, 5, |
323 SkShader::kClamp_TileMode); | 330 SkShader::kClamp_TileMode, NULL); |
324 paint.setShader(shader); | 331 paint.setShader(shader); |
325 canvas->drawRect(r, paint); | 332 canvas->drawRect(r, paint); |
326 shader->unref(); | 333 shader->unref(); |
327 } | 334 } |
328 | 335 |
329 private: | 336 private: |
330 typedef GM INHERITED; | 337 typedef GM INHERITED; |
331 }; | 338 }; |
332 | 339 |
333 /// Checks quality of large radial gradients, which may display | 340 /// Checks quality of large radial gradients, which may display |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 center.set(cx, cy); | 415 center.set(cx, cy); |
409 | 416 |
410 // We can either interpolate endpoints and premultiply each point (defau
lt, more precision), | 417 // We can either interpolate endpoints and premultiply each point (defau
lt, more precision), |
411 // or premultiply the endpoints first, avoiding the need to premultiply
each point (cheap). | 418 // or premultiply the endpoints first, avoiding the need to premultiply
each point (cheap). |
412 const uint32_t flags[] = { 0, SkGradientShader::kInterpolateColorsInPrem
ul_Flag }; | 419 const uint32_t flags[] = { 0, SkGradientShader::kInterpolateColorsInPrem
ul_Flag }; |
413 | 420 |
414 for (size_t i = 0; i < SK_ARRAY_COUNT(flags); i++) { | 421 for (size_t i = 0; i < SK_ARRAY_COUNT(flags); i++) { |
415 SkAutoTUnref<SkShader> sweep( | 422 SkAutoTUnref<SkShader> sweep( |
416 SkGradientShader::CreateSweep(cx, cy, sweep_colors, | 423 SkGradientShader::CreateSweep(cx, cy, sweep_colors, |
417 NULL, SK_ARRAY_COUNT(sweep_col
ors), | 424 NULL, SK_ARRAY_COUNT(sweep_col
ors), |
418 flags[i], NULL)); | 425 NULL, flags[i])); |
419 SkAutoTUnref<SkShader> radial1( | 426 SkAutoTUnref<SkShader> radial1( |
420 SkGradientShader::CreateRadial(center, radius, colors1, | 427 SkGradientShader::CreateRadial(center, radius, colors1, |
421 NULL, SK_ARRAY_COUNT(colors1)
, | 428 NULL, SK_ARRAY_COUNT(colors1)
, |
422 SkShader::kClamp_TileMode, | 429 SkShader::kClamp_TileMode, |
423 flags[i], NULL)); | 430 NULL, flags[i])); |
424 SkAutoTUnref<SkShader> radial2( | 431 SkAutoTUnref<SkShader> radial2( |
425 SkGradientShader::CreateRadial(center, radius, colors2, | 432 SkGradientShader::CreateRadial(center, radius, colors2, |
426 NULL, SK_ARRAY_COUNT(colors2)
, | 433 NULL, SK_ARRAY_COUNT(colors2)
, |
427 SkShader::kClamp_TileMode, | 434 SkShader::kClamp_TileMode, |
428 flags[i], NULL)); | 435 NULL, flags[i])); |
429 paint1.setShader(sweep); | 436 paint1.setShader(sweep); |
430 paint2.setShader(radial1); | 437 paint2.setShader(radial1); |
431 paint3.setShader(radial2); | 438 paint3.setShader(radial2); |
432 | 439 |
433 canvas->drawCircle(cx, cy, radius, paint1); | 440 canvas->drawCircle(cx, cy, radius, paint1); |
434 canvas->drawCircle(cx, cy, radius, paint3); | 441 canvas->drawCircle(cx, cy, radius, paint3); |
435 canvas->drawCircle(cx, cy, radius, paint2); | 442 canvas->drawCircle(cx, cy, radius, paint2); |
436 | 443 |
437 canvas->translate(400, 0); | 444 canvas->translate(400, 0); |
438 } | 445 } |
(...skipping 19 matching lines...) Expand all Loading... |
458 | 465 |
459 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } | 466 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } |
460 static GMRegistry reg5(MyFactory5); | 467 static GMRegistry reg5(MyFactory5); |
461 | 468 |
462 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } | 469 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } |
463 static GMRegistry reg6(MyFactory6); | 470 static GMRegistry reg6(MyFactory6); |
464 | 471 |
465 static GM* MyFactory7(void*) { return new RadialGradient2GM; } | 472 static GM* MyFactory7(void*) { return new RadialGradient2GM; } |
466 static GMRegistry reg7(MyFactory7); | 473 static GMRegistry reg7(MyFactory7); |
467 } | 474 } |
OLD | NEW |