| 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 #include "gm.h" | 8 #include "gm.h" |
| 8 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 9 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
| 10 #include "SkUnitMappers.h" | |
| 11 | 11 |
| 12 namespace skiagm { | 12 namespace skiagm { |
| 13 | 13 |
| 14 static void makebm(SkBitmap* bm, int w, int h) { | 14 static void makebm(SkBitmap* bm, int w, int h) { |
| 15 bm->allocN32Pixels(w, h); | 15 bm->allocN32Pixels(w, h); |
| 16 bm->eraseColor(SK_ColorTRANSPARENT); | 16 bm->eraseColor(SK_ColorTRANSPARENT); |
| 17 | 17 |
| 18 SkCanvas canvas(*bm); | 18 SkCanvas canvas(*bm); |
| 19 SkScalar s = SkIntToScalar(SkMin32(w, h)); | 19 SkScalar s = SkIntToScalar(SkMin32(w, h)); |
| 20 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; | 20 static const SkPoint kPts0[] = { { 0, 0 }, { s, s } }; |
| 21 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } }; | 21 static const SkPoint kPts1[] = { { s/2, 0 }, { s/2, s } }; |
| 22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 22 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 23 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; | 23 static const SkColor kColors0[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; |
| 24 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 }; | 24 static const SkColor kColors1[] = {0xF08000F0, 0x8080F000, 0xF000F080 }; |
| 25 | 25 |
| 26 | 26 |
| 27 SkPaint paint; | 27 SkPaint paint; |
| 28 | 28 |
| 29 SkUnitMapper* um = NULL; | |
| 30 | |
| 31 um = new SkCosineMapper; | |
| 32 | |
| 33 SkAutoUnref au(um); | |
| 34 | |
| 35 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos, | 29 paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos, |
| 36 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode, um))->u
nref(); | 30 SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref
(); |
| 37 canvas.drawPaint(paint); | 31 canvas.drawPaint(paint); |
| 38 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos, | 32 paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos, |
| 39 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref
(); | 33 SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref
(); |
| 40 canvas.drawPaint(paint); | 34 canvas.drawPaint(paint); |
| 41 } | 35 } |
| 42 | 36 |
| 43 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
| 44 | 38 |
| 45 struct LabeledMatrix { | 39 struct LabeledMatrix { |
| 46 SkMatrix fMatrix; | 40 SkMatrix fMatrix; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 private: | 131 private: |
| 138 SkBitmap fBmp; | 132 SkBitmap fBmp; |
| 139 typedef GM INHERITED; | 133 typedef GM INHERITED; |
| 140 }; | 134 }; |
| 141 | 135 |
| 142 /////////////////////////////////////////////////////////////////////////////// | 136 /////////////////////////////////////////////////////////////////////////////// |
| 143 | 137 |
| 144 static GM* MyFactory(void*) { return new ShaderText3GM; } | 138 static GM* MyFactory(void*) { return new ShaderText3GM; } |
| 145 static GMRegistry reg(MyFactory); | 139 static GMRegistry reg(MyFactory); |
| 146 } | 140 } |
| OLD | NEW |