epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 8 | #include "gm.h" |
| 9 | #include "SkGradientShader.h" |
| 10 | |
| 11 | namespace skiagm { |
| 12 | |
| 13 | struct GradData { |
| 14 | int fCount; |
| 15 | const SkColor* fColors; |
| 16 | const SkScalar* fPos; |
| 17 | }; |
| 18 | |
| 19 | static const SkColor gColors[] = { |
| 20 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK |
| 21 | }; |
| 22 | static const SkScalar gPos0[] = { 0, SK_Scalar1 }; |
| 23 | static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 }; |
| 24 | static const SkScalar gPos2[] = { |
| 25 | 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1 |
| 26 | }; |
| 27 | |
| 28 | static const GradData gGradData[] = { |
| 29 | { 2, gColors, NULL }, |
| 30 | { 2, gColors, gPos0 }, |
| 31 | { 2, gColors, gPos1 }, |
| 32 | { 5, gColors, NULL }, |
| 33 | { 5, gColors, gPos2 } |
| 34 | }; |
| 35 | |
| 36 | static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
| 37 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 38 | return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
| 39 | data.fCount, tm, mapper); |
| 40 | } |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 41 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 42 | static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
| 43 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 44 | SkPoint center; |
| 45 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 46 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 47 | return SkGradientShader::CreateRadial(center, center.fX, data.fColors, |
| 48 | data.fPos, data.fCount, tm, mapper); |
| 49 | } |
| 50 | |
| 51 | static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
sugoi@google.com | 0f0d9b7 | 2013-02-27 15:41:12 +0000 | [diff] [blame] | 52 | SkShader::TileMode, SkUnitMapper* mapper) { |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 53 | SkPoint center; |
| 54 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 55 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 56 | return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
| 57 | data.fPos, data.fCount, mapper); |
| 58 | } |
| 59 | |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 60 | static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, |
| 61 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 62 | SkPoint center0, center1; |
| 63 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 64 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 65 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 66 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 67 | return SkGradientShader::CreateTwoPointRadial( |
| 68 | center1, (pts[1].fX - pts[0].fX) / 7, |
| 69 | center0, (pts[1].fX - pts[0].fX) / 2, |
| 70 | data.fColors, data.fPos, data.fCount, tm, mapper); |
| 71 | } |
| 72 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 73 | static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, |
| 74 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 75 | SkPoint center0, center1; |
| 76 | SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); |
| 77 | SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); |
| 78 | center0.set(pts[0].fX + radius0, pts[0].fY + radius0); |
| 79 | center1.set(pts[1].fX - radius1, pts[1].fY - radius1); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 80 | return SkGradientShader::CreateTwoPointConical(center1, radius1, |
| 81 | center0, radius0, |
| 82 | data.fColors, data.fPos, |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 83 | data.fCount, tm, mapper); |
| 84 | } |
| 85 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 86 | typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
reed@google.com | f3c1cc9 | 2010-12-23 16:45:33 +0000 | [diff] [blame] | 87 | SkShader::TileMode tm, SkUnitMapper* mapper); |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 88 | static const GradMaker gGradMakers[] = { |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 89 | MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /////////////////////////////////////////////////////////////////////////////// |
| 93 | |
| 94 | class GradientsGM : public GM { |
| 95 | public: |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 96 | GradientsGM() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 97 | this->setBGColor(0xFFDDDDDD); |
| 98 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 99 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 100 | protected: |
| 101 | SkString onShortName() { |
| 102 | return SkString("gradients"); |
| 103 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 104 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 105 | virtual SkISize onISize() { return make_isize(640, 615); } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 106 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 107 | virtual void onDraw(SkCanvas* canvas) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 108 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 109 | SkPoint pts[2] = { |
| 110 | { 0, 0 }, |
| 111 | { SkIntToScalar(100), SkIntToScalar(100) } |
| 112 | }; |
| 113 | SkShader::TileMode tm = SkShader::kClamp_TileMode; |
| 114 | SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; |
| 115 | SkPaint paint; |
| 116 | paint.setAntiAlias(true); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 117 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 118 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 119 | for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
| 120 | canvas->save(); |
| 121 | for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
| 122 | SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL); |
| 123 | paint.setShader(shader); |
| 124 | canvas->drawRect(r, paint); |
| 125 | shader->unref(); |
| 126 | canvas->translate(0, SkIntToScalar(120)); |
| 127 | } |
| 128 | canvas->restore(); |
| 129 | canvas->translate(SkIntToScalar(120), 0); |
| 130 | } |
| 131 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 132 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 133 | private: |
| 134 | typedef GM INHERITED; |
| 135 | }; |
| 136 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 137 | // Based on the original gradient slide, but with perspective applied to the |
| 138 | // gradient shaders' local matrices |
| 139 | class GradientsLocalPerspectiveGM : public GM { |
| 140 | public: |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 141 | GradientsLocalPerspectiveGM() { |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 142 | this->setBGColor(0xFFDDDDDD); |
| 143 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 144 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 145 | protected: |
| 146 | SkString onShortName() { |
| 147 | return SkString("gradients_local_perspective"); |
| 148 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 149 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 150 | virtual SkISize onISize() { return make_isize(640, 615); } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 151 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 152 | virtual void onDraw(SkCanvas* canvas) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 153 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 154 | SkPoint pts[2] = { |
| 155 | { 0, 0 }, |
| 156 | { SkIntToScalar(100), SkIntToScalar(100) } |
| 157 | }; |
| 158 | SkShader::TileMode tm = SkShader::kClamp_TileMode; |
| 159 | SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; |
| 160 | SkPaint paint; |
| 161 | paint.setAntiAlias(true); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 162 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 163 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 164 | for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
| 165 | canvas->save(); |
| 166 | for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
| 167 | SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 168 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 169 | // apply an increasing y perspective as we move to the right |
| 170 | SkMatrix perspective; |
| 171 | perspective.setIdentity(); |
borenet@google.com | b796119 | 2012-08-20 18:58:26 +0000 | [diff] [blame] | 172 | perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1), |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 173 | SkIntToScalar(500))); |
borenet@google.com | b796119 | 2012-08-20 18:58:26 +0000 | [diff] [blame] | 174 | perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1), |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 175 | SkIntToScalar(10))); |
| 176 | shader->setLocalMatrix(perspective); |
| 177 | |
| 178 | paint.setShader(shader); |
| 179 | canvas->drawRect(r, paint); |
| 180 | shader->unref(); |
| 181 | canvas->translate(0, SkIntToScalar(120)); |
| 182 | } |
| 183 | canvas->restore(); |
| 184 | canvas->translate(SkIntToScalar(120), 0); |
| 185 | } |
| 186 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 187 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 188 | private: |
| 189 | typedef GM INHERITED; |
| 190 | }; |
| 191 | |
| 192 | // Based on the original gradient slide, but with perspective applied to |
| 193 | // the view matrix |
| 194 | class GradientsViewPerspectiveGM : public GradientsGM { |
| 195 | protected: |
| 196 | SkString onShortName() { |
| 197 | return SkString("gradients_view_perspective"); |
| 198 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 199 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 200 | virtual SkISize onISize() { return make_isize(640, 400); } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 201 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 202 | virtual void onDraw(SkCanvas* canvas) { |
| 203 | SkMatrix perspective; |
| 204 | perspective.setIdentity(); |
| 205 | perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); |
| 206 | perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25))); |
scroggo@google.com | 837d31a | 2012-08-15 18:42:45 +0000 | [diff] [blame] | 207 | canvas->concat(perspective); |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 208 | INHERITED::onDraw(canvas); |
| 209 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 210 | |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 211 | private: |
| 212 | typedef GradientsGM INHERITED; |
| 213 | }; |
| 214 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 215 | /* |
| 216 | Inspired by this <canvas> javascript, where we need to detect that we are not |
| 217 | solving a quadratic equation, but must instead solve a linear (since our X^2 |
| 218 | coefficient is 0) |
| 219 | |
| 220 | ctx.fillStyle = '#f00'; |
| 221 | ctx.fillRect(0, 0, 100, 50); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 222 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 223 | var g = ctx.createRadialGradient(-80, 25, 70, 0, 25, 150); |
| 224 | g.addColorStop(0, '#f00'); |
| 225 | g.addColorStop(0.01, '#0f0'); |
| 226 | g.addColorStop(0.99, '#0f0'); |
| 227 | g.addColorStop(1, '#f00'); |
| 228 | ctx.fillStyle = g; |
| 229 | ctx.fillRect(0, 0, 100, 50); |
| 230 | */ |
| 231 | class GradientsDegenrate2PointGM : public GM { |
| 232 | public: |
| 233 | GradientsDegenrate2PointGM() {} |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 234 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 235 | protected: |
| 236 | SkString onShortName() { |
| 237 | return SkString("gradients_degenerate_2pt"); |
| 238 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 239 | |
| 240 | virtual SkISize onISize() { return make_isize(320, 320); } |
| 241 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 242 | void drawBG(SkCanvas* canvas) { |
| 243 | canvas->drawColor(SK_ColorBLUE); |
| 244 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 245 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 246 | virtual void onDraw(SkCanvas* canvas) { |
| 247 | this->drawBG(canvas); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 248 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 249 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorRED }; |
| 250 | SkScalar pos[] = { 0, SkFloatToScalar(0.01f), SkFloatToScalar(0.99f), SK_Scalar1 }; |
epoger@google.com | 59f3abf | 2011-07-21 15:50:33 +0000 | [diff] [blame] | 251 | SkPoint c0; |
| 252 | c0.iset(-80, 25); |
| 253 | SkScalar r0 = SkIntToScalar(70); |
| 254 | SkPoint c1; |
| 255 | c1.iset(0, 25); |
| 256 | SkScalar r1 = SkIntToScalar(150); |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 257 | SkShader* s = SkGradientShader::CreateTwoPointRadial(c0, r0, c1, r1, colors, |
| 258 | pos, SK_ARRAY_COUNT(pos), |
| 259 | SkShader::kClamp_TileMode); |
| 260 | SkPaint paint; |
| 261 | paint.setShader(s)->unref(); |
| 262 | canvas->drawPaint(paint); |
| 263 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 264 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 265 | private: |
| 266 | typedef GM INHERITED; |
| 267 | }; |
| 268 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 269 | /// Tests correctness of *optimized* codepaths in gradients. |
| 270 | |
| 271 | class ClampedGradientsGM : public GM { |
| 272 | public: |
| 273 | ClampedGradientsGM() {} |
| 274 | |
| 275 | protected: |
| 276 | SkString onShortName() { return SkString("clamped_gradients"); } |
| 277 | |
| 278 | virtual SkISize onISize() { return make_isize(640, 510); } |
| 279 | |
| 280 | void drawBG(SkCanvas* canvas) { |
| 281 | canvas->drawColor(0xFFDDDDDD); |
| 282 | } |
| 283 | |
| 284 | virtual void onDraw(SkCanvas* canvas) { |
| 285 | this->drawBG(canvas); |
| 286 | |
| 287 | SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(300) }; |
| 288 | SkPaint paint; |
| 289 | paint.setAntiAlias(true); |
| 290 | |
| 291 | SkPoint center; |
| 292 | center.iset(0, 300); |
| 293 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 294 | SkShader* shader = SkGradientShader::CreateRadial( |
| 295 | SkPoint(center), |
bungeman@google.com | 01744a4 | 2011-10-06 19:37:39 +0000 | [diff] [blame] | 296 | SkIntToScalar(200), gColors, NULL, 5, |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 297 | SkShader::kClamp_TileMode, NULL); |
| 298 | paint.setShader(shader); |
| 299 | canvas->drawRect(r, paint); |
| 300 | shader->unref(); |
| 301 | } |
| 302 | |
| 303 | private: |
| 304 | typedef GM INHERITED; |
| 305 | }; |
| 306 | |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 307 | /// Checks quality of large radial gradients, which may display |
| 308 | /// some banding. |
| 309 | |
| 310 | class RadialGradientGM : public GM { |
| 311 | public: |
| 312 | RadialGradientGM() {} |
| 313 | |
| 314 | protected: |
| 315 | SkString onShortName() { return SkString("radial_gradient"); } |
reed@google.com | bb0948f | 2012-01-31 14:44:13 +0000 | [diff] [blame] | 316 | virtual SkISize onISize() { return make_isize(1280, 1280); } |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 317 | void drawBG(SkCanvas* canvas) { |
| 318 | canvas->drawColor(0xFF000000); |
| 319 | } |
| 320 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | bb0948f | 2012-01-31 14:44:13 +0000 | [diff] [blame] | 321 | const SkISize dim = this->getISize(); |
| 322 | |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 323 | this->drawBG(canvas); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 324 | |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 325 | SkPaint paint; |
| 326 | paint.setDither(true); |
| 327 | SkPoint center; |
reed@google.com | bb0948f | 2012-01-31 14:44:13 +0000 | [diff] [blame] | 328 | center.set(SkIntToScalar(dim.width())/2, SkIntToScalar(dim.height())/2); |
| 329 | SkScalar radius = SkIntToScalar(dim.width())/2; |
| 330 | const SkColor colors[] = { 0x7f7f7f7f, 0x7f7f7f7f, 0xb2000000 }; |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 331 | const SkScalar pos[] = { SkFloatToScalar(0.0f), |
| 332 | SkFloatToScalar(0.35f), |
| 333 | SkFloatToScalar(1.0f) }; |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 334 | SkShader* shader = |
| 335 | SkGradientShader::CreateRadial(center, radius, colors, |
reed@google.com | bb0948f | 2012-01-31 14:44:13 +0000 | [diff] [blame] | 336 | pos, SK_ARRAY_COUNT(pos), |
| 337 | SkShader::kClamp_TileMode); |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 338 | paint.setShader(shader)->unref(); |
reed@google.com | bb0948f | 2012-01-31 14:44:13 +0000 | [diff] [blame] | 339 | SkRect r = { |
| 340 | 0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height()) |
| 341 | }; |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 342 | canvas->drawRect(r, paint); |
| 343 | } |
| 344 | private: |
| 345 | typedef GM INHERITED; |
| 346 | }; |
| 347 | |
| 348 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 349 | |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 350 | /////////////////////////////////////////////////////////////////////////////// |
| 351 | |
| 352 | static GM* MyFactory(void*) { return new GradientsGM; } |
| 353 | static GMRegistry reg(MyFactory); |
| 354 | |
reed@google.com | ac864a9 | 2011-06-27 18:11:17 +0000 | [diff] [blame] | 355 | static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; } |
| 356 | static GMRegistry reg2(MyFactory2); |
| 357 | |
tomhudson@google.com | 5ea050f | 2011-09-26 15:03:55 +0000 | [diff] [blame] | 358 | static GM* MyFactory3(void*) { return new ClampedGradientsGM; } |
| 359 | static GMRegistry reg3(MyFactory3); |
| 360 | |
tomhudson@google.com | b18e58c | 2012-01-30 20:00:13 +0000 | [diff] [blame] | 361 | static GM* MyFactory4(void*) { return new RadialGradientGM; } |
| 362 | static GMRegistry reg4(MyFactory4); |
rileya@google.com | 5cf2c28 | 2012-07-09 14:42:16 +0000 | [diff] [blame] | 363 | |
| 364 | static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } |
| 365 | static GMRegistry reg5(MyFactory5); |
| 366 | |
| 367 | static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } |
| 368 | static GMRegistry reg6(MyFactory6); |
reed@android.com | 42309d4 | 2009-06-22 02:06:35 +0000 | [diff] [blame] | 369 | } |