| OLD | NEW |
| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkGpuBlurUtils.h" | 13 #include "SkGpuBlurUtils.h" |
| 14 #include "SkBlurImage_opts.h" | 14 #include "SkBlurImage_opts.h" |
| 15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 16 #include "GrContext.h" | 16 #include "GrContext.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 // This rather arbitrary-looking value results in a maximum box blur kernel size | 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 | 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 | 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 | 22 // the limit on sigma ensures consistent behaviour between the GPU and |
| 23 // raster paths. | 23 // raster paths. |
| 24 #define MAX_SIGMA SkIntToScalar(532) | 24 #define MAX_SIGMA SkIntToScalar(532) |
| 25 | 25 |
| 26 static SkVector mapSigma(const SkSize& localSigma, const SkMatrix& ctm) { |
| 27 SkVector sigma = SkVector::Make(localSigma.width(), localSigma.height()); |
| 28 ctm.mapVectors(&sigma, 1); |
| 29 sigma.fX = SkMinScalar(SkScalarAbs(sigma.fX), MAX_SIGMA); |
| 30 sigma.fY = SkMinScalar(SkScalarAbs(sigma.fY), MAX_SIGMA); |
| 31 return sigma; |
| 32 } |
| 33 |
| 26 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | 34 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 27 SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer) | 35 SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer) |
| 28 : INHERITED(1, buffer) { | 36 : INHERITED(1, buffer) { |
| 29 fSigma.fWidth = buffer.readScalar(); | 37 fSigma.fWidth = buffer.readScalar(); |
| 30 fSigma.fHeight = buffer.readScalar(); | 38 fSigma.fHeight = buffer.readScalar(); |
| 31 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && | 39 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && |
| 32 SkScalarIsFinite(fSigma.fHeight) && | 40 SkScalarIsFinite(fSigma.fHeight) && |
| 33 (fSigma.fWidth >= 0) && | 41 (fSigma.fWidth >= 0) && |
| 34 (fSigma.fHeight >= 0)); | 42 (fSigma.fHeight >= 0)); |
| 35 } | 43 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 SkAutoLockPixels alp(src); | 178 SkAutoLockPixels alp(src); |
| 171 if (!src.getPixels()) { | 179 if (!src.getPixels()) { |
| 172 return false; | 180 return false; |
| 173 } | 181 } |
| 174 | 182 |
| 175 if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.heig
ht()))) { | 183 if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.heig
ht()))) { |
| 176 return false; | 184 return false; |
| 177 } | 185 } |
| 178 dst->getBounds(&dstBounds); | 186 dst->getBounds(&dstBounds); |
| 179 | 187 |
| 180 SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); | 188 SkVector sigma = mapSigma(fSigma, ctx.ctm()); |
| 181 ctx.ctm().mapVectors(&sigma, 1); | |
| 182 sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA); | |
| 183 sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA); | |
| 184 | 189 |
| 185 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; | 190 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; |
| 186 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; | 191 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; |
| 187 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs
etX); | 192 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs
etX); |
| 188 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs
etY); | 193 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs
etY); |
| 189 | 194 |
| 190 if (kernelSizeX < 0 || kernelSizeY < 0) { | 195 if (kernelSizeX < 0 || kernelSizeY < 0) { |
| 191 return false; | 196 return false; |
| 192 } | 197 } |
| 193 | 198 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 *dst = src; | 251 *dst = src; |
| 247 } | 252 } |
| 248 | 253 |
| 249 dst->outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)), | 254 dst->outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)), |
| 250 SkScalarMul(fSigma.height(), SkIntToScalar(3))); | 255 SkScalarMul(fSigma.height(), SkIntToScalar(3))); |
| 251 } | 256 } |
| 252 | 257 |
| 253 bool SkBlurImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 258 bool SkBlurImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 254 SkIRect* dst) const { | 259 SkIRect* dst) const { |
| 255 SkIRect bounds = src; | 260 SkIRect bounds = src; |
| 256 SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); | 261 SkVector sigma = mapSigma(fSigma, ctm); |
| 257 ctm.mapVectors(&sigma, 1); | |
| 258 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), | 262 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), |
| 259 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); | 263 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); |
| 260 if (getInput(0) && !getInput(0)->filterBounds(bounds, ctm, &bounds)) { | 264 if (getInput(0) && !getInput(0)->filterBounds(bounds, ctm, &bounds)) { |
| 261 return false; | 265 return false; |
| 262 } | 266 } |
| 263 *dst = bounds; | 267 *dst = bounds; |
| 264 return true; | 268 return true; |
| 265 } | 269 } |
| 266 | 270 |
| 267 bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 271 bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 268 SkBitmap* result, SkIPoint* offset) const
{ | 272 SkBitmap* result, SkIPoint* offset) const
{ |
| 269 #if SK_SUPPORT_GPU | 273 #if SK_SUPPORT_GPU |
| 270 SkBitmap input = src; | 274 SkBitmap input = src; |
| 271 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 275 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 272 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input,
&srcOffset)) { | 276 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input,
&srcOffset)) { |
| 273 return false; | 277 return false; |
| 274 } | 278 } |
| 275 SkIRect rect; | 279 SkIRect rect; |
| 276 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &rect, &input)) { | 280 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &rect, &input)) { |
| 277 return false; | 281 return false; |
| 278 } | 282 } |
| 279 GrTexture* source = input.getTexture(); | 283 GrTexture* source = input.getTexture(); |
| 280 SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height()); | 284 SkVector sigma = mapSigma(fSigma, ctx.ctm()); |
| 281 ctx.ctm().mapVectors(&sigma, 1); | |
| 282 sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA); | |
| 283 sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA); | |
| 284 offset->fX = rect.fLeft; | 285 offset->fX = rect.fLeft; |
| 285 offset->fY = rect.fTop; | 286 offset->fY = rect.fTop; |
| 286 rect.offset(-srcOffset); | 287 rect.offset(-srcOffset); |
| 287 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(
), | 288 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(
), |
| 288 source, | 289 source, |
| 289 false, | 290 false, |
| 290 SkRect::Make(rect), | 291 SkRect::Make(rect), |
| 291 true, | 292 true, |
| 292 sigma.x(), | 293 sigma.x(), |
| 293 sigma.y())); | 294 sigma.y())); |
| 294 WrapTexture(tex, rect.width(), rect.height(), result); | 295 WrapTexture(tex, rect.width(), rect.height(), result); |
| 295 return true; | 296 return true; |
| 296 #else | 297 #else |
| 297 SkDEBUGFAIL("Should not call in GPU-less build"); | 298 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 298 return false; | 299 return false; |
| 299 #endif | 300 #endif |
| 300 } | 301 } |
| OLD | NEW |