senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 8 | #include "SkAutoPixmapStorage.h" |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 9 | #include "SkColorPriv.h" |
mtklein | dce5ce4 | 2015-08-04 08:49:21 -0700 | [diff] [blame] | 10 | #include "SkGpuBlurUtils.h" |
| 11 | #include "SkOpts.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 12 | #include "SkReadBuffer.h" |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 13 | #include "SkSpecialImage.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 14 | #include "SkWriteBuffer.h" |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 15 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 16 | #if SK_SUPPORT_GPU |
senorblanco@chromium.org | 302cffb | 2012-08-01 20:16:34 +0000 | [diff] [blame] | 17 | #include "GrContext.h" |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 18 | #include "GrTextureProxy.h" |
robertphillips | 1de87df | 2016-01-14 06:03:29 -0800 | [diff] [blame] | 19 | #include "SkGr.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 20 | #endif |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 21 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 22 | class SkBlurImageFilterImpl : public SkImageFilter { |
| 23 | public: |
| 24 | SkBlurImageFilterImpl(SkScalar sigmaX, |
| 25 | SkScalar sigmaY, |
| 26 | sk_sp<SkImageFilter> input, |
| 27 | const CropRect* cropRect); |
| 28 | |
| 29 | SkRect computeFastBounds(const SkRect&) const override; |
| 30 | |
| 31 | SK_TO_STRING_OVERRIDE() |
| 32 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurImageFilterImpl) |
| 33 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 34 | protected: |
| 35 | void flatten(SkWriteBuffer&) const override; |
| 36 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
| 37 | SkIPoint* offset) const override; |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame^] | 38 | sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override; |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 39 | SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override; |
| 40 | |
| 41 | private: |
| 42 | SkSize fSigma; |
| 43 | typedef SkImageFilter INHERITED; |
| 44 | |
| 45 | friend class SkImageFilter; |
| 46 | }; |
| 47 | |
| 48 | SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkImageFilter) |
| 49 | SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilterImpl) |
| 50 | SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 51 | |
| 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | sk_sp<SkImageFilter> SkImageFilter::MakeBlur(SkScalar sigmaX, SkScalar sigmaY, |
robertphillips | 225db44 | 2016-04-17 14:27:05 -0700 | [diff] [blame] | 55 | sk_sp<SkImageFilter> input, |
| 56 | const CropRect* cropRect) { |
| 57 | if (0 == sigmaX && 0 == sigmaY && !cropRect) { |
| 58 | return input; |
| 59 | } |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 60 | return sk_sp<SkImageFilter>(new SkBlurImageFilterImpl(sigmaX, sigmaY, input, cropRect)); |
robertphillips | 225db44 | 2016-04-17 14:27:05 -0700 | [diff] [blame] | 61 | } |
| 62 | |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 63 | // This rather arbitrary-looking value results in a maximum box blur kernel size |
| 64 | // of 1000 pixels on the raster path, which matches the WebKit and Firefox |
| 65 | // implementations. Since the GPU path does not compute a box blur, putting |
| 66 | // the limit on sigma ensures consistent behaviour between the GPU and |
| 67 | // raster paths. |
| 68 | #define MAX_SIGMA SkIntToScalar(532) |
| 69 | |
senorblanco | 6404981 | 2016-02-01 10:32:42 -0800 | [diff] [blame] | 70 | static SkVector map_sigma(const SkSize& localSigma, const SkMatrix& ctm) { |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 71 | SkVector sigma = SkVector::Make(localSigma.width(), localSigma.height()); |
| 72 | ctm.mapVectors(&sigma, 1); |
| 73 | sigma.fX = SkMinScalar(SkScalarAbs(sigma.fX), MAX_SIGMA); |
| 74 | sigma.fY = SkMinScalar(SkScalarAbs(sigma.fY), MAX_SIGMA); |
| 75 | return sigma; |
| 76 | } |
| 77 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 78 | SkBlurImageFilterImpl::SkBlurImageFilterImpl(SkScalar sigmaX, |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 79 | SkScalar sigmaY, |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 80 | sk_sp<SkImageFilter> input, |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 81 | const CropRect* cropRect) |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 82 | : INHERITED(&input, 1, cropRect) |
| 83 | , fSigma(SkSize::Make(sigmaX, sigmaY)) { |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 84 | } |
| 85 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 86 | sk_sp<SkFlattenable> SkBlurImageFilterImpl::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 87 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 88 | SkScalar sigmaX = buffer.readScalar(); |
| 89 | SkScalar sigmaY = buffer.readScalar(); |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 90 | return SkImageFilter::MakeBlur(sigmaX, sigmaY, common.getInput(0), &common.cropRect()); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 91 | } |
| 92 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 93 | void SkBlurImageFilterImpl::flatten(SkWriteBuffer& buffer) const { |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 94 | this->INHERITED::flatten(buffer); |
| 95 | buffer.writeScalar(fSigma.fWidth); |
| 96 | buffer.writeScalar(fSigma.fHeight); |
| 97 | } |
| 98 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 99 | static void get_box3_params(SkScalar s, int *kernelSize, int* kernelSize3, int *lowOffset, |
| 100 | int *highOffset) { |
schenney@chromium.org | 73f3ded | 2011-12-20 22:31:40 +0000 | [diff] [blame] | 101 | float pi = SkScalarToFloat(SK_ScalarPI); |
| 102 | int d = static_cast<int>(floorf(SkScalarToFloat(s) * 3.0f * sqrtf(2.0f * pi) / 4.0f + 0.5f)); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 103 | *kernelSize = d; |
| 104 | if (d % 2 == 1) { |
| 105 | *lowOffset = *highOffset = (d - 1) / 2; |
| 106 | *kernelSize3 = d; |
| 107 | } else { |
| 108 | *highOffset = d / 2; |
| 109 | *lowOffset = *highOffset - 1; |
| 110 | *kernelSize3 = d + 1; |
| 111 | } |
| 112 | } |
| 113 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 114 | sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* source, |
robertphillips | d728f0c | 2016-11-21 11:05:03 -0800 | [diff] [blame] | 115 | const Context& ctx, |
| 116 | SkIPoint* offset) const { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 117 | SkIPoint inputOffset = SkIPoint::Make(0, 0); |
| 118 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 119 | sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 120 | if (!input) { |
| 121 | return nullptr; |
senorblanco@chromium.org | 6840076 | 2013-05-24 15:04:07 +0000 | [diff] [blame] | 122 | } |
| 123 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 124 | SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY, |
| 125 | input->width(), input->height()); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 126 | |
senorblanco | afec27f | 2016-02-16 09:11:18 -0800 | [diff] [blame] | 127 | SkIRect dstBounds; |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 128 | if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) { |
| 129 | return nullptr; |
senorblanco | db64af3 | 2015-12-09 10:11:43 -0800 | [diff] [blame] | 130 | } |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 131 | if (!inputBounds.intersect(dstBounds)) { |
| 132 | return nullptr; |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 133 | } |
| 134 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 135 | const SkVector sigma = map_sigma(fSigma, ctx.ctm()); |
| 136 | |
| 137 | #if SK_SUPPORT_GPU |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 138 | if (source->isTextureBacked()) { |
| 139 | GrContext* context = source->getContext(); |
Brian Osman | 5f50092 | 2016-12-29 11:50:48 -0500 | [diff] [blame] | 140 | |
| 141 | // Ensure the input is in the destination's gamut. This saves us from having to do the |
| 142 | // xform during the filter itself. |
| 143 | input = ImageToColorSpace(input.get(), ctx.outputProperties()); |
| 144 | |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 145 | sk_sp<GrTextureProxy> inputTexture(input->asTextureProxyRef(context)); |
Robert Phillips | 833dcf4 | 2016-11-18 08:44:13 -0500 | [diff] [blame] | 146 | if (!inputTexture) { |
| 147 | return nullptr; |
| 148 | } |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 149 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 150 | if (0 == sigma.x() && 0 == sigma.y()) { |
| 151 | offset->fX = inputBounds.x(); |
| 152 | offset->fY = inputBounds.y(); |
| 153 | return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 154 | -inputOffset.y())); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 155 | } |
| 156 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 157 | offset->fX = dstBounds.fLeft; |
| 158 | offset->fY = dstBounds.fTop; |
| 159 | inputBounds.offset(-inputOffset); |
| 160 | dstBounds.offset(-inputOffset); |
Brian Osman | 5f50092 | 2016-12-29 11:50:48 -0500 | [diff] [blame] | 161 | // Typically, we would create the RTC with the output's color space (from ctx), but we |
| 162 | // always blur in the PixelConfig of the *input*. Those might not be compatible (if they |
| 163 | // have different transfer functions). We've already guaranteed that those color spaces |
| 164 | // have the same gamut, so in this case, we do everything in the input's color space. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 165 | sk_sp<GrRenderTargetContext> renderTargetContext(SkGpuBlurUtils::GaussianBlur( |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 166 | context, |
Robert Phillips | 08c5ec7 | 2017-01-30 12:26:47 -0500 | [diff] [blame] | 167 | std::move(inputTexture), |
Brian Osman | 5f50092 | 2016-12-29 11:50:48 -0500 | [diff] [blame] | 168 | sk_ref_sp(input->getColorSpace()), |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 169 | dstBounds, |
| 170 | &inputBounds, |
| 171 | sigma.x(), |
| 172 | sigma.y())); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 173 | if (!renderTargetContext) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 174 | return nullptr; |
| 175 | } |
| 176 | |
Robert Phillips | 2c6d2bf | 2017-02-21 10:19:29 -0500 | [diff] [blame] | 177 | return SkSpecialImage::MakeDeferredFromGpu(context, |
| 178 | SkIRect::MakeWH(dstBounds.width(), |
| 179 | dstBounds.height()), |
| 180 | kNeedNewImageUniqueID_SpecialImage, |
| 181 | renderTargetContext->asTextureProxyRef(), |
| 182 | renderTargetContext->refColorSpace(), |
| 183 | &source->props()); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 184 | } |
| 185 | #endif |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 186 | |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 187 | int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; |
| 188 | int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 189 | get_box3_params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffsetX); |
| 190 | get_box3_params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffsetY); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 191 | |
| 192 | if (kernelSizeX < 0 || kernelSizeY < 0) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 193 | return nullptr; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | if (kernelSizeX == 0 && kernelSizeY == 0) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 197 | offset->fX = inputBounds.x(); |
| 198 | offset->fY = inputBounds.y(); |
| 199 | return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 200 | -inputOffset.y())); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 201 | } |
| 202 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 203 | SkBitmap inputBM; |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 204 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 205 | if (!input->getROPixels(&inputBM)) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 206 | return nullptr; |
senorblanco | 6404981 | 2016-02-01 10:32:42 -0800 | [diff] [blame] | 207 | } |
| 208 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 209 | if (inputBM.colorType() != kN32_SkColorType) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 210 | return nullptr; |
senorblanco | 6404981 | 2016-02-01 10:32:42 -0800 | [diff] [blame] | 211 | } |
senorblanco | 6404981 | 2016-02-01 10:32:42 -0800 | [diff] [blame] | 212 | |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 213 | SkImageInfo info = SkImageInfo::Make(dstBounds.width(), dstBounds.height(), |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 214 | inputBM.colorType(), inputBM.alphaType()); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 215 | |
| 216 | SkBitmap tmp, dst; |
| 217 | if (!tmp.tryAllocPixels(info) || !dst.tryAllocPixels(info)) { |
| 218 | return nullptr; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 219 | } |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 220 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 221 | SkAutoLockPixels inputLock(inputBM), tmpLock(tmp), dstLock(dst); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 222 | |
senorblanco | 29a440d | 2015-11-02 12:55:47 -0800 | [diff] [blame] | 223 | offset->fX = dstBounds.fLeft; |
| 224 | offset->fY = dstBounds.fTop; |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 225 | SkPMColor* t = tmp.getAddr32(0, 0); |
| 226 | SkPMColor* d = dst.getAddr32(0, 0); |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 227 | int w = dstBounds.width(), h = dstBounds.height(); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 228 | const SkPMColor* s = inputBM.getAddr32(inputBounds.x() - inputOffset.x(), |
| 229 | inputBounds.y() - inputOffset.y()); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 230 | inputBounds.offset(-dstBounds.x(), -dstBounds.y()); |
senorblanco | 29a440d | 2015-11-02 12:55:47 -0800 | [diff] [blame] | 231 | dstBounds.offset(-dstBounds.x(), -dstBounds.y()); |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 232 | SkIRect inputBoundsT = SkIRect::MakeLTRB(inputBounds.top(), inputBounds.left(), |
| 233 | inputBounds.bottom(), inputBounds.right()); |
senorblanco | 29a440d | 2015-11-02 12:55:47 -0800 | [diff] [blame] | 234 | SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width()); |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 235 | int sw = int(inputBM.rowBytes() >> 2); |
senorblanco@chromium.org | 27eec46 | 2013-11-08 20:49:04 +0000 | [diff] [blame] | 236 | |
mtklein | dce5ce4 | 2015-08-04 08:49:21 -0700 | [diff] [blame] | 237 | /** |
| 238 | * |
| 239 | * In order to make memory accesses cache-friendly, we reorder the passes to |
| 240 | * use contiguous memory reads wherever possible. |
| 241 | * |
| 242 | * For example, the 6 passes of the X-and-Y blur case are rewritten as |
| 243 | * follows. Instead of 3 passes in X and 3 passes in Y, we perform |
| 244 | * 2 passes in X, 1 pass in X transposed to Y on write, 2 passes in X, |
| 245 | * then 1 pass in X transposed to Y on write. |
| 246 | * |
| 247 | * +----+ +----+ +----+ +---+ +---+ +---+ +----+ |
| 248 | * + AB + ----> | AB | ----> | AB | -----> | A | ----> | A | ----> | A | -----> | AB | |
| 249 | * +----+ blurX +----+ blurX +----+ blurXY | B | blurX | B | blurX | B | blurXY +----+ |
| 250 | * +---+ +---+ +---+ |
| 251 | * |
| 252 | * In this way, two of the y-blurs become x-blurs applied to transposed |
| 253 | * images, and all memory reads are contiguous. |
| 254 | */ |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 255 | if (kernelSizeX > 0 && kernelSizeY > 0) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 256 | SkOpts::box_blur_xx(s, sw, inputBounds, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
| 257 | SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
| 258 | SkOpts::box_blur_xy(d, w, dstBounds, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
| 259 | SkOpts::box_blur_xx(t, h, dstBoundsT, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
| 260 | SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
| 261 | SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 262 | } else if (kernelSizeX > 0) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 263 | SkOpts::box_blur_xx(s, sw, inputBounds, d, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
| 264 | SkOpts::box_blur_xx(d, w, dstBounds, t, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
| 265 | SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 266 | } else if (kernelSizeY > 0) { |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 267 | SkOpts::box_blur_yx(s, sw, inputBoundsT, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
| 268 | SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
| 269 | SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 270 | } |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 271 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 272 | return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(dstBounds.width(), |
robertphillips | 1579e3c | 2016-03-24 05:01:23 -0700 | [diff] [blame] | 273 | dstBounds.height()), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 274 | dst, &source->props()); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame^] | 277 | sk_sp<SkImageFilter> SkBlurImageFilterImpl::onMakeColorSpace(SkColorSpaceXformer* xformer) |
| 278 | const { |
| 279 | SkASSERT(1 == this->countInputs()); |
| 280 | if (!this->getInput(0)) { |
| 281 | return sk_ref_sp(const_cast<SkBlurImageFilterImpl*>(this)); |
| 282 | } |
| 283 | |
| 284 | sk_sp<SkImageFilter> input = this->getInput(0)->makeColorSpace(xformer); |
| 285 | return SkImageFilter::MakeBlur(fSigma.width(), fSigma.height(), std::move(input), |
| 286 | this->getCropRectIfSet()); |
| 287 | } |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 288 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 289 | SkRect SkBlurImageFilterImpl::computeFastBounds(const SkRect& src) const { |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 290 | SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src) : src; |
Mike Reed | a99b6ce | 2017-02-04 11:04:26 -0500 | [diff] [blame] | 291 | bounds.outset(fSigma.width() * 3, fSigma.height() * 3); |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 292 | return bounds; |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 293 | } |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 294 | |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 295 | SkIRect SkBlurImageFilterImpl::onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm, |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 296 | MapDirection) const { |
senorblanco | 6404981 | 2016-02-01 10:32:42 -0800 | [diff] [blame] | 297 | SkVector sigma = map_sigma(fSigma, ctm); |
Mike Reed | a99b6ce | 2017-02-04 11:04:26 -0500 | [diff] [blame] | 298 | return src.makeOutset(SkScalarCeilToInt(sigma.x() * 3), SkScalarCeilToInt(sigma.y() * 3)); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 299 | } |
| 300 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 301 | #ifndef SK_IGNORE_TO_STRING |
vjiaoblack | e1e5c74 | 2016-08-23 11:13:14 -0700 | [diff] [blame] | 302 | void SkBlurImageFilterImpl::toString(SkString* str) const { |
| 303 | str->appendf("SkBlurImageFilterImpl: ("); |
robertphillips | 33cca88 | 2014-12-22 06:52:04 -0800 | [diff] [blame] | 304 | str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); |
| 305 | |
| 306 | if (this->getInput(0)) { |
| 307 | this->getInput(0)->toString(str); |
| 308 | } |
| 309 | |
| 310 | str->append("))"); |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 311 | } |
| 312 | #endif |