epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkBlurMaskFilter.h" |
| 10 | #include "SkBlurMask.h" |
robertphillips@google.com | 736dd03 | 2013-07-15 15:06:54 +0000 | [diff] [blame] | 11 | #include "SkGpuBlurUtils.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 12 | #include "SkReadBuffer.h" |
| 13 | #include "SkWriteBuffer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkMaskFilter.h" |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 15 | #include "SkRRect.h" |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 16 | #include "SkRTConf.h" |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 17 | #include "SkStringUtils.h" |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 18 | #include "SkStrokeRec.h" |
| 19 | |
| 20 | #if SK_SUPPORT_GPU |
| 21 | #include "GrContext.h" |
| 22 | #include "GrTexture.h" |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 23 | #include "GrEffect.h" |
| 24 | #include "gl/GrGLEffect.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 25 | #include "gl/GrGLShaderBuilder.h" |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 26 | #include "effects/GrSimpleTextureEffect.h" |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 27 | #include "GrTBackendEffectFactory.h" |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 28 | #include "SkGrPixelRef.h" |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 29 | #include "SkDraw.h" |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 30 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | |
commit-bot@chromium.org | 508022c | 2014-05-01 15:24:55 +0000 | [diff] [blame] | 32 | SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { |
| 33 | return SkBlurMask::ConvertRadiusToSigma(radius); |
| 34 | } |
| 35 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | class SkBlurMaskFilterImpl : public SkMaskFilter { |
| 37 | public: |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 38 | SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | |
| 40 | // overrides from SkMaskFilter |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 41 | virtual SkMask::Format getFormat() const SK_OVERRIDE; |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 42 | virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 43 | SkIPoint* margin) const SK_OVERRIDE; |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 44 | |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 45 | #if SK_SUPPORT_GPU |
skia.committer@gmail.com | 1842adf | 2013-07-04 07:01:07 +0000 | [diff] [blame] | 46 | virtual bool canFilterMaskGPU(const SkRect& devBounds, |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 47 | const SkIRect& clipBounds, |
| 48 | const SkMatrix& ctm, |
| 49 | SkRect* maskRect) const SK_OVERRIDE; |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 50 | virtual bool directFilterMaskGPU(GrContext* context, |
| 51 | GrPaint* grp, |
| 52 | const SkStrokeRec& strokeRec, |
| 53 | const SkPath& path) const SK_OVERRIDE; |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 54 | virtual bool directFilterRRectMaskGPU(GrContext* context, |
| 55 | GrPaint* grp, |
| 56 | const SkStrokeRec& strokeRec, |
| 57 | const SkRRect& rrect) const SK_OVERRIDE; |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 58 | |
skia.committer@gmail.com | 1842adf | 2013-07-04 07:01:07 +0000 | [diff] [blame] | 59 | virtual bool filterMaskGPU(GrTexture* src, |
commit-bot@chromium.org | 41bf930 | 2014-01-08 22:25:53 +0000 | [diff] [blame] | 60 | const SkMatrix& ctm, |
skia.committer@gmail.com | 1842adf | 2013-07-04 07:01:07 +0000 | [diff] [blame] | 61 | const SkRect& maskRect, |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 62 | GrTexture** result, |
commit-bot@chromium.org | 41bf930 | 2014-01-08 22:25:53 +0000 | [diff] [blame] | 63 | bool canOverwriteSrc) const SK_OVERRIDE; |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 64 | #endif |
| 65 | |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 66 | virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE; |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 67 | virtual bool asABlur(BlurRec*) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 69 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 70 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurMaskFilterImpl) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 72 | protected: |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 73 | virtual FilterReturn filterRectsToNine(const SkRect[], int count, const SkMatrix&, |
| 74 | const SkIRect& clipBounds, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 75 | NinePatch*) const SK_OVERRIDE; |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 76 | |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 77 | virtual FilterReturn filterRRectToNine(const SkRRect&, const SkMatrix&, |
| 78 | const SkIRect& clipBounds, |
| 79 | NinePatch*) const SK_OVERRIDE; |
| 80 | |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 81 | bool filterRectMask(SkMask* dstM, const SkRect& r, const SkMatrix& matrix, |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 82 | SkIPoint* margin, SkMask::CreateMode createMode) const; |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 83 | bool filterRRectMask(SkMask* dstM, const SkRRect& r, const SkMatrix& matrix, |
| 84 | SkIPoint* margin, SkMask::CreateMode createMode) const; |
skia.committer@gmail.com | 453995e | 2012-11-10 02:01:26 +0000 | [diff] [blame] | 85 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | private: |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 87 | // To avoid unseemly allocation requests (esp. for finite platforms like |
| 88 | // handset) we limit the radius so something manageable. (as opposed to |
| 89 | // a request like 10,000) |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 90 | static const SkScalar kMAX_BLUR_SIGMA; |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 91 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 92 | SkScalar fSigma; |
| 93 | SkBlurStyle fBlurStyle; |
| 94 | uint32_t fBlurFlags; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 95 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 96 | SkBlurQuality getQuality() const { |
| 97 | return (fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag) ? |
| 98 | kHigh_SkBlurQuality : kLow_SkBlurQuality; |
| 99 | } |
| 100 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 101 | SkBlurMaskFilterImpl(SkReadBuffer&); |
| 102 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 103 | |
| 104 | SkScalar computeXformedSigma(const SkMatrix& ctm) const { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 105 | bool ignoreTransform = SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag); |
| 106 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 107 | SkScalar xformedSigma = ignoreTransform ? fSigma : ctm.mapRadius(fSigma); |
| 108 | return SkMinScalar(xformedSigma, kMAX_BLUR_SIGMA); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 109 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 110 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 111 | typedef SkMaskFilter INHERITED; |
| 112 | }; |
| 113 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 114 | const SkScalar SkBlurMaskFilterImpl::kMAX_BLUR_SIGMA = SkIntToScalar(128); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 115 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 116 | SkMaskFilter* SkBlurMaskFilter::Create(SkBlurStyle style, SkScalar sigma, uint32_t flags) { |
| 117 | if (!SkScalarIsFinite(sigma) || sigma <= 0) { |
| 118 | return NULL; |
| 119 | } |
| 120 | if ((unsigned)style > (unsigned)kLastEnum_SkBlurStyle) { |
| 121 | return NULL; |
| 122 | } |
| 123 | if (flags > SkBlurMaskFilter::kAll_BlurFlag) { |
| 124 | return NULL; |
| 125 | } |
| 126 | return SkNEW_ARGS(SkBlurMaskFilterImpl, (sigma, style, flags)); |
| 127 | } |
| 128 | |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 129 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 131 | SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle style, uint32_t flags) |
| 132 | : fSigma(sigma) |
| 133 | , fBlurStyle(style) |
| 134 | , fBlurFlags(flags) { |
| 135 | SkASSERT(fSigma > 0); |
| 136 | SkASSERT((unsigned)style <= kLastEnum_SkBlurStyle); |
senorblanco@chromium.org | 038aff6 | 2010-12-06 23:45:58 +0000 | [diff] [blame] | 137 | SkASSERT(flags <= SkBlurMaskFilter::kAll_BlurFlag); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 138 | } |
| 139 | |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 140 | SkMask::Format SkBlurMaskFilterImpl::getFormat() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 141 | return SkMask::kA8_Format; |
| 142 | } |
| 143 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 144 | bool SkBlurMaskFilterImpl::asABlur(BlurRec* rec) const { |
| 145 | if (fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) { |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | if (rec) { |
| 150 | rec->fSigma = fSigma; |
| 151 | rec->fStyle = fBlurStyle; |
| 152 | rec->fQuality = this->getQuality(); |
| 153 | } |
| 154 | return true; |
| 155 | } |
| 156 | |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 157 | bool SkBlurMaskFilterImpl::filterMask(SkMask* dst, const SkMask& src, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 158 | const SkMatrix& matrix, |
| 159 | SkIPoint* margin) const{ |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 160 | SkScalar sigma = this->computeXformedSigma(matrix); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 161 | return SkBlurMask::BoxBlur(dst, src, sigma, fBlurStyle, this->getQuality(), margin); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 162 | } |
| 163 | |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 164 | bool SkBlurMaskFilterImpl::filterRectMask(SkMask* dst, const SkRect& r, |
| 165 | const SkMatrix& matrix, |
| 166 | SkIPoint* margin, SkMask::CreateMode createMode) const{ |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 167 | SkScalar sigma = computeXformedSigma(matrix); |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 168 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 169 | return SkBlurMask::BlurRect(sigma, dst, r, fBlurStyle, |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 170 | margin, createMode); |
| 171 | } |
| 172 | |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 173 | bool SkBlurMaskFilterImpl::filterRRectMask(SkMask* dst, const SkRRect& r, |
| 174 | const SkMatrix& matrix, |
| 175 | SkIPoint* margin, SkMask::CreateMode createMode) const{ |
| 176 | SkScalar sigma = computeXformedSigma(matrix); |
| 177 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 178 | return SkBlurMask::BlurRRect(sigma, dst, r, fBlurStyle, |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 179 | margin, createMode); |
| 180 | } |
| 181 | |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 182 | #include "SkCanvas.h" |
| 183 | |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 184 | static bool prepare_to_draw_into_mask(const SkRect& bounds, SkMask* mask) { |
| 185 | SkASSERT(mask != NULL); |
| 186 | |
| 187 | bounds.roundOut(&mask->fBounds); |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 188 | mask->fRowBytes = SkAlign4(mask->fBounds.width()); |
| 189 | mask->fFormat = SkMask::kA8_Format; |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 190 | const size_t size = mask->computeImageSize(); |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 191 | mask->fImage = SkMask::AllocImage(size); |
| 192 | if (NULL == mask->fImage) { |
| 193 | return false; |
| 194 | } |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 195 | |
| 196 | // FIXME: use sk_calloc in AllocImage? |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 197 | sk_bzero(mask->fImage, size); |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 198 | return true; |
| 199 | } |
| 200 | |
| 201 | static bool draw_rrect_into_mask(const SkRRect rrect, SkMask* mask) { |
| 202 | if (!prepare_to_draw_into_mask(rrect.rect(), mask)) { |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | // FIXME: This code duplicates code in draw_rects_into_mask, below. Is there a |
| 207 | // clean way to share more code? |
| 208 | SkBitmap bitmap; |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 209 | bitmap.installMaskPixels(*mask); |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 210 | |
| 211 | SkCanvas canvas(bitmap); |
| 212 | canvas.translate(-SkIntToScalar(mask->fBounds.left()), |
| 213 | -SkIntToScalar(mask->fBounds.top())); |
| 214 | |
| 215 | SkPaint paint; |
| 216 | paint.setAntiAlias(true); |
| 217 | canvas.drawRRect(rrect, paint); |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | static bool draw_rects_into_mask(const SkRect rects[], int count, SkMask* mask) { |
| 222 | if (!prepare_to_draw_into_mask(rects[0], mask)) { |
| 223 | return false; |
| 224 | } |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 225 | |
| 226 | SkBitmap bitmap; |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 227 | bitmap.installPixels(SkImageInfo::Make(mask->fBounds.width(), |
| 228 | mask->fBounds.height(), |
| 229 | kAlpha_8_SkColorType, |
| 230 | kPremul_SkAlphaType), |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 231 | mask->fImage, mask->fRowBytes); |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 232 | |
| 233 | SkCanvas canvas(bitmap); |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 234 | canvas.translate(-SkIntToScalar(mask->fBounds.left()), |
| 235 | -SkIntToScalar(mask->fBounds.top())); |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 236 | |
| 237 | SkPaint paint; |
| 238 | paint.setAntiAlias(true); |
| 239 | |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 240 | if (1 == count) { |
| 241 | canvas.drawRect(rects[0], paint); |
| 242 | } else { |
| 243 | // todo: do I need a fast way to do this? |
| 244 | SkPath path; |
| 245 | path.addRect(rects[0]); |
| 246 | path.addRect(rects[1]); |
| 247 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 248 | canvas.drawPath(path, paint); |
| 249 | } |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 250 | return true; |
| 251 | } |
| 252 | |
reed@google.com | f276fa7 | 2012-11-21 14:14:10 +0000 | [diff] [blame] | 253 | static bool rect_exceeds(const SkRect& r, SkScalar v) { |
| 254 | return r.fLeft < -v || r.fTop < -v || r.fRight > v || r.fBottom > v || |
| 255 | r.width() > v || r.height() > v; |
reed@google.com | 07784a0 | 2012-11-19 21:09:14 +0000 | [diff] [blame] | 256 | } |
| 257 | |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 258 | #ifdef SK_IGNORE_FAST_RRECT_BLUR |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 259 | SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", false, "Use the faster analytic blur approach for ninepatch rects" ); |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 260 | #else |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 261 | SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", true, "Use the faster analytic blur approach for ninepatch round rects" ); |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 262 | #endif |
| 263 | |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 264 | SkMaskFilter::FilterReturn |
| 265 | SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& matrix, |
| 266 | const SkIRect& clipBounds, |
| 267 | NinePatch* patch) const { |
| 268 | SkASSERT(patch != NULL); |
| 269 | switch (rrect.getType()) { |
| 270 | case SkRRect::kUnknown_Type: |
| 271 | // Unknown should never be returned. |
| 272 | SkASSERT(false); |
| 273 | // Fall through. |
| 274 | case SkRRect::kEmpty_Type: |
| 275 | // Nothing to draw. |
| 276 | return kFalse_FilterReturn; |
| 277 | |
| 278 | case SkRRect::kRect_Type: |
| 279 | // We should have caught this earlier. |
| 280 | SkASSERT(false); |
| 281 | // Fall through. |
| 282 | case SkRRect::kOval_Type: |
| 283 | // The nine patch special case does not handle ovals, and we |
| 284 | // already have code for rectangles. |
| 285 | return kUnimplemented_FilterReturn; |
| 286 | |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 287 | // These three can take advantage of this fast path. |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 288 | case SkRRect::kSimple_Type: |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 289 | case SkRRect::kNinePatch_Type: |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 290 | case SkRRect::kComplex_Type: |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | |
| 294 | // TODO: report correct metrics for innerstyle, where we do not grow the |
| 295 | // total bounds, but we do need an inset the size of our blur-radius |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 296 | if (kInner_SkBlurStyle == fBlurStyle) { |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 297 | return kUnimplemented_FilterReturn; |
| 298 | } |
| 299 | |
| 300 | // TODO: take clipBounds into account to limit our coordinates up front |
| 301 | // for now, just skip too-large src rects (to take the old code path). |
| 302 | if (rect_exceeds(rrect.rect(), SkIntToScalar(32767))) { |
| 303 | return kUnimplemented_FilterReturn; |
| 304 | } |
| 305 | |
| 306 | SkIPoint margin; |
| 307 | SkMask srcM, dstM; |
| 308 | rrect.rect().roundOut(&srcM.fBounds); |
| 309 | srcM.fImage = NULL; |
| 310 | srcM.fFormat = SkMask::kA8_Format; |
| 311 | srcM.fRowBytes = 0; |
| 312 | |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 313 | bool filterResult = false; |
| 314 | if (c_analyticBlurRRect) { |
| 315 | // special case for fast round rect blur |
| 316 | // don't actually do the blur the first time, just compute the correct size |
| 317 | filterResult = this->filterRRectMask(&dstM, rrect, matrix, &margin, |
| 318 | SkMask::kJustComputeBounds_CreateMode); |
| 319 | } |
| 320 | |
| 321 | if (!filterResult) { |
| 322 | filterResult = this->filterMask(&dstM, srcM, matrix, &margin); |
| 323 | } |
| 324 | |
| 325 | if (!filterResult) { |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 326 | return kFalse_FilterReturn; |
| 327 | } |
| 328 | |
| 329 | // Now figure out the appropriate width and height of the smaller round rectangle |
| 330 | // to stretch. It will take into account the larger radius per side as well as double |
| 331 | // the margin, to account for inner and outer blur. |
| 332 | const SkVector& UL = rrect.radii(SkRRect::kUpperLeft_Corner); |
| 333 | const SkVector& UR = rrect.radii(SkRRect::kUpperRight_Corner); |
| 334 | const SkVector& LR = rrect.radii(SkRRect::kLowerRight_Corner); |
| 335 | const SkVector& LL = rrect.radii(SkRRect::kLowerLeft_Corner); |
| 336 | |
| 337 | const SkScalar leftUnstretched = SkTMax(UL.fX, LL.fX) + SkIntToScalar(2 * margin.fX); |
| 338 | const SkScalar rightUnstretched = SkTMax(UR.fX, LR.fX) + SkIntToScalar(2 * margin.fX); |
| 339 | |
| 340 | // Extra space in the middle to ensure an unchanging piece for stretching. Use 3 to cover |
| 341 | // any fractional space on either side plus 1 for the part to stretch. |
| 342 | const SkScalar stretchSize = SkIntToScalar(3); |
| 343 | |
| 344 | const SkScalar totalSmallWidth = leftUnstretched + rightUnstretched + stretchSize; |
| 345 | if (totalSmallWidth >= rrect.rect().width()) { |
| 346 | // There is no valid piece to stretch. |
| 347 | return kUnimplemented_FilterReturn; |
| 348 | } |
| 349 | |
| 350 | const SkScalar topUnstretched = SkTMax(UL.fY, UR.fY) + SkIntToScalar(2 * margin.fY); |
| 351 | const SkScalar bottomUnstretched = SkTMax(LL.fY, LR.fY) + SkIntToScalar(2 * margin.fY); |
| 352 | |
| 353 | const SkScalar totalSmallHeight = topUnstretched + bottomUnstretched + stretchSize; |
| 354 | if (totalSmallHeight >= rrect.rect().height()) { |
| 355 | // There is no valid piece to stretch. |
| 356 | return kUnimplemented_FilterReturn; |
| 357 | } |
| 358 | |
| 359 | SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight); |
| 360 | |
| 361 | SkRRect smallRR; |
| 362 | SkVector radii[4]; |
| 363 | radii[SkRRect::kUpperLeft_Corner] = UL; |
| 364 | radii[SkRRect::kUpperRight_Corner] = UR; |
| 365 | radii[SkRRect::kLowerRight_Corner] = LR; |
| 366 | radii[SkRRect::kLowerLeft_Corner] = LL; |
| 367 | smallRR.setRectRadii(smallR, radii); |
| 368 | |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 369 | bool analyticBlurWorked = false; |
| 370 | if (c_analyticBlurRRect) { |
| 371 | analyticBlurWorked = |
| 372 | this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin, |
| 373 | SkMask::kComputeBoundsAndRenderImage_CreateMode); |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 374 | } |
| 375 | |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 376 | if (!analyticBlurWorked) { |
| 377 | if (!draw_rrect_into_mask(smallRR, &srcM)) { |
| 378 | return kFalse_FilterReturn; |
| 379 | } |
robertphillips@google.com | ad99358 | 2013-11-11 18:45:18 +0000 | [diff] [blame] | 380 | |
commit-bot@chromium.org | a477154 | 2014-03-10 21:42:06 +0000 | [diff] [blame] | 381 | SkAutoMaskFreeImage amf(srcM.fImage); |
| 382 | |
| 383 | if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) { |
| 384 | return kFalse_FilterReturn; |
| 385 | } |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | patch->fMask.fBounds.offsetTo(0, 0); |
| 389 | patch->fOuterRect = dstM.fBounds; |
| 390 | patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1; |
| 391 | patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1; |
| 392 | return kTrue_FilterReturn; |
| 393 | } |
| 394 | |
humper@google.com | e86af1f | 2013-03-11 21:23:36 +0000 | [diff] [blame] | 395 | SK_CONF_DECLARE( bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects" ); |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 396 | |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 397 | SkMaskFilter::FilterReturn |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 398 | SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count, |
| 399 | const SkMatrix& matrix, |
| 400 | const SkIRect& clipBounds, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 401 | NinePatch* patch) const { |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 402 | if (count < 1 || count > 2) { |
| 403 | return kUnimplemented_FilterReturn; |
| 404 | } |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 405 | |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 406 | // TODO: report correct metrics for innerstyle, where we do not grow the |
| 407 | // total bounds, but we do need an inset the size of our blur-radius |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 408 | if (kInner_SkBlurStyle == fBlurStyle || kOuter_SkBlurStyle == fBlurStyle) { |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 409 | return kUnimplemented_FilterReturn; |
| 410 | } |
| 411 | |
reed@google.com | 07784a0 | 2012-11-19 21:09:14 +0000 | [diff] [blame] | 412 | // TODO: take clipBounds into account to limit our coordinates up front |
| 413 | // for now, just skip too-large src rects (to take the old code path). |
reed@google.com | f276fa7 | 2012-11-21 14:14:10 +0000 | [diff] [blame] | 414 | if (rect_exceeds(rects[0], SkIntToScalar(32767))) { |
reed@google.com | 07784a0 | 2012-11-19 21:09:14 +0000 | [diff] [blame] | 415 | return kUnimplemented_FilterReturn; |
| 416 | } |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 417 | |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 418 | SkIPoint margin; |
| 419 | SkMask srcM, dstM; |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 420 | rects[0].roundOut(&srcM.fBounds); |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 421 | srcM.fImage = NULL; |
| 422 | srcM.fFormat = SkMask::kA8_Format; |
| 423 | srcM.fRowBytes = 0; |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 424 | |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 425 | bool filterResult = false; |
| 426 | if (count == 1 && c_analyticBlurNinepatch) { |
| 427 | // special case for fast rect blur |
| 428 | // don't actually do the blur the first time, just compute the correct size |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 429 | filterResult = this->filterRectMask(&dstM, rects[0], matrix, &margin, |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 430 | SkMask::kJustComputeBounds_CreateMode); |
| 431 | } else { |
| 432 | filterResult = this->filterMask(&dstM, srcM, matrix, &margin); |
| 433 | } |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 434 | |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 435 | if (!filterResult) { |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 436 | return kFalse_FilterReturn; |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * smallR is the smallest version of 'rect' that will still guarantee that |
| 441 | * we get the same blur results on all edges, plus 1 center row/col that is |
| 442 | * representative of the extendible/stretchable edges of the ninepatch. |
| 443 | * Since our actual edge may be fractional we inset 1 more to be sure we |
| 444 | * don't miss any interior blur. |
| 445 | * x is an added pixel of blur, and { and } are the (fractional) edge |
| 446 | * pixels from the original rect. |
| 447 | * |
| 448 | * x x { x x .... x x } x x |
| 449 | * |
| 450 | * Thus, in this case, we inset by a total of 5 (on each side) beginning |
| 451 | * with our outer-rect (dstM.fBounds) |
| 452 | */ |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 453 | SkRect smallR[2]; |
| 454 | SkIPoint center; |
| 455 | |
| 456 | // +2 is from +1 for each edge (to account for possible fractional edges |
| 457 | int smallW = dstM.fBounds.width() - srcM.fBounds.width() + 2; |
| 458 | int smallH = dstM.fBounds.height() - srcM.fBounds.height() + 2; |
| 459 | SkIRect innerIR; |
| 460 | |
| 461 | if (1 == count) { |
| 462 | innerIR = srcM.fBounds; |
| 463 | center.set(smallW, smallH); |
| 464 | } else { |
| 465 | SkASSERT(2 == count); |
| 466 | rects[1].roundIn(&innerIR); |
| 467 | center.set(smallW + (innerIR.left() - srcM.fBounds.left()), |
| 468 | smallH + (innerIR.top() - srcM.fBounds.top())); |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 469 | } |
| 470 | |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 471 | // +1 so we get a clean, stretchable, center row/col |
| 472 | smallW += 1; |
| 473 | smallH += 1; |
| 474 | |
| 475 | // we want the inset amounts to be integral, so we don't change any |
| 476 | // fractional phase on the fRight or fBottom of our smallR. |
| 477 | const SkScalar dx = SkIntToScalar(innerIR.width() - smallW); |
| 478 | const SkScalar dy = SkIntToScalar(innerIR.height() - smallH); |
| 479 | if (dx < 0 || dy < 0) { |
| 480 | // we're too small, relative to our blur, to break into nine-patch, |
| 481 | // so we ask to have our normal filterMask() be called. |
| 482 | return kUnimplemented_FilterReturn; |
| 483 | } |
| 484 | |
| 485 | smallR[0].set(rects[0].left(), rects[0].top(), rects[0].right() - dx, rects[0].bottom() - dy); |
robertphillips@google.com | 112a23e | 2013-09-03 17:17:43 +0000 | [diff] [blame] | 486 | if (smallR[0].width() < 2 || smallR[0].height() < 2) { |
| 487 | return kUnimplemented_FilterReturn; |
| 488 | } |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 489 | if (2 == count) { |
| 490 | smallR[1].set(rects[1].left(), rects[1].top(), |
| 491 | rects[1].right() - dx, rects[1].bottom() - dy); |
| 492 | SkASSERT(!smallR[1].isEmpty()); |
| 493 | } |
| 494 | |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 495 | if (count > 1 || !c_analyticBlurNinepatch) { |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 496 | if (!draw_rects_into_mask(smallR, count, &srcM)) { |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 497 | return kFalse_FilterReturn; |
| 498 | } |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 499 | |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 500 | SkAutoMaskFreeImage amf(srcM.fImage); |
reed@google.com | d198a5b | 2012-11-27 15:18:04 +0000 | [diff] [blame] | 501 | |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 502 | if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) { |
| 503 | return kFalse_FilterReturn; |
| 504 | } |
| 505 | } else { |
skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 506 | if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin, |
humper@google.com | 7c5d7b7 | 2013-03-11 20:16:28 +0000 | [diff] [blame] | 507 | SkMask::kComputeBoundsAndRenderImage_CreateMode)) { |
| 508 | return kFalse_FilterReturn; |
| 509 | } |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 510 | } |
reed@google.com | dab9b4f | 2012-11-19 16:45:14 +0000 | [diff] [blame] | 511 | patch->fMask.fBounds.offsetTo(0, 0); |
| 512 | patch->fOuterRect = dstM.fBounds; |
| 513 | patch->fCenter = center; |
reed@google.com | d729b3e | 2012-11-09 14:30:48 +0000 | [diff] [blame] | 514 | return kTrue_FilterReturn; |
| 515 | } |
| 516 | |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 517 | void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src, |
| 518 | SkRect* dst) const { |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 519 | SkScalar pad = 3.0f * fSigma; |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 520 | |
| 521 | dst->set(src.fLeft - pad, src.fTop - pad, |
| 522 | src.fRight + pad, src.fBottom + pad); |
reed@google.com | 9efd9a0 | 2012-01-30 15:41:43 +0000 | [diff] [blame] | 523 | } |
| 524 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 525 | SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkReadBuffer& buffer) |
reed@google.com | 03016a3 | 2011-08-12 14:59:59 +0000 | [diff] [blame] | 526 | : SkMaskFilter(buffer) { |
commit-bot@chromium.org | fed2ab6 | 2014-01-23 15:16:05 +0000 | [diff] [blame] | 527 | fSigma = buffer.readScalar(); |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 528 | fBlurStyle = (SkBlurStyle)buffer.readInt(); |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 529 | fBlurFlags = buffer.readUInt() & SkBlurMaskFilter::kAll_BlurFlag; |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 530 | SkASSERT(fSigma > 0); |
| 531 | SkASSERT((unsigned)fBlurStyle <= kLastEnum_SkBlurStyle); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 532 | } |
| 533 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 534 | void SkBlurMaskFilterImpl::flatten(SkWriteBuffer& buffer) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 535 | this->INHERITED::flatten(buffer); |
robertphillips@google.com | 11e0555 | 2013-12-03 19:46:58 +0000 | [diff] [blame] | 536 | buffer.writeScalar(fSigma); |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 537 | buffer.writeInt(fBlurStyle); |
| 538 | buffer.writeUInt(fBlurFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 539 | } |
| 540 | |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 541 | #if SK_SUPPORT_GPU |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 542 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 543 | class GrGLRectBlurEffect; |
| 544 | |
| 545 | class GrRectBlurEffect : public GrEffect { |
| 546 | public: |
| 547 | virtual ~GrRectBlurEffect(); |
| 548 | |
| 549 | static const char* Name() { return "RectBlur"; } |
| 550 | |
| 551 | typedef GrGLRectBlurEffect GLEffect; |
| 552 | |
| 553 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 554 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 555 | |
| 556 | /** |
| 557 | * Create a simple filter effect with custom bicubic coefficients. |
| 558 | */ |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 559 | static GrEffect* Create(GrContext *context, const SkRect& rect, float sigma) { |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 560 | GrTexture *blurProfileTexture = NULL; |
| 561 | int doubleProfileSize = SkScalarCeilToInt(12*sigma); |
| 562 | |
| 563 | if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.height()) { |
| 564 | // if the blur sigma is too large so the gaussian overlaps the whole |
| 565 | // rect in either direction, fall back to CPU path for now. |
| 566 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 567 | return NULL; |
| 568 | } |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 569 | |
| 570 | bool createdBlurProfileTexture = CreateBlurProfileTexture(context, sigma, &blurProfileTexture); |
| 571 | SkAutoTUnref<GrTexture> hunref(blurProfileTexture); |
| 572 | if (!createdBlurProfileTexture) { |
| 573 | return NULL; |
| 574 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 575 | return SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture)); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 576 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 577 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 578 | const SkRect& getRect() const { return fRect; } |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 579 | float getSigma() const { return fSigma; } |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 580 | |
| 581 | private: |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 582 | GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 583 | virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 584 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 585 | static bool CreateBlurProfileTexture(GrContext *context, float sigma, |
| 586 | GrTexture **blurProfileTexture); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 587 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 588 | SkRect fRect; |
| 589 | float fSigma; |
| 590 | GrTextureAccess fBlurProfileAccess; |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 591 | |
| 592 | GR_DECLARE_EFFECT_TEST; |
| 593 | |
| 594 | typedef GrEffect INHERITED; |
| 595 | }; |
| 596 | |
| 597 | class GrGLRectBlurEffect : public GrGLEffect { |
| 598 | public: |
| 599 | GrGLRectBlurEffect(const GrBackendEffectFactory& factory, |
| 600 | const GrDrawEffect&); |
| 601 | virtual void emitCode(GrGLShaderBuilder*, |
| 602 | const GrDrawEffect&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 603 | const GrEffectKey&, |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 604 | const char* outputColor, |
| 605 | const char* inputColor, |
| 606 | const TransformedCoordsArray&, |
| 607 | const TextureSamplerArray&) SK_OVERRIDE; |
| 608 | |
| 609 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; |
| 610 | |
| 611 | private: |
| 612 | typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 613 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 614 | UniformHandle fProxyRectUniform; |
| 615 | UniformHandle fProfileSizeUniform; |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 616 | |
| 617 | typedef GrGLEffect INHERITED; |
| 618 | }; |
| 619 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 620 | |
| 621 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 622 | GrGLRectBlurEffect::GrGLRectBlurEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 623 | : INHERITED(factory) { |
| 624 | } |
| 625 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 626 | void OutputRectBlurProfileLookup(GrGLShaderBuilder* builder, |
| 627 | const GrGLShaderBuilder::TextureSampler& sampler, |
| 628 | const char *output, |
| 629 | const char *profileSize, const char *loc, |
| 630 | const char *blurred_width, |
| 631 | const char *sharp_width) { |
| 632 | builder->fsCodeAppendf("\tfloat %s;\n", output); |
| 633 | builder->fsCodeAppendf("\t\t{\n"); |
| 634 | builder->fsCodeAppendf("\t\t\tfloat coord = (0.5 * (abs(2.0*%s - %s) - %s))/%s;\n", |
| 635 | loc, blurred_width, sharp_width, profileSize); |
| 636 | builder->fsCodeAppendf("\t\t\t%s = ", output); |
| 637 | builder->fsAppendTextureLookup(sampler, "vec2(coord,0.5)"); |
| 638 | builder->fsCodeAppend(".a;\n"); |
| 639 | builder->fsCodeAppendf("\t\t}\n"); |
| 640 | } |
| 641 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 642 | void GrGLRectBlurEffect::emitCode(GrGLShaderBuilder* builder, |
| 643 | const GrDrawEffect&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 644 | const GrEffectKey& key, |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 645 | const char* outputColor, |
| 646 | const char* inputColor, |
| 647 | const TransformedCoordsArray& coords, |
| 648 | const TextureSamplerArray& samplers) { |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 649 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 650 | const char *rectName; |
| 651 | const char *profileSizeName; |
| 652 | |
| 653 | fProxyRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 654 | kVec4f_GrSLType, |
| 655 | "proxyRect", |
| 656 | &rectName); |
| 657 | fProfileSizeUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 658 | kFloat_GrSLType, |
| 659 | "profileSize", |
| 660 | &profileSizeName); |
| 661 | |
| 662 | const char *fragmentPos = builder->fragmentPosition(); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 663 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 664 | if (inputColor) { |
| 665 | builder->fsCodeAppendf("\tvec4 src=%s;\n", inputColor); |
| 666 | } else { |
| 667 | builder->fsCodeAppendf("\tvec4 src=vec4(1)\n;"); |
| 668 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 669 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 670 | builder->fsCodeAppendf("\tvec2 translatedPos = %s.xy - %s.xy;\n", fragmentPos, rectName ); |
| 671 | builder->fsCodeAppendf("\tfloat width = %s.z - %s.x;\n", rectName, rectName); |
| 672 | builder->fsCodeAppendf("\tfloat height = %s.w - %s.y;\n", rectName, rectName); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 673 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 674 | builder->fsCodeAppendf("\tvec2 smallDims = vec2(width - %s, height-%s);\n", profileSizeName, profileSizeName); |
| 675 | builder->fsCodeAppendf("\tfloat center = 2.0 * floor(%s/2.0 + .25) - 1.0;\n", profileSizeName); |
| 676 | builder->fsCodeAppendf("\tvec2 wh = smallDims - vec2(center,center);\n"); |
| 677 | |
| 678 | OutputRectBlurProfileLookup(builder, samplers[0], "horiz_lookup", profileSizeName, "translatedPos.x", "width", "wh.x"); |
| 679 | OutputRectBlurProfileLookup(builder, samplers[0], "vert_lookup", profileSizeName, "translatedPos.y", "height", "wh.y"); |
| 680 | |
| 681 | builder->fsCodeAppendf("\tfloat final = horiz_lookup * vert_lookup;\n"); |
| 682 | builder->fsCodeAppendf("\t%s = src * vec4(final);\n", outputColor ); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void GrGLRectBlurEffect::setData(const GrGLUniformManager& uman, |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 686 | const GrDrawEffect& drawEffect) { |
| 687 | const GrRectBlurEffect& rbe = drawEffect.castEffect<GrRectBlurEffect>(); |
| 688 | SkRect rect = rbe.getRect(); |
| 689 | |
| 690 | uman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 691 | uman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 692 | } |
| 693 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 694 | bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, |
| 695 | GrTexture **blurProfileTexture) { |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 696 | GrTextureParams params; |
| 697 | GrTextureDesc texDesc; |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 698 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 699 | unsigned int profile_size = SkScalarCeilToInt(6*sigma); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 700 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 701 | texDesc.fWidth = profile_size; |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 702 | texDesc.fHeight = 1; |
| 703 | texDesc.fConfig = kAlpha_8_GrPixelConfig; |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 704 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 705 | static const GrCacheID::Domain gBlurProfileDomain = GrCacheID::GenerateDomain(); |
| 706 | GrCacheID::Key key; |
| 707 | memset(&key, 0, sizeof(key)); |
| 708 | key.fData32[0] = profile_size; |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 709 | key.fData32[1] = 1; |
| 710 | GrCacheID blurProfileKey(gBlurProfileDomain, key); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 711 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 712 | uint8_t *profile = NULL; |
commit-bot@chromium.org | cc787fa | 2014-01-31 01:00:49 +0000 | [diff] [blame] | 713 | SkAutoTDeleteArray<uint8_t> ada(NULL); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 714 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 715 | *blurProfileTexture = context->findAndRefTexture(texDesc, blurProfileKey, ¶ms); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 716 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 717 | if (NULL == *blurProfileTexture) { |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 718 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 719 | SkBlurMask::ComputeBlurProfile(sigma, &profile); |
commit-bot@chromium.org | cc787fa | 2014-01-31 01:00:49 +0000 | [diff] [blame] | 720 | ada.reset(profile); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 721 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 722 | *blurProfileTexture = context->createTexture(¶ms, texDesc, blurProfileKey, |
| 723 | profile, 0); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 724 | |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 725 | if (NULL == *blurProfileTexture) { |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 726 | return false; |
| 727 | } |
| 728 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 729 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 730 | return true; |
| 731 | } |
| 732 | |
| 733 | GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma, |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 734 | GrTexture *blur_profile) |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 735 | : INHERITED(), |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 736 | fRect(rect), |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 737 | fSigma(sigma), |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 738 | fBlurProfileAccess(blur_profile) { |
| 739 | this->addTextureAccess(&fBlurProfileAccess); |
| 740 | this->setWillReadFragmentPosition(); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | GrRectBlurEffect::~GrRectBlurEffect() { |
| 744 | } |
| 745 | |
| 746 | const GrBackendEffectFactory& GrRectBlurEffect::getFactory() const { |
| 747 | return GrTBackendEffectFactory<GrRectBlurEffect>::getInstance(); |
| 748 | } |
| 749 | |
| 750 | bool GrRectBlurEffect::onIsEqual(const GrEffect& sBase) const { |
| 751 | const GrRectBlurEffect& s = CastEffect<GrRectBlurEffect>(sBase); |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 752 | return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 756 | *validFlags = 0; |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | GR_DEFINE_EFFECT_TEST(GrRectBlurEffect); |
| 761 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 762 | GrEffect* GrRectBlurEffect::TestCreate(SkRandom* random, |
| 763 | GrContext* context, |
| 764 | const GrDrawTargetCaps&, |
| 765 | GrTexture**) { |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 766 | float sigma = random->nextRangeF(3,8); |
| 767 | float width = random->nextRangeF(200,300); |
| 768 | float height = random->nextRangeF(200,300); |
| 769 | return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigma); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, |
| 774 | GrPaint* grp, |
| 775 | const SkStrokeRec& strokeRec, |
| 776 | const SkPath& path) const { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 777 | if (fBlurStyle != kNormal_SkBlurStyle) { |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 778 | return false; |
| 779 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 780 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 781 | SkRect rect; |
| 782 | if (!path.isRect(&rect)) { |
| 783 | return false; |
| 784 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 785 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 786 | if (!strokeRec.isFillStyle()) { |
| 787 | return false; |
| 788 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 789 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 790 | SkMatrix ctm = context->getMatrix(); |
| 791 | SkScalar xformedSigma = this->computeXformedSigma(ctm); |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 792 | |
| 793 | int pad=SkScalarCeilToInt(6*xformedSigma)/2; |
| 794 | rect.outset(SkIntToScalar(pad), SkIntToScalar(pad)); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 795 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 796 | SkAutoTUnref<GrEffect> effect(GrRectBlurEffect::Create(context, rect, xformedSigma)); |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 797 | if (!effect) { |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | GrContext::AutoMatrix am; |
| 802 | if (!am.setIdentity(context, grp)) { |
| 803 | return false; |
| 804 | } |
| 805 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 806 | grp->addCoverageEffect(effect); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 807 | |
commit-bot@chromium.org | cf34bc0 | 2014-01-30 15:34:43 +0000 | [diff] [blame] | 808 | context->drawRect(*grp, rect); |
| 809 | return true; |
| 810 | } |
| 811 | |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 812 | class GrGLRRectBlurEffect; |
| 813 | |
| 814 | class GrRRectBlurEffect : public GrEffect { |
| 815 | public: |
| 816 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 817 | static GrEffect* Create(GrContext* context, float sigma, const SkRRect&); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 818 | |
| 819 | virtual ~GrRRectBlurEffect() {}; |
| 820 | static const char* Name() { return "GrRRectBlur"; } |
| 821 | |
| 822 | const SkRRect& getRRect() const { return fRRect; } |
| 823 | float getSigma() const { return fSigma; } |
| 824 | |
| 825 | typedef GrGLRRectBlurEffect GLEffect; |
| 826 | |
| 827 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| 828 | |
| 829 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 830 | |
| 831 | private: |
| 832 | GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); |
| 833 | |
| 834 | virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; |
| 835 | |
| 836 | SkRRect fRRect; |
| 837 | float fSigma; |
| 838 | GrTextureAccess fNinePatchAccess; |
| 839 | |
| 840 | GR_DECLARE_EFFECT_TEST; |
| 841 | |
| 842 | typedef GrEffect INHERITED; |
| 843 | }; |
| 844 | |
| 845 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 846 | GrEffect* GrRRectBlurEffect::Create(GrContext* context, float sigma, const SkRRect& rrect) { |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 847 | if (!rrect.isSimpleCircular()) { |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 848 | return NULL; |
| 849 | } |
| 850 | |
| 851 | // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be |
| 852 | // sufficiently small relative to both the size of the corner radius and the |
| 853 | // width (and height) of the rrect. |
| 854 | |
| 855 | unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f); |
| 856 | unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x()); |
| 857 | if (cornerRadius + blurRadius > rrect.width()/2 || |
| 858 | cornerRadius + blurRadius > rrect.height()/2) { |
| 859 | return NULL; |
| 860 | } |
| 861 | |
| 862 | static const GrCacheID::Domain gRRectBlurDomain = GrCacheID::GenerateDomain(); |
| 863 | GrCacheID::Key key; |
| 864 | memset(&key, 0, sizeof(key)); |
| 865 | key.fData32[0] = blurRadius; |
| 866 | key.fData32[1] = cornerRadius; |
| 867 | GrCacheID blurRRectNinePatchID(gRRectBlurDomain, key); |
| 868 | |
| 869 | GrTextureParams params; |
| 870 | params.setFilterMode(GrTextureParams::kBilerp_FilterMode); |
| 871 | |
| 872 | unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1; |
| 873 | unsigned int texSide = smallRectSide + 2*blurRadius; |
| 874 | GrTextureDesc texDesc; |
| 875 | texDesc.fWidth = texSide; |
| 876 | texDesc.fHeight = texSide; |
| 877 | texDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 878 | |
| 879 | GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, blurRRectNinePatchID, ¶ms); |
| 880 | |
| 881 | if (NULL == blurNinePatchTexture) { |
| 882 | SkMask mask; |
| 883 | |
| 884 | mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide); |
| 885 | mask.fFormat = SkMask::kA8_Format; |
| 886 | mask.fRowBytes = mask.fBounds.width(); |
| 887 | mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize()); |
| 888 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 889 | |
| 890 | memset(mask.fImage, 0, mask.computeTotalImageSize()); |
| 891 | |
| 892 | SkRect smallRect; |
| 893 | smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSide)); |
| 894 | |
| 895 | SkRRect smallRRect; |
| 896 | smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius)); |
| 897 | |
| 898 | SkPath path; |
| 899 | path.addRRect( smallRRect ); |
| 900 | |
| 901 | SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_Style); |
| 902 | |
| 903 | SkMask blurred_mask; |
| 904 | SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHigh_SkBlurQuality, NULL, true ); |
| 905 | |
| 906 | blurNinePatchTexture = context->createTexture(¶ms, texDesc, blurRRectNinePatchID, blurred_mask.fImage, 0); |
commit-bot@chromium.org | 6b127cd | 2014-04-29 04:41:33 +0000 | [diff] [blame] | 907 | SkMask::FreeImage(blurred_mask.fImage); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 908 | } |
| 909 | |
commit-bot@chromium.org | 6b127cd | 2014-04-29 04:41:33 +0000 | [diff] [blame] | 910 | SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 911 | if (NULL == blurNinePatchTexture) { |
| 912 | return NULL; |
| 913 | } |
| 914 | |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 915 | return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | void GrRRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 919 | *validFlags = 0; |
| 920 | } |
| 921 | |
| 922 | const GrBackendEffectFactory& GrRRectBlurEffect::getFactory() const { |
| 923 | return GrTBackendEffectFactory<GrRRectBlurEffect>::getInstance(); |
| 924 | } |
| 925 | |
| 926 | GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTexture *ninePatchTexture) |
| 927 | : fRRect(rrect), |
| 928 | fSigma(sigma), |
| 929 | fNinePatchAccess(ninePatchTexture) { |
| 930 | this->addTextureAccess(&fNinePatchAccess); |
| 931 | this->setWillReadFragmentPosition(); |
| 932 | } |
| 933 | |
| 934 | bool GrRRectBlurEffect::onIsEqual(const GrEffect& other) const { |
| 935 | const GrRRectBlurEffect& rrbe = CastEffect<GrRRectBlurEffect>(other); |
| 936 | return fRRect.getSimpleRadii().fX == rrbe.fRRect.getSimpleRadii().fX && fSigma == rrbe.fSigma; |
| 937 | } |
| 938 | |
| 939 | ////////////////////////////////////////////////////////////////////////////// |
| 940 | |
| 941 | GR_DEFINE_EFFECT_TEST(GrRRectBlurEffect); |
| 942 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 943 | GrEffect* GrRRectBlurEffect::TestCreate(SkRandom* random, |
| 944 | GrContext* context, |
| 945 | const GrDrawTargetCaps& caps, |
| 946 | GrTexture*[]) { |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 947 | SkScalar w = random->nextRangeScalar(100.f, 1000.f); |
| 948 | SkScalar h = random->nextRangeScalar(100.f, 1000.f); |
| 949 | SkScalar r = random->nextRangeF(1.f, 9.f); |
| 950 | SkScalar sigma = random->nextRangeF(1.f,10.f); |
| 951 | SkRRect rrect; |
| 952 | rrect.setRectXY(SkRect::MakeWH(w, h), r, r); |
| 953 | return GrRRectBlurEffect::Create(context, sigma, rrect); |
| 954 | } |
| 955 | |
| 956 | ////////////////////////////////////////////////////////////////////////////// |
| 957 | |
| 958 | class GrGLRRectBlurEffect : public GrGLEffect { |
| 959 | public: |
| 960 | GrGLRRectBlurEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 961 | |
| 962 | virtual void emitCode(GrGLShaderBuilder* builder, |
| 963 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 964 | const GrEffectKey& key, |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 965 | const char* outputColor, |
| 966 | const char* inputColor, |
| 967 | const TransformedCoordsArray&, |
| 968 | const TextureSamplerArray&) SK_OVERRIDE; |
| 969 | |
| 970 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; |
| 971 | |
| 972 | private: |
| 973 | GrGLUniformManager::UniformHandle fProxyRectUniform; |
| 974 | GrGLUniformManager::UniformHandle fCornerRadiusUniform; |
| 975 | GrGLUniformManager::UniformHandle fBlurRadiusUniform; |
| 976 | typedef GrGLEffect INHERITED; |
| 977 | }; |
| 978 | |
| 979 | GrGLRRectBlurEffect::GrGLRRectBlurEffect(const GrBackendEffectFactory& factory, |
| 980 | const GrDrawEffect& drawEffect) |
| 981 | : INHERITED (factory) { |
| 982 | } |
| 983 | |
| 984 | void GrGLRRectBlurEffect::emitCode(GrGLShaderBuilder* builder, |
| 985 | const GrDrawEffect& drawEffect, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame^] | 986 | const GrEffectKey& key, |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 987 | const char* outputColor, |
| 988 | const char* inputColor, |
| 989 | const TransformedCoordsArray&, |
| 990 | const TextureSamplerArray& samplers) { |
| 991 | const char *rectName; |
| 992 | const char *cornerRadiusName; |
| 993 | const char *blurRadiusName; |
| 994 | |
| 995 | // The proxy rect has left, top, right, and bottom edges correspond to |
| 996 | // components x, y, z, and w, respectively. |
| 997 | |
| 998 | fProxyRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 999 | kVec4f_GrSLType, |
| 1000 | "proxyRect", |
| 1001 | &rectName); |
| 1002 | fCornerRadiusUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 1003 | kFloat_GrSLType, |
| 1004 | "cornerRadius", |
| 1005 | &cornerRadiusName); |
| 1006 | fBlurRadiusUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 1007 | kFloat_GrSLType, |
| 1008 | "blurRadius", |
| 1009 | &blurRadiusName); |
| 1010 | const char* fragmentPos = builder->fragmentPosition(); |
| 1011 | |
| 1012 | // warp the fragment position to the appropriate part of the 9patch blur texture |
| 1013 | |
| 1014 | builder->fsCodeAppendf("\t\tvec2 rectCenter = (%s.xy + %s.zw)/2.0;\n", rectName, rectName); |
bsalomon | 2290000 | 2014-06-24 11:16:52 -0700 | [diff] [blame] | 1015 | builder->fsCodeAppendf("\t\tvec2 translatedFragPos = %s.xy - %s.xy;\n", fragmentPos, rectName); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 1016 | builder->fsCodeAppendf("\t\tfloat threshold = %s + 2.0*%s;\n", cornerRadiusName, blurRadiusName ); |
| 1017 | builder->fsCodeAppendf("\t\tvec2 middle = %s.zw - %s.xy - 2.0*threshold;\n", rectName, rectName ); |
| 1018 | |
| 1019 | builder->fsCodeAppendf("\t\tif (translatedFragPos.x >= threshold && translatedFragPos.x < (middle.x+threshold)) {\n" ); |
| 1020 | builder->fsCodeAppendf("\t\t\ttranslatedFragPos.x = threshold;\n"); |
| 1021 | builder->fsCodeAppendf("\t\t} else if (translatedFragPos.x >= (middle.x + threshold)) {\n"); |
commit-bot@chromium.org | 7ba1702 | 2014-05-19 18:51:05 +0000 | [diff] [blame] | 1022 | builder->fsCodeAppendf("\t\t\ttranslatedFragPos.x -= middle.x - 1.0;\n"); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 1023 | builder->fsCodeAppendf("\t\t}\n"); |
| 1024 | |
| 1025 | builder->fsCodeAppendf("\t\tif (translatedFragPos.y > threshold && translatedFragPos.y < (middle.y+threshold)) {\n" ); |
| 1026 | builder->fsCodeAppendf("\t\t\ttranslatedFragPos.y = threshold;\n"); |
| 1027 | builder->fsCodeAppendf("\t\t} else if (translatedFragPos.y >= (middle.y + threshold)) {\n"); |
commit-bot@chromium.org | 7ba1702 | 2014-05-19 18:51:05 +0000 | [diff] [blame] | 1028 | builder->fsCodeAppendf("\t\t\ttranslatedFragPos.y -= middle.y - 1.0;\n"); |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 1029 | builder->fsCodeAppendf("\t\t}\n"); |
| 1030 | |
| 1031 | builder->fsCodeAppendf("\t\tvec2 proxyDims = vec2(2.0*threshold+1.0);\n"); |
| 1032 | builder->fsCodeAppendf("\t\tvec2 texCoord = translatedFragPos / proxyDims;\n"); |
| 1033 | |
| 1034 | builder->fsCodeAppendf("\t%s = ", outputColor); |
| 1035 | builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "texCoord"); |
| 1036 | builder->fsCodeAppend(";\n"); |
| 1037 | } |
| 1038 | |
| 1039 | void GrGLRRectBlurEffect::setData(const GrGLUniformManager& uman, |
| 1040 | const GrDrawEffect& drawEffect) { |
| 1041 | const GrRRectBlurEffect& brre = drawEffect.castEffect<GrRRectBlurEffect>(); |
| 1042 | SkRRect rrect = brre.getRRect(); |
| 1043 | |
| 1044 | float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f); |
| 1045 | uman.set1f(fBlurRadiusUniform, blurRadius); |
| 1046 | |
| 1047 | SkRect rect = rrect.getBounds(); |
| 1048 | rect.outset(blurRadius, blurRadius); |
| 1049 | uman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1050 | |
| 1051 | SkScalar radius = 0; |
| 1052 | SkASSERT(rrect.isSimpleCircular() || rrect.isRect()); |
| 1053 | radius = rrect.getSimpleRadii().fX; |
| 1054 | uman.set1f(fCornerRadiusUniform, radius); |
| 1055 | } |
| 1056 | |
| 1057 | |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 1058 | bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context, |
| 1059 | GrPaint* grp, |
| 1060 | const SkStrokeRec& strokeRec, |
| 1061 | const SkRRect& rrect) const { |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 1062 | if (fBlurStyle != kNormal_SkBlurStyle) { |
| 1063 | return false; |
| 1064 | } |
| 1065 | |
| 1066 | if (!strokeRec.isFillStyle()) { |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
| 1070 | SkRect proxy_rect = rrect.rect(); |
| 1071 | SkMatrix ctm = context->getMatrix(); |
| 1072 | SkScalar xformedSigma = this->computeXformedSigma(ctm); |
| 1073 | float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); |
| 1074 | proxy_rect.outset(extra, extra); |
| 1075 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 1076 | SkAutoTUnref<GrEffect> effect(GrRRectBlurEffect::Create( |
commit-bot@chromium.org | 3d8bf23 | 2014-04-28 19:49:24 +0000 | [diff] [blame] | 1077 | context, xformedSigma, rrect)); |
| 1078 | if (!effect) { |
| 1079 | return false; |
| 1080 | } |
| 1081 | |
| 1082 | GrContext::AutoMatrix am; |
| 1083 | if (!am.setIdentity(context, grp)) { |
| 1084 | return false; |
| 1085 | } |
| 1086 | |
| 1087 | grp->addCoverageEffect(effect); |
| 1088 | |
| 1089 | context->drawRect(*grp, proxy_rect); |
| 1090 | return true; |
commit-bot@chromium.org | 8213970 | 2014-03-10 22:53:20 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1093 | bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds, |
| 1094 | const SkIRect& clipBounds, |
| 1095 | const SkMatrix& ctm, |
| 1096 | SkRect* maskRect) const { |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1097 | SkScalar xformedSigma = this->computeXformedSigma(ctm); |
| 1098 | if (xformedSigma <= 0) { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1099 | return false; |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 1100 | } |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1101 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1102 | static const SkScalar kMIN_GPU_BLUR_SIZE = SkIntToScalar(64); |
| 1103 | static const SkScalar kMIN_GPU_BLUR_SIGMA = SkIntToScalar(32); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1104 | |
| 1105 | if (srcBounds.width() <= kMIN_GPU_BLUR_SIZE && |
| 1106 | srcBounds.height() <= kMIN_GPU_BLUR_SIZE && |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1107 | xformedSigma <= kMIN_GPU_BLUR_SIGMA) { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1108 | // We prefer to blur small rect with small radius via CPU. |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
| 1112 | if (NULL == maskRect) { |
| 1113 | // don't need to compute maskRect |
| 1114 | return true; |
| 1115 | } |
| 1116 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1117 | float sigma3 = 3 * SkScalarToFloat(xformedSigma); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1118 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 1119 | SkRect clipRect = SkRect::Make(clipBounds); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1120 | SkRect srcRect(srcBounds); |
| 1121 | |
| 1122 | // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area. |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 1123 | srcRect.outset(sigma3, sigma3); |
| 1124 | clipRect.outset(sigma3, sigma3); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1125 | srcRect.intersect(clipRect); |
| 1126 | *maskRect = srcRect; |
skia.committer@gmail.com | 1842adf | 2013-07-04 07:01:07 +0000 | [diff] [blame] | 1127 | return true; |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
skia.committer@gmail.com | 1842adf | 2013-07-04 07:01:07 +0000 | [diff] [blame] | 1130 | bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, |
commit-bot@chromium.org | 439ff1b | 2014-01-13 16:39:39 +0000 | [diff] [blame] | 1131 | const SkMatrix& ctm, |
skia.committer@gmail.com | 1842adf | 2013-07-04 07:01:07 +0000 | [diff] [blame] | 1132 | const SkRect& maskRect, |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1133 | GrTexture** result, |
| 1134 | bool canOverwriteSrc) const { |
| 1135 | SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height()); |
| 1136 | |
| 1137 | GrContext* context = src->getContext(); |
| 1138 | |
| 1139 | GrContext::AutoWideOpenIdentityDraw awo(context, NULL); |
| 1140 | |
commit-bot@chromium.org | 439ff1b | 2014-01-13 16:39:39 +0000 | [diff] [blame] | 1141 | SkScalar xformedSigma = this->computeXformedSigma(ctm); |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1142 | SkASSERT(xformedSigma > 0); |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1143 | |
| 1144 | // If we're doing a normal blur, we can clobber the pathTexture in the |
| 1145 | // gaussianBlur. Otherwise, we need to save it for later compositing. |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 1146 | bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle); |
robertphillips@google.com | 736dd03 | 2013-07-15 15:06:54 +0000 | [diff] [blame] | 1147 | *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc, |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1148 | clipRect, false, xformedSigma, xformedSigma); |
robertphillips@google.com | 3cc820c | 2013-07-03 19:36:55 +0000 | [diff] [blame] | 1149 | if (NULL == *result) { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1150 | return false; |
| 1151 | } |
| 1152 | |
| 1153 | if (!isNormalBlur) { |
| 1154 | context->setIdentityMatrix(); |
| 1155 | GrPaint paint; |
| 1156 | SkMatrix matrix; |
| 1157 | matrix.setIDiv(src->width(), src->height()); |
| 1158 | // Blend pathTexture over blurTexture. |
| 1159 | GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget()); |
commit-bot@chromium.org | 42dacab | 2013-07-13 17:24:24 +0000 | [diff] [blame] | 1160 | paint.addColorEffect(GrSimpleTextureEffect::Create(src, matrix))->unref(); |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 1161 | if (kInner_SkBlurStyle == fBlurStyle) { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1162 | // inner: dst = dst * src |
| 1163 | paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff); |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 1164 | } else if (kSolid_SkBlurStyle == fBlurStyle) { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1165 | // solid: dst = src + dst - src * dst |
| 1166 | // = (1 - dst) * src + 1 * dst |
| 1167 | paint.setBlendFunc(kIDC_GrBlendCoeff, kOne_GrBlendCoeff); |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 1168 | } else if (kOuter_SkBlurStyle == fBlurStyle) { |
robertphillips@google.com | 4914931 | 2013-07-03 15:34:35 +0000 | [diff] [blame] | 1169 | // outer: dst = dst * (1 - src) |
| 1170 | // = 0 * src + (1 - src) * dst |
| 1171 | paint.setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff); |
| 1172 | } |
| 1173 | context->drawRect(paint, clipRect); |
| 1174 | } |
| 1175 | |
| 1176 | return true; |
| 1177 | } |
| 1178 | |
| 1179 | #endif // SK_SUPPORT_GPU |
| 1180 | |
| 1181 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 1182 | #ifndef SK_IGNORE_TO_STRING |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 1183 | void SkBlurMaskFilterImpl::toString(SkString* str) const { |
| 1184 | str->append("SkBlurMaskFilterImpl: ("); |
| 1185 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 1186 | str->append("sigma: "); |
| 1187 | str->appendScalar(fSigma); |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 1188 | str->append(" "); |
| 1189 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 1190 | static const char* gStyleName[kLastEnum_SkBlurStyle + 1] = { |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 1191 | "normal", "solid", "outer", "inner" |
| 1192 | }; |
| 1193 | |
| 1194 | str->appendf("style: %s ", gStyleName[fBlurStyle]); |
| 1195 | str->append("flags: ("); |
| 1196 | if (fBlurFlags) { |
| 1197 | bool needSeparator = false; |
skia.committer@gmail.com | 8eaddb0 | 2013-03-19 07:15:10 +0000 | [diff] [blame] | 1198 | SkAddFlagToString(str, |
| 1199 | SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag), |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 1200 | "IgnoreXform", &needSeparator); |
skia.committer@gmail.com | 8eaddb0 | 2013-03-19 07:15:10 +0000 | [diff] [blame] | 1201 | SkAddFlagToString(str, |
| 1202 | SkToBool(fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag), |
robertphillips@google.com | 0bd80fa | 2013-03-18 17:53:38 +0000 | [diff] [blame] | 1203 | "HighQuality", &needSeparator); |
| 1204 | } else { |
| 1205 | str->append("None"); |
| 1206 | } |
| 1207 | str->append("))"); |
| 1208 | } |
| 1209 | #endif |
| 1210 | |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 1211 | SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
| 1212 | SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
| 1213 | SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |