blob: 4ab9944d8ca2ce573b3898c64bee64232cbfbbee [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"
bsalomon848faf02014-07-11 10:01:02 -070025#include "gl/GrGLShaderBuilder.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000026#include "effects/GrSimpleTextureEffect.h"
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000027#include "GrTBackendEffectFactory.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000028#include "SkGrPixelRef.h"
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +000029#include "SkDraw.h"
robertphillips@google.com49149312013-07-03 15:34:35 +000030#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000031
commit-bot@chromium.org508022c2014-05-01 15:24:55 +000032SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) {
33 return SkBlurMask::ConvertRadiusToSigma(radius);
34}
35
reed@android.com8a1c16f2008-12-17 15:59:43 +000036class SkBlurMaskFilterImpl : public SkMaskFilter {
37public:
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000038 SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags);
reed@android.com8a1c16f2008-12-17 15:59:43 +000039
40 // overrides from SkMaskFilter
reed@google.com30711b72012-12-18 19:18:39 +000041 virtual SkMask::Format getFormat() const SK_OVERRIDE;
reed@google.com03016a32011-08-12 14:59:59 +000042 virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
reed@google.com30711b72012-12-18 19:18:39 +000043 SkIPoint* margin) const SK_OVERRIDE;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000044
robertphillips@google.com49149312013-07-03 15:34:35 +000045#if SK_SUPPORT_GPU
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +000046 virtual bool canFilterMaskGPU(const SkRect& devBounds,
robertphillips@google.com49149312013-07-03 15:34:35 +000047 const SkIRect& clipBounds,
48 const SkMatrix& ctm,
49 SkRect* maskRect) const SK_OVERRIDE;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000050 virtual bool directFilterMaskGPU(GrContext* context,
51 GrPaint* grp,
52 const SkStrokeRec& strokeRec,
53 const SkPath& path) const SK_OVERRIDE;
commit-bot@chromium.org82139702014-03-10 22:53:20 +000054 virtual bool directFilterRRectMaskGPU(GrContext* context,
55 GrPaint* grp,
56 const SkStrokeRec& strokeRec,
57 const SkRRect& rrect) const SK_OVERRIDE;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +000058
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +000059 virtual bool filterMaskGPU(GrTexture* src,
commit-bot@chromium.org41bf9302014-01-08 22:25:53 +000060 const SkMatrix& ctm,
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +000061 const SkRect& maskRect,
robertphillips@google.com49149312013-07-03 15:34:35 +000062 GrTexture** result,
commit-bot@chromium.org41bf9302014-01-08 22:25:53 +000063 bool canOverwriteSrc) const SK_OVERRIDE;
robertphillips@google.com49149312013-07-03 15:34:35 +000064#endif
65
reed@google.com30711b72012-12-18 19:18:39 +000066 virtual void computeFastBounds(const SkRect&, SkRect*) const SK_OVERRIDE;
reed@google.comdaaafa62014-04-29 15:20:16 +000067 virtual bool asABlur(BlurRec*) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000069 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000070 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurMaskFilterImpl)
reed@android.com8a1c16f2008-12-17 15:59:43 +000071
reed@google.comd729b3e2012-11-09 14:30:48 +000072protected:
reed@google.comdab9b4f2012-11-19 16:45:14 +000073 virtual FilterReturn filterRectsToNine(const SkRect[], int count, const SkMatrix&,
74 const SkIRect& clipBounds,
reed@google.com30711b72012-12-18 19:18:39 +000075 NinePatch*) const SK_OVERRIDE;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000076
scroggo@google.coma8e33a92013-11-08 18:02:53 +000077 virtual FilterReturn filterRRectToNine(const SkRRect&, const SkMatrix&,
78 const SkIRect& clipBounds,
79 NinePatch*) const SK_OVERRIDE;
80
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +000081 bool filterRectMask(SkMask* dstM, const SkRect& r, const SkMatrix& matrix,
humper@google.com7c5d7b72013-03-11 20:16:28 +000082 SkIPoint* margin, SkMask::CreateMode createMode) const;
commit-bot@chromium.orga4771542014-03-10 21:42:06 +000083 bool filterRRectMask(SkMask* dstM, const SkRRect& r, const SkMatrix& matrix,
84 SkIPoint* margin, SkMask::CreateMode createMode) const;
skia.committer@gmail.com453995e2012-11-10 02:01:26 +000085
reed@android.com8a1c16f2008-12-17 15:59:43 +000086private:
robertphillips@google.com49149312013-07-03 15:34:35 +000087 // To avoid unseemly allocation requests (esp. for finite platforms like
88 // handset) we limit the radius so something manageable. (as opposed to
89 // a request like 10,000)
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000090 static const SkScalar kMAX_BLUR_SIGMA;
robertphillips@google.com49149312013-07-03 15:34:35 +000091
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000092 SkScalar fSigma;
93 SkBlurStyle fBlurStyle;
94 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000095
reed@google.comdaaafa62014-04-29 15:20:16 +000096 SkBlurQuality getQuality() const {
97 return (fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag) ?
98 kHigh_SkBlurQuality : kLow_SkBlurQuality;
99 }
100
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000101 SkBlurMaskFilterImpl(SkReadBuffer&);
102 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000103
104 SkScalar computeXformedSigma(const SkMatrix& ctm) const {
robertphillips@google.com49149312013-07-03 15:34:35 +0000105 bool ignoreTransform = SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
106
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000107 SkScalar xformedSigma = ignoreTransform ? fSigma : ctm.mapRadius(fSigma);
108 return SkMinScalar(xformedSigma, kMAX_BLUR_SIGMA);
robertphillips@google.com49149312013-07-03 15:34:35 +0000109 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000110
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111 typedef SkMaskFilter INHERITED;
112};
113
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000114const SkScalar SkBlurMaskFilterImpl::kMAX_BLUR_SIGMA = SkIntToScalar(128);
robertphillips@google.com49149312013-07-03 15:34:35 +0000115
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000116SkMaskFilter* SkBlurMaskFilter::Create(SkBlurStyle style, SkScalar sigma, uint32_t flags) {
117 if (!SkScalarIsFinite(sigma) || sigma <= 0) {
118 return NULL;
119 }
120 if ((unsigned)style > (unsigned)kLastEnum_SkBlurStyle) {
121 return NULL;
122 }
123 if (flags > SkBlurMaskFilter::kAll_BlurFlag) {
124 return NULL;
125 }
126 return SkNEW_ARGS(SkBlurMaskFilterImpl, (sigma, style, flags));
127}
128
reed@google.com03016a32011-08-12 14:59:59 +0000129///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000130
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000131SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle style, uint32_t flags)
132 : fSigma(sigma)
133 , fBlurStyle(style)
134 , fBlurFlags(flags) {
135 SkASSERT(fSigma > 0);
136 SkASSERT((unsigned)style <= kLastEnum_SkBlurStyle);
senorblanco@chromium.org038aff62010-12-06 23:45:58 +0000137 SkASSERT(flags <= SkBlurMaskFilter::kAll_BlurFlag);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000138}
139
reed@google.com30711b72012-12-18 19:18:39 +0000140SkMask::Format SkBlurMaskFilterImpl::getFormat() const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000141 return SkMask::kA8_Format;
142}
143
reed@google.comdaaafa62014-04-29 15:20:16 +0000144bool SkBlurMaskFilterImpl::asABlur(BlurRec* rec) const {
145 if (fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) {
146 return false;
147 }
148
149 if (rec) {
150 rec->fSigma = fSigma;
151 rec->fStyle = fBlurStyle;
152 rec->fQuality = this->getQuality();
153 }
154 return true;
155}
156
reed@google.com03016a32011-08-12 14:59:59 +0000157bool SkBlurMaskFilterImpl::filterMask(SkMask* dst, const SkMask& src,
reed@google.com30711b72012-12-18 19:18:39 +0000158 const SkMatrix& matrix,
159 SkIPoint* margin) const{
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000160 SkScalar sigma = this->computeXformedSigma(matrix);
reed@google.comdaaafa62014-04-29 15:20:16 +0000161 return SkBlurMask::BoxBlur(dst, src, sigma, fBlurStyle, this->getQuality(), margin);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000162}
163
humper@google.com7c5d7b72013-03-11 20:16:28 +0000164bool SkBlurMaskFilterImpl::filterRectMask(SkMask* dst, const SkRect& r,
165 const SkMatrix& matrix,
166 SkIPoint* margin, SkMask::CreateMode createMode) const{
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000167 SkScalar sigma = computeXformedSigma(matrix);
humper@google.com7c5d7b72013-03-11 20:16:28 +0000168
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000169 return SkBlurMask::BlurRect(sigma, dst, r, fBlurStyle,
humper@google.com7c5d7b72013-03-11 20:16:28 +0000170 margin, createMode);
171}
172
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000173bool SkBlurMaskFilterImpl::filterRRectMask(SkMask* dst, const SkRRect& r,
174 const SkMatrix& matrix,
175 SkIPoint* margin, SkMask::CreateMode createMode) const{
176 SkScalar sigma = computeXformedSigma(matrix);
177
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000178 return SkBlurMask::BlurRRect(sigma, dst, r, fBlurStyle,
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000179 margin, createMode);
180}
181
reed@google.comd729b3e2012-11-09 14:30:48 +0000182#include "SkCanvas.h"
183
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000184static bool prepare_to_draw_into_mask(const SkRect& bounds, SkMask* mask) {
185 SkASSERT(mask != NULL);
186
187 bounds.roundOut(&mask->fBounds);
reed@google.comd729b3e2012-11-09 14:30:48 +0000188 mask->fRowBytes = SkAlign4(mask->fBounds.width());
189 mask->fFormat = SkMask::kA8_Format;
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000190 const size_t size = mask->computeImageSize();
reed@google.comd729b3e2012-11-09 14:30:48 +0000191 mask->fImage = SkMask::AllocImage(size);
192 if (NULL == mask->fImage) {
193 return false;
194 }
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000195
196 // FIXME: use sk_calloc in AllocImage?
reed@google.comd729b3e2012-11-09 14:30:48 +0000197 sk_bzero(mask->fImage, size);
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000198 return true;
199}
200
201static bool draw_rrect_into_mask(const SkRRect rrect, SkMask* mask) {
202 if (!prepare_to_draw_into_mask(rrect.rect(), mask)) {
203 return false;
204 }
205
206 // FIXME: This code duplicates code in draw_rects_into_mask, below. Is there a
207 // clean way to share more code?
208 SkBitmap bitmap;
commit-bot@chromium.orgdac52252014-02-17 21:21:46 +0000209 bitmap.installMaskPixels(*mask);
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000210
211 SkCanvas canvas(bitmap);
212 canvas.translate(-SkIntToScalar(mask->fBounds.left()),
213 -SkIntToScalar(mask->fBounds.top()));
214
215 SkPaint paint;
216 paint.setAntiAlias(true);
217 canvas.drawRRect(rrect, paint);
218 return true;
219}
220
221static bool draw_rects_into_mask(const SkRect rects[], int count, SkMask* mask) {
222 if (!prepare_to_draw_into_mask(rects[0], mask)) {
223 return false;
224 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000225
226 SkBitmap bitmap;
commit-bot@chromium.orge24ad232014-02-16 22:03:38 +0000227 bitmap.installPixels(SkImageInfo::Make(mask->fBounds.width(),
228 mask->fBounds.height(),
229 kAlpha_8_SkColorType,
230 kPremul_SkAlphaType),
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +0000231 mask->fImage, mask->fRowBytes);
reed@google.comd729b3e2012-11-09 14:30:48 +0000232
233 SkCanvas canvas(bitmap);
reed@google.comdab9b4f2012-11-19 16:45:14 +0000234 canvas.translate(-SkIntToScalar(mask->fBounds.left()),
235 -SkIntToScalar(mask->fBounds.top()));
reed@google.comd729b3e2012-11-09 14:30:48 +0000236
237 SkPaint paint;
238 paint.setAntiAlias(true);
239
reed@google.comdab9b4f2012-11-19 16:45:14 +0000240 if (1 == count) {
241 canvas.drawRect(rects[0], paint);
242 } else {
243 // todo: do I need a fast way to do this?
244 SkPath path;
245 path.addRect(rects[0]);
246 path.addRect(rects[1]);
247 path.setFillType(SkPath::kEvenOdd_FillType);
248 canvas.drawPath(path, paint);
249 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000250 return true;
251}
252
reed@google.comf276fa72012-11-21 14:14:10 +0000253static bool rect_exceeds(const SkRect& r, SkScalar v) {
254 return r.fLeft < -v || r.fTop < -v || r.fRight > v || r.fBottom > v ||
255 r.width() > v || r.height() > v;
reed@google.com07784a02012-11-19 21:09:14 +0000256}
257
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000258#ifdef SK_IGNORE_FAST_RRECT_BLUR
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000259SK_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 +0000260#else
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000261SK_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 +0000262#endif
263
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000264SkMaskFilter::FilterReturn
265SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& matrix,
266 const SkIRect& clipBounds,
267 NinePatch* patch) const {
268 SkASSERT(patch != NULL);
269 switch (rrect.getType()) {
270 case SkRRect::kUnknown_Type:
271 // Unknown should never be returned.
272 SkASSERT(false);
273 // Fall through.
274 case SkRRect::kEmpty_Type:
275 // Nothing to draw.
276 return kFalse_FilterReturn;
277
278 case SkRRect::kRect_Type:
279 // We should have caught this earlier.
280 SkASSERT(false);
281 // Fall through.
282 case SkRRect::kOval_Type:
283 // The nine patch special case does not handle ovals, and we
284 // already have code for rectangles.
285 return kUnimplemented_FilterReturn;
286
commit-bot@chromium.orgf338d7c2014-03-17 21:17:30 +0000287 // These three can take advantage of this fast path.
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000288 case SkRRect::kSimple_Type:
commit-bot@chromium.orgf338d7c2014-03-17 21:17:30 +0000289 case SkRRect::kNinePatch_Type:
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000290 case SkRRect::kComplex_Type:
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000291 break;
292 }
293
294 // TODO: report correct metrics for innerstyle, where we do not grow the
295 // total bounds, but we do need an inset the size of our blur-radius
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000296 if (kInner_SkBlurStyle == fBlurStyle) {
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000297 return kUnimplemented_FilterReturn;
298 }
299
300 // TODO: take clipBounds into account to limit our coordinates up front
301 // for now, just skip too-large src rects (to take the old code path).
302 if (rect_exceeds(rrect.rect(), SkIntToScalar(32767))) {
303 return kUnimplemented_FilterReturn;
304 }
305
306 SkIPoint margin;
307 SkMask srcM, dstM;
308 rrect.rect().roundOut(&srcM.fBounds);
309 srcM.fImage = NULL;
310 srcM.fFormat = SkMask::kA8_Format;
311 srcM.fRowBytes = 0;
312
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000313 bool filterResult = false;
314 if (c_analyticBlurRRect) {
315 // special case for fast round rect blur
316 // don't actually do the blur the first time, just compute the correct size
317 filterResult = this->filterRRectMask(&dstM, rrect, matrix, &margin,
318 SkMask::kJustComputeBounds_CreateMode);
319 }
320
321 if (!filterResult) {
322 filterResult = this->filterMask(&dstM, srcM, matrix, &margin);
323 }
324
325 if (!filterResult) {
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000326 return kFalse_FilterReturn;
327 }
328
329 // Now figure out the appropriate width and height of the smaller round rectangle
330 // to stretch. It will take into account the larger radius per side as well as double
331 // the margin, to account for inner and outer blur.
332 const SkVector& UL = rrect.radii(SkRRect::kUpperLeft_Corner);
333 const SkVector& UR = rrect.radii(SkRRect::kUpperRight_Corner);
334 const SkVector& LR = rrect.radii(SkRRect::kLowerRight_Corner);
335 const SkVector& LL = rrect.radii(SkRRect::kLowerLeft_Corner);
336
337 const SkScalar leftUnstretched = SkTMax(UL.fX, LL.fX) + SkIntToScalar(2 * margin.fX);
338 const SkScalar rightUnstretched = SkTMax(UR.fX, LR.fX) + SkIntToScalar(2 * margin.fX);
339
340 // Extra space in the middle to ensure an unchanging piece for stretching. Use 3 to cover
341 // any fractional space on either side plus 1 for the part to stretch.
342 const SkScalar stretchSize = SkIntToScalar(3);
343
344 const SkScalar totalSmallWidth = leftUnstretched + rightUnstretched + stretchSize;
345 if (totalSmallWidth >= rrect.rect().width()) {
346 // There is no valid piece to stretch.
347 return kUnimplemented_FilterReturn;
348 }
349
350 const SkScalar topUnstretched = SkTMax(UL.fY, UR.fY) + SkIntToScalar(2 * margin.fY);
351 const SkScalar bottomUnstretched = SkTMax(LL.fY, LR.fY) + SkIntToScalar(2 * margin.fY);
352
353 const SkScalar totalSmallHeight = topUnstretched + bottomUnstretched + stretchSize;
354 if (totalSmallHeight >= rrect.rect().height()) {
355 // There is no valid piece to stretch.
356 return kUnimplemented_FilterReturn;
357 }
358
359 SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight);
360
361 SkRRect smallRR;
362 SkVector radii[4];
363 radii[SkRRect::kUpperLeft_Corner] = UL;
364 radii[SkRRect::kUpperRight_Corner] = UR;
365 radii[SkRRect::kLowerRight_Corner] = LR;
366 radii[SkRRect::kLowerLeft_Corner] = LL;
367 smallRR.setRectRadii(smallR, radii);
368
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000369 bool analyticBlurWorked = false;
370 if (c_analyticBlurRRect) {
371 analyticBlurWorked =
372 this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin,
373 SkMask::kComputeBoundsAndRenderImage_CreateMode);
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000374 }
375
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000376 if (!analyticBlurWorked) {
377 if (!draw_rrect_into_mask(smallRR, &srcM)) {
378 return kFalse_FilterReturn;
379 }
robertphillips@google.comad993582013-11-11 18:45:18 +0000380
commit-bot@chromium.orga4771542014-03-10 21:42:06 +0000381 SkAutoMaskFreeImage amf(srcM.fImage);
382
383 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
384 return kFalse_FilterReturn;
385 }
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000386 }
387
388 patch->fMask.fBounds.offsetTo(0, 0);
389 patch->fOuterRect = dstM.fBounds;
390 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1;
391 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1;
392 return kTrue_FilterReturn;
393}
394
humper@google.come86af1f2013-03-11 21:23:36 +0000395SK_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 +0000396
reed@google.comd729b3e2012-11-09 14:30:48 +0000397SkMaskFilter::FilterReturn
reed@google.comdab9b4f2012-11-19 16:45:14 +0000398SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count,
399 const SkMatrix& matrix,
400 const SkIRect& clipBounds,
reed@google.com30711b72012-12-18 19:18:39 +0000401 NinePatch* patch) const {
reed@google.comdab9b4f2012-11-19 16:45:14 +0000402 if (count < 1 || count > 2) {
403 return kUnimplemented_FilterReturn;
404 }
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000405
reed@google.com57850b92012-12-17 21:20:53 +0000406 // TODO: report correct metrics for innerstyle, where we do not grow the
407 // total bounds, but we do need an inset the size of our blur-radius
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000408 if (kInner_SkBlurStyle == fBlurStyle || kOuter_SkBlurStyle == fBlurStyle) {
reed@google.com57850b92012-12-17 21:20:53 +0000409 return kUnimplemented_FilterReturn;
410 }
411
reed@google.com07784a02012-11-19 21:09:14 +0000412 // TODO: take clipBounds into account to limit our coordinates up front
413 // for now, just skip too-large src rects (to take the old code path).
reed@google.comf276fa72012-11-21 14:14:10 +0000414 if (rect_exceeds(rects[0], SkIntToScalar(32767))) {
reed@google.com07784a02012-11-19 21:09:14 +0000415 return kUnimplemented_FilterReturn;
416 }
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000417
reed@google.comd729b3e2012-11-09 14:30:48 +0000418 SkIPoint margin;
419 SkMask srcM, dstM;
reed@google.comdab9b4f2012-11-19 16:45:14 +0000420 rects[0].roundOut(&srcM.fBounds);
reed@google.comd729b3e2012-11-09 14:30:48 +0000421 srcM.fImage = NULL;
422 srcM.fFormat = SkMask::kA8_Format;
423 srcM.fRowBytes = 0;
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000424
humper@google.com7c5d7b72013-03-11 20:16:28 +0000425 bool filterResult = false;
426 if (count == 1 && c_analyticBlurNinepatch) {
427 // special case for fast rect blur
428 // don't actually do the blur the first time, just compute the correct size
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000429 filterResult = this->filterRectMask(&dstM, rects[0], matrix, &margin,
humper@google.com7c5d7b72013-03-11 20:16:28 +0000430 SkMask::kJustComputeBounds_CreateMode);
431 } else {
432 filterResult = this->filterMask(&dstM, srcM, matrix, &margin);
433 }
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000434
humper@google.com7c5d7b72013-03-11 20:16:28 +0000435 if (!filterResult) {
reed@google.comd729b3e2012-11-09 14:30:48 +0000436 return kFalse_FilterReturn;
437 }
438
439 /*
440 * smallR is the smallest version of 'rect' that will still guarantee that
441 * we get the same blur results on all edges, plus 1 center row/col that is
442 * representative of the extendible/stretchable edges of the ninepatch.
443 * Since our actual edge may be fractional we inset 1 more to be sure we
444 * don't miss any interior blur.
445 * x is an added pixel of blur, and { and } are the (fractional) edge
446 * pixels from the original rect.
447 *
448 * x x { x x .... x x } x x
449 *
450 * Thus, in this case, we inset by a total of 5 (on each side) beginning
451 * with our outer-rect (dstM.fBounds)
452 */
reed@google.comdab9b4f2012-11-19 16:45:14 +0000453 SkRect smallR[2];
454 SkIPoint center;
455
456 // +2 is from +1 for each edge (to account for possible fractional edges
457 int smallW = dstM.fBounds.width() - srcM.fBounds.width() + 2;
458 int smallH = dstM.fBounds.height() - srcM.fBounds.height() + 2;
459 SkIRect innerIR;
460
461 if (1 == count) {
462 innerIR = srcM.fBounds;
463 center.set(smallW, smallH);
464 } else {
465 SkASSERT(2 == count);
466 rects[1].roundIn(&innerIR);
467 center.set(smallW + (innerIR.left() - srcM.fBounds.left()),
468 smallH + (innerIR.top() - srcM.fBounds.top()));
reed@google.comd729b3e2012-11-09 14:30:48 +0000469 }
470
reed@google.comdab9b4f2012-11-19 16:45:14 +0000471 // +1 so we get a clean, stretchable, center row/col
472 smallW += 1;
473 smallH += 1;
474
475 // we want the inset amounts to be integral, so we don't change any
476 // fractional phase on the fRight or fBottom of our smallR.
477 const SkScalar dx = SkIntToScalar(innerIR.width() - smallW);
478 const SkScalar dy = SkIntToScalar(innerIR.height() - smallH);
479 if (dx < 0 || dy < 0) {
480 // we're too small, relative to our blur, to break into nine-patch,
481 // so we ask to have our normal filterMask() be called.
482 return kUnimplemented_FilterReturn;
483 }
484
485 smallR[0].set(rects[0].left(), rects[0].top(), rects[0].right() - dx, rects[0].bottom() - dy);
robertphillips@google.com112a23e2013-09-03 17:17:43 +0000486 if (smallR[0].width() < 2 || smallR[0].height() < 2) {
487 return kUnimplemented_FilterReturn;
488 }
reed@google.comdab9b4f2012-11-19 16:45:14 +0000489 if (2 == count) {
490 smallR[1].set(rects[1].left(), rects[1].top(),
491 rects[1].right() - dx, rects[1].bottom() - dy);
492 SkASSERT(!smallR[1].isEmpty());
493 }
494
humper@google.com7c5d7b72013-03-11 20:16:28 +0000495 if (count > 1 || !c_analyticBlurNinepatch) {
scroggo@google.coma8e33a92013-11-08 18:02:53 +0000496 if (!draw_rects_into_mask(smallR, count, &srcM)) {
humper@google.com7c5d7b72013-03-11 20:16:28 +0000497 return kFalse_FilterReturn;
498 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000499
humper@google.com7c5d7b72013-03-11 20:16:28 +0000500 SkAutoMaskFreeImage amf(srcM.fImage);
reed@google.comd198a5b2012-11-27 15:18:04 +0000501
humper@google.com7c5d7b72013-03-11 20:16:28 +0000502 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
503 return kFalse_FilterReturn;
504 }
505 } else {
skia.committer@gmail.com2e71f162013-03-12 07:12:32 +0000506 if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin,
humper@google.com7c5d7b72013-03-11 20:16:28 +0000507 SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
508 return kFalse_FilterReturn;
509 }
reed@google.comd729b3e2012-11-09 14:30:48 +0000510 }
reed@google.comdab9b4f2012-11-19 16:45:14 +0000511 patch->fMask.fBounds.offsetTo(0, 0);
512 patch->fOuterRect = dstM.fBounds;
513 patch->fCenter = center;
reed@google.comd729b3e2012-11-09 14:30:48 +0000514 return kTrue_FilterReturn;
515}
516
reed@google.com30711b72012-12-18 19:18:39 +0000517void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src,
518 SkRect* dst) const {
robertphillips@google.com7ce661d2013-08-27 16:14:03 +0000519 SkScalar pad = 3.0f * fSigma;
robertphillips@google.com17ad2bd2013-07-30 12:15:19 +0000520
521 dst->set(src.fLeft - pad, src.fTop - pad,
522 src.fRight + pad, src.fBottom + pad);
reed@google.com9efd9a02012-01-30 15:41:43 +0000523}
524
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000525SkBlurMaskFilterImpl::SkBlurMaskFilterImpl(SkReadBuffer& buffer)
reed@google.com03016a32011-08-12 14:59:59 +0000526 : SkMaskFilter(buffer) {
commit-bot@chromium.orgfed2ab62014-01-23 15:16:05 +0000527 fSigma = buffer.readScalar();
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000528 fBlurStyle = (SkBlurStyle)buffer.readInt();
djsollen@google.comc73dd5c2012-08-07 15:54:32 +0000529 fBlurFlags = buffer.readUInt() & SkBlurMaskFilter::kAll_BlurFlag;
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000530 SkASSERT(fSigma > 0);
531 SkASSERT((unsigned)fBlurStyle <= kLastEnum_SkBlurStyle);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000532}
533
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000534void SkBlurMaskFilterImpl::flatten(SkWriteBuffer& buffer) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000535 this->INHERITED::flatten(buffer);
robertphillips@google.com11e05552013-12-03 19:46:58 +0000536 buffer.writeScalar(fSigma);
djsollen@google.comc73dd5c2012-08-07 15:54:32 +0000537 buffer.writeInt(fBlurStyle);
538 buffer.writeUInt(fBlurFlags);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000539}
540
robertphillips@google.com49149312013-07-03 15:34:35 +0000541#if SK_SUPPORT_GPU
reed@google.com2b75f422011-07-07 13:43:38 +0000542
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000543class GrGLRectBlurEffect;
544
545class GrRectBlurEffect : public GrEffect {
546public:
547 virtual ~GrRectBlurEffect();
548
549 static const char* Name() { return "RectBlur"; }
550
551 typedef GrGLRectBlurEffect GLEffect;
552
553 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
554 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
555
556 /**
557 * Create a simple filter effect with custom bicubic coefficients.
558 */
bsalomon83d081a2014-07-08 09:56:10 -0700559 static GrEffect* Create(GrContext *context, const SkRect& rect, 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 }
bsalomon55fad7a2014-07-08 07:34:20 -0700575 return SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture));
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000576 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000577
humper4a24cd82014-06-17 13:39:29 -0700578 const SkRect& getRect() const { return fRect; }
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000579 float getSigma() const { return fSigma; }
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000580
581private:
humper4a24cd82014-06-17 13:39:29 -0700582 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile);
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000583 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000584
humper4a24cd82014-06-17 13:39:29 -0700585 static bool CreateBlurProfileTexture(GrContext *context, float sigma,
586 GrTexture **blurProfileTexture);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000587
humper4a24cd82014-06-17 13:39:29 -0700588 SkRect fRect;
589 float fSigma;
590 GrTextureAccess fBlurProfileAccess;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000591
592 GR_DECLARE_EFFECT_TEST;
593
594 typedef GrEffect INHERITED;
595};
596
597class GrGLRectBlurEffect : public GrGLEffect {
598public:
599 GrGLRectBlurEffect(const GrBackendEffectFactory& factory,
600 const GrDrawEffect&);
601 virtual void emitCode(GrGLShaderBuilder*,
602 const GrDrawEffect&,
603 EffectKey,
604 const char* outputColor,
605 const char* inputColor,
606 const TransformedCoordsArray&,
607 const TextureSamplerArray&) SK_OVERRIDE;
608
609 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
610
611private:
612 typedef GrGLUniformManager::UniformHandle UniformHandle;
613
humper4a24cd82014-06-17 13:39:29 -0700614 UniformHandle fProxyRectUniform;
615 UniformHandle fProfileSizeUniform;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000616
617 typedef GrGLEffect INHERITED;
618};
619
humper4a24cd82014-06-17 13:39:29 -0700620
621
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000622GrGLRectBlurEffect::GrGLRectBlurEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
623 : INHERITED(factory) {
624}
625
humper4a24cd82014-06-17 13:39:29 -0700626void OutputRectBlurProfileLookup(GrGLShaderBuilder* builder,
627 const GrGLShaderBuilder::TextureSampler& sampler,
628 const char *output,
629 const char *profileSize, const char *loc,
630 const char *blurred_width,
631 const char *sharp_width) {
632 builder->fsCodeAppendf("\tfloat %s;\n", output);
633 builder->fsCodeAppendf("\t\t{\n");
634 builder->fsCodeAppendf("\t\t\tfloat coord = (0.5 * (abs(2.0*%s - %s) - %s))/%s;\n",
635 loc, blurred_width, sharp_width, profileSize);
636 builder->fsCodeAppendf("\t\t\t%s = ", output);
637 builder->fsAppendTextureLookup(sampler, "vec2(coord,0.5)");
638 builder->fsCodeAppend(".a;\n");
639 builder->fsCodeAppendf("\t\t}\n");
640}
641
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000642void GrGLRectBlurEffect::emitCode(GrGLShaderBuilder* builder,
643 const GrDrawEffect&,
644 EffectKey key,
645 const char* outputColor,
646 const char* inputColor,
647 const TransformedCoordsArray& coords,
648 const TextureSamplerArray& samplers) {
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000649
humper4a24cd82014-06-17 13:39:29 -0700650 const char *rectName;
651 const char *profileSizeName;
652
653 fProxyRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
654 kVec4f_GrSLType,
655 "proxyRect",
656 &rectName);
657 fProfileSizeUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
658 kFloat_GrSLType,
659 "profileSize",
660 &profileSizeName);
661
662 const char *fragmentPos = builder->fragmentPosition();
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000663
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000664 if (inputColor) {
665 builder->fsCodeAppendf("\tvec4 src=%s;\n", inputColor);
666 } else {
667 builder->fsCodeAppendf("\tvec4 src=vec4(1)\n;");
668 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000669
humper4a24cd82014-06-17 13:39:29 -0700670 builder->fsCodeAppendf("\tvec2 translatedPos = %s.xy - %s.xy;\n", fragmentPos, rectName );
671 builder->fsCodeAppendf("\tfloat width = %s.z - %s.x;\n", rectName, rectName);
672 builder->fsCodeAppendf("\tfloat height = %s.w - %s.y;\n", rectName, rectName);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000673
humper4a24cd82014-06-17 13:39:29 -0700674 builder->fsCodeAppendf("\tvec2 smallDims = vec2(width - %s, height-%s);\n", profileSizeName, profileSizeName);
675 builder->fsCodeAppendf("\tfloat center = 2.0 * floor(%s/2.0 + .25) - 1.0;\n", profileSizeName);
676 builder->fsCodeAppendf("\tvec2 wh = smallDims - vec2(center,center);\n");
677
678 OutputRectBlurProfileLookup(builder, samplers[0], "horiz_lookup", profileSizeName, "translatedPos.x", "width", "wh.x");
679 OutputRectBlurProfileLookup(builder, samplers[0], "vert_lookup", profileSizeName, "translatedPos.y", "height", "wh.y");
680
681 builder->fsCodeAppendf("\tfloat final = horiz_lookup * vert_lookup;\n");
682 builder->fsCodeAppendf("\t%s = src * vec4(final);\n", outputColor );
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000683}
684
685void GrGLRectBlurEffect::setData(const GrGLUniformManager& uman,
humper4a24cd82014-06-17 13:39:29 -0700686 const GrDrawEffect& drawEffect) {
687 const GrRectBlurEffect& rbe = drawEffect.castEffect<GrRectBlurEffect>();
688 SkRect rect = rbe.getRect();
689
690 uman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
691 uman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma()));
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000692}
693
humper4a24cd82014-06-17 13:39:29 -0700694bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma,
695 GrTexture **blurProfileTexture) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000696 GrTextureParams params;
697 GrTextureDesc texDesc;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000698
humper4a24cd82014-06-17 13:39:29 -0700699 unsigned int profile_size = SkScalarCeilToInt(6*sigma);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000700
humper4a24cd82014-06-17 13:39:29 -0700701 texDesc.fWidth = profile_size;
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000702 texDesc.fHeight = 1;
703 texDesc.fConfig = kAlpha_8_GrPixelConfig;
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000704
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000705 static const GrCacheID::Domain gBlurProfileDomain = GrCacheID::GenerateDomain();
706 GrCacheID::Key key;
707 memset(&key, 0, sizeof(key));
708 key.fData32[0] = profile_size;
humper4a24cd82014-06-17 13:39:29 -0700709 key.fData32[1] = 1;
710 GrCacheID blurProfileKey(gBlurProfileDomain, key);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000711
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000712 uint8_t *profile = NULL;
commit-bot@chromium.orgcc787fa2014-01-31 01:00:49 +0000713 SkAutoTDeleteArray<uint8_t> ada(NULL);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000714
humper4a24cd82014-06-17 13:39:29 -0700715 *blurProfileTexture = context->findAndRefTexture(texDesc, blurProfileKey, &params);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000716
humper4a24cd82014-06-17 13:39:29 -0700717 if (NULL == *blurProfileTexture) {
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000718
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000719 SkBlurMask::ComputeBlurProfile(sigma, &profile);
commit-bot@chromium.orgcc787fa2014-01-31 01:00:49 +0000720 ada.reset(profile);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000721
humper4a24cd82014-06-17 13:39:29 -0700722 *blurProfileTexture = context->createTexture(&params, texDesc, blurProfileKey,
723 profile, 0);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000724
humper4a24cd82014-06-17 13:39:29 -0700725 if (NULL == *blurProfileTexture) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000726 return false;
727 }
728 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000729
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000730 return true;
731}
732
733GrRectBlurEffect::GrRectBlurEffect(const SkRect& rect, float sigma,
humper4a24cd82014-06-17 13:39:29 -0700734 GrTexture *blur_profile)
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000735 : INHERITED(),
humper4a24cd82014-06-17 13:39:29 -0700736 fRect(rect),
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000737 fSigma(sigma),
humper4a24cd82014-06-17 13:39:29 -0700738 fBlurProfileAccess(blur_profile) {
739 this->addTextureAccess(&fBlurProfileAccess);
740 this->setWillReadFragmentPosition();
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000741}
742
743GrRectBlurEffect::~GrRectBlurEffect() {
744}
745
746const GrBackendEffectFactory& GrRectBlurEffect::getFactory() const {
747 return GrTBackendEffectFactory<GrRectBlurEffect>::getInstance();
748}
749
750bool GrRectBlurEffect::onIsEqual(const GrEffect& sBase) const {
751 const GrRectBlurEffect& s = CastEffect<GrRectBlurEffect>(sBase);
humper4a24cd82014-06-17 13:39:29 -0700752 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect();
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000753}
754
755void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
756 *validFlags = 0;
757 return;
758}
759
760GR_DEFINE_EFFECT_TEST(GrRectBlurEffect);
761
bsalomon83d081a2014-07-08 09:56:10 -0700762GrEffect* GrRectBlurEffect::TestCreate(SkRandom* random,
763 GrContext* context,
764 const GrDrawTargetCaps&,
765 GrTexture**) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000766 float sigma = random->nextRangeF(3,8);
767 float width = random->nextRangeF(200,300);
768 float height = random->nextRangeF(200,300);
769 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigma);
770}
771
772
773bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
774 GrPaint* grp,
775 const SkStrokeRec& strokeRec,
776 const SkPath& path) const {
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000777 if (fBlurStyle != kNormal_SkBlurStyle) {
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000778 return false;
779 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000780
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000781 SkRect rect;
782 if (!path.isRect(&rect)) {
783 return false;
784 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000785
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000786 if (!strokeRec.isFillStyle()) {
787 return false;
788 }
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000789
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000790 SkMatrix ctm = context->getMatrix();
791 SkScalar xformedSigma = this->computeXformedSigma(ctm);
humper4a24cd82014-06-17 13:39:29 -0700792
793 int pad=SkScalarCeilToInt(6*xformedSigma)/2;
794 rect.outset(SkIntToScalar(pad), SkIntToScalar(pad));
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000795
bsalomon83d081a2014-07-08 09:56:10 -0700796 SkAutoTUnref<GrEffect> effect(GrRectBlurEffect::Create(context, rect, xformedSigma));
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000797 if (!effect) {
798 return false;
799 }
800
801 GrContext::AutoMatrix am;
802 if (!am.setIdentity(context, grp)) {
803 return false;
804 }
805
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000806 grp->addCoverageEffect(effect);
skia.committer@gmail.com4c18e9f2014-01-31 03:01:59 +0000807
commit-bot@chromium.orgcf34bc02014-01-30 15:34:43 +0000808 context->drawRect(*grp, rect);
809 return true;
810}
811
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000812class GrGLRRectBlurEffect;
813
814class GrRRectBlurEffect : public GrEffect {
815public:
816
bsalomon83d081a2014-07-08 09:56:10 -0700817 static GrEffect* Create(GrContext* context, float sigma, const SkRRect&);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000818
819 virtual ~GrRRectBlurEffect() {};
820 static const char* Name() { return "GrRRectBlur"; }
821
822 const SkRRect& getRRect() const { return fRRect; }
823 float getSigma() const { return fSigma; }
824
825 typedef GrGLRRectBlurEffect GLEffect;
826
827 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
828
829 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
830
831private:
832 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture);
833
834 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
835
836 SkRRect fRRect;
837 float fSigma;
838 GrTextureAccess fNinePatchAccess;
839
840 GR_DECLARE_EFFECT_TEST;
841
842 typedef GrEffect INHERITED;
843};
844
845
bsalomon83d081a2014-07-08 09:56:10 -0700846GrEffect* GrRRectBlurEffect::Create(GrContext* context, float sigma, const SkRRect& rrect) {
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000847 if (!rrect.isSimpleCircular()) {
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000848 return NULL;
849 }
850
851 // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be
852 // sufficiently small relative to both the size of the corner radius and the
853 // width (and height) of the rrect.
854
855 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f);
856 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x());
857 if (cornerRadius + blurRadius > rrect.width()/2 ||
858 cornerRadius + blurRadius > rrect.height()/2) {
859 return NULL;
860 }
861
862 static const GrCacheID::Domain gRRectBlurDomain = GrCacheID::GenerateDomain();
863 GrCacheID::Key key;
864 memset(&key, 0, sizeof(key));
865 key.fData32[0] = blurRadius;
866 key.fData32[1] = cornerRadius;
867 GrCacheID blurRRectNinePatchID(gRRectBlurDomain, key);
868
869 GrTextureParams params;
870 params.setFilterMode(GrTextureParams::kBilerp_FilterMode);
871
872 unsigned int smallRectSide = 2*(blurRadius + cornerRadius) + 1;
873 unsigned int texSide = smallRectSide + 2*blurRadius;
874 GrTextureDesc texDesc;
875 texDesc.fWidth = texSide;
876 texDesc.fHeight = texSide;
877 texDesc.fConfig = kAlpha_8_GrPixelConfig;
878
879 GrTexture *blurNinePatchTexture = context->findAndRefTexture(texDesc, blurRRectNinePatchID, &params);
880
881 if (NULL == blurNinePatchTexture) {
882 SkMask mask;
883
884 mask.fBounds = SkIRect::MakeWH(smallRectSide, smallRectSide);
885 mask.fFormat = SkMask::kA8_Format;
886 mask.fRowBytes = mask.fBounds.width();
887 mask.fImage = SkMask::AllocImage(mask.computeTotalImageSize());
888 SkAutoMaskFreeImage amfi(mask.fImage);
889
890 memset(mask.fImage, 0, mask.computeTotalImageSize());
891
892 SkRect smallRect;
893 smallRect.setWH(SkIntToScalar(smallRectSide), SkIntToScalar(smallRectSide));
894
895 SkRRect smallRRect;
896 smallRRect.setRectXY(smallRect, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
897
898 SkPath path;
899 path.addRRect( smallRRect );
900
901 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_Style);
902
903 SkMask blurred_mask;
904 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHigh_SkBlurQuality, NULL, true );
905
906 blurNinePatchTexture = context->createTexture(&params, texDesc, blurRRectNinePatchID, blurred_mask.fImage, 0);
commit-bot@chromium.org6b127cd2014-04-29 04:41:33 +0000907 SkMask::FreeImage(blurred_mask.fImage);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000908 }
909
commit-bot@chromium.org6b127cd2014-04-29 04:41:33 +0000910 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000911 if (NULL == blurNinePatchTexture) {
912 return NULL;
913 }
914
bsalomon55fad7a2014-07-08 07:34:20 -0700915 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture));
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000916}
917
918void GrRRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
919 *validFlags = 0;
920}
921
922const GrBackendEffectFactory& GrRRectBlurEffect::getFactory() const {
923 return GrTBackendEffectFactory<GrRRectBlurEffect>::getInstance();
924}
925
926GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTexture *ninePatchTexture)
927 : fRRect(rrect),
928 fSigma(sigma),
929 fNinePatchAccess(ninePatchTexture) {
930 this->addTextureAccess(&fNinePatchAccess);
931 this->setWillReadFragmentPosition();
932}
933
934bool GrRRectBlurEffect::onIsEqual(const GrEffect& other) const {
935 const GrRRectBlurEffect& rrbe = CastEffect<GrRRectBlurEffect>(other);
936 return fRRect.getSimpleRadii().fX == rrbe.fRRect.getSimpleRadii().fX && fSigma == rrbe.fSigma;
937}
938
939//////////////////////////////////////////////////////////////////////////////
940
941GR_DEFINE_EFFECT_TEST(GrRRectBlurEffect);
942
bsalomon83d081a2014-07-08 09:56:10 -0700943GrEffect* GrRRectBlurEffect::TestCreate(SkRandom* random,
944 GrContext* context,
945 const GrDrawTargetCaps& caps,
946 GrTexture*[]) {
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +0000947 SkScalar w = random->nextRangeScalar(100.f, 1000.f);
948 SkScalar h = random->nextRangeScalar(100.f, 1000.f);
949 SkScalar r = random->nextRangeF(1.f, 9.f);
950 SkScalar sigma = random->nextRangeF(1.f,10.f);
951 SkRRect rrect;
952 rrect.setRectXY(SkRect::MakeWH(w, h), r, r);
953 return GrRRectBlurEffect::Create(context, sigma, rrect);
954}
955
956//////////////////////////////////////////////////////////////////////////////
957
958class GrGLRRectBlurEffect : public GrGLEffect {
959public:
960 GrGLRRectBlurEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
961
962 virtual void emitCode(GrGLShaderBuilder* builder,
963 const GrDrawEffect& drawEffect,
964 EffectKey key,
965 const char* outputColor,
966 const char* inputColor,
967 const TransformedCoordsArray&,
968 const TextureSamplerArray&) SK_OVERRIDE;
969
970 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
971
972private:
973 GrGLUniformManager::UniformHandle fProxyRectUniform;
974 GrGLUniformManager::UniformHandle fCornerRadiusUniform;
975 GrGLUniformManager::UniformHandle fBlurRadiusUniform;
976 typedef GrGLEffect INHERITED;
977};
978
979GrGLRRectBlurEffect::GrGLRRectBlurEffect(const GrBackendEffectFactory& factory,
980 const GrDrawEffect& drawEffect)
981 : INHERITED (factory) {
982}
983
984void GrGLRRectBlurEffect::emitCode(GrGLShaderBuilder* builder,
985 const GrDrawEffect& drawEffect,
986 EffectKey key,
987 const char* outputColor,
988 const char* inputColor,
989 const TransformedCoordsArray&,
990 const TextureSamplerArray& samplers) {
991 const char *rectName;
992 const char *cornerRadiusName;
993 const char *blurRadiusName;
994
995 // The proxy rect has left, top, right, and bottom edges correspond to
996 // components x, y, z, and w, respectively.
997
998 fProxyRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
999 kVec4f_GrSLType,
1000 "proxyRect",
1001 &rectName);
1002 fCornerRadiusUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1003 kFloat_GrSLType,
1004 "cornerRadius",
1005 &cornerRadiusName);
1006 fBlurRadiusUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1007 kFloat_GrSLType,
1008 "blurRadius",
1009 &blurRadiusName);
1010 const char* fragmentPos = builder->fragmentPosition();
1011
1012 // warp the fragment position to the appropriate part of the 9patch blur texture
1013
1014 builder->fsCodeAppendf("\t\tvec2 rectCenter = (%s.xy + %s.zw)/2.0;\n", rectName, rectName);
bsalomon22900002014-06-24 11:16:52 -07001015 builder->fsCodeAppendf("\t\tvec2 translatedFragPos = %s.xy - %s.xy;\n", fragmentPos, rectName);
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001016 builder->fsCodeAppendf("\t\tfloat threshold = %s + 2.0*%s;\n", cornerRadiusName, blurRadiusName );
1017 builder->fsCodeAppendf("\t\tvec2 middle = %s.zw - %s.xy - 2.0*threshold;\n", rectName, rectName );
1018
1019 builder->fsCodeAppendf("\t\tif (translatedFragPos.x >= threshold && translatedFragPos.x < (middle.x+threshold)) {\n" );
1020 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.x = threshold;\n");
1021 builder->fsCodeAppendf("\t\t} else if (translatedFragPos.x >= (middle.x + threshold)) {\n");
commit-bot@chromium.org7ba17022014-05-19 18:51:05 +00001022 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.x -= middle.x - 1.0;\n");
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001023 builder->fsCodeAppendf("\t\t}\n");
1024
1025 builder->fsCodeAppendf("\t\tif (translatedFragPos.y > threshold && translatedFragPos.y < (middle.y+threshold)) {\n" );
1026 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.y = threshold;\n");
1027 builder->fsCodeAppendf("\t\t} else if (translatedFragPos.y >= (middle.y + threshold)) {\n");
commit-bot@chromium.org7ba17022014-05-19 18:51:05 +00001028 builder->fsCodeAppendf("\t\t\ttranslatedFragPos.y -= middle.y - 1.0;\n");
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001029 builder->fsCodeAppendf("\t\t}\n");
1030
1031 builder->fsCodeAppendf("\t\tvec2 proxyDims = vec2(2.0*threshold+1.0);\n");
1032 builder->fsCodeAppendf("\t\tvec2 texCoord = translatedFragPos / proxyDims;\n");
1033
1034 builder->fsCodeAppendf("\t%s = ", outputColor);
1035 builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "texCoord");
1036 builder->fsCodeAppend(";\n");
1037}
1038
1039void GrGLRRectBlurEffect::setData(const GrGLUniformManager& uman,
1040 const GrDrawEffect& drawEffect) {
1041 const GrRRectBlurEffect& brre = drawEffect.castEffect<GrRRectBlurEffect>();
1042 SkRRect rrect = brre.getRRect();
1043
1044 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f);
1045 uman.set1f(fBlurRadiusUniform, blurRadius);
1046
1047 SkRect rect = rrect.getBounds();
1048 rect.outset(blurRadius, blurRadius);
1049 uman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
1050
1051 SkScalar radius = 0;
1052 SkASSERT(rrect.isSimpleCircular() || rrect.isRect());
1053 radius = rrect.getSimpleRadii().fX;
1054 uman.set1f(fCornerRadiusUniform, radius);
1055}
1056
1057
commit-bot@chromium.org82139702014-03-10 22:53:20 +00001058bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrContext* context,
1059 GrPaint* grp,
1060 const SkStrokeRec& strokeRec,
1061 const SkRRect& rrect) const {
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001062 if (fBlurStyle != kNormal_SkBlurStyle) {
1063 return false;
1064 }
1065
1066 if (!strokeRec.isFillStyle()) {
1067 return false;
1068 }
1069
1070 SkRect proxy_rect = rrect.rect();
1071 SkMatrix ctm = context->getMatrix();
1072 SkScalar xformedSigma = this->computeXformedSigma(ctm);
1073 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f);
1074 proxy_rect.outset(extra, extra);
1075
bsalomon83d081a2014-07-08 09:56:10 -07001076 SkAutoTUnref<GrEffect> effect(GrRRectBlurEffect::Create(
commit-bot@chromium.org3d8bf232014-04-28 19:49:24 +00001077 context, xformedSigma, rrect));
1078 if (!effect) {
1079 return false;
1080 }
1081
1082 GrContext::AutoMatrix am;
1083 if (!am.setIdentity(context, grp)) {
1084 return false;
1085 }
1086
1087 grp->addCoverageEffect(effect);
1088
1089 context->drawRect(*grp, proxy_rect);
1090 return true;
commit-bot@chromium.org82139702014-03-10 22:53:20 +00001091}
1092
robertphillips@google.com49149312013-07-03 15:34:35 +00001093bool SkBlurMaskFilterImpl::canFilterMaskGPU(const SkRect& srcBounds,
1094 const SkIRect& clipBounds,
1095 const SkMatrix& ctm,
1096 SkRect* maskRect) const {
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001097 SkScalar xformedSigma = this->computeXformedSigma(ctm);
1098 if (xformedSigma <= 0) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001099 return false;
reed@google.com2b75f422011-07-07 13:43:38 +00001100 }
robertphillips@google.com49149312013-07-03 15:34:35 +00001101
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001102 static const SkScalar kMIN_GPU_BLUR_SIZE = SkIntToScalar(64);
1103 static const SkScalar kMIN_GPU_BLUR_SIGMA = SkIntToScalar(32);
robertphillips@google.com49149312013-07-03 15:34:35 +00001104
1105 if (srcBounds.width() <= kMIN_GPU_BLUR_SIZE &&
1106 srcBounds.height() <= kMIN_GPU_BLUR_SIZE &&
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001107 xformedSigma <= kMIN_GPU_BLUR_SIGMA) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001108 // We prefer to blur small rect with small radius via CPU.
1109 return false;
1110 }
1111
1112 if (NULL == maskRect) {
1113 // don't need to compute maskRect
1114 return true;
1115 }
1116
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001117 float sigma3 = 3 * SkScalarToFloat(xformedSigma);
robertphillips@google.com49149312013-07-03 15:34:35 +00001118
reed@google.com44699382013-10-31 17:28:30 +00001119 SkRect clipRect = SkRect::Make(clipBounds);
robertphillips@google.com49149312013-07-03 15:34:35 +00001120 SkRect srcRect(srcBounds);
1121
1122 // Outset srcRect and clipRect by 3 * sigma, to compute affected blur area.
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001123 srcRect.outset(sigma3, sigma3);
1124 clipRect.outset(sigma3, sigma3);
robertphillips@google.com49149312013-07-03 15:34:35 +00001125 srcRect.intersect(clipRect);
1126 *maskRect = srcRect;
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +00001127 return true;
reed@google.com2b75f422011-07-07 13:43:38 +00001128}
1129
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +00001130bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
commit-bot@chromium.org439ff1b2014-01-13 16:39:39 +00001131 const SkMatrix& ctm,
skia.committer@gmail.com1842adf2013-07-04 07:01:07 +00001132 const SkRect& maskRect,
robertphillips@google.com49149312013-07-03 15:34:35 +00001133 GrTexture** result,
1134 bool canOverwriteSrc) const {
1135 SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
1136
1137 GrContext* context = src->getContext();
1138
1139 GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
1140
commit-bot@chromium.org439ff1b2014-01-13 16:39:39 +00001141 SkScalar xformedSigma = this->computeXformedSigma(ctm);
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001142 SkASSERT(xformedSigma > 0);
robertphillips@google.com49149312013-07-03 15:34:35 +00001143
1144 // If we're doing a normal blur, we can clobber the pathTexture in the
1145 // gaussianBlur. Otherwise, we need to save it for later compositing.
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001146 bool isNormalBlur = (kNormal_SkBlurStyle == fBlurStyle);
robertphillips@google.com736dd032013-07-15 15:06:54 +00001147 *result = SkGpuBlurUtils::GaussianBlur(context, src, isNormalBlur && canOverwriteSrc,
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001148 clipRect, false, xformedSigma, xformedSigma);
robertphillips@google.com3cc820c2013-07-03 19:36:55 +00001149 if (NULL == *result) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001150 return false;
1151 }
1152
1153 if (!isNormalBlur) {
1154 context->setIdentityMatrix();
1155 GrPaint paint;
1156 SkMatrix matrix;
1157 matrix.setIDiv(src->width(), src->height());
1158 // Blend pathTexture over blurTexture.
1159 GrContext::AutoRenderTarget art(context, (*result)->asRenderTarget());
commit-bot@chromium.org42dacab2013-07-13 17:24:24 +00001160 paint.addColorEffect(GrSimpleTextureEffect::Create(src, matrix))->unref();
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001161 if (kInner_SkBlurStyle == fBlurStyle) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001162 // inner: dst = dst * src
1163 paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001164 } else if (kSolid_SkBlurStyle == fBlurStyle) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001165 // solid: dst = src + dst - src * dst
1166 // = (1 - dst) * src + 1 * dst
1167 paint.setBlendFunc(kIDC_GrBlendCoeff, kOne_GrBlendCoeff);
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001168 } else if (kOuter_SkBlurStyle == fBlurStyle) {
robertphillips@google.com49149312013-07-03 15:34:35 +00001169 // outer: dst = dst * (1 - src)
1170 // = 0 * src + (1 - src) * dst
1171 paint.setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff);
1172 }
1173 context->drawRect(paint, clipRect);
1174 }
1175
1176 return true;
1177}
1178
1179#endif // SK_SUPPORT_GPU
1180
1181
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +00001182#ifndef SK_IGNORE_TO_STRING
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001183void SkBlurMaskFilterImpl::toString(SkString* str) const {
1184 str->append("SkBlurMaskFilterImpl: (");
1185
robertphillips@google.com7ce661d2013-08-27 16:14:03 +00001186 str->append("sigma: ");
1187 str->appendScalar(fSigma);
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001188 str->append(" ");
1189
commit-bot@chromium.orge3964552014-04-28 16:25:35 +00001190 static const char* gStyleName[kLastEnum_SkBlurStyle + 1] = {
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001191 "normal", "solid", "outer", "inner"
1192 };
1193
1194 str->appendf("style: %s ", gStyleName[fBlurStyle]);
1195 str->append("flags: (");
1196 if (fBlurFlags) {
1197 bool needSeparator = false;
skia.committer@gmail.com8eaddb02013-03-19 07:15:10 +00001198 SkAddFlagToString(str,
1199 SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag),
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001200 "IgnoreXform", &needSeparator);
skia.committer@gmail.com8eaddb02013-03-19 07:15:10 +00001201 SkAddFlagToString(str,
1202 SkToBool(fBlurFlags & SkBlurMaskFilter::kHighQuality_BlurFlag),
robertphillips@google.com0bd80fa2013-03-18 17:53:38 +00001203 "HighQuality", &needSeparator);
1204 } else {
1205 str->append("None");
1206 }
1207 str->append("))");
1208}
1209#endif
1210
caryclark@google.comd26147a2011-12-15 14:16:43 +00001211SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1212 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1213SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END