blob: fca38a1eaacda14cc8511da783e8d36efaf2a64a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00009#include "SkBlurMaskFilter.h"
10#include "SkBlurMask.h"
robertphillips@google.com736dd032013-07-15 15:06:54 +000011#include "SkGpuBlurUtils.h"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000012#include "SkReadBuffer.h"
13#include "SkWriteBuffer.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkMaskFilter.h"
scroggo@google.coma8e33a92013-11-08 18:02:53 +000015#include "SkRRect.h"
humper@google.com7c5d7b72013-03-11 20:16:28 +000016#include "SkRTConf.h"
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +000017#include "SkStringUtils.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000018#include "SkStrokeRec.h"
19
20#if SK_SUPPORT_GPU
21#include "GrContext.h"
22#include "GrTexture.h"
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000023#include "GrEffect.h"
24#include "gl/GrGLEffect.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000025#include "effects/GrSimpleTextureEffect.h"
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000026#include "GrTBackendEffectFactory.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000027#include "SkGrPixelRef.h"
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +000028#include "SkDraw.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000029#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000030
commit-bot@chromium.org508022c2014-05-01 15:24:55 +000031SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) {
32 return SkBlurMask::ConvertRadiusToSigma(radius);
33}
34
reed@android.com8a1c16f2008-12-17 15:59:43 +000035class SkBlurMaskFilterImpl : public SkMaskFilter {
36public:
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000037 SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags);
reed@android.com8a1c16f2008-12-17 15:59:43 +000038
39 // overrides from SkMaskFilter
reed@google.com30711b72012-12-18 19:18:39 +000040 virtual SkMask::Format getFormat() const SK_OVERRIDE;
reed@google.com03016a32011-08-12 14:59:59 +000041 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
reed@google.com30711b72012-12-18 19:18:39 +000042 SkIPoint* margin) const SK_OVERRIDE;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000043
robertphillips@google.com49149312013-07-03 15:34:35 +000044#if SK_SUPPORT_GPU
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +000045 virtual bool canFilterMaskGPU(const SkRect& devBounds,
robertphillips@google.com49149312013-07-03 15:34:35 +000046 const SkIRect& clipBounds,
47 const SkMatrix& ctm,
48 SkRect* maskRect) const SK_OVERRIDE;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000049 virtual bool directFilterMaskGPU(GrContext* context,
50 GrPaint* grp,
51 const SkStrokeRec& strokeRec,
52 const SkPath& path) const SK_OVERRIDE;
commit-bot@chromium.org82139702014-03-10 22:53:20 +000053 virtual bool directFilterRRectMaskGPU(GrContext* context,
54 GrPaint* grp,
55 const SkStrokeRec& strokeRec,
56 const SkRRect& rrect) const SK_OVERRIDE;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000057
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +000058 virtual bool filterMaskGPU(GrTexture* src,
commit-bot@chromium.org41bf9302014-01-08 22:25:53 +000059 const SkMatrix& ctm,
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +000060 const SkRect& maskRect,
robertphillips@google.com49149312013-07-03 15:34:35 +000061 GrTexture** result,
commit-bot@chromium.org41bf9302014-01-08 22:25:53 +000062 bool canOverwriteSrc) const SK_OVERRIDE;
robertphillips@google.com49149312013-07-03 15:34:35 +000063#endif
64
reed@google.com30711b72012-12-18 19:18:39 +000065 virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
reed@google.comdaaafa62014-04-29 15:20:16 +000066 virtual bool asABlur(BlurRec*) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000067
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000068 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000069 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurMaskFilterImpl)
reed@android.com8a1c16f2008-12-17 15:59:43 +000070
reed@google.comd729b3e2012-11-09 14:30:48 +000071protected:
reed@google.comdab9b4f2012-11-19 16:45:14 +000072 virtual FilterReturn filterRectsToNine(const SkRect[], int count, const SkMatrix&,
73 const SkIRect& clipBounds,
reed@google.com30711b72012-12-18 19:18:39 +000074 NinePatch*) const SK_OVERRIDE;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000075
scroggo@google.coma8e33a92013-11-08 18:02:53 +000076 virtual FilterReturn filterRRectToNine(const SkRRect&, const SkMatrix&,
77 const SkIRect& clipBounds,
78 NinePatch*) const SK_OVERRIDE;
79
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000080 bool filterRectMask(SkMask* dstM, const SkRect& r, const SkMatrix& matrix,
humper@google.com7c5d7b72013-03-11 20:16:28 +000081 SkIPoint* margin, SkMask::CreateMode createMode) const;
commit-bot@chromium.orga4771542014-03-10 21:42:06 +000082 bool filterRRectMask(SkMask* dstM, const SkRRect& r, const SkMatrix& matrix,
83 SkIPoint* margin, SkMask::CreateMode createMode) const;
skia.committer@gmail.com453995e2012-11-10 02:01:26 +000084
reed@android.com8a1c16f2008-12-17 15:59:43 +000085private:
robertphillips@google.com49149312013-07-03 15:34:35 +000086 // To avoid unseemly allocation requests (esp. for finite platforms like
87 // handset) we limit the radius so something manageable. (as opposed to
88 // a request like 10,000)
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000089 static const SkScalar kMAX_BLUR_SIGMA;
robertphillips@google.com49149312013-07-03 15:34:35 +000090
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000091 SkScalar fSigma;
92 SkBlurStyle fBlurStyle;
93 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000094
reed@google.comdaaafa62014-04-29 15:20:16 +000095 SkBlurQuality getQuality() const {
96 return (fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag) ?
97 kHigh_SkBlurQuality : kLow_SkBlurQuality;
98 }
99
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000100 SkBlurMaskFilterImpl(SkReadBuffer&);
101 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000102
103 SkScalar computeXformedSigma(const SkMatrix& ctm) const {
robertphillips@google.com49149312013-07-03 15:34:35 +0000104 bool ignoreTransform = SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
105
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000106 SkScalar xformedSigma = ignoreTransform ? fSigma : ctm.mapRadius(fSigma);
107 return SkMinScalar(xformedSigma, kMAX_BLUR_SIGMA);
robertphillips@google.com49149312013-07-03 15:34:35 +0000108 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000109
reed@android.com8a1c16f2008-12-17 15:59:43 +0000110 typedef SkMaskFilter INHERITED;
111};
112
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000113const SkScalar SkBlurMaskFilterImpl::kMAX_BLUR_SIGMA = SkIntToScalar(128);
robertphillips@google.com49149312013-07-03 15:34:35 +0000114
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000115SkMaskFilter* SkBlurMaskFilter::Create(SkBlurStyle style, SkScalar sigma, uint32_t flags) {
116 if (!SkScalarIsFinite(sigma) || sigma <= 0) {
117 return NULL;
118 }
119 if ((unsigned)style > (unsigned)kLastEnum_SkBlurStyle) {
120 return NULL;
121 }
122 if (flags > SkBlurMaskFilter::kAll_BlurFlag) {
123 return NULL;
124 }
125 return SkNEW_ARGS(SkBlurMaskFilterImpl, (sigma, style, flags));
126}
127
reed@google.com03016a32011-08-12 14:59:59 +0000128///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000129
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000130SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle style, uint32_t flags)
131 : fSigma(sigma)
132 , fBlurStyle(style)
133 , fBlurFlags(flags) {
134 SkASSERT(fSigma > 0);
135 SkASSERT((unsigned)style <= kLastEnum_SkBlurStyle);
senorblanco@chromium.org038aff62010-12-06 23:45:58 +0000136 SkASSERT(flags <= SkBlurMaskFilter::kAll_BlurFlag);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000137}
138
reed@google.com30711b72012-12-18 19:18:39 +0000139SkMask::Format SkBlurMaskFilterImpl::getFormat() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000140 return SkMask::kA8_Format;
141}
142
reed@google.comdaaafa62014-04-29 15:20:16 +0000143bool SkBlurMaskFilterImpl::asABlur(BlurRec* rec) const {
144 if (fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) {
145 return false;
146 }
147
148 if (rec) {
149 rec->fSigma = fSigma;
150 rec->fStyle = fBlurStyle;
151 rec->fQuality = this->getQuality();
152 }
153 return true;
154}
155
reed@google.com03016a32011-08-12 14:59:59 +0000156bool SkBlurMaskFilterImpl::filterMask(SkMask* dst, const SkMask& src,
reed@google.com30711b72012-12-18 19:18:39 +0000157 const SkMatrix& matrix,
158 SkIPoint* margin) const{
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000159 SkScalar sigma = this->computeXformedSigma(matrix);
reed@google.comdaaafa62014-04-29 15:20:16 +0000160 return SkBlurMask::BoxBlur(dst, src, sigma, fBlurStyle, this->getQuality(), margin);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000161}
162
humper@google.com7c5d7b72013-03-11 20:16:28 +0000163bool SkBlurMaskFilterImpl::filterRectMask(SkMask* dst, const SkRect& r,
164 const SkMatrix& matrix,
165 SkIPoint* margin, SkMask::CreateMode createMode) const{
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000166 SkScalar sigma = computeXformedSigma(matrix);
humper@google.com7c5d7b72013-03-11 20:16:28 +0000167
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000168 return SkBlurMask::BlurRect(sigma, dst, r, fBlurStyle,
humper@google.com7c5d7b72013-03-11 20:16:28 +0000169 margin, createMode);
170}
171
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000172bool SkBlurMaskFilterImpl::filterRRectMask(SkMask* dst, const SkRRect& r,
173 const SkMatrix& matrix,
174 SkIPoint* margin, SkMask::CreateMode createMode) const{
175 SkScalar sigma = computeXformedSigma(matrix);
176
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000177 return SkBlurMask::BlurRRect(sigma, dst, r, fBlurStyle,
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000178 margin, createMode);
179}
180
reed@google.comd729b3e2012-11-09 14:30:48 +0000181#include "SkCanvas.h"
182
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000183static bool prepare_to_draw_into_mask(const SkRect& bounds, SkMask* mask) {
184 SkASSERT(mask != NULL);
185
186 bounds.roundOut(&mask->fBounds);
reed@google.comd729b3e2012-11-09 14:30:48 +0000187 mask->fRowBytes = SkAlign4(mask->fBounds.width());
188 mask->fFormat = SkMask::kA8_Format;
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000189 const size_t size = mask->computeImageSize();
reed@google.comd729b3e2012-11-09 14:30:48 +0000190 mask->fImage = SkMask::AllocImage(size);
191 if (NULL == mask->fImage) {
192 return false;
193 }
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000194
195 // FIXME: use sk_calloc in AllocImage?
reed@google.comd729b3e2012-11-09 14:30:48 +0000196 sk_bzero(mask->fImage, size);
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000197 return true;
198}
199
200static bool draw_rrect_into_mask(const SkRRect rrect, SkMask* mask) {
201 if (!prepare_to_draw_into_mask(rrect.rect(), mask)) {
202 return false;
203 }
204
205 // FIXME: This code duplicates code in draw_rects_into_mask, below. Is there a
206 // clean way to share more code?
207 SkBitmap bitmap;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000208 bitmap.installMaskPixels(*mask);
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000209
210 SkCanvas canvas(bitmap);
211 canvas.translate(-SkIntToScalar(mask->fBounds.left()),
212 -SkIntToScalar(mask->fBounds.top()));
213
214 SkPaint paint;
215 paint.setAntiAlias(true);
216 canvas.drawRRect(rrect, paint);
217 return true;
218}
219
220static bool draw_rects_into_mask(const SkRect rects[], int count, SkMask* mask) {
221 if (!prepare_to_draw_into_mask(rects[0], mask)) {
222 return false;
223 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000224
225 SkBitmap bitmap;
commit-bot@chromium.orge24ad232014-02-16 22:03:38 +0000226 bitmap.installPixels(SkImageInfo::Make(mask->fBounds.width(),
227 mask->fBounds.height(),
228 kAlpha_8_SkColorType,
229 kPremul_SkAlphaType),
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +0000230 mask->fImage, mask->fRowBytes);
reed@google.comd729b3e2012-11-09 14:30:48 +0000231
232 SkCanvas canvas(bitmap);
reed@google.comdab9b4f2012-11-19 16:45:14 +0000233 canvas.translate(-SkIntToScalar(mask->fBounds.left()),
234 -SkIntToScalar(mask->fBounds.top()));
reed@google.comd729b3e2012-11-09 14:30:48 +0000235
236 SkPaint paint;
237 paint.setAntiAlias(true);
238
reed@google.comdab9b4f2012-11-19 16:45:14 +0000239 if (1 == count) {
240 canvas.drawRect(rects[0], paint);
241 } else {
242 // todo: do I need a fast way to do this?
243 SkPath path;
244 path.addRect(rects[0]);
245 path.addRect(rects[1]);
246 path.setFillType(SkPath::kEvenOdd_FillType);
247 canvas.drawPath(path, paint);
248 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000249 return true;
250}
251
reed@google.comf276fa72012-11-21 14:14:10 +0000252static bool rect_exceeds(const SkRect& r, SkScalar v) {
253 return r.fLeft < -v || r.fTop < -v || r.fRight > v || r.fBottom > v ||
254 r.width() > v || r.height() > v;
reed@google.com07784a02012-11-19 21:09:14 +0000255}
256
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000257#ifdef SK_IGNORE_FAST_RRECT_BLUR
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000258SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", false, "Use the faster analytic blur approach for ninepatch rects" );
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000259#else
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000260SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", true, "Use the faster analytic blur approach for ninepatch round rects" );
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000261#endif
262
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000263SkMaskFilter::FilterReturn
264SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& matrix,
265 const SkIRect& clipBounds,
266 NinePatch* patch) const {
267 SkASSERT(patch != NULL);
268 switch (rrect.getType()) {
269 case SkRRect::kUnknown_Type:
270 // Unknown should never be returned.
271 SkASSERT(false);
272 // Fall through.
273 case SkRRect::kEmpty_Type:
274 // Nothing to draw.
275 return kFalse_FilterReturn;
276
277 case SkRRect::kRect_Type:
278 // We should have caught this earlier.
279 SkASSERT(false);
280 // Fall through.
281 case SkRRect::kOval_Type:
282 // The nine patch special case does not handle ovals, and we
283 // already have code for rectangles.
284 return kUnimplemented_FilterReturn;
285
commit-bot@chromium.orgf338d7c2014-03-17 21:17:30 +0000286 // These three can take advantage of this fast path.
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000287 case SkRRect::kSimple_Type:
commit-bot@chromium.orgf338d7c2014-03-17 21:17:30 +0000288 case SkRRect::kNinePatch_Type:
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000289 case SkRRect::kComplex_Type:
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000290 break;
291 }
292
293 // TODO: report correct metrics for innerstyle, where we do not grow the
294 // total bounds, but we do need an inset the size of our blur-radius
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000295 if (kInner_SkBlurStyle == fBlurStyle) {
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000296 return kUnimplemented_FilterReturn;
297 }
298
299 // TODO: take clipBounds into account to limit our coordinates up front
300 // for now, just skip too-large src rects (to take the old code path).
301 if (rect_exceeds(rrect.rect(), SkIntToScalar(32767))) {
302 return kUnimplemented_FilterReturn;
303 }
304
305 SkIPoint margin;
306 SkMask srcM, dstM;
307 rrect.rect().roundOut(&srcM.fBounds);
308 srcM.fImage = NULL;
309 srcM.fFormat = SkMask::kA8_Format;
310 srcM.fRowBytes = 0;
311
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000312 bool filterResult = false;
313 if (c_analyticBlurRRect) {
314 // special case for fast round rect blur
315 // don't actually do the blur the first time, just compute the correct size
316 filterResult = this->filterRRectMask(&dstM, rrect, matrix, &margin,
317 SkMask::kJustComputeBounds_CreateMode);
318 }
319
320 if (!filterResult) {
321 filterResult = this->filterMask(&dstM, srcM, matrix, &margin);
322 }
323
324 if (!filterResult) {
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000325 return kFalse_FilterReturn;
326 }
327
328 // Now figure out the appropriate width and height of the smaller round rectangle
329 // to stretch. It will take into account the larger radius per side as well as double
330 // the margin, to account for inner and outer blur.
331 const SkVector& UL = rrect.radii(SkRRect::kUpperLeft_Corner);
332 const SkVector& UR = rrect.radii(SkRRect::kUpperRight_Corner);
333 const SkVector& LR = rrect.radii(SkRRect::kLowerRight_Corner);
334 const SkVector& LL = rrect.radii(SkRRect::kLowerLeft_Corner);
335
336 const SkScalar leftUnstretched = SkTMax(UL.fX, LL.fX) + SkIntToScalar(2 * margin.fX);
337 const SkScalar rightUnstretched = SkTMax(UR.fX, LR.fX) + SkIntToScalar(2 * margin.fX);
338
339 // Extra space in the middle to ensure an unchanging piece for stretching. Use 3 to cover
340 // any fractional space on either side plus 1 for the part to stretch.
341 const SkScalar stretchSize = SkIntToScalar(3);
342
343 const SkScalar totalSmallWidth = leftUnstretched + rightUnstretched + stretchSize;
344 if (totalSmallWidth >= rrect.rect().width()) {
345 // There is no valid piece to stretch.
346 return kUnimplemented_FilterReturn;
347 }
348
349 const SkScalar topUnstretched = SkTMax(UL.fY, UR.fY) + SkIntToScalar(2 * margin.fY);
350 const SkScalar bottomUnstretched = SkTMax(LL.fY, LR.fY) + SkIntToScalar(2 * margin.fY);
351
352 const SkScalar totalSmallHeight = topUnstretched + bottomUnstretched + stretchSize;
353 if (totalSmallHeight >= rrect.rect().height()) {
354 // There is no valid piece to stretch.
355 return kUnimplemented_FilterReturn;
356 }
357
358 SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight);
359
360 SkRRect smallRR;
361 SkVector radii[4];
362 radii[SkRRect::kUpperLeft_Corner] = UL;
363 radii[SkRRect::kUpperRight_Corner] = UR;
364 radii[SkRRect::kLowerRight_Corner] = LR;
365 radii[SkRRect::kLowerLeft_Corner] = LL;
366 smallRR.setRectRadii(smallR, radii);
367
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000368 bool analyticBlurWorked = false;
369 if (c_analyticBlurRRect) {
370 analyticBlurWorked =
371 this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin,
372 SkMask::kComputeBoundsAndRenderImage_CreateMode);
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000373 }
374
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000375 if (!analyticBlurWorked) {
376 if (!draw_rrect_into_mask(smallRR, &srcM)) {
377 return kFalse_FilterReturn;
378 }
robertphillips@google.comad993582013-11-11 18:45:18 +0000379
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000380 SkAutoMaskFreeImage amf(srcM.fImage);
381
382 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
383 return kFalse_FilterReturn;
384 }
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000385 }
386
387 patch->fMask.fBounds.offsetTo(0, 0);
388 patch->fOuterRect = dstM.fBounds;
389 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1;
390 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1;
391 return kTrue_FilterReturn;
392}
393
humper@google.come86af1f2013-03-11 21:23:36 +0000394SK_CONF_DECLARE( bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects" );
humper@google.com7c5d7b72013-03-11 20:16:28 +0000395
reed@google.comd729b3e2012-11-09 14:30:48 +0000396SkMaskFilter::FilterReturn
reed@google.comdab9b4f2012-11-19 16:45:14 +0000397SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count,
398 const SkMatrix& matrix,
399 const SkIRect& clipBounds,
reed@google.com30711b72012-12-18 19:18:39 +0000400 NinePatch* patch) const {
reed@google.comdab9b4f2012-11-19 16:45:14 +0000401 if (count < 1 || count > 2) {
402 return kUnimplemented_FilterReturn;
403 }
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000404
reed@google.com57850b92012-12-17 21:20:53 +0000405 // TODO: report correct metrics for innerstyle, where we do not grow the
406 // total bounds, but we do need an inset the size of our blur-radius
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000407 if (kInner_SkBlurStyle == fBlurStyle || kOuter_SkBlurStyle == fBlurStyle) {
reed@google.com57850b92012-12-17 21:20:53 +0000408 return kUnimplemented_FilterReturn;
409 }
410
reed@google.com07784a02012-11-19 21:09:14 +0000411 // TODO: take clipBounds into account to limit our coordinates up front
412 // for now, just skip too-large src rects (to take the old code path).
reed@google.comf276fa72012-11-21 14:14:10 +0000413 if (rect_exceeds(rects[0], SkIntToScalar(32767))) {
reed@google.com07784a02012-11-19 21:09:14 +0000414 return kUnimplemented_FilterReturn;
415 }
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000416
reed@google.comd729b3e2012-11-09 14:30:48 +0000417 SkIPoint margin;
418 SkMask srcM, dstM;
reed@google.comdab9b4f2012-11-19 16:45:14 +0000419 rects[0].roundOut(&srcM.fBounds);
reed@google.comd729b3e2012-11-09 14:30:48 +0000420 srcM.fImage = NULL;
421 srcM.fFormat = SkMask::kA8_Format;
422 srcM.fRowBytes = 0;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000423
humper@google.com7c5d7b72013-03-11 20:16:28 +0000424 bool filterResult = false;
425 if (count == 1 && c_analyticBlurNinepatch) {
426 // special case for fast rect blur
427 // don't actually do the blur the first time, just compute the correct size
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000428 filterResult = this->filterRectMask(&dstM, rects[0], matrix, &margin,
humper@google.com7c5d7b72013-03-11 20:16:28 +0000429 SkMask::kJustComputeBounds_CreateMode);
430 } else {
431 filterResult = this->filterMask(&dstM, srcM, matrix, &margin);
432 }
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000433
humper@google.com7c5d7b72013-03-11 20:16:28 +0000434 if (!filterResult) {
reed@google.comd729b3e2012-11-09 14:30:48 +0000435 return kFalse_FilterReturn;
436 }
437
438 /*
439 * smallR is the smallest version of 'rect' that will still guarantee that
440 * we get the same blur results on all edges, plus 1 center row/col that is
441 * representative of the extendible/stretchable edges of the ninepatch.
442 * Since our actual edge may be fractional we inset 1 more to be sure we
443 * don't miss any interior blur.
444 * x is an added pixel of blur, and { and } are the (fractional) edge
445 * pixels from the original rect.
446 *
447 * x x { x x .... x x } x x
448 *
449 * Thus, in this case, we inset by a total of 5 (on each side) beginning
450 * with our outer-rect (dstM.fBounds)
451 */
reed@google.comdab9b4f2012-11-19 16:45:14 +0000452 SkRect smallR[2];
453 SkIPoint center;
454
455 // +2 is from +1 for each edge (to account for possible fractional edges
456 int smallW = dstM.fBounds.width() - srcM.fBounds.width() + 2;
457 int smallH = dstM.fBounds.height() - srcM.fBounds.height() + 2;
458 SkIRect innerIR;
459
460 if (1 == count) {
461 innerIR = srcM.fBounds;
462 center.set(smallW, smallH);
463 } else {
464 SkASSERT(2 == count);
465 rects[1].roundIn(&innerIR);
466 center.set(smallW + (innerIR.left() - srcM.fBounds.left()),
467 smallH + (innerIR.top() - srcM.fBounds.top()));
reed@google.comd729b3e2012-11-09 14:30:48 +0000468 }
469
reed@google.comdab9b4f2012-11-19 16:45:14 +0000470 // +1 so we get a clean, stretchable, center row/col
471 smallW += 1;
472 smallH += 1;
473
474 // we want the inset amounts to be integral, so we don't change any
475 // fractional phase on the fRight or fBottom of our smallR.
476 const SkScalar dx = SkIntToScalar(innerIR.width() - smallW);
477 const SkScalar dy = SkIntToScalar(innerIR.height() - smallH);
478 if (dx < 0 || dy < 0) {
479 // we're too small, relative to our blur, to break into nine-patch,
480 // so we ask to have our normal filterMask() be called.
481 return kUnimplemented_FilterReturn;
482 }
483
484 smallR[0].set(rects[0].left(), rects[0].top(), rects[0].right() - dx, rects[0].bottom() - dy);
robertphillips@google.com112a23e2013-09-03 17:17:43 +0000485 if (smallR[0].width() < 2 || smallR[0].height() < 2) {
486 return kUnimplemented_FilterReturn;
487 }
reed@google.comdab9b4f2012-11-19 16:45:14 +0000488 if (2 == count) {
489 smallR[1].set(rects[1].left(), rects[1].top(),
490 rects[1].right() - dx, rects[1].bottom() - dy);
491 SkASSERT(!smallR[1].isEmpty());
492 }
493
humper@google.com7c5d7b72013-03-11 20:16:28 +0000494 if (count > 1 || !c_analyticBlurNinepatch) {
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000495 if (!draw_rects_into_mask(smallR, count, &srcM)) {
humper@google.com7c5d7b72013-03-11 20:16:28 +0000496 return kFalse_FilterReturn;
497 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000498
humper@google.com7c5d7b72013-03-11 20:16:28 +0000499 SkAutoMaskFreeImage amf(srcM.fImage);
reed@google.comd198a5b2012-11-27 15:18:04 +0000500
humper@google.com7c5d7b72013-03-11 20:16:28 +0000501 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
502 return kFalse_FilterReturn;
503 }
504 } else {
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000505 if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin,
humper@google.com7c5d7b72013-03-11 20:16:28 +0000506 SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
507 return kFalse_FilterReturn;
508 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000509 }
reed@google.comdab9b4f2012-11-19 16:45:14 +0000510 patch->fMask.fBounds.offsetTo(0, 0);
511 patch->fOuterRect = dstM.fBounds;
512 patch->fCenter = center;
reed@google.comd729b3e2012-11-09 14:30:48 +0000513 return kTrue_FilterReturn;
514}
515
reed@google.com30711b72012-12-18 19:18:39 +0000516void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src,
517 SkRect* dst) const {
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000518 SkScalar pad = 3.0f * fSigma;
robertphillips@google.com17ad2bd2013-07-30 12:15:19 +0000519
520 dst->set(src.fLeft - pad, src.fTop - pad,
521 src.fRight + pad, src.fBottom + pad);
reed@google.com9efd9a02012-01-30 15:41:43 +0000522}
523
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000524SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkReadBuffer& buffer)
reed@google.com03016a32011-08-12 14:59:59 +0000525 : SkMaskFilter(buffer) {
commit-bot@chromium.orgfed2ab62014-01-23 15:16:05 +0000526 fSigma = buffer.readScalar();
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000527 fBlurStyle = (SkBlurStyle)buffer.readInt();
djsollen@google.comc73dd5c2012-08-07 15:54:32 +0000528 fBlurFlags = buffer.readUInt() & SkBlurMaskFilter::kAll_BlurFlag;
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000529 SkASSERT(fSigma > 0);
530 SkASSERT((unsigned)fBlurStyle <= kLastEnum_SkBlurStyle);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000531}
532
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000533void SkBlurMaskFilterImpl::flatten(SkWriteBuffer& buffer) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000534 this->INHERITED::flatten(buffer);
robertphillips@google.com11e05552013-12-03 19:46:58 +0000535 buffer.writeScalar(fSigma);
djsollen@google.comc73dd5c2012-08-07 15:54:32 +0000536 buffer.writeInt(fBlurStyle);
537 buffer.writeUInt(fBlurFlags);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000538}
539
robertphillips@google.com49149312013-07-03 15:34:35 +0000540#if SK_SUPPORT_GPU
reed@google.com2b75f422011-07-07 13:43:38 +0000541
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000542class GrGLRectBlurEffect;
543
544class GrRectBlurEffect : public GrEffect {
545public:
546 virtual ~GrRectBlurEffect();
547
548 static const char* Name() { return "RectBlur"; }
549
550 typedef GrGLRectBlurEffect GLEffect;
551
552 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
553 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
554
555 /**
556 * Create a simple filter effect with custom bicubic coefficients.
557 */
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000558 static GrEffectRef* Create(GrContext *context, const SkRect& rect,
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000559 float sigma) {
humper4a24cd82014-06-17 13:39:29 -0700560 GrTexture *blurProfileTexture = NULL;
561 int doubleProfileSize = SkScalarCeilToInt(12*sigma);
562
563 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.height()) {
564 // if the blur sigma is too large so the gaussian overlaps the whole
565 // rect in either direction, fall back to CPU path for now.
566
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000567 return NULL;
568 }
humper4a24cd82014-06-17 13:39:29 -0700569
570 bool createdBlurProfileTexture = CreateBlurProfileTexture(context, sigma, &blurProfileTexture);
571 SkAutoTUnref<GrTexture> hunref(blurProfileTexture);
572 if (!createdBlurProfileTexture) {
573 return NULL;
574 }
575 AutoEffectUnref effect(SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture)));
skia.committer@gmail.comba124482014-02-01 03:01:57 +0000576 return CreateEffectRef(effect);
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000577 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000578
humper4a24cd82014-06-17 13:39:29 -0700579 const SkRect& getRect() const { return fRect; }
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000580 float getSigma() const { return fSigma; }
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000581
582private:
humper4a24cd82014-06-17 13:39:29 -0700583 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile);
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000584 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000585
humper4a24cd82014-06-17 13:39:29 -0700586 static bool CreateBlurProfileTexture(GrContext *context, float sigma,
587 GrTexture **blurProfileTexture);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000588
humper4a24cd82014-06-17 13:39:29 -0700589 SkRect fRect;
590 float fSigma;
591 GrTextureAccess fBlurProfileAccess;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000592
593 GR_DECLARE_EFFECT_TEST;
594
595 typedef GrEffect INHERITED;
596};
597
598class GrGLRectBlurEffect : public GrGLEffect {
599public:
600 GrGLRectBlurEffect(const GrBackendEffectFactory& factory,
601 const GrDrawEffect&);
602 virtual void emitCode(GrGLShaderBuilder*,
603 const GrDrawEffect&,
604 EffectKey,
605 const char* outputColor,
606 const char* inputColor,
607 const TransformedCoordsArray&,
608 const TextureSamplerArray&) SK_OVERRIDE;
609
610 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
611
612private:
613 typedef GrGLUniformManager::UniformHandle UniformHandle;
614
humper4a24cd82014-06-17 13:39:29 -0700615 UniformHandle fProxyRectUniform;
616 UniformHandle fProfileSizeUniform;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000617
618 typedef GrGLEffect INHERITED;
619};
620
humper4a24cd82014-06-17 13:39:29 -0700621
622
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000623GrGLRectBlurEffect::GrGLRectBlurEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
624 : INHERITED(factory) {
625}
626
humper4a24cd82014-06-17 13:39:29 -0700627void OutputRectBlurProfileLookup(GrGLShaderBuilder* builder,
628 const GrGLShaderBuilder::TextureSampler& sampler,
629 const char *output,
630 const char *profileSize, const char *loc,
631 const char *blurred_width,
632 const char *sharp_width) {
633 builder->fsCodeAppendf("\tfloat %s;\n", output);
634 builder->fsCodeAppendf("\t\t{\n");
635 builder->fsCodeAppendf("\t\t\tfloat coord = (0.5 * (abs(2.0*%s - %s) - %s))/%s;\n",
636 loc, blurred_width, sharp_width, profileSize);
637 builder->fsCodeAppendf("\t\t\t%s = ", output);
638 builder->fsAppendTextureLookup(sampler, "vec2(coord,0.5)");
639 builder->fsCodeAppend(".a;\n");
640 builder->fsCodeAppendf("\t\t}\n");
641}
642
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000643void GrGLRectBlurEffect::emitCode(GrGLShaderBuilder* builder,
644 const GrDrawEffect&,
645 EffectKey key,
646 const char* outputColor,
647 const char* inputColor,
648 const TransformedCoordsArray& coords,
649 const TextureSamplerArray& samplers) {
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000650
humper4a24cd82014-06-17 13:39:29 -0700651 const char *rectName;
652 const char *profileSizeName;
653
654 fProxyRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
655 kVec4f_GrSLType,
656 "proxyRect",
657 &rectName);
658 fProfileSizeUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
659 kFloat_GrSLType,
660 "profileSize",
661 &profileSizeName);
662
663 const char *fragmentPos = builder->fragmentPosition();
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000664
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000665 if (inputColor) {
666 builder->fsCodeAppendf("\tvec4 src=%s;\n", inputColor);
667 } else {
668 builder->fsCodeAppendf("\tvec4 src=vec4(1)\n;");
669 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000670
humper4a24cd82014-06-17 13:39:29 -0700671 builder->fsCodeAppendf("\tvec2 translatedPos = %s.xy - %s.xy;\n", fragmentPos, rectName );
672 builder->fsCodeAppendf("\tfloat width = %s.z - %s.x;\n", rectName, rectName);
673 builder->fsCodeAppendf("\tfloat height = %s.w - %s.y;\n", rectName, rectName);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000674
humper4a24cd82014-06-17 13:39:29 -0700675 builder->fsCodeAppendf("\tvec2 smallDims = vec2(width - %s, height-%s);\n", profileSizeName, profileSizeName);
676 builder->fsCodeAppendf("\tfloat center = 2.0 * floor(%s/2.0 + .25) - 1.0;\n", profileSizeName);
677 builder->fsCodeAppendf("\tvec2 wh = smallDims - vec2(center,center);\n");
678
679 OutputRectBlurProfileLookup(builder, samplers[0], "horiz_lookup", profileSizeName, "translatedPos.x", "width", "wh.x");
680 OutputRectBlurProfileLookup(builder, samplers[0], "vert_lookup", profileSizeName, "translatedPos.y", "height", "wh.y");
681
682 builder->fsCodeAppendf("\tfloat final = horiz_lookup * vert_lookup;\n");
683 builder->fsCodeAppendf("\t%s = src * vec4(final);\n", outputColor );
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000684}
685
686void GrGLRectBlurEffect::setData(const GrGLUniformManager& uman,
humper4a24cd82014-06-17 13:39:29 -0700687 const GrDrawEffect& drawEffect) {
688 const GrRectBlurEffect& rbe = drawEffect.castEffect<GrRectBlurEffect>();
689 SkRect rect = rbe.getRect();
690
691 uman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
692 uman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma()));
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000693}
694
humper4a24cd82014-06-17 13:39:29 -0700695bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma,
696 GrTexture **blurProfileTexture) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000697 GrTextureParams params;
698 GrTextureDesc texDesc;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000699
humper4a24cd82014-06-17 13:39:29 -0700700 unsigned int profile_size = SkScalarCeilToInt(6*sigma);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000701
humper4a24cd82014-06-17 13:39:29 -0700702 texDesc.fWidth = profile_size;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000703 texDesc.fHeight = 1;
704 texDesc.fConfig = kAlpha_8_GrPixelConfig;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000705
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000706 static const GrCacheID::Domain gBlurProfileDomain = GrCacheID::GenerateDomain();
707 GrCacheID::Key key;
708 memset(&key, 0, sizeof(key));
709 key.fData32[0] = profile_size;
humper4a24cd82014-06-17 13:39:29 -0700710 key.fData32[1] = 1;
711 GrCacheID blurProfileKey(gBlurProfileDomain, key);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000712
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000713 uint8_t *profile = NULL;
commit-bot@chromium.orgcc787fa2014-01-31 01:00:49 +0000714 SkAutoTDeleteArray<uint8_t> ada(NULL);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000715
humper4a24cd82014-06-17 13:39:29 -0700716 *blurProfileTexture = context->findAndRefTexture(texDesc, blurProfileKey, &params);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000717
humper4a24cd82014-06-17 13:39:29 -0700718 if (NULL == *blurProfileTexture) {
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000719
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000720 SkBlurMask::ComputeBlurProfile(sigma, &profile);
commit-bot@chromium.orgcc787fa2014-01-31 01:00:49 +0000721 ada.reset(profile);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000722
humper4a24cd82014-06-17 13:39:29 -0700723 *blurProfileTexture = context->createTexture(&params, texDesc, blurProfileKey,
724 profile, 0);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000725
humper4a24cd82014-06-17 13:39:29 -0700726 if (NULL == *blurProfileTexture) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000727 return false;
728 }
729 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000730
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000731 return true;
732}
733
734GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma,
humper4a24cd82014-06-17 13:39:29 -0700735 GrTexture *blur_profile)
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000736 : INHERITED(),
humper4a24cd82014-06-17 13:39:29 -0700737 fRect(rect),
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000738 fSigma(sigma),
humper4a24cd82014-06-17 13:39:29 -0700739 fBlurProfileAccess(blur_profile) {
740 this->addTextureAccess(&fBlurProfileAccess);
741 this->setWillReadFragmentPosition();
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000742}
743
744GrRectBlurEffect::~GrRectBlurEffect() {
745}
746
747const GrBackendEffectFactory& GrRectBlurEffect::getFactory() const {
748 return GrTBackendEffectFactory<GrRectBlurEffect>::getInstance();
749}
750
751bool GrRectBlurEffect::onIsEqual(const GrEffect& sBase) const {
752 const GrRectBlurEffect& s = CastEffect<GrRectBlurEffect>(sBase);
humper4a24cd82014-06-17 13:39:29 -0700753 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect();
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000754}
755
756void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
757 *validFlags = 0;
758 return;
759}
760
761GR_DEFINE_EFFECT_TEST(GrRectBlurEffect);
762
763GrEffectRef* GrRectBlurEffect::TestCreate(SkRandom* random,
764 GrContext* context,
765 const GrDrawTargetCaps&,
766 GrTexture**) {
767 float sigma = random->nextRangeF(3,8);
768 float width = random->nextRangeF(200,300);
769 float height = random->nextRangeF(200,300);
770 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigma);
771}
772
773
774bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
775 GrPaint* grp,
776 const SkStrokeRec& strokeRec,
777 const SkPath& path) const {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000778 if (fBlurStyle != kNormal_SkBlurStyle) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000779 return false;
780 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000781
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000782 SkRect rect;
783 if (!path.isRect(&rect)) {
784 return false;
785 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000786
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000787 if (!strokeRec.isFillStyle()) {
788 return false;
789 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000790
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000791 SkMatrix ctm = context->getMatrix();
792 SkScalar xformedSigma = this->computeXformedSigma(ctm);
humper4a24cd82014-06-17 13:39:29 -0700793
794 int pad=SkScalarCeilToInt(6*xformedSigma)/2;
795 rect.outset(SkIntToScalar(pad), SkIntToScalar(pad));
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000796
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000797 SkAutoTUnref<GrEffectRef> effect(GrRectBlurEffect::Create(
798 context, rect, xformedSigma));
799 if (!effect) {
800 return false;
801 }
802
803 GrContext::AutoMatrix am;
804 if (!am.setIdentity(context, grp)) {
805 return false;
806 }
807
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000808 grp->addCoverageEffect(effect);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000809
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000810 context->drawRect(*grp, rect);
811 return true;
812}
813
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000814class GrGLRRectBlurEffect;
815
816class GrRRectBlurEffect : public GrEffect {
817public:
818
819 static GrEffectRef* Create(GrContext* context, float sigma, const SkRRect&);
820
821 virtual ~GrRRectBlurEffect() {};
822 static const char* Name() { return "GrRRectBlur"; }
823
824 const SkRRect& getRRect() const { return fRRect; }
825 float getSigma() const { return fSigma; }
826
827 typedef GrGLRRectBlurEffect GLEffect;
828
829 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
830
831 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
832
833private:
834 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture);
835
836 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
837
838 SkRRect fRRect;
839 float fSigma;
840 GrTextureAccess fNinePatchAccess;
841
842 GR_DECLARE_EFFECT_TEST;
843
844 typedef GrEffect INHERITED;
845};
846
847
848GrEffectRef* GrRRectBlurEffect::Create(GrContext* context, float sigma, const SkRRect& rrect) {
849 if (!rrect.isSimpleCircular()) {
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000850 return NULL;
851 }
852
853 // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be
854 // sufficiently small relative to both the size of the corner radius and the
855 // width (and height) of the rrect.
856
857 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f);
858 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x());
859 if (cornerRadius + blurRadius > rrect.width()/2 ||
860 cornerRadius + blurRadius > rrect.height()/2) {
861 return NULL;
862 }
863
864 static const GrCacheID::Domain gRRectBlurDomain = GrCacheID::GenerateDomain();
865 GrCacheID::Key key;
866 memset(&key, 0, sizeof(key));
867 key.fData32[0] = blurRadius;
868 key.fData32[1] = cornerRadius;
869 GrCacheID blurRRectNinePatchID(gRRectBlurDomain, key);
870
871 GrTextureParams params;
872 params.setFilterMode(GrTextureParams::kBilerp_FilterMode);
873
874 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1;
875 unsigned int texSide = smallRectSide + 2*blurRadius;
876 GrTextureDesc texDesc;
877 texDesc.fWidth = texSide;
878 texDesc.fHeight = texSide;
879 texDesc.fConfig = kAlpha_8_GrPixelConfig;
880
881 GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, blurRRectNinePatchID, &params);
882
883 if (NULL == blurNinePatchTexture) {
884 SkMask mask;
885
886 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide);
887 mask.fFormat = SkMask::kA8_Format;
888 mask.fRowBytes = mask.fBounds.width();
889 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize());
890 SkAutoMaskFreeImage amfi(mask.fImage);
891
892 memset(mask.fImage, 0, mask.computeTotalImageSize());
893
894 SkRect smallRect;
895 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSide));
896
897 SkRRect smallRRect;
898 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
899
900 SkPath path;
901 path.addRRect( smallRRect );
902
903 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_Style);
904
905 SkMask blurred_mask;
906 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHigh_SkBlurQuality, NULL, true );
907
908 blurNinePatchTexture = context->createTexture(&params, texDesc, blurRRectNinePatchID, blurred_mask.fImage, 0);
commit-bot@chromium.org6b127cd2014-04-29 04:41:33 +0000909 SkMask::FreeImage(blurred_mask.fImage);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000910 }
911
commit-bot@chromium.org6b127cd2014-04-29 04:41:33 +0000912 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000913 if (NULL == blurNinePatchTexture) {
914 return NULL;
915 }
916
917 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrRRectBlurEffect,
918 (sigma, rrect, blurNinePatchTexture))));
919}
920
921void GrRRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
922 *validFlags = 0;
923}
924
925const GrBackendEffectFactory& GrRRectBlurEffect::getFactory() const {
926 return GrTBackendEffectFactory<GrRRectBlurEffect>::getInstance();
927}
928
929GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTexture *ninePatchTexture)
930 : fRRect(rrect),
931 fSigma(sigma),
932 fNinePatchAccess(ninePatchTexture) {
933 this->addTextureAccess(&fNinePatchAccess);
934 this->setWillReadFragmentPosition();
935}
936
937bool GrRRectBlurEffect::onIsEqual(const GrEffect& other) const {
938 const GrRRectBlurEffect& rrbe = CastEffect<GrRRectBlurEffect>(other);
939 return fRRect.getSimpleRadii().fX == rrbe.fRRect.getSimpleRadii().fX && fSigma == rrbe.fSigma;
940}
941
942//////////////////////////////////////////////////////////////////////////////
943
944GR_DEFINE_EFFECT_TEST(GrRRectBlurEffect);
945
946GrEffectRef* GrRRectBlurEffect::TestCreate(SkRandom* random,
947 GrContext* context,
948 const GrDrawTargetCaps& caps,
949 GrTexture*[]) {
950 SkScalar w = random->nextRangeScalar(100.f, 1000.f);
951 SkScalar h = random->nextRangeScalar(100.f, 1000.f);
952 SkScalar r = random->nextRangeF(1.f, 9.f);
953 SkScalar sigma = random->nextRangeF(1.f,10.f);
954 SkRRect rrect;
955 rrect.setRectXY(SkRect::MakeWH(w, h), r, r);
956 return GrRRectBlurEffect::Create(context, sigma, rrect);
957}
958
959//////////////////////////////////////////////////////////////////////////////
960
961class GrGLRRectBlurEffect : public GrGLEffect {
962public:
963 GrGLRRectBlurEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
964
965 virtual void emitCode(GrGLShaderBuilder* builder,
966 const GrDrawEffect& drawEffect,
967 EffectKey key,
968 const char* outputColor,
969 const char* inputColor,
970 const TransformedCoordsArray&,
971 const TextureSamplerArray&) SK_OVERRIDE;
972
973 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
974
975private:
976 GrGLUniformManager::UniformHandle fProxyRectUniform;
977 GrGLUniformManager::UniformHandle fCornerRadiusUniform;
978 GrGLUniformManager::UniformHandle fBlurRadiusUniform;
979 typedef GrGLEffect INHERITED;
980};
981
982GrGLRRectBlurEffect::GrGLRRectBlurEffect(const GrBackendEffectFactory& factory,
983 const GrDrawEffect& drawEffect)
984 : INHERITED (factory) {
985}
986
987void GrGLRRectBlurEffect::emitCode(GrGLShaderBuilder* builder,
988 const GrDrawEffect& drawEffect,
989 EffectKey key,
990 const char* outputColor,
991 const char* inputColor,
992 const TransformedCoordsArray&,
993 const TextureSamplerArray& samplers) {
994 const char *rectName;
995 const char *cornerRadiusName;
996 const char *blurRadiusName;
997
998 // The proxy rect has left, top, right, and bottom edges correspond to
999 // components x, y, z, and w, respectively.
1000
1001 fProxyRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1002 kVec4f_GrSLType,
1003 "proxyRect",
1004 &rectName);
1005 fCornerRadiusUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1006 kFloat_GrSLType,
1007 "cornerRadius",
1008 &cornerRadiusName);
1009 fBlurRadiusUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1010 kFloat_GrSLType,
1011 "blurRadius",
1012 &blurRadiusName);
1013 const char* fragmentPos = builder->fragmentPosition();
1014
1015 // warp the fragment position to the appropriate part of the 9patch blur texture
1016
1017 builder->fsCodeAppendf("\t\tvec2 rectCenter = (%s.xy + %s.zw)/2.0;\n", rectName, rectName);
1018 builder->fsCodeAppendf("\t\tvec2 translatedFragPos = %s.xy - %s.xy;\n", fragmentPos, rectName);
1019 builder->fsCodeAppendf("\t\tfloat threshold = %s + 2.0*%s;\n", cornerRadiusName, blurRadiusName );
1020 builder->fsCodeAppendf("\t\tvec2 middle = %s.zw - %s.xy - 2.0*threshold;\n", rectName, rectName );
1021
1022 builder->fsCodeAppendf("\t\tif (translatedFragPos.x >= threshold && translatedFragPos.x < (middle.x+threshold)) {\n" );
1023 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.x = threshold;\n");
1024 builder->fsCodeAppendf("\t\t} else if (translatedFragPos.x >= (middle.x + threshold)) {\n");
commit-bot@chromium.org7ba17022014-05-19 18:51:05 +00001025 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.x -= middle.x - 1.0;\n");
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001026 builder->fsCodeAppendf("\t\t}\n");
1027
1028 builder->fsCodeAppendf("\t\tif (translatedFragPos.y > threshold && translatedFragPos.y < (middle.y+threshold)) {\n" );
1029 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.y = threshold;\n");
1030 builder->fsCodeAppendf("\t\t} else if (translatedFragPos.y >= (middle.y + threshold)) {\n");
commit-bot@chromium.org7ba17022014-05-19 18:51:05 +00001031 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.y -= middle.y - 1.0;\n");
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001032 builder->fsCodeAppendf("\t\t}\n");
1033
1034 builder->fsCodeAppendf("\t\tvec2 proxyDims = vec2(2.0*threshold+1.0);\n");
1035 builder->fsCodeAppendf("\t\tvec2 texCoord = translatedFragPos / proxyDims;\n");
1036
1037 builder->fsCodeAppendf("\t%s = ", outputColor);
1038 builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "texCoord");
1039 builder->fsCodeAppend(";\n");
1040}
1041
1042void GrGLRRectBlurEffect::setData(const GrGLUniformManager& uman,
1043 const GrDrawEffect& drawEffect) {
1044 const GrRRectBlurEffect& brre = drawEffect.castEffect<GrRRectBlurEffect>();
1045 SkRRect rrect = brre.getRRect();
1046
1047 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f);
1048 uman.set1f(fBlurRadiusUniform, blurRadius);
1049
1050 SkRect rect = rrect.getBounds();
1051 rect.outset(blurRadius, blurRadius);
1052 uman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1053
1054 SkScalar radius = 0;
1055 SkASSERT(rrect.isSimpleCircular() || rrect.isRect());
1056 radius = rrect.getSimpleRadii().fX;
1057 uman.set1f(fCornerRadiusUniform, radius);
1058}
1059
1060
commit-bot@chromium.org82139702014-03-10 22:53:20 +00001061bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
1062 GrPaint* grp,
1063 const SkStrokeRec& strokeRec,
1064 const SkRRect& rrect) const {
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001065 if (fBlurStyle != kNormal_SkBlurStyle) {
1066 return false;
1067 }
1068
1069 if (!strokeRec.isFillStyle()) {
1070 return false;
1071 }
1072
1073 SkRect proxy_rect = rrect.rect();
1074 SkMatrix ctm = context->getMatrix();
1075 SkScalar xformedSigma = this->computeXformedSigma(ctm);
1076 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f);
1077 proxy_rect.outset(extra, extra);
1078
1079 SkAutoTUnref<GrEffectRef> effect(GrRRectBlurEffect::Create(
1080 context, xformedSigma, rrect));
1081 if (!effect) {
1082 return false;
1083 }
1084
1085 GrContext::AutoMatrix am;
1086 if (!am.setIdentity(context, grp)) {
1087 return false;
1088 }
1089
1090 grp->addCoverageEffect(effect);
1091
1092 context->drawRect(*grp, proxy_rect);
1093 return true;
commit-bot@chromium.org82139702014-03-10 22:53:20 +00001094}
1095
robertphillips@google.com49149312013-07-03 15:34:35 +00001096bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds,
1097 const SkIRect& clipBounds,
1098 const SkMatrix& ctm,
1099 SkRect* maskRect) const {
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001100 SkScalar xformedSigma = this->computeXformedSigma(ctm);
1101 if (xformedSigma <= 0) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001102 return false;
reed@google.com2b75f422011-07-07 13:43:38 +00001103 }
robertphillips@google.com49149312013-07-03 15:34:35 +00001104
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001105 static const SkScalar kMIN_GPU_BLUR_SIZE = SkIntToScalar(64);
1106 static const SkScalar kMIN_GPU_BLUR_SIGMA = SkIntToScalar(32);
robertphillips@google.com49149312013-07-03 15:34:35 +00001107
1108 if (srcBounds.width() <= kMIN_GPU_BLUR_SIZE &&
1109 srcBounds.height() <= kMIN_GPU_BLUR_SIZE &&
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001110 xformedSigma <= kMIN_GPU_BLUR_SIGMA) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001111 // We prefer to blur small rect with small radius via CPU.
1112 return false;
1113 }
1114
1115 if (NULL == maskRect) {
1116 // don't need to compute maskRect
1117 return true;
1118 }
1119
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001120 float sigma3 = 3 * SkScalarToFloat(xformedSigma);
robertphillips@google.com49149312013-07-03 15:34:35 +00001121
reed@google.com44699382013-10-31 17:28:30 +00001122 SkRect clipRect = SkRect::Make(clipBounds);
robertphillips@google.com49149312013-07-03 15:34:35 +00001123 SkRect srcRect(srcBounds);
1124
1125 // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area.
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001126 srcRect.outset(sigma3, sigma3);
1127 clipRect.outset(sigma3, sigma3);
robertphillips@google.com49149312013-07-03 15:34:35 +00001128 srcRect.intersect(clipRect);
1129 *maskRect = srcRect;
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +00001130 return true;
reed@google.com2b75f422011-07-07 13:43:38 +00001131}
1132
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +00001133bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
commit-bot@chromium.org439ff1b2014-01-13 16:39:39 +00001134 const SkMatrix& ctm,
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +00001135 const SkRect& maskRect,
robertphillips@google.com49149312013-07-03 15:34:35 +00001136 GrTexture** result,
1137 bool canOverwriteSrc) const {
1138 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
1139
1140 GrContext* context = src->getContext();
1141
1142 GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
1143
commit-bot@chromium.org439ff1b2014-01-13 16:39:39 +00001144 SkScalar xformedSigma = this->computeXformedSigma(ctm);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001145 SkASSERT(xformedSigma > 0);
robertphillips@google.com49149312013-07-03 15:34:35 +00001146
1147 // If we're doing a normal blur, we can clobber the pathTexture in the
1148 // gaussianBlur. Otherwise, we need to save it for later compositing.
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001149 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
robertphillips@google.com736dd032013-07-15 15:06:54 +00001150 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc,
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001151 clipRect, false, xformedSigma, xformedSigma);
robertphillips@google.com3cc820c2013-07-03 19:36:55 +00001152 if (NULL == *result) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001153 return false;
1154 }
1155
1156 if (!isNormalBlur) {
1157 context->setIdentityMatrix();
1158 GrPaint paint;
1159 SkMatrix matrix;
1160 matrix.setIDiv(src->width(), src->height());
1161 // Blend pathTexture over blurTexture.
1162 GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget());
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +00001163 paint.addColorEffect(GrSimpleTextureEffect::Create(src, matrix))->unref();
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001164 if (kInner_SkBlurStyle == fBlurStyle) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001165 // inner: dst = dst * src
1166 paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001167 } else if (kSolid_SkBlurStyle == fBlurStyle) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001168 // solid: dst = src + dst - src * dst
1169 // = (1 - dst) * src + 1 * dst
1170 paint.setBlendFunc(kIDC_GrBlendCoeff, kOne_GrBlendCoeff);
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001171 } else if (kOuter_SkBlurStyle == fBlurStyle) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001172 // outer: dst = dst * (1 - src)
1173 // = 0 * src + (1 - src) * dst
1174 paint.setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff);
1175 }
1176 context->drawRect(paint, clipRect);
1177 }
1178
1179 return true;
1180}
1181
1182#endif // SK_SUPPORT_GPU
1183
1184
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +00001185#ifndef SK_IGNORE_TO_STRING
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001186void SkBlurMaskFilterImpl::toString(SkString* str) const {
1187 str->append("SkBlurMaskFilterImpl: (");
1188
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001189 str->append("sigma: ");
1190 str->appendScalar(fSigma);
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001191 str->append(" ");
1192
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001193 static const char* gStyleName[kLastEnum_SkBlurStyle + 1] = {
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001194 "normal", "solid", "outer", "inner"
1195 };
1196
1197 str->appendf("style: %s ", gStyleName[fBlurStyle]);
1198 str->append("flags: (");
1199 if (fBlurFlags) {
1200 bool needSeparator = false;
skia.committer@gmail.com8eaddb02013-03-19 07:15:10 +00001201 SkAddFlagToString(str,
1202 SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag),
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001203 "IgnoreXform", &needSeparator);
skia.committer@gmail.com8eaddb02013-03-19 07:15:10 +00001204 SkAddFlagToString(str,
1205 SkToBool(fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag),
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001206 "HighQuality", &needSeparator);
1207 } else {
1208 str->append("None");
1209 }
1210 str->append("))");
1211}
1212#endif
1213
caryclark@google.comd26147a2011-12-15 14:16:43 +00001214SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1215 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1216SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END