Minor clean up related to blur mask filters
authorrobertphillips <robertphillips@google.com>
Fri, 5 Aug 2016 14:51:29 +0000 (07:51 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 5 Aug 2016 14:51:30 +0000 (07:51 -0700)
This is the non-substantive portion of: https://codereview.chromium.org/2201133002/ (Implement GPU occluded blur mask filter)

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2214163003

Review-Url: https://codereview.chromium.org/2214163003

gm/occludedrrectblur.cpp
src/effects/SkBlurMaskFilter.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/SkGpuDevice_drawTexture.cpp

index da2bf5d..937b179 100644 (file)
@@ -149,7 +149,9 @@ static void draw_90(SkCanvas* canvas, const SkVector& v, SkScalar dist, const Sk
 static void draw_90_simple(SkCanvas* canvas, const SkVector& v,
                            SkScalar dist, const SkPoint& center) {
     static const int kLength = 128;
-    static const int kWidth = 32;
+    // The width needs to be larger than 2*3*blurRadii+2*cornerRadius for the analytic
+    // RRect blur to kick in
+    static const int kWidth = 47;
 
     SkIRect r;
     if (fabs(v.fX) < fabs(v.fY)) {
@@ -293,18 +295,18 @@ protected:
                    SkVector::Make(kRoot3Over2, -0.5f), 120, center);
 
         draw_45_simple(canvas, SkVector::Make(-SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2),
-                       190, center);
+                       210, center);
         draw_45_simple(canvas, SkVector::Make(SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2),
-                       190, center);
+                       210, center);
         draw_45_simple(canvas, SkVector::Make(SK_ScalarRoot2Over2, SK_ScalarRoot2Over2),
-                       190, center);
+                       210, center);
         draw_45_simple(canvas, SkVector::Make(-SK_ScalarRoot2Over2, SK_ScalarRoot2Over2),
-                       190, center);
+                       210, center);
 
-        draw_90_simple(canvas, SkVector::Make(-1.0f, 0.0f), 150, center);
-        draw_90_simple(canvas, SkVector::Make(0.0f, -1.0f), 150, center);
-        draw_90_simple(canvas, SkVector::Make(1.0f, 0.0f), 150, center);
-        draw_90_simple(canvas, SkVector::Make(0.0f, 1.0f), 150, center);
+        draw_90_simple(canvas, SkVector::Make(-1.0f, 0.0f), 160, center);
+        draw_90_simple(canvas, SkVector::Make(0.0f, -1.0f), 160, center);
+        draw_90_simple(canvas, SkVector::Make(1.0f, 0.0f), 160, center);
+        draw_90_simple(canvas, SkVector::Make(0.0f, 1.0f), 160, center);
     }
 
 private:
index 38b5313..4215733 100644 (file)
@@ -89,6 +89,10 @@ protected:
     bool filterRRectMask(SkMask* dstM, const SkRRect& r, const SkMatrix& matrix,
                         SkIPoint* margin, SkMask::CreateMode createMode) const;
 
+    bool ignoreXform() const {
+        return SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
+    }
+
 private:
     // To avoid unseemly allocation requests (esp. for finite platforms like
     // handset) we limit the radius so something manageable. (as opposed to
@@ -108,9 +112,7 @@ private:
     void flatten(SkWriteBuffer&) const override;
 
     SkScalar computeXformedSigma(const SkMatrix& ctm) const {
-        bool ignoreTransform = SkToBool(fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
-
-        SkScalar xformedSigma = ignoreTransform ? fSigma : ctm.mapRadius(fSigma);
+        SkScalar xformedSigma = this->ignoreXform() ? fSigma : ctm.mapRadius(fSigma);
         return SkMinScalar(xformedSigma, kMAX_BLUR_SIGMA);
     }
 
@@ -128,9 +130,9 @@ sk_sp<SkMaskFilter> SkBlurMaskFilter::Make(SkBlurStyle style, SkScalar sigma, ui
     if ((unsigned)style > (unsigned)kLastEnum_SkBlurStyle) {
         return nullptr;
     }
-    if (flags > SkBlurMaskFilter::kAll_BlurFlag) {
-        return nullptr;
-    }
+    SkASSERT(flags <= SkBlurMaskFilter::kAll_BlurFlag);
+    flags &= SkBlurMaskFilter::kAll_BlurFlag;
+
     return sk_sp<SkMaskFilter>(new SkBlurMaskFilterImpl(sigma, style, flags));
 }
 
@@ -150,7 +152,7 @@ SkMask::Format SkBlurMaskFilterImpl::getFormat() const {
 }
 
 bool SkBlurMaskFilterImpl::asABlur(BlurRec* rec) const {
-    if (fBlurFlags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) {
+    if (this->ignoreXform()) {
         return false;
     }
 
@@ -1169,10 +1171,6 @@ bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid
     }
 
     SkScalar xformedSigma = this->computeXformedSigma(viewMatrix);
-    float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f);
-
-    SkRect proxyRect = rrect.rect();
-    proxyRect.outset(extra, extra);
 
     sk_sp<GrFragmentProcessor> fp(GrRRectBlurEffect::Make(texProvider, xformedSigma, rrect));
     if (!fp) {
@@ -1186,6 +1184,11 @@ bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid
         return false;
     }
 
+    float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f);
+
+    SkRect proxyRect = rrect.rect();
+    proxyRect.outset(extra, extra);
+
     drawContext->fillRectWithLocalMatrix(clip, *grp, SkMatrix::I(), proxyRect, inverse);
     return true;
 }
index b1c6407..cd34b1f 100644 (file)
@@ -407,7 +407,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
+void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect,
                             const SkPaint& paint) {
     ASSERT_SINGLE_OWNER
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext);
@@ -423,7 +423,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
         // try to hit the fast path for drawing filtered round rects
 
         SkRRect devRRect;
-        if (rect.transform(*draw.fMatrix, &devRRect)) {
+        if (rrect.transform(*draw.fMatrix, &devRRect)) {
             if (devRRect.allCornersCircular()) {
                 SkRect maskRect;
                 if (paint.getMaskFilter()->canFilterMaskGPU(devRRect,
@@ -457,7 +457,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
         // A path effect will presumably transform this rrect into something else.
         SkPath path;
         path.setIsVolatile(true);
-        path.addRRect(rect);
+        path.addRRect(rrect);
         GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
                                             fClip, path, paint,
                                             *draw.fMatrix, nullptr,
@@ -467,7 +467,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
 
     SkASSERT(!style.pathEffect());
 
-    fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, style);
+    fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rrect, style);
 }
 
 
index da0a4ac..2843c31 100644 (file)
@@ -226,15 +226,13 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
 
     // First see if we can do the draw + mask filter direct to the dst.
     SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
-    SkRRect rrect;
-    rrect.setRect(clippedDstRect);
     if (mf->directFilterRRectMaskGPU(fContext->textureProvider(),
                                       fDrawContext.get(),
                                       &grPaint,
                                       clip,
                                       viewMatrix,
                                       rec,
-                                      rrect)) {
+                                      SkRRect::MakeRect(clippedDstRect))) {
         return;
     }
     SkPath rectPath;