| 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 #include "gm.h" | 7 #include "gm.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 10 #include "SkUnitMappers.h" |
| 10 | 11 |
| 11 namespace skiagm { | 12 namespace skiagm { |
| 12 | 13 |
| 13 static void makebm(SkBitmap* bm, int w, int h) { | 14 static void makebm(SkBitmap* bm, int w, int h) { |
| 14 bm->allocN32Pixels(w, h); | 15 bm->allocN32Pixels(w, h); |
| 15 bm->eraseColor(SK_ColorTRANSPARENT); | 16 bm->eraseColor(SK_ColorTRANSPARENT); |
| 16 | 17 |
| 17 SkCanvas canvas(*bm); | 18 SkCanvas canvas(*bm); |
| 18 SkScalar s = SkIntToScalar(SkMin32(w, h)); | 19 SkScalar s = SkIntToScalar(SkMin32(w, h)); |
| 19 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; | 20 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; |
| 20 static const SkPoint kPts1[] = { { s, 0 }, { 0, s } }; | 21 static const SkPoint kPts1[] = { { s, 0 }, { 0, s } }; |
| 21 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 22 static const SkColor kColors0[] = {0x40FF00FF, 0xF0FFFF00, 0x4000FFFF }; | 23 static const SkColor kColors0[] = {0x40FF00FF, 0xF0FFFF00, 0x4000FFFF }; |
| 23 static const SkColor kColors1[] = {0xF0FF00FF, 0x80FFFF00, 0xF000FFFF }; | 24 static const SkColor kColors1[] = {0xF0FF00FF, 0x80FFFF00, 0xF000FFFF }; |
| 24 | 25 |
| 25 | 26 |
| 26 SkPaint paint; | 27 SkPaint paint; |
| 27 | 28 |
| 29 SkUnitMapper* um = NULL; |
| 30 |
| 31 um = new SkCosineMapper; |
| 32 |
| 33 SkAutoUnref au(um); |
| 34 |
| 28 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos, | 35 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos, |
| 29 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref
(); | 36 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode, um))->u
nref(); |
| 30 canvas.drawPaint(paint); | 37 canvas.drawPaint(paint); |
| 31 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos, | 38 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos, |
| 32 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref
(); | 39 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref
(); |
| 33 canvas.drawPaint(paint); | 40 canvas.drawPaint(paint); |
| 34 } | 41 } |
| 35 | 42 |
| 36 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
| 37 | 44 |
| 38 struct LabeledMatrix { | 45 struct LabeledMatrix { |
| 39 SkMatrix fMatrix; | 46 SkMatrix fMatrix; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 210 |
| 204 private: | 211 private: |
| 205 typedef GM INHERITED; | 212 typedef GM INHERITED; |
| 206 }; | 213 }; |
| 207 | 214 |
| 208 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
| 209 | 216 |
| 210 static GM* MyFactory(void*) { return new ShaderText2GM; } | 217 static GM* MyFactory(void*) { return new ShaderText2GM; } |
| 211 static GMRegistry reg(MyFactory); | 218 static GMRegistry reg(MyFactory); |
| 212 } | 219 } |
| OLD | NEW |