diff --git a/include/effects/SkBlurDrawLooper.h b/include/effects/SkBlurDrawLooper.h index fa730e382c..eeed1b6c20 100644 --- a/include/effects/SkBlurDrawLooper.h +++ b/include/effects/SkBlurDrawLooper.h @@ -31,8 +31,10 @@ public: kIgnoreTransform_BlurFlag = 0x01, kOverrideColor_BlurFlag = 0x02, kHighQuality_BlurFlag = 0x04, + /** faster, but may discretize the radius */ + kCoarseRadius_BlurFlag = 0x08, /** mask for all blur flags */ - kAll_BlurFlag = 0x07 + kAll_BlurFlag = 0x0F }; SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color, diff --git a/include/effects/SkBlurMaskFilter.h b/include/effects/SkBlurMaskFilter.h index 2ab321aa7a..e957a9ddd4 100644 --- a/include/effects/SkBlurMaskFilter.h +++ b/include/effects/SkBlurMaskFilter.h @@ -29,8 +29,10 @@ public: kIgnoreTransform_BlurFlag = 0x01, /** Use a smother, higher qulity blur algorithm */ kHighQuality_BlurFlag = 0x02, + /** Do faster blurs by rounding the radius to a set of sub-integer values */ + kCoarseRadius_BlurFlag = 0x04, /** mask for all blur flags */ - kAll_BlurFlag = 0x03 + kAll_BlurFlag = 0x07 }; /** Create a blur maskfilter. diff --git a/src/effects/SkBlurDrawLooper.cpp b/src/effects/SkBlurDrawLooper.cpp index e6e2ffdd8c..8854225636 100644 --- a/src/effects/SkBlurDrawLooper.cpp +++ b/src/effects/SkBlurDrawLooper.cpp @@ -27,6 +27,10 @@ SkBlurDrawLooper::SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkBlurMaskFilter::kHighQuality_BlurFlag : SkBlurMaskFilter::kNone_BlurFlag; + blurFlags |= flags & kCoarseRadius_BlurFlag ? + SkBlurMaskFilter::kCoarseRadius_BlurFlag : + SkBlurMaskFilter::kNone_BlurFlag; + fBlur = SkBlurMaskFilter::Create(radius, SkBlurMaskFilter::kNormal_BlurStyle, blurFlags); diff --git a/src/effects/SkBlurMask.cpp b/src/effects/SkBlurMask.cpp index e762ae6f65..4873685dc3 100644 --- a/src/effects/SkBlurMask.cpp +++ b/src/effects/SkBlurMask.cpp @@ -34,8 +34,9 @@ static int boxBlur(const uint8_t* src, int src_y_stride, uint8_t* dst, uint8_t* dptr = dst + y * dst_y_stride; const uint8_t* right = src + y * src_y_stride; const uint8_t* left = right; - for (int x = 0; x < leftRadius - rightRadius; x++) { - *dptr++ = 0; + for (int x = 0; x < rightRadius - leftRadius; x++) { + *dptr = 0; + dptr += dst_x_stride; } for (int x = 0; x < border; ++x) { sum += *right++; @@ -57,8 +58,9 @@ static int boxBlur(const uint8_t* src, int src_y_stride, uint8_t* dst, sum -= *left++; dptr += dst_x_stride; } - for (int x = 0; x < rightRadius - leftRadius; x++) { - *dptr++ = 0; + for (int x = 0; x < leftRadius - rightRadius; x++) { + *dptr = 0; + dptr += dst_x_stride; } SkASSERT(sum == 0); } diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 6cc19c16ab..2e031d8056 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -97,8 +97,13 @@ bool SkBlurMaskFilterImpl::filterMask(SkMask* dst, const SkMask& src, (fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag) ? SkBlurMask::kHigh_Quality : SkBlurMask::kLow_Quality; - return SkBlurMask::Blur(dst, src, radius, (SkBlurMask::Style)fBlurStyle, - blurQuality, margin); + if (fBlurFlags & SkBlurMaskFilter::kCoarseRadius_BlurFlag) { + return SkBlurMask::BlurSeparable(dst, src, radius, (SkBlurMask::Style)fBlurStyle, + blurQuality, margin); + } else { + return SkBlurMask::Blur(dst, src, radius, (SkBlurMask::Style)fBlurStyle, + blurQuality, margin); + } } #include "SkCanvas.h"