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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "SkBitmapSource.h" | |
10 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
11 #include "SkColor.h" | 10 #include "SkColor.h" |
12 #include "SkDisplacementMapEffect.h" | 11 #include "SkDisplacementMapEffect.h" |
13 #include "SkDropShadowImageFilter.h" | 12 #include "SkDropShadowImageFilter.h" |
14 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
14 #include "SkImage.h" | |
15 #include "SkImageSource.h" | |
15 #include "SkLightingImageFilter.h" | 16 #include "SkLightingImageFilter.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 "SkPoint3.h" | 20 #include "SkPoint3.h" |
20 #include "SkRectShaderImageFilter.h" | 21 #include "SkRectShaderImageFilter.h" |
21 #include "SkScalar.h" | 22 #include "SkScalar.h" |
23 #include "SkSurface.h" | |
22 #include "gm.h" | 24 #include "gm.h" |
23 | 25 |
24 #define RESIZE_FACTOR SkIntToScalar(4) | 26 #define RESIZE_FACTOR SkIntToScalar(4) |
25 | 27 |
26 namespace skiagm { | 28 namespace skiagm { |
27 | 29 |
28 class ImageFiltersScaledGM : public GM { | 30 class ImageFiltersScaledGM : public GM { |
29 public: | 31 public: |
30 ImageFiltersScaledGM() { | 32 ImageFiltersScaledGM() { |
31 this->setBGColor(0x00000000); | 33 this->setBGColor(0x00000000); |
32 } | 34 } |
33 | 35 |
34 protected: | 36 protected: |
35 | 37 |
36 SkString onShortName() override { | 38 SkString onShortName() override { |
37 return SkString("imagefiltersscaled"); | 39 return SkString("imagefiltersscaled"); |
38 } | 40 } |
39 | 41 |
40 SkISize onISize() override { | 42 SkISize onISize() override { |
41 return SkISize::Make(1428, 500); | 43 return SkISize::Make(1428, 500); |
42 } | 44 } |
43 | 45 |
robertphillips
2015/09/15 17:43:52
Make this static & have it return an SkImage* (lik
f(malita)
2015/09/15 18:12:53
Done.
| |
44 void makeGradientCircle(int width, int height) { | 46 void makeGradientCircle(int width, int height) { |
45 SkScalar x = SkIntToScalar(width / 2); | 47 SkScalar x = SkIntToScalar(width / 2); |
46 SkScalar y = SkIntToScalar(height / 2); | 48 SkScalar y = SkIntToScalar(height / 2); |
47 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn tToScalar(5)); | 49 SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIn tToScalar(5)); |
48 fGradientCircle.allocN32Pixels(width, height); | 50 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, hei ght)); |
49 SkCanvas canvas(fGradientCircle); | 51 SkCanvas* canvas = surface->getCanvas(); |
50 canvas.clear(0x00000000); | 52 canvas->clear(0x00000000); |
51 SkColor colors[2]; | 53 SkColor colors[2]; |
52 colors[0] = SK_ColorWHITE; | 54 colors[0] = SK_ColorWHITE; |
53 colors[1] = SK_ColorBLACK; | 55 colors[1] = SK_ColorBLACK; |
54 SkAutoTUnref<SkShader> shader( | 56 SkAutoTUnref<SkShader> shader( |
55 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, | 57 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, |
56 SkShader::kClamp_TileMode) | 58 SkShader::kClamp_TileMode) |
57 ); | 59 ); |
58 SkPaint paint; | 60 SkPaint paint; |
59 paint.setShader(shader); | 61 paint.setShader(shader); |
60 canvas.drawCircle(x, y, radius, paint); | 62 canvas->drawCircle(x, y, radius, paint); |
63 | |
64 fGradientCircle.reset(surface->newImageSnapshot()); | |
61 } | 65 } |
62 | 66 |
63 void onOnceBeforeDraw() override { | 67 void onOnceBeforeDraw() override { |
64 fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(64, 64, | 68 fCheckerboard.reset(SkImage::NewFromBitmap( |
65 0xFFA0A0A0, 0x FF404040, 8); | 69 sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF40 4040, 8))); |
66 this->makeGradientCircle(64, 64); | 70 this->makeGradientCircle(64, 64); |
67 } | 71 } |
68 | 72 |
69 void onDraw(SkCanvas* canvas) override { | 73 void onDraw(SkCanvas* canvas) override { |
70 canvas->clear(SK_ColorBLACK); | 74 canvas->clear(SK_ColorBLACK); |
71 | 75 |
72 SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCir cle)); | 76 SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCirc le)); |
73 SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fChecker board)); | 77 SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerb oard)); |
74 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( | 78 SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise( |
75 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); | 79 SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0)); |
76 | 80 |
77 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); | 81 SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10)); |
78 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10), | 82 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10), |
79 SkIntToScalar(-10), | 83 SkIntToScalar(-10), |
80 SkIntToScalar(20)); | 84 SkIntToScalar(20)); |
81 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40 ), 0); | 85 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40 ), 0); |
82 SkScalar spotExponent = SK_Scalar1; | 86 SkScalar spotExponent = SK_Scalar1; |
83 SkScalar cutoffAngle = SkIntToScalar(15); | 87 SkScalar cutoffAngle = SkIntToScalar(15); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 canvas->restore(); | 147 canvas->restore(); |
144 canvas->translate(0, r.height() * scales[j].fY + margin); | 148 canvas->translate(0, r.height() * scales[j].fY + margin); |
145 } | 149 } |
146 | 150 |
147 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 151 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
148 filters[i]->unref(); | 152 filters[i]->unref(); |
149 } | 153 } |
150 } | 154 } |
151 | 155 |
152 private: | 156 private: |
153 SkBitmap fCheckerboard; | 157 SkAutoTUnref<SkImage> fCheckerboard, fGradientCircle; |
154 SkBitmap fGradientCircle; | |
155 | 158 |
156 typedef GM INHERITED; | 159 typedef GM INHERITED; |
157 }; | 160 }; |
158 | 161 |
159 ////////////////////////////////////////////////////////////////////////////// | 162 ////////////////////////////////////////////////////////////////////////////// |
160 | 163 |
161 DEF_GM(return new ImageFiltersScaledGM;) | 164 DEF_GM(return new ImageFiltersScaledGM;) |
162 } | 165 } |
OLD | NEW |