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 | |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 8 | #include "SkBitmap.h" |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 9 | #include "SkBlurImageFilter.h" |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 10 | #include "SkColorPriv.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 11 | #include "SkReadBuffer.h" |
| 12 | #include "SkWriteBuffer.h" |
robertphillips@google.com | 736dd03 | 2013-07-15 15:06:54 +0000 | [diff] [blame] | 13 | #include "SkGpuBlurUtils.h" |
senorblanco@chromium.org | 27eec46 | 2013-11-08 20:49:04 +0000 | [diff] [blame] | 14 | #include "SkBlurImage_opts.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 15 | #if SK_SUPPORT_GPU |
senorblanco@chromium.org | 302cffb | 2012-08-01 20:16:34 +0000 | [diff] [blame] | 16 | #include "GrContext.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 17 | #endif |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 18 | |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 19 | // This rather arbitrary-looking value results in a maximum box blur kernel size |
| 20 | // of 1000 pixels on the raster path, which matches the WebKit and Firefox |
| 21 | // implementations. Since the GPU path does not compute a box blur, putting |
| 22 | // the limit on sigma ensures consistent behaviour between the GPU and |
| 23 | // raster paths. |
| 24 | #define MAX_SIGMA SkIntToScalar(532) |
| 25 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 26 | #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 27 | SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer) |
commit-bot@chromium.org | ce33d60 | 2013-11-25 21:46:31 +0000 | [diff] [blame] | 28 | : INHERITED(1, buffer) { |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 29 | fSigma.fWidth = buffer.readScalar(); |
| 30 | fSigma.fHeight = buffer.readScalar(); |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 31 | buffer.validate(SkScalarIsFinite(fSigma.fWidth) && |
| 32 | SkScalarIsFinite(fSigma.fHeight) && |
| 33 | (fSigma.fWidth >= 0) && |
| 34 | (fSigma.fHeight >= 0)); |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 35 | } |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 36 | #endif |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 37 | |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 38 | SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, |
| 39 | SkScalar sigmaY, |
| 40 | SkImageFilter* input, |
senorblanco | 5e5f948 | 2014-08-26 12:27:12 -0700 | [diff] [blame^] | 41 | const CropRect* cropRect, |
| 42 | uint32_t uniqueID) |
| 43 | : INHERITED(1, &input, cropRect, uniqueID), fSigma(SkSize::Make(sigmaX, sigmaY)) { |
senorblanco@chromium.org | 60014ca | 2011-11-09 16:05:58 +0000 | [diff] [blame] | 44 | } |
| 45 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 46 | SkFlattenable* SkBlurImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 47 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 48 | SkScalar sigmaX = buffer.readScalar(); |
| 49 | SkScalar sigmaY = buffer.readScalar(); |
senorblanco | 5e5f948 | 2014-08-26 12:27:12 -0700 | [diff] [blame^] | 50 | return Create(sigmaX, sigmaY, common.getInput(0), &common.cropRect(), common.uniqueID()); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 51 | } |
| 52 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 53 | void SkBlurImageFilter::flatten(SkWriteBuffer& buffer) const { |
senorblanco@chromium.org | 54e01b2 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 54 | this->INHERITED::flatten(buffer); |
| 55 | buffer.writeScalar(fSigma.fWidth); |
| 56 | buffer.writeScalar(fSigma.fHeight); |
| 57 | } |
| 58 | |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 59 | enum BlurDirection { |
| 60 | kX, kY |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * |
| 65 | * In order to make memory accesses cache-friendly, we reorder the passes to |
| 66 | * use contiguous memory reads wherever possible. |
| 67 | * |
| 68 | * For example, the 6 passes of the X-and-Y blur case are rewritten as |
| 69 | * follows. Instead of 3 passes in X and 3 passes in Y, we perform |
| 70 | * 2 passes in X, 1 pass in X transposed to Y on write, 2 passes in X, |
| 71 | * then 1 pass in X transposed to Y on write. |
| 72 | * |
| 73 | * +----+ +----+ +----+ +---+ +---+ +---+ +----+ |
| 74 | * + AB + ----> | AB | ----> | AB | -----> | A | ----> | A | ----> | A | -----> | AB | |
| 75 | * +----+ blurX +----+ blurX +----+ blurXY | B | blurX | B | blurX | B | blurXY +----+ |
| 76 | * +---+ +---+ +---+ |
| 77 | * |
| 78 | * In this way, two of the y-blurs become x-blurs applied to transposed |
| 79 | * images, and all memory reads are contiguous. |
| 80 | */ |
| 81 | |
| 82 | template<BlurDirection srcDirection, BlurDirection dstDirection> |
| 83 | static void boxBlur(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize, |
| 84 | int leftOffset, int rightOffset, int width, int height) |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 85 | { |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 86 | int rightBorder = SkMin32(rightOffset + 1, width); |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 87 | int srcStrideX = srcDirection == kX ? 1 : srcStride; |
| 88 | int dstStrideX = dstDirection == kX ? 1 : height; |
| 89 | int srcStrideY = srcDirection == kX ? srcStride : 1; |
| 90 | int dstStrideY = dstDirection == kX ? width : 1; |
senorblanco@chromium.org | fe2faa8 | 2013-11-04 16:07:33 +0000 | [diff] [blame] | 91 | uint32_t scale = (1 << 24) / kernelSize; |
| 92 | uint32_t half = 1 << 23; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 93 | for (int y = 0; y < height; ++y) { |
| 94 | int sumA = 0, sumR = 0, sumG = 0, sumB = 0; |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 95 | const SkPMColor* p = src; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 96 | for (int i = 0; i < rightBorder; ++i) { |
| 97 | sumA += SkGetPackedA32(*p); |
| 98 | sumR += SkGetPackedR32(*p); |
| 99 | sumG += SkGetPackedG32(*p); |
| 100 | sumB += SkGetPackedB32(*p); |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 101 | p += srcStrideX; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 102 | } |
| 103 | |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 104 | const SkPMColor* sptr = src; |
| 105 | SkColor* dptr = dst; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 106 | for (int x = 0; x < width; ++x) { |
senorblanco@chromium.org | fe2faa8 | 2013-11-04 16:07:33 +0000 | [diff] [blame] | 107 | *dptr = SkPackARGB32((sumA * scale + half) >> 24, |
| 108 | (sumR * scale + half) >> 24, |
| 109 | (sumG * scale + half) >> 24, |
| 110 | (sumB * scale + half) >> 24); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 111 | if (x >= leftOffset) { |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 112 | SkColor l = *(sptr - leftOffset * srcStrideX); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 113 | sumA -= SkGetPackedA32(l); |
| 114 | sumR -= SkGetPackedR32(l); |
| 115 | sumG -= SkGetPackedG32(l); |
| 116 | sumB -= SkGetPackedB32(l); |
| 117 | } |
| 118 | if (x + rightOffset + 1 < width) { |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 119 | SkColor r = *(sptr + (rightOffset + 1) * srcStrideX); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 120 | sumA += SkGetPackedA32(r); |
| 121 | sumR += SkGetPackedR32(r); |
| 122 | sumG += SkGetPackedG32(r); |
| 123 | sumB += SkGetPackedB32(r); |
| 124 | } |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 125 | sptr += srcStrideX; |
| 126 | if (srcDirection == kY) { |
| 127 | SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); |
| 128 | } |
| 129 | dptr += dstStrideX; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 130 | } |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 131 | src += srcStrideY; |
| 132 | dst += dstStrideY; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
commit-bot@chromium.org | 7b32070 | 2013-07-10 21:22:18 +0000 | [diff] [blame] | 136 | static void getBox3Params(SkScalar s, int *kernelSize, int* kernelSize3, int *lowOffset, |
| 137 | int *highOffset) |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 138 | { |
schenney@chromium.org | 73f3ded | 2011-12-20 22:31:40 +0000 | [diff] [blame] | 139 | float pi = SkScalarToFloat(SK_ScalarPI); |
| 140 | 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] | 141 | *kernelSize = d; |
| 142 | if (d % 2 == 1) { |
| 143 | *lowOffset = *highOffset = (d - 1) / 2; |
| 144 | *kernelSize3 = d; |
| 145 | } else { |
| 146 | *highOffset = d / 2; |
| 147 | *lowOffset = *highOffset - 1; |
| 148 | *kernelSize3 = d + 1; |
| 149 | } |
| 150 | } |
| 151 | |
senorblanco@chromium.org | f1369ce | 2012-08-20 14:53:21 +0000 | [diff] [blame] | 152 | bool SkBlurImageFilter::onFilterImage(Proxy* proxy, |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 153 | const SkBitmap& source, const Context& ctx, |
commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 154 | SkBitmap* dst, SkIPoint* offset) const { |
senorblanco@chromium.org | 6840076 | 2013-05-24 15:04:07 +0000 | [diff] [blame] | 155 | SkBitmap src = source; |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 156 | SkIPoint srcOffset = SkIPoint::Make(0, 0); |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 157 | if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) { |
senorblanco@chromium.org | 6840076 | 2013-05-24 15:04:07 +0000 | [diff] [blame] | 158 | return false; |
| 159 | } |
| 160 | |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 161 | if (src.colorType() != kN32_SkColorType) { |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 162 | return false; |
| 163 | } |
| 164 | |
senorblanco@chromium.org | 1182529 | 2014-03-14 17:44:41 +0000 | [diff] [blame] | 165 | SkIRect srcBounds, dstBounds; |
| 166 | if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &srcBounds, &src)) { |
reed@google.com | 76dd277 | 2012-01-05 21:15:07 +0000 | [diff] [blame] | 167 | return false; |
| 168 | } |
| 169 | |
senorblanco@chromium.org | 1182529 | 2014-03-14 17:44:41 +0000 | [diff] [blame] | 170 | SkAutoLockPixels alp(src); |
| 171 | if (!src.getPixels()) { |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 172 | return false; |
| 173 | } |
| 174 | |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 175 | if (!dst->allocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) { |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 176 | return false; |
| 177 | } |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 178 | dst->getBounds(&dstBounds); |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 179 | |
senorblanco@chromium.org | ba31f1d | 2014-05-07 20:56:08 +0000 | [diff] [blame] | 180 | SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); |
| 181 | ctx.ctm().mapVectors(&sigma, 1); |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 182 | sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA); |
| 183 | sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA); |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 184 | |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 185 | int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; |
| 186 | int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 187 | getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffsetX); |
| 188 | getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffsetY); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 189 | |
| 190 | if (kernelSizeX < 0 || kernelSizeY < 0) { |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | if (kernelSizeX == 0 && kernelSizeY == 0) { |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 195 | src.copyTo(dst, dst->colorType()); |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 196 | offset->fX = srcBounds.fLeft; |
| 197 | offset->fY = srcBounds.fTop; |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 198 | return true; |
| 199 | } |
| 200 | |
| 201 | SkBitmap temp; |
reed | c77392e | 2014-06-02 13:07:26 -0700 | [diff] [blame] | 202 | if (!temp.allocPixels(dst->info())) { |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 206 | offset->fX = srcBounds.fLeft; |
| 207 | offset->fY = srcBounds.fTop; |
| 208 | srcBounds.offset(-srcOffset); |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 209 | const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top()); |
| 210 | SkPMColor* t = temp.getAddr32(0, 0); |
| 211 | SkPMColor* d = dst->getAddr32(0, 0); |
| 212 | int w = dstBounds.width(), h = dstBounds.height(); |
| 213 | int sw = src.rowBytesAsPixels(); |
senorblanco@chromium.org | 05edd02 | 2013-11-11 20:12:34 +0000 | [diff] [blame] | 214 | SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY, boxBlurYX; |
| 215 | if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY, &boxBlurYX)) { |
senorblanco@chromium.org | 27eec46 | 2013-11-08 20:49:04 +0000 | [diff] [blame] | 216 | boxBlurX = boxBlur<kX, kX>; |
| 217 | boxBlurY = boxBlur<kY, kY>; |
| 218 | boxBlurXY = boxBlur<kX, kY>; |
senorblanco@chromium.org | 05edd02 | 2013-11-11 20:12:34 +0000 | [diff] [blame] | 219 | boxBlurYX = boxBlur<kY, kX>; |
senorblanco@chromium.org | 27eec46 | 2013-11-08 20:49:04 +0000 | [diff] [blame] | 220 | } |
| 221 | |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 222 | if (kernelSizeX > 0 && kernelSizeY > 0) { |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 223 | boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
| 224 | boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
| 225 | boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
| 226 | boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
| 227 | boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
| 228 | boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 229 | } else if (kernelSizeX > 0) { |
senorblanco@chromium.org | 0cc00c2 | 2013-11-07 18:35:12 +0000 | [diff] [blame] | 230 | boxBlurX(s, sw, d, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
| 231 | boxBlurX(d, w, t, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
| 232 | boxBlurX(t, w, d, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 233 | } else if (kernelSizeY > 0) { |
senorblanco@chromium.org | 05edd02 | 2013-11-11 20:12:34 +0000 | [diff] [blame] | 234 | boxBlurYX(s, sw, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
| 235 | boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
| 236 | boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
senorblanco@chromium.org | ae814c7 | 2011-12-20 20:02:19 +0000 | [diff] [blame] | 237 | } |
| 238 | return true; |
| 239 | } |
| 240 | |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 241 | |
| 242 | void SkBlurImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { |
| 243 | if (getInput(0)) { |
| 244 | getInput(0)->computeFastBounds(src, dst); |
| 245 | } else { |
| 246 | *dst = src; |
| 247 | } |
| 248 | |
| 249 | dst->outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)), |
| 250 | SkScalarMul(fSigma.height(), SkIntToScalar(3))); |
| 251 | } |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 252 | |
| 253 | bool SkBlurImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 254 | SkIRect* dst) const { |
| 255 | SkIRect bounds = src; |
senorblanco@chromium.org | ba31f1d | 2014-05-07 20:56:08 +0000 | [diff] [blame] | 256 | SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); |
| 257 | ctm.mapVectors(&sigma, 1); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 258 | bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), |
| 259 | SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 260 | if (getInput(0) && !getInput(0)->filterBounds(bounds, ctm, &bounds)) { |
| 261 | return false; |
| 262 | } |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 263 | *dst = bounds; |
| 264 | return true; |
| 265 | } |
| 266 | |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 267 | bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx, |
commit-bot@chromium.org | ae761f7 | 2014-02-05 22:32:02 +0000 | [diff] [blame] | 268 | SkBitmap* result, SkIPoint* offset) const { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 269 | #if SK_SUPPORT_GPU |
senorblanco@chromium.org | 6aa6fec | 2014-03-03 22:13:56 +0000 | [diff] [blame] | 270 | SkBitmap input = src; |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 271 | SkIPoint srcOffset = SkIPoint::Make(0, 0); |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 272 | if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) { |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 273 | return false; |
| 274 | } |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 275 | SkIRect rect; |
senorblanco@chromium.org | 1182529 | 2014-03-14 17:44:41 +0000 | [diff] [blame] | 276 | if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &rect, &input)) { |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 277 | return false; |
| 278 | } |
senorblanco@chromium.org | 1182529 | 2014-03-14 17:44:41 +0000 | [diff] [blame] | 279 | GrTexture* source = input.getTexture(); |
senorblanco@chromium.org | ba31f1d | 2014-05-07 20:56:08 +0000 | [diff] [blame] | 280 | SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); |
| 281 | ctx.ctm().mapVectors(&sigma, 1); |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 282 | sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA); |
| 283 | sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA); |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 284 | offset->fX = rect.fLeft; |
| 285 | offset->fY = rect.fTop; |
| 286 | rect.offset(-srcOffset); |
skia.committer@gmail.com | 6ae6383 | 2013-07-23 07:01:05 +0000 | [diff] [blame] | 287 | SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(), |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 288 | source, |
| 289 | false, |
| 290 | SkRect::Make(rect), |
| 291 | true, |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 292 | sigma.x(), |
| 293 | sigma.y())); |
senorblanco@chromium.org | 6aa6fec | 2014-03-03 22:13:56 +0000 | [diff] [blame] | 294 | WrapTexture(tex, rect.width(), rect.height(), result); |
| 295 | return true; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 296 | #else |
| 297 | SkDEBUGFAIL("Should not call in GPU-less build"); |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 298 | return false; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 299 | #endif |
senorblanco@chromium.org | 302cffb | 2012-08-01 20:16:34 +0000 | [diff] [blame] | 300 | } |