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 "gm.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
11 #include "SkBlurImageFilter.h" | 11 #include "SkBlurImageFilter.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 "SkMorphologyImageFilter.h" | 15 #include "SkMorphologyImageFilter.h" |
16 #include "SkOffsetImageFilter.h" | 16 #include "SkOffsetImageFilter.h" |
| 17 #include "SkPerlinNoiseShader.h" |
| 18 #include "SkRectShaderImageFilter.h" |
17 #include "SkResizeImageFilter.h" | 19 #include "SkResizeImageFilter.h" |
18 #include "SkScalar.h" | 20 #include "SkScalar.h" |
19 | 21 |
20 #define RESIZE_FACTOR SkIntToScalar(4) | 22 #define RESIZE_FACTOR SkIntToScalar(4) |
21 | 23 |
22 namespace skiagm { | 24 namespace skiagm { |
23 | 25 |
24 class ImageFiltersScaledGM : public GM { | 26 class ImageFiltersScaledGM : public GM { |
25 public: | 27 public: |
26 ImageFiltersScaledGM() : fInitialized(false) { | 28 ImageFiltersScaledGM() : fInitialized(false) { |
27 this->setBGColor(0x00000000); | 29 this->setBGColor(0x00000000); |
28 } | 30 } |
29 | 31 |
30 protected: | 32 protected: |
31 virtual SkString onShortName() { | 33 virtual SkString onShortName() { |
32 return SkString("imagefiltersscaled"); | 34 return SkString("imagefiltersscaled"); |
33 } | 35 } |
34 | 36 |
35 virtual SkISize onISize() { | 37 virtual SkISize onISize() { |
36 return make_isize(1020, 500); | 38 return make_isize(1140, 500); |
37 } | 39 } |
38 | 40 |
39 void make_checkerboard() { | 41 void make_checkerboard() { |
40 fCheckerboard.allocN32Pixels(64, 64); | 42 fCheckerboard.allocN32Pixels(64, 64); |
41 SkCanvas canvas(fCheckerboard); | 43 SkCanvas canvas(fCheckerboard); |
42 canvas.clear(0x00000000); | 44 canvas.clear(0x00000000); |
43 SkPaint darkPaint; | 45 SkPaint darkPaint; |
44 darkPaint.setColor(0xFF404040); | 46 darkPaint.setColor(0xFF404040); |
45 SkPaint lightPaint; | 47 SkPaint lightPaint; |
46 lightPaint.setColor(0xFFA0A0A0); | 48 lightPaint.setColor(0xFFA0A0A0); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 virtual void onDraw(SkCanvas* canvas) { | 81 virtual void onDraw(SkCanvas* canvas) { |
80 if (!fInitialized) { | 82 if (!fInitialized) { |
81 this->make_checkerboard(); | 83 this->make_checkerboard(); |
82 this->make_gradient_circle(64, 64); | 84 this->make_gradient_circle(64, 64); |
83 fInitialized = true; | 85 fInitialized = true; |
84 } | 86 } |
85 canvas->clear(0x00000000); | 87 canvas->clear(0x00000000); |
86 | 88 |
87 SkAutoTUnref<SkImageFilter> gradient(new SkBitmapSource(fGradientCircle)
); | 89 SkAutoTUnref<SkImageFilter> gradient(new SkBitmapSource(fGradientCircle)
); |
88 SkAutoTUnref<SkImageFilter> checkerboard(new SkBitmapSource(fCheckerboar
d)); | 90 SkAutoTUnref<SkImageFilter> checkerboard(new SkBitmapSource(fCheckerboar
d)); |
| 91 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( |
| 92 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); |
89 | 93 |
90 SkImageFilter* filters[] = { | 94 SkImageFilter* filters[] = { |
91 new SkBlurImageFilter(SkIntToScalar(4), SkIntToScalar(4)), | 95 new SkBlurImageFilter(SkIntToScalar(4), SkIntToScalar(4)), |
92 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI
ntToScalar(3), | 96 new SkDropShadowImageFilter(SkIntToScalar(5), SkIntToScalar(10), SkI
ntToScalar(3), |
93 SK_ColorYELLOW), | 97 SK_ColorYELLOW), |
94 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, | 98 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, |
95 SkDisplacementMapEffect::kR_ChannelSelec
torType, | 99 SkDisplacementMapEffect::kR_ChannelSelec
torType, |
96 SkIntToScalar(12), | 100 SkIntToScalar(12), |
97 gradient.get(), | 101 gradient.get(), |
98 checkerboard.get()), | 102 checkerboard.get()), |
99 new SkDilateImageFilter(1, 1, checkerboard.get()), | 103 new SkDilateImageFilter(1, 1, checkerboard.get()), |
100 new SkErodeImageFilter(1, 1, checkerboard.get()), | 104 new SkErodeImageFilter(1, 1, checkerboard.get()), |
101 new SkOffsetImageFilter(SkIntToScalar(32), 0), | 105 new SkOffsetImageFilter(SkIntToScalar(32), 0), |
102 new SkResizeImageFilter(RESIZE_FACTOR, RESIZE_FACTOR, SkPaint::kNone
_FilterLevel), | 106 new SkResizeImageFilter(RESIZE_FACTOR, RESIZE_FACTOR, SkPaint::kNone
_FilterLevel), |
| 107 SkRectShaderImageFilter::Create(noise), |
103 }; | 108 }; |
104 | 109 |
105 SkVector scales[] = { | 110 SkVector scales[] = { |
106 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)), | 111 SkVector::Make(SkScalarInvert(2), SkScalarInvert(2)), |
107 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)), | 112 SkVector::Make(SkIntToScalar(1), SkIntToScalar(1)), |
108 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)), | 113 SkVector::Make(SkIntToScalar(1), SkIntToScalar(2)), |
109 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)), | 114 SkVector::Make(SkIntToScalar(2), SkIntToScalar(1)), |
110 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)), | 115 SkVector::Make(SkIntToScalar(2), SkIntToScalar(2)), |
111 }; | 116 }; |
112 | 117 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 SkBitmap fGradientCircle; | 155 SkBitmap fGradientCircle; |
151 typedef GM INHERITED; | 156 typedef GM INHERITED; |
152 }; | 157 }; |
153 | 158 |
154 ////////////////////////////////////////////////////////////////////////////// | 159 ////////////////////////////////////////////////////////////////////////////// |
155 | 160 |
156 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } | 161 static GM* MyFactory(void*) { return new ImageFiltersScaledGM; } |
157 static GMRegistry reg(MyFactory); | 162 static GMRegistry reg(MyFactory); |
158 | 163 |
159 } | 164 } |
OLD | NEW |