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" | 9 #include "SkBitmapSource.h" |
10 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 colors[1] = SK_ColorBLACK; | 52 colors[1] = SK_ColorBLACK; |
53 SkAutoTUnref<SkShader> shader( | 53 SkAutoTUnref<SkShader> shader( |
54 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, | 54 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors,
NULL, 2, |
55 SkShader::kClamp_TileMode) | 55 SkShader::kClamp_TileMode) |
56 ); | 56 ); |
57 SkPaint paint; | 57 SkPaint paint; |
58 paint.setShader(shader); | 58 paint.setShader(shader); |
59 canvas.drawCircle(x, y, radius, paint); | 59 canvas.drawCircle(x, y, radius, paint); |
60 } | 60 } |
61 | 61 |
| 62 static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, siz
e_t i, |
| 63 const SkRect& primBounds, const SkRect& clip
Bounds) { |
| 64 SkPaint paint; |
| 65 paint.setColor(SK_ColorWHITE); |
| 66 paint.setImageFilter(filter); |
| 67 paint.setAntiAlias(true); |
| 68 canvas->save(); |
| 69 canvas->clipRect(clipBounds); |
| 70 if (5 == i) { |
| 71 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); |
| 72 } else if (6 == i) { |
| 73 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), |
| 74 SkScalarInvert(RESIZE_FACTOR_Y)); |
| 75 } |
| 76 canvas->drawCircle(primBounds.centerX(), primBounds.centerY(), |
| 77 primBounds.width() * 2 / 5, paint); |
| 78 canvas->restore(); |
| 79 } |
| 80 |
62 void onDraw(SkCanvas* canvas) override { | 81 void onDraw(SkCanvas* canvas) override { |
63 if (!fInitialized) { | 82 if (!fInitialized) { |
64 fCheckerboard.allocN32Pixels(64, 64); | 83 fCheckerboard.allocN32Pixels(64, 64); |
65 SkCanvas checkerboardCanvas(fCheckerboard); | 84 SkCanvas checkerboardCanvas(fCheckerboard); |
66 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0x
FF404040, 8); | 85 sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0x
FF404040, 8); |
67 | 86 |
68 this->make_gradient_circle(64, 64); | 87 this->make_gradient_circle(64, 64); |
69 fInitialized = true; | 88 fInitialized = true; |
70 } | 89 } |
71 canvas->clear(SK_ColorBLACK); | 90 canvas->clear(SK_ColorBLACK); |
(...skipping 12 matching lines...) Expand all Loading... |
84 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), | 103 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), |
85 SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelS
electorType, | 104 SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelS
electorType, |
86 SkDisplacementMapEffect::kR_ChannelS
electorType, | 105 SkDisplacementMapEffect::kR_ChannelS
electorType, |
87 SkIntToScalar(12), | 106 SkIntToScalar(12), |
88 gradient.get(), | 107 gradient.get(), |
89 checkerboard.get()), | 108 checkerboard.get()), |
90 SkDilateImageFilter::Create(2, 2, checkerboard.get()), | 109 SkDilateImageFilter::Create(2, 2, checkerboard.get()), |
91 SkErodeImageFilter::Create(2, 2, checkerboard.get()), | 110 SkErodeImageFilter::Create(2, 2, checkerboard.get()), |
92 SkOffsetImageFilter::Create(SkIntToScalar(-16), SkIntToScalar(32)), | 111 SkOffsetImageFilter::Create(SkIntToScalar(-16), SkIntToScalar(32)), |
93 SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQualit
y), | 112 SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQualit
y), |
94 SkRectShaderImageFilter::Create(noise), | |
95 }; | 113 }; |
96 | 114 |
97 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); | 115 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
98 SkScalar margin = SkIntToScalar(16); | 116 SkScalar margin = SkIntToScalar(16); |
99 SkRect bounds = r; | 117 SkRect bounds = r; |
100 bounds.outset(margin, margin); | 118 bounds.outset(margin, margin); |
101 | 119 |
| 120 canvas->save(); |
102 for (int xOffset = 0; xOffset < 80; xOffset += 16) { | 121 for (int xOffset = 0; xOffset < 80; xOffset += 16) { |
103 canvas->save(); | 122 canvas->save(); |
104 bounds.fLeft = SkIntToScalar(xOffset); | 123 bounds.fLeft = SkIntToScalar(xOffset); |
105 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 124 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
106 SkPaint paint; | 125 draw_clipped_filter(canvas, filters[i], i, r, bounds); |
107 paint.setColor(SK_ColorWHITE); | |
108 paint.setImageFilter(filters[i]); | |
109 paint.setAntiAlias(true); | |
110 canvas->save(); | |
111 canvas->clipRect(bounds); | |
112 if (5 == i) { | |
113 canvas->translate(SkIntToScalar(16), SkIntToScalar(-32)); | |
114 } else if (6 == i) { | |
115 canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), | |
116 SkScalarInvert(RESIZE_FACTOR_Y)); | |
117 } | |
118 canvas->drawCircle(r.centerX(), r.centerY(), r.width() * 2 / 5,
paint); | |
119 canvas->restore(); | |
120 canvas->translate(r.width() + margin, 0); | 126 canvas->translate(r.width() + margin, 0); |
121 } | 127 } |
122 canvas->restore(); | 128 canvas->restore(); |
123 canvas->translate(0, r.height() + margin); | 129 canvas->translate(0, r.height() + margin); |
124 } | 130 } |
| 131 canvas->restore(); |
125 | 132 |
126 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 133 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
127 SkSafeUnref(filters[i]); | 134 SkSafeUnref(filters[i]); |
128 } | 135 } |
| 136 |
| 137 SkImageFilter* rectFilter = SkRectShaderImageFilter::Create(noise); |
| 138 canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0); |
| 139 for (int xOffset = 0; xOffset < 80; xOffset += 16) { |
| 140 bounds.fLeft = SkIntToScalar(xOffset); |
| 141 draw_clipped_filter(canvas, rectFilter, 0, r, bounds); |
| 142 canvas->translate(0, r.height() + margin); |
| 143 } |
| 144 SkSafeUnref(rectFilter); |
129 } | 145 } |
130 | 146 |
131 private: | 147 private: |
132 bool fInitialized; | 148 bool fInitialized; |
133 SkBitmap fCheckerboard; | 149 SkBitmap fCheckerboard; |
134 SkBitmap fGradientCircle; | 150 SkBitmap fGradientCircle; |
135 typedef GM INHERITED; | 151 typedef GM INHERITED; |
136 }; | 152 }; |
137 | 153 |
138 ////////////////////////////////////////////////////////////////////////////// | 154 ////////////////////////////////////////////////////////////////////////////// |
139 | 155 |
140 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } | 156 static GM* MyFactory(void*) { return new ImageFiltersClippedGM; } |
141 static GMRegistry reg(MyFactory); | 157 static GMRegistry reg(MyFactory); |
142 | 158 |
143 } | 159 } |
OLD | NEW |