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 "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkDropShadowImageFilter.h" | 10 #include "SkDropShadowImageFilter.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 SkCanvas temp(bm); | 75 SkCanvas temp(bm); |
76 temp.clear(SK_ColorMAGENTA); | 76 temp.clear(SK_ColorMAGENTA); |
77 | 77 |
78 canvas->drawBitmapRect(bm, r, &p); | 78 canvas->drawBitmapRect(bm, r, &p); |
79 } | 79 } |
80 | 80 |
81 static const drawMth gDrawMthds[] = { | 81 static const drawMth gDrawMthds[] = { |
82 draw_rect, draw_oval, draw_rrect, draw_drrect, draw_path, draw_points, draw_
bitmap | 82 draw_rect, draw_oval, draw_rrect, draw_drrect, draw_path, draw_points, draw_
bitmap |
83 }; | 83 }; |
84 | 84 |
85 static void add_paint(SkImageFilter* filter, SkTArray<SkPaint>* paints) { | 85 static void add_paint(SkTArray<SkPaint>* paints, sk_sp<SkImageFilter> filter) { |
86 SkPaint& p = paints->push_back(); | 86 SkPaint& p = paints->push_back(); |
87 p.setImageFilter(filter); | 87 p.setImageFilter(std::move(filter)); |
88 SkASSERT(p.canComputeFastBounds()); | 88 SkASSERT(p.canComputeFastBounds()); |
89 } | 89 } |
90 | 90 |
91 // Create a selection of imagefilter-based paints to test | 91 // Create a selection of imagefilter-based paints to test |
92 static void create_paints(SkImageFilter* source, SkTArray<SkPaint>* paints) { | 92 static void create_paints(SkTArray<SkPaint>* paints, sk_sp<SkImageFilter> source
) { |
93 { | 93 { |
94 SkMatrix scale; | 94 SkMatrix scale; |
95 scale.setScale(2.0f, 2.0f); | 95 scale.setScale(2.0f, 2.0f); |
96 | 96 |
97 SkAutoTUnref<SkImageFilter> scaleMIF( | 97 sk_sp<SkImageFilter> scaleMIF( |
98 SkImageFilter::CreateMatrixFilter(scale, kLow_SkFilterQuality, sourc
e)); | 98 SkImageFilter::CreateMatrixFilter(scale, kLow_SkFilterQuality, sourc
e.get())); |
99 | 99 |
100 add_paint(scaleMIF, paints); | 100 add_paint(paints, std::move(scaleMIF)); |
101 } | 101 } |
102 | 102 |
103 { | 103 { |
104 SkMatrix rot; | 104 SkMatrix rot; |
105 rot.setRotate(-33.3f); | 105 rot.setRotate(-33.3f); |
106 | 106 |
107 SkAutoTUnref<SkImageFilter> rotMIF( | 107 sk_sp<SkImageFilter> rotMIF( |
108 SkImageFilter::CreateMatrixFilter(rot, kLow_SkFilterQuality, source)
); | 108 SkImageFilter::CreateMatrixFilter(rot, kLow_SkFilterQuality, source.
get())); |
109 | 109 |
110 add_paint(rotMIF, paints); | 110 add_paint(paints, std::move(rotMIF)); |
111 } | 111 } |
112 | 112 |
113 { | 113 { |
114 SkRect src = SkRect::MakeXYWH(20, 20, 10, 10); | 114 SkRect src = SkRect::MakeXYWH(20, 20, 10, 10); |
115 SkRect dst = SkRect::MakeXYWH(30, 30, 30, 30); | 115 SkRect dst = SkRect::MakeXYWH(30, 30, 30, 30); |
116 SkAutoTUnref<SkImageFilter> tileIF( | 116 sk_sp<SkImageFilter> tileIF(SkTileImageFilter::Create(src, dst, nullptr)
); |
117 SkTileImageFilter::Create(src, dst, nullptr)); | |
118 | 117 |
119 add_paint(tileIF, paints); | 118 add_paint(paints, std::move(tileIF)); |
120 } | 119 } |
121 | 120 |
122 { | 121 { |
123 static const SkDropShadowImageFilter::ShadowMode kBoth = | 122 static const SkDropShadowImageFilter::ShadowMode kBoth = |
124 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode
; | 123 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode
; |
125 | 124 |
126 SkAutoTUnref<SkImageFilter> dsif( | 125 sk_sp<SkImageFilter> dsif( |
127 SkDropShadowImageFilter::Create(10.0f, 10.0f, | 126 SkDropShadowImageFilter::Create(10.0f, 10.0f, |
128 3.0f, 3.0f, | 127 3.0f, 3.0f, |
129 SK_ColorRED, kBoth, | 128 SK_ColorRED, kBoth, |
130 source, nullptr)); | 129 source.get(), nullptr)); |
131 | 130 |
132 add_paint(dsif, paints); | 131 add_paint(paints, std::move(dsif)); |
133 } | 132 } |
134 | 133 |
135 { | 134 { |
136 SkAutoTUnref<SkImageFilter> dsif( | 135 sk_sp<SkImageFilter> dsif( |
137 SkDropShadowImageFilter::Create(27.0f, 27.0f, | 136 SkDropShadowImageFilter::Create(27.0f, 27.0f, |
138 3.0f, 3.0f, | 137 3.0f, 3.0f, |
139 SK_ColorRED, | 138 SK_ColorRED, |
140 SkDropShadowImageFilter::kDrawShadow
Only_ShadowMode, | 139 SkDropShadowImageFilter::kDrawShadow
Only_ShadowMode, |
141 source, nullptr)); | 140 source.get(), nullptr)); |
142 | 141 |
143 add_paint(dsif, paints); | 142 add_paint(paints, std::move(dsif)); |
144 } | 143 } |
145 | 144 |
146 { | 145 add_paint(paints, SkBlurImageFilter::Make(3, 3, source)); |
147 SkAutoTUnref<SkImageFilter> bif(SkBlurImageFilter::Create(3, 3, source))
; | 146 add_paint(paints, SkOffsetImageFilter::Make(15, 15, source)); |
148 | |
149 add_paint(bif, paints); | |
150 } | |
151 | |
152 { | |
153 sk_sp<SkImageFilter> oif(SkOffsetImageFilter::Make(15, 15, | |
154 sk_ref_sp<SkImageFilt
er>(source))); | |
155 | |
156 add_paint(oif.get(), paints); | |
157 } | |
158 } | 147 } |
159 | 148 |
160 // This GM visualizes the fast bounds for various combinations of geometry | 149 // This GM visualizes the fast bounds for various combinations of geometry |
161 // and image filter | 150 // and image filter |
162 class ImageFilterFastBoundGM : public GM { | 151 class ImageFilterFastBoundGM : public GM { |
163 public: | 152 public: |
164 ImageFilterFastBoundGM() { | 153 ImageFilterFastBoundGM() { |
165 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); | 154 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
166 } | 155 } |
167 | 156 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 canvas->restore(); | 225 canvas->restore(); |
237 } | 226 } |
238 | 227 |
239 void onDraw(SkCanvas* canvas) override{ | 228 void onDraw(SkCanvas* canvas) override{ |
240 | 229 |
241 SkPaint blackFill; | 230 SkPaint blackFill; |
242 | 231 |
243 //----------- | 232 //----------- |
244 // Normal paints (no source) | 233 // Normal paints (no source) |
245 SkTArray<SkPaint> paints; | 234 SkTArray<SkPaint> paints; |
246 create_paints(nullptr, &paints); | 235 create_paints(&paints, nullptr); |
247 | 236 |
248 //----------- | 237 //----------- |
249 // Paints with a PictureImageFilter as a source | 238 // Paints with a PictureImageFilter as a source |
250 sk_sp<SkPicture> pic; | 239 sk_sp<SkPicture> pic; |
251 | 240 |
252 { | 241 { |
253 SkPictureRecorder rec; | 242 SkPictureRecorder rec; |
254 | 243 |
255 SkCanvas* c = rec.beginRecording(10, 10); | 244 SkCanvas* c = rec.beginRecording(10, 10); |
256 c->drawRect(SkRect::MakeWH(10, 10), blackFill); | 245 c->drawRect(SkRect::MakeWH(10, 10), blackFill); |
257 pic = rec.finishRecordingAsPicture(); | 246 pic = rec.finishRecordingAsPicture(); |
258 } | 247 } |
259 | 248 |
260 sk_sp<SkImageFilter> pif(SkPictureImageFilter::Make(pic)); | |
261 | |
262 SkTArray<SkPaint> pifPaints; | 249 SkTArray<SkPaint> pifPaints; |
263 create_paints(pif.get(), &pifPaints); | 250 create_paints(&pifPaints, SkPictureImageFilter::Make(pic)); |
264 | 251 |
265 //----------- | 252 //----------- |
266 // Paints with a SkImageSource as a source | 253 // Paints with a SkImageSource as a source |
267 | 254 |
268 auto surface(SkSurface::MakeRasterN32Premul(10, 10)); | 255 auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
269 { | 256 { |
270 SkPaint p; | 257 SkPaint p; |
271 SkCanvas* temp = surface->getCanvas(); | 258 SkCanvas* temp = surface->getCanvas(); |
272 temp->clear(SK_ColorYELLOW); | 259 temp->clear(SK_ColorYELLOW); |
273 p.setColor(SK_ColorBLUE); | 260 p.setColor(SK_ColorBLUE); |
274 temp->drawRect(SkRect::MakeLTRB(5, 5, 10, 10), p); | 261 temp->drawRect(SkRect::MakeLTRB(5, 5, 10, 10), p); |
275 p.setColor(SK_ColorGREEN); | 262 p.setColor(SK_ColorGREEN); |
276 temp->drawRect(SkRect::MakeLTRB(5, 0, 10, 5), p); | 263 temp->drawRect(SkRect::MakeLTRB(5, 0, 10, 5), p); |
277 } | 264 } |
278 | 265 |
279 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 266 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
280 sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image))); | 267 sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image))); |
281 | |
282 SkTArray<SkPaint> bmsPaints; | 268 SkTArray<SkPaint> bmsPaints; |
283 create_paints(imageSource.get(), &bmsPaints); | 269 create_paints(&bmsPaints, std::move(imageSource)); |
284 | 270 |
285 //----------- | 271 //----------- |
286 SkASSERT(paints.count() == kNumVertTiles); | 272 SkASSERT(paints.count() == kNumVertTiles); |
287 SkASSERT(paints.count() == pifPaints.count()); | 273 SkASSERT(paints.count() == pifPaints.count()); |
288 SkASSERT(paints.count() == bmsPaints.count()); | 274 SkASSERT(paints.count() == bmsPaints.count()); |
289 | 275 |
290 // horizontal separators | 276 // horizontal separators |
291 for (int i = 1; i < paints.count(); ++i) { | 277 for (int i = 1; i < paints.count(); ++i) { |
292 canvas->drawLine(0, | 278 canvas->drawLine(0, |
293 i*SkIntToScalar(kTileHeight), | 279 i*SkIntToScalar(kTileHeight), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 314 } |
329 | 315 |
330 private: | 316 private: |
331 typedef GM INHERITED; | 317 typedef GM INHERITED; |
332 }; | 318 }; |
333 | 319 |
334 ////////////////////////////////////////////////////////////////////////////// | 320 ////////////////////////////////////////////////////////////////////////////// |
335 | 321 |
336 DEF_GM(return new ImageFilterFastBoundGM;) | 322 DEF_GM(return new ImageFilterFastBoundGM;) |
337 } | 323 } |
OLD | NEW |