OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkColorMatrixFilter.h" | 10 #include "SkColorMatrixFilter.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 canvas->save(); | 59 canvas->save(); |
60 do_draw(canvas, modes[i], nullptr); | 60 do_draw(canvas, modes[i], nullptr); |
61 canvas->translate(240, 0); | 61 canvas->translate(240, 0); |
62 do_draw(canvas, modes[i], imf); | 62 do_draw(canvas, modes[i], imf); |
63 canvas->restore(); | 63 canvas->restore(); |
64 | 64 |
65 canvas->translate(0, 240); | 65 canvas->translate(0, 240); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 static SkImage* make_image(SkCanvas* canvas) { | 69 static sk_sp<SkImage> make_image(SkCanvas* canvas) { |
70 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 70 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
71 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); | 71 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
72 if (!surface) { | 72 if (!surface) { |
73 surface.reset(SkSurface::NewRaster(info)); | 73 surface.reset(SkSurface::NewRaster(info)); |
74 } | 74 } |
75 surface->getCanvas()->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), SkPaint()); | 75 surface->getCanvas()->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), SkPaint()); |
76 return surface->newImageSnapshot(); | 76 return surface->makeImageSnapshot(); |
77 } | 77 } |
78 | 78 |
79 // Compare blurs when we're tightly clipped (fast) and not as tightly (slower) | 79 // Compare blurs when we're tightly clipped (fast) and not as tightly (slower) |
80 // | 80 // |
81 // Expect the two to draw the same (modulo the extra border of pixels when the c
lip is larger) | 81 // Expect the two to draw the same (modulo the extra border of pixels when the c
lip is larger) |
82 // | 82 // |
83 DEF_SIMPLE_GM(fast_slow_blurimagefilter, canvas, 620, 260) { | 83 DEF_SIMPLE_GM(fast_slow_blurimagefilter, canvas, 620, 260) { |
84 SkAutoTUnref<SkImage> image(make_image(canvas)); | 84 sk_sp<SkImage> image(make_image(canvas)); |
85 const SkRect r = SkRect::MakeIWH(image->width(), image->height()); | 85 const SkRect r = SkRect::MakeIWH(image->width(), image->height()); |
86 | 86 |
87 canvas->translate(10, 10); | 87 canvas->translate(10, 10); |
88 for (SkScalar sigma = 8; sigma <= 128; sigma *= 2) { | 88 for (SkScalar sigma = 8; sigma <= 128; sigma *= 2) { |
89 SkPaint paint; | 89 SkPaint paint; |
90 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(sigma, sigma)
); | 90 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(sigma, sigma)
); |
91 paint.setImageFilter(blur); | 91 paint.setImageFilter(blur); |
92 | 92 |
93 canvas->save(); | 93 canvas->save(); |
94 // we outset the clip by 1, to fall out of the fast-case in drawImage | 94 // we outset the clip by 1, to fall out of the fast-case in drawImage |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 SkScalar fSx, fSy, fTx, fTy; | 155 SkScalar fSx, fSy, fTx, fTy; |
156 } xforms[] = { | 156 } xforms[] = { |
157 { 1, 1, 0, 0 }, | 157 { 1, 1, 0, 0 }, |
158 { 0.5f, 0.5f, 530, 0 }, | 158 { 0.5f, 0.5f, 530, 0 }, |
159 { 0.25f, 0.25f, 530, 275 }, | 159 { 0.25f, 0.25f, 530, 275 }, |
160 { 0.125f, 0.125f, 530, 420 }, | 160 { 0.125f, 0.125f, 530, 420 }, |
161 }; | 161 }; |
162 | 162 |
163 SkPaint paint; | 163 SkPaint paint; |
164 paint.setFilterQuality(kMedium_SkFilterQuality); | 164 paint.setFilterQuality(kMedium_SkFilterQuality); |
165 SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_512.png")); | 165 sk_sp<SkImage> image(GetResourceAsImage("mandrill_512.png")); |
166 | 166 |
167 canvas->translate(20, 20); | 167 canvas->translate(20, 20); |
168 for (const auto& xform : xforms) { | 168 for (const auto& xform : xforms) { |
169 canvas->save(); | 169 canvas->save(); |
170 canvas->translate(xform.fTx, xform.fTy); | 170 canvas->translate(xform.fTx, xform.fTy); |
171 canvas->scale(xform.fSx, xform.fSy); | 171 canvas->scale(xform.fSx, xform.fSy); |
172 canvas->drawImage(image, 0, 0, &paint); | 172 canvas->drawImage(image, 0, 0, &paint); |
173 draw_set(canvas, filters, SK_ARRAY_COUNT(filters)); | 173 draw_set(canvas, filters, SK_ARRAY_COUNT(filters)); |
174 canvas->restore(); | 174 canvas->restore(); |
175 } | 175 } |
176 | 176 |
177 for (auto& filter : filters) { | 177 for (auto& filter : filters) { |
178 filter->unref(); | 178 filter->unref(); |
179 } | 179 } |
180 } | 180 } |
OLD | NEW |