Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: src/core/SkBlurImageFilter.cpp

Issue 2255803003: Moving SkBlurImageFilter into core (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: ... made req changes onto correct branch Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/effects/SkBlurImageFilter.h ('k') | src/core/SkGpuBlurUtils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
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 "SkBlurImageFilter.h"
9
10 #include "SkAutoPixmapStorage.h" 8 #include "SkAutoPixmapStorage.h"
11 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
12 #include "SkGpuBlurUtils.h" 10 #include "SkGpuBlurUtils.h"
13 #include "SkOpts.h" 11 #include "SkOpts.h"
14 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
15 #include "SkSpecialImage.h" 13 #include "SkSpecialImage.h"
16 #include "SkWriteBuffer.h" 14 #include "SkWriteBuffer.h"
17 15
18 #if SK_SUPPORT_GPU 16 #if SK_SUPPORT_GPU
19 #include "GrContext.h" 17 #include "GrContext.h"
20 #include "SkGr.h" 18 #include "SkGr.h"
21 #endif 19 #endif
22 20
23 sk_sp<SkImageFilter> SkBlurImageFilter::Make(SkScalar sigmaX, SkScalar sigmaY, 21 class SkBlurImageFilterImpl : public SkImageFilter {
22 public:
23 SkBlurImageFilterImpl(SkScalar sigmaX,
24 SkScalar sigmaY,
25 sk_sp<SkImageFilter> input,
26 const CropRect* cropRect);
27
28 SkRect computeFastBounds(const SkRect&) const override;
29
30 SK_TO_STRING_OVERRIDE()
31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurImageFilterImpl)
32
33 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
34 static SkImageFilter* Create(SkScalar sigmaX, SkScalar sigmaY, SkImageFilter * input = nullptr,
35 const CropRect* cropRect = nullptr) {
36 return SkImageFilter::MakeBlur(sigmaX, sigmaY, sk_ref_sp<SkImageFilter>( input),
37 cropRect).release();
38 }
39 #endif
40
41 protected:
42 void flatten(SkWriteBuffer&) const override;
43 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
44 SkIPoint* offset) const override;
45 SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection ) const override;
46
47 private:
48 SkSize fSigma;
49 typedef SkImageFilter INHERITED;
50
51 friend class SkImageFilter;
52 };
53
54 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkImageFilter)
55 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilterImpl)
56 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
57
58 ///////////////////////////////////////////////////////////////////////////////
59
60 sk_sp<SkImageFilter> SkImageFilter::MakeBlur(SkScalar sigmaX, SkScalar sigmaY,
24 sk_sp<SkImageFilter> input, 61 sk_sp<SkImageFilter> input,
25 const CropRect* cropRect) { 62 const CropRect* cropRect) {
26 if (0 == sigmaX && 0 == sigmaY && !cropRect) { 63 if (0 == sigmaX && 0 == sigmaY && !cropRect) {
27 return input; 64 return input;
28 } 65 }
29 return sk_sp<SkImageFilter>(new SkBlurImageFilter(sigmaX, sigmaY, input, cro pRect)); 66 return sk_sp<SkImageFilter>(new SkBlurImageFilterImpl(sigmaX, sigmaY, input, cropRect));
30 } 67 }
31 68
32 // This rather arbitrary-looking value results in a maximum box blur kernel size 69 // This rather arbitrary-looking value results in a maximum box blur kernel size
33 // of 1000 pixels on the raster path, which matches the WebKit and Firefox 70 // of 1000 pixels on the raster path, which matches the WebKit and Firefox
34 // implementations. Since the GPU path does not compute a box blur, putting 71 // implementations. Since the GPU path does not compute a box blur, putting
35 // the limit on sigma ensures consistent behaviour between the GPU and 72 // the limit on sigma ensures consistent behaviour between the GPU and
36 // raster paths. 73 // raster paths.
37 #define MAX_SIGMA SkIntToScalar(532) 74 #define MAX_SIGMA SkIntToScalar(532)
38 75
39 static SkVector map_sigma(const SkSize& localSigma, const SkMatrix& ctm) { 76 static SkVector map_sigma(const SkSize& localSigma, const SkMatrix& ctm) {
40 SkVector sigma = SkVector::Make(localSigma.width(), localSigma.height()); 77 SkVector sigma = SkVector::Make(localSigma.width(), localSigma.height());
41 ctm.mapVectors(&sigma, 1); 78 ctm.mapVectors(&sigma, 1);
42 sigma.fX = SkMinScalar(SkScalarAbs(sigma.fX), MAX_SIGMA); 79 sigma.fX = SkMinScalar(SkScalarAbs(sigma.fX), MAX_SIGMA);
43 sigma.fY = SkMinScalar(SkScalarAbs(sigma.fY), MAX_SIGMA); 80 sigma.fY = SkMinScalar(SkScalarAbs(sigma.fY), MAX_SIGMA);
44 return sigma; 81 return sigma;
45 } 82 }
46 83
47 SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, 84 SkBlurImageFilterImpl::SkBlurImageFilterImpl(SkScalar sigmaX,
48 SkScalar sigmaY, 85 SkScalar sigmaY,
49 sk_sp<SkImageFilter> input, 86 sk_sp<SkImageFilter> input,
50 const CropRect* cropRect) 87 const CropRect* cropRect)
51 : INHERITED(&input, 1, cropRect) 88 : INHERITED(&input, 1, cropRect)
52 , fSigma(SkSize::Make(sigmaX, sigmaY)) { 89 , fSigma(SkSize::Make(sigmaX, sigmaY)) {
53 } 90 }
54 91
55 sk_sp<SkFlattenable> SkBlurImageFilter::CreateProc(SkReadBuffer& buffer) { 92 sk_sp<SkFlattenable> SkBlurImageFilterImpl::CreateProc(SkReadBuffer& buffer) {
56 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 93 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
57 SkScalar sigmaX = buffer.readScalar(); 94 SkScalar sigmaX = buffer.readScalar();
58 SkScalar sigmaY = buffer.readScalar(); 95 SkScalar sigmaY = buffer.readScalar();
59 return Make(sigmaX, sigmaY, common.getInput(0), &common.cropRect()); 96 return SkImageFilter::MakeBlur(sigmaX, sigmaY, common.getInput(0), &common.c ropRect());
60 } 97 }
61 98
62 void SkBlurImageFilter::flatten(SkWriteBuffer& buffer) const { 99 void SkBlurImageFilterImpl::flatten(SkWriteBuffer& buffer) const {
63 this->INHERITED::flatten(buffer); 100 this->INHERITED::flatten(buffer);
64 buffer.writeScalar(fSigma.fWidth); 101 buffer.writeScalar(fSigma.fWidth);
65 buffer.writeScalar(fSigma.fHeight); 102 buffer.writeScalar(fSigma.fHeight);
66 } 103 }
67 104
68 static void get_box3_params(SkScalar s, int *kernelSize, int* kernelSize3, int * lowOffset, 105 static void get_box3_params(SkScalar s, int *kernelSize, int* kernelSize3, int * lowOffset,
69 int *highOffset) { 106 int *highOffset) {
70 float pi = SkScalarToFloat(SK_ScalarPI); 107 float pi = SkScalarToFloat(SK_ScalarPI);
71 int d = static_cast<int>(floorf(SkScalarToFloat(s) * 3.0f * sqrtf(2.0f * pi) / 4.0f + 0.5f)); 108 int d = static_cast<int>(floorf(SkScalarToFloat(s) * 3.0f * sqrtf(2.0f * pi) / 4.0f + 0.5f));
72 *kernelSize = d; 109 *kernelSize = d;
73 if (d % 2 == 1) { 110 if (d % 2 == 1) {
74 *lowOffset = *highOffset = (d - 1) / 2; 111 *lowOffset = *highOffset = (d - 1) / 2;
75 *kernelSize3 = d; 112 *kernelSize3 = d;
76 } else { 113 } else {
77 *highOffset = d / 2; 114 *highOffset = d / 2;
78 *lowOffset = *highOffset - 1; 115 *lowOffset = *highOffset - 1;
79 *kernelSize3 = d + 1; 116 *kernelSize3 = d + 1;
80 } 117 }
81 } 118 }
82 119
83 sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source, 120 sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc e,
84 const Context& ctx, 121 const Context& ctx,
85 SkIPoint* offset) const { 122 SkIPoint* offset) const {
86 SkIPoint inputOffset = SkIPoint::Make(0, 0); 123 SkIPoint inputOffset = SkIPoint::Make(0, 0);
87 124
88 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ; 125 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ;
89 if (!input) { 126 if (!input) {
90 return nullptr; 127 return nullptr;
91 } 128 }
92 129
93 SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY, 130 SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); 261 SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w);
225 SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); 262 SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w);
226 } 263 }
227 264
228 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(dstBounds.width(), 265 return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(dstBounds.width(),
229 dstBounds.height()), 266 dstBounds.height()),
230 dst, &source->props()); 267 dst, &source->props());
231 } 268 }
232 269
233 270
234 SkRect SkBlurImageFilter::computeFastBounds(const SkRect& src) const { 271 SkRect SkBlurImageFilterImpl::computeFastBounds(const SkRect& src) const {
235 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src ) : src; 272 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src ) : src;
236 bounds.outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)), 273 bounds.outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)),
237 SkScalarMul(fSigma.height(), SkIntToScalar(3))); 274 SkScalarMul(fSigma.height(), SkIntToScalar(3)));
238 return bounds; 275 return bounds;
239 } 276 }
240 277
241 SkIRect SkBlurImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix & ctm, 278 SkIRect SkBlurImageFilterImpl::onFilterNodeBounds(const SkIRect& src, const SkMa trix& ctm,
242 MapDirection) const { 279 MapDirection) const {
243 SkVector sigma = map_sigma(fSigma, ctm); 280 SkVector sigma = map_sigma(fSigma, ctm);
244 return src.makeOutset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar (3))), 281 return src.makeOutset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar (3))),
245 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar (3)))); 282 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar (3))));
246 } 283 }
247 284
248 #ifndef SK_IGNORE_TO_STRING 285 #ifndef SK_IGNORE_TO_STRING
249 void SkBlurImageFilter::toString(SkString* str) const { 286 void SkBlurImageFilterImpl::toString(SkString* str) const {
250 str->appendf("SkBlurImageFilter: ("); 287 str->appendf("SkBlurImageFilterImpl: (");
251 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); 288 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight);
252 289
253 if (this->getInput(0)) { 290 if (this->getInput(0)) {
254 this->getInput(0)->toString(str); 291 this->getInput(0)->toString(str);
255 } 292 }
256 293
257 str->append("))"); 294 str->append("))");
258 } 295 }
259 #endif 296 #endif
OLDNEW
« no previous file with comments | « include/effects/SkBlurImageFilter.h ('k') | src/core/SkGpuBlurUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698