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