OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "Checkerboard.h" |
9 #include "SkColor.h" | |
10 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
11 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
| 11 #include "SkColor.h" |
12 #include "SkDisplacementMapEffect.h" | 12 #include "SkDisplacementMapEffect.h" |
13 #include "SkDropShadowImageFilter.h" | 13 #include "SkDropShadowImageFilter.h" |
14 #include "SkGradientShader.h" | 14 #include "SkGradientShader.h" |
15 #include "SkLightingImageFilter.h" | 15 #include "SkLightingImageFilter.h" |
| 16 #include "SkMatrixImageFilter.h" |
16 #include "SkMorphologyImageFilter.h" | 17 #include "SkMorphologyImageFilter.h" |
17 #include "SkOffsetImageFilter.h" | 18 #include "SkOffsetImageFilter.h" |
18 #include "SkPerlinNoiseShader.h" | 19 #include "SkPerlinNoiseShader.h" |
19 #include "SkRectShaderImageFilter.h" | 20 #include "SkRectShaderImageFilter.h" |
20 #include "SkMatrixImageFilter.h" | |
21 #include "SkScalar.h" | 21 #include "SkScalar.h" |
| 22 #include "gm.h" |
22 | 23 |
23 #define RESIZE_FACTOR SkIntToScalar(4) | 24 #define RESIZE_FACTOR SkIntToScalar(4) |
24 | 25 |
25 namespace skiagm { | 26 namespace skiagm { |
26 | 27 |
27 class ImageFiltersScaledGM : public GM { | 28 class ImageFiltersScaledGM : public GM { |
28 public: | 29 public: |
29 ImageFiltersScaledGM() : fInitialized(false) { | 30 ImageFiltersScaledGM() : fInitialized(false) { |
30 this->setBGColor(0x00000000); | 31 this->setBGColor(0x00000000); |
31 } | 32 } |
32 | 33 |
33 protected: | 34 protected: |
34 | 35 |
35 virtual SkString onShortName() { | 36 virtual SkString onShortName() { |
36 return SkString("imagefiltersscaled"); | 37 return SkString("imagefiltersscaled"); |
37 } | 38 } |
38 | 39 |
39 virtual SkISize onISize() { | 40 virtual SkISize onISize() { |
40 return SkISize::Make(1428, 500); | 41 return SkISize::Make(1428, 500); |
41 } | 42 } |
42 | 43 |
43 void make_checkerboard() { | |
44 fCheckerboard.allocN32Pixels(64, 64); | |
45 SkCanvas canvas(fCheckerboard); | |
46 canvas.clear(0x00000000); | |
47 SkPaint darkPaint; | |
48 darkPaint.setColor(0xFF404040); | |
49 SkPaint lightPaint; | |
50 lightPaint.setColor(0xFFA0A0A0); | |
51 for (int y = 0; y < 64; y += 16) { | |
52 for (int x = 0; x < 64; x += 16) { | |
53 canvas.save(); | |
54 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | |
55 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | |
56 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | |
57 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | |
58 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | |
59 canvas.restore(); | |
60 } | |
61 } | |
62 } | |
63 | |
64 void make_gradient_circle(int width, int height) { | 44 void make_gradient_circle(int width, int height) { |
65 SkScalar x = SkIntToScalar(width / 2); | 45 SkScalar x = SkIntToScalar(width / 2); |
66 SkScalar y = SkIntToScalar(height / 2); | 46 SkScalar y = SkIntToScalar(height / 2); |
67 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn
tToScalar(5)); | 47 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn
tToScalar(5)); |
68 fGradientCircle.allocN32Pixels(width, height); | 48 fGradientCircle.allocN32Pixels(width, height); |
69 SkCanvas canvas(fGradientCircle); | 49 SkCanvas canvas(fGradientCircle); |
70 canvas.clear(0x00000000); | 50 canvas.clear(0x00000000); |
71 SkColor colors[2]; | 51 SkColor colors[2]; |
72 colors[0] = SK_ColorWHITE; | 52 colors[0] = SK_ColorWHITE; |
73 colors[1] = SK_ColorBLACK; | 53 colors[1] = SK_ColorBLACK; |
74 SkAutoTUnref<SkShader> shader( | 54 SkAutoTUnref<SkShader> shader( |
75 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, | 55 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, |
76 SkShader::kClamp_TileMode) | 56 SkShader::kClamp_TileMode) |
77 ); | 57 ); |
78 SkPaint paint; | 58 SkPaint paint; |
79 paint.setShader(shader); | 59 paint.setShader(shader); |
80 canvas.drawCircle(x, y, radius, paint); | 60 canvas.drawCircle(x, y, radius, paint); |
81 } | 61 } |
82 | 62 |
83 virtual void onDraw(SkCanvas* canvas) { | 63 virtual void onDraw(SkCanvas* canvas) { |
84 if (!fInitialized) { | 64 if (!fInitialized) { |
85 this->make_checkerboard(); | 65 fCheckerboard.allocN32Pixels(64, 64); |
| 66 SkCanvas checkerboardCanvas(fCheckerboard); |
| 67 sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF4040
40, 8); |
| 68 |
86 this->make_gradient_circle(64, 64); | 69 this->make_gradient_circle(64, 64); |
87 fInitialized = true; | 70 fInitialized = true; |
88 } | 71 } |
89 canvas->clear(0x00000000); | 72 canvas->clear(0x00000000); |
90 | 73 |
91 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir
cle)); | 74 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir
cle)); |
92 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker
board)); | 75 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker
board)); |
93 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( | 76 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( |
94 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); | 77 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); |
95 | 78 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 SkBitmap fGradientCircle; | 155 SkBitmap fGradientCircle; |
173 typedef GM INHERITED; | 156 typedef GM INHERITED; |
174 }; | 157 }; |
175 | 158 |
176 ////////////////////////////////////////////////////////////////////////////// | 159 ////////////////////////////////////////////////////////////////////////////// |
177 | 160 |
178 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } | 161 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } |
179 static GMRegistry reg(MyFactory); | 162 static GMRegistry reg(MyFactory); |
180 | 163 |
181 } | 164 } |
OLD | NEW |