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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
11 #include "SkUnitMappers.h" | 11 #include "SkUnitMappers.h" |
12 | 12 |
13 namespace skiagm { | 13 namespace skiagm { |
14 | 14 |
15 static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) { | 15 static void makebm(SkBitmap* bm, int w, int h) { |
16 bm->allocConfigPixels(config, w, h); | 16 bm->allocN32Pixels(w, h); |
17 bm->eraseColor(SK_ColorTRANSPARENT); | 17 bm->eraseColor(SK_ColorTRANSPARENT); |
18 | 18 |
19 SkCanvas canvas(*bm); | 19 SkCanvas canvas(*bm); |
20 SkScalar s = SkIntToScalar(SkMin32(w, h)); | 20 SkScalar s = SkIntToScalar(SkMin32(w, h)); |
21 SkPoint pts[] = { { 0, 0 }, { s, s } }; | 21 SkPoint pts[] = { { 0, 0 }, { s, s } }; |
22 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; | 22 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
23 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 23 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
24 SkPaint paint; | 24 SkPaint paint; |
25 | 25 |
26 SkUnitMapper* um = NULL; | 26 SkUnitMapper* um = NULL; |
27 | 27 |
28 um = new SkCosineMapper; | 28 um = new SkCosineMapper; |
29 | 29 |
30 SkAutoUnref au(um); | 30 SkAutoUnref au(um); |
31 | 31 |
32 paint.setDither(true); | 32 paint.setDither(true); |
33 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, | 33 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, |
34 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref()
; | 34 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref()
; |
35 canvas.drawPaint(paint); | 35 canvas.drawPaint(paint); |
36 } | 36 } |
37 | 37 |
38 static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty, | 38 static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty, |
39 int w, int h) { | 39 int w, int h) { |
40 static SkBitmap bmp; | 40 static SkBitmap bmp; |
41 if (bmp.isNull()) { | 41 if (bmp.isNull()) { |
42 makebm(&bmp, SkBitmap::kARGB_8888_Config, w/2, h/4); | 42 makebm(&bmp, w/2, h/4); |
43 } | 43 } |
44 return SkShader::CreateBitmapShader(bmp, tx, ty); | 44 return SkShader::CreateBitmapShader(bmp, tx, ty); |
45 } | 45 } |
46 | 46 |
47 /////////////////////////////////////////////////////////////////////////////// | 47 /////////////////////////////////////////////////////////////////////////////// |
48 | 48 |
49 struct GradData { | 49 struct GradData { |
50 int fCount; | 50 int fCount; |
51 const SkColor* fColors; | 51 const SkColor* fColors; |
52 const SkScalar* fPos; | 52 const SkScalar* fPos; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 typedef GM INHERITED; | 205 typedef GM INHERITED; |
206 }; | 206 }; |
207 | 207 |
208 /////////////////////////////////////////////////////////////////////////////// | 208 /////////////////////////////////////////////////////////////////////////////// |
209 | 209 |
210 #ifndef SK_BUILD_FOR_ANDROID | 210 #ifndef SK_BUILD_FOR_ANDROID |
211 static GM* MyFactory(void*) { return new ShaderTextGM; } | 211 static GM* MyFactory(void*) { return new ShaderTextGM; } |
212 static GMRegistry reg(MyFactory); | 212 static GMRegistry reg(MyFactory); |
213 #endif | 213 #endif |
214 } | 214 } |
OLD | NEW |