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