OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return SkGradientShader::CreateTwoPointConical( | 73 return SkGradientShader::CreateTwoPointConical( |
74 center1, (pts[1].fX - pts[0].
fX) / 7, | 74 center1, (pts[1].fX - pts[0].
fX) / 7, |
75 center0, (pts[1].fX - pts[0].
fX) / 2, | 75 center0, (pts[1].fX - pts[0].
fX) / 2, |
76 data.fColors, data.fPos, data
.fCount, tm, | 76 data.fColors, data.fPos, data
.fCount, tm, |
77 0, &localMatrix); | 77 0, &localMatrix); |
78 } | 78 } |
79 | 79 |
80 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, | 80 static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, |
81 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ | 81 SkShader::TileMode tm, const SkMatrix& localMatrix)
{ |
82 SkPoint center0, center1; | 82 SkPoint center0, center1; |
83 SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10; | 83 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
84 SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3; | 84 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); | 85 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); | 86 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
87 return SkGradientShader::CreateTwoPointConical(center1, radius1, | 87 return SkGradientShader::CreateTwoPointConical(center1, radius1, |
88 center0, radius0, | 88 center0, radius0, |
89 data.fColors, data.fPos, | 89 data.fColors, data.fPos, |
90 data.fCount, tm, 0, &localMat
rix); | 90 data.fCount, tm, 0, &localMat
rix); |
91 } | 91 } |
92 | 92 |
93 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, | 93 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
94 SkShader::TileMode tm, const SkMatrix& localMatri
x); | 94 SkShader::TileMode tm, const SkMatrix& localMatri
x); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 SkPaint paint; | 178 SkPaint paint; |
179 paint.setAntiAlias(true); | 179 paint.setAntiAlias(true); |
180 | 180 |
181 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); | 181 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
182 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { | 182 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
183 canvas->save(); | 183 canvas->save(); |
184 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { | 184 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
185 // apply an increasing y perspective as we move to the right | 185 // apply an increasing y perspective as we move to the right |
186 SkMatrix perspective; | 186 SkMatrix perspective; |
187 perspective.setIdentity(); | 187 perspective.setIdentity(); |
188 perspective.setPerspY(SkIntToScalar(i+1) / 500); | 188 perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1), |
189 perspective.setSkewX(SkIntToScalar(i+1) / 10); | 189 SkIntToScalar(500))); |
| 190 perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1), |
| 191 SkIntToScalar(10))); |
190 | 192 |
191 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspec
tive); | 193 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspec
tive); |
192 | 194 |
193 paint.setShader(shader); | 195 paint.setShader(shader); |
194 canvas->drawRect(r, paint); | 196 canvas->drawRect(r, paint); |
195 shader->unref(); | 197 shader->unref(); |
196 canvas->translate(0, SkIntToScalar(120)); | 198 canvas->translate(0, SkIntToScalar(120)); |
197 } | 199 } |
198 canvas->restore(); | 200 canvas->restore(); |
199 canvas->translate(SkIntToScalar(120), 0); | 201 canvas->translate(SkIntToScalar(120), 0); |
(...skipping 11 matching lines...) Expand all Loading... |
211 protected: | 213 protected: |
212 SkString onShortName() { | 214 SkString onShortName() { |
213 return SkString("gradients_view_perspective"); | 215 return SkString("gradients_view_perspective"); |
214 } | 216 } |
215 | 217 |
216 virtual SkISize onISize() { return SkISize::Make(840, 500); } | 218 virtual SkISize onISize() { return SkISize::Make(840, 500); } |
217 | 219 |
218 virtual void onDraw(SkCanvas* canvas) { | 220 virtual void onDraw(SkCanvas* canvas) { |
219 SkMatrix perspective; | 221 SkMatrix perspective; |
220 perspective.setIdentity(); | 222 perspective.setIdentity(); |
221 perspective.setPerspY(0.001f); | 223 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); |
222 perspective.setSkewX(SkIntToScalar(8) / 25); | 224 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25))); |
223 canvas->concat(perspective); | 225 canvas->concat(perspective); |
224 INHERITED::onDraw(canvas); | 226 INHERITED::onDraw(canvas); |
225 } | 227 } |
226 | 228 |
227 private: | 229 private: |
228 typedef GradientsGM INHERITED; | 230 typedef GradientsGM INHERITED; |
229 }; | 231 }; |
230 DEF_GM( return new GradientsViewPerspectiveGM; ) | 232 DEF_GM( return new GradientsViewPerspectiveGM; ) |
231 | 233 |
232 /* | 234 /* |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 paint.setShader(fShader); | 456 paint.setShader(fShader); |
455 canvas->drawRect(SkRect::MakeWH(500, 500), paint); | 457 canvas->drawRect(SkRect::MakeWH(500, 500), paint); |
456 } | 458 } |
457 | 459 |
458 private: | 460 private: |
459 typedef GM INHERITED; | 461 typedef GM INHERITED; |
460 }; | 462 }; |
461 DEF_GM( return new RadialGradient3GM; ) | 463 DEF_GM( return new RadialGradient3GM; ) |
462 | 464 |
463 } | 465 } |
OLD | NEW |