SkBlurDrawLooper: Start by deleting flags
authorMatt Sarett <msarett@google.com>
Thu, 23 Mar 2017 20:23:38 +0000 (16:23 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 23 Mar 2017 20:58:30 +0000 (20:58 +0000)
Android is the only user of this looper.  They never pass any flags.

BUG=skia:

Change-Id: I87b02ef7bc0ed94bca82637d60adddf34575a3e6
Reviewed-on: https://skia-review.googlesource.com/10057
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Reed <reed@google.com>
gm/circles.cpp
gm/rects.cpp
gm/shadows.cpp
include/effects/SkBlurDrawLooper.h
src/effects/SkBlurDrawLooper.cpp
tests/BlurTest.cpp

index 53ca5ddb1bb3f204408bc1e6fa93b1b4a9675ffc..5c53fe2b0e9bd2f700eed4af5eaa1f17ec3f5685 100644 (file)
@@ -77,10 +77,7 @@ protected:
         p.setAntiAlias(true);
         p.setLooper(SkBlurDrawLooper::Make(SK_ColorBLUE,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
-                                     SkIntToScalar(5), SkIntToScalar(10),
-                                     SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag));
+                                     SkIntToScalar(5), SkIntToScalar(10)));
         fPaints.push_back(p);
         }
 
index 28649b21c59b4c2bbce5f48ce9a87731de6f9f04..d8c2fd9a42602caf9b0aeef8b57552061b2850e4 100644 (file)
@@ -93,10 +93,7 @@ protected:
             p.setAntiAlias(true);
             p.setLooper(SkBlurDrawLooper::Make(SK_ColorWHITE,
                                          SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
-                                         SkIntToScalar(5), SkIntToScalar(10),
-                                         SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                         SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                         SkBlurDrawLooper::kHighQuality_BlurFlag));
+                                         SkIntToScalar(5), SkIntToScalar(10)));
             fPaints.push_back(p);
         }
 
index e550a8a6fdd40b3de20159b3ba92ec77ba05dcaa..5dba270c66eff0ffbba1b3a7d97f589dbcf437d9 100644 (file)
@@ -60,32 +60,19 @@ protected:
         sk_sp<SkDrawLooper> shadowLoopers[] = {
               SkBlurDrawLooper::Make(SK_ColorBLUE,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
-                                     SkIntToScalar(5), SkIntToScalar(10),
-                                     SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+                                     SkIntToScalar(5), SkIntToScalar(10)),
               SkBlurDrawLooper::Make(SK_ColorBLUE,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(10)),
-                                     SkIntToScalar(5), SkIntToScalar(10),
-                                     SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kOverrideColor_BlurFlag),
+                                     SkIntToScalar(5), SkIntToScalar(10)),
               SkBlurDrawLooper::Make(SK_ColorBLACK,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
                                      SkIntToScalar(5),
-                                     SkIntToScalar(10),
-                                     SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+                                     SkIntToScalar(10)),
               SkBlurDrawLooper::Make(0x7FFF0000,
                                      SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
-                                     SkIntToScalar(-5), SkIntToScalar(-10),
-                                     SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+                                     SkIntToScalar(-5), SkIntToScalar(-10)),
             SkBlurDrawLooper::Make(SK_ColorBLACK, SkIntToScalar(0),
-                                     SkIntToScalar(5), SkIntToScalar(5),
-                                     SkBlurDrawLooper::kIgnoreTransform_BlurFlag |
-                                     SkBlurDrawLooper::kOverrideColor_BlurFlag |
-                                     SkBlurDrawLooper::kHighQuality_BlurFlag),
+                                     SkIntToScalar(5), SkIntToScalar(5)),
         };
 
         constexpr struct {
index 84f87ae243b8c994ff663aa728f725ae8b8d569e..415018a2ad4e82854c1f5d23caf009b05e4db588 100644 (file)
@@ -23,22 +23,8 @@ class SkColorFilter;
 */
 class SK_API SkBlurDrawLooper : public SkDrawLooper {
 public:
-    enum BlurFlags {
-        kNone_BlurFlag = 0x00,
-        /**
-            The blur layer's dx/dy/radius aren't affected by the canvas
-            transform.
-        */
-        kIgnoreTransform_BlurFlag   = 0x01,
-        kOverrideColor_BlurFlag     = 0x02,
-        kHighQuality_BlurFlag       = 0x04,
-        /** mask for all blur flags */
-        kAll_BlurFlag               = 0x07
-    };
-
-    static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
-                                    uint32_t flags = kNone_BlurFlag) {
-        return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
+    static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy) {
+        return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy));
     }
 
     SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
@@ -47,8 +33,7 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
 
 protected:
-    SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
-                     uint32_t flags);
+    SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy);
 
     void flatten(SkWriteBuffer&) const override;
 
@@ -56,10 +41,8 @@ protected:
 
 private:
     sk_sp<SkMaskFilter>  fBlur;
-    sk_sp<SkColorFilter> fColorFilter;
     SkScalar        fDx, fDy, fSigma;
     SkColor         fBlurColor;
-    uint32_t        fBlurFlags;
 
     enum State {
         kBeforeEdge,
@@ -78,7 +61,7 @@ private:
         State fState;
     };
 
-    void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
+    void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color);
     void initEffects();
 
     typedef SkDrawLooper INHERITED;
index 4d21c004c981885e52a1025d290dd90daef3ffe6..34ce093a9e72b804c38a79d2b1f33215ce9d3690 100644 (file)
 #include "SkStringUtils.h"
 
 SkBlurDrawLooper::SkBlurDrawLooper(SkColor color, SkScalar sigma,
-                                   SkScalar dx, SkScalar dy, uint32_t flags) {
-    this->init(sigma, dx, dy, color, flags);
+                                   SkScalar dx, SkScalar dy) {
+    this->init(sigma, dx, dy, color);
 }
 
 // only call from constructor
 void SkBlurDrawLooper::initEffects() {
-    SkASSERT(fBlurFlags <= kAll_BlurFlag);
     if (fSigma > 0) {
-        uint32_t flags = fBlurFlags & kIgnoreTransform_BlurFlag ?
-                            SkBlurMaskFilter::kIgnoreTransform_BlurFlag :
-                            SkBlurMaskFilter::kNone_BlurFlag;
-
-        flags |= fBlurFlags & kHighQuality_BlurFlag ?
-                    SkBlurMaskFilter::kHighQuality_BlurFlag :
-                    SkBlurMaskFilter::kNone_BlurFlag;
-
-        fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, fSigma, flags);
+        fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, fSigma,
+                                       SkBlurMaskFilter::kNone_BlurFlag);
     } else {
         fBlur = nullptr;
     }
-
-    if (fBlurFlags & kOverrideColor_BlurFlag) {
-        // Set alpha to 1 for the override since transparency will already
-        // be baked into the blurred mask.
-        SkColor opaqueColor = SkColorSetA(fBlurColor, 255);
-        //The SrcIn xfer mode will multiply 'color' by the incoming alpha
-        fColorFilter = SkColorFilter::MakeModeFilter(opaqueColor, SkBlendMode::kSrcIn);
-    } else {
-        fColorFilter = nullptr;
-    }
 }
 
-void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
-                            SkColor color, uint32_t flags) {
+void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color) {
     fSigma = sigma;
     fDx = dx;
     fDy = dy;
     fBlurColor = color;
-    fBlurFlags = flags;
 
     this->initEffects();
 }
@@ -67,8 +47,7 @@ sk_sp<SkFlattenable> SkBlurDrawLooper::CreateProc(SkReadBuffer& buffer) {
     const SkScalar sigma = buffer.readScalar();
     const SkScalar dx = buffer.readScalar();
     const SkScalar dy = buffer.readScalar();
-    const uint32_t flags = buffer.read32();
-    return Make(color, sigma, dx, dy, flags);
+    return Make(color, sigma, dx, dy);
 }
 
 void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
@@ -76,11 +55,10 @@ void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
     buffer.writeScalar(fSigma);
     buffer.writeScalar(fDx);
     buffer.writeScalar(fDy);
-    buffer.write32(fBlurFlags);
 }
 
 bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
-    if (fSigma <= 0 || (fBlurFlags & fBlurFlags & kIgnoreTransform_BlurFlag)) {
+    if (fSigma <= 0) {
         return false;
     }
 
@@ -89,8 +67,7 @@ bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
         rec->fColor = fBlurColor;
         rec->fOffset.set(fDx, fDy);
         rec->fStyle = kNormal_SkBlurStyle;
-        rec->fQuality = (fBlurFlags & kHighQuality_BlurFlag) ?
-                        kHigh_SkBlurQuality : kLow_SkBlurQuality;
+        rec->fQuality = kLow_SkBlurQuality;
     }
     return true;
 }
@@ -126,15 +103,8 @@ bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas,
             paint->setColor(fLooper->fBlurColor);
 #endif
             paint->setMaskFilter(fLooper->fBlur);
-            paint->setColorFilter(fLooper->fColorFilter);
             canvas->save();
-            if (fLooper->fBlurFlags & kIgnoreTransform_BlurFlag) {
-                SkMatrix transform(canvas->getTotalMatrix());
-                transform.postTranslate(fLooper->fDx, fLooper->fDy);
-                canvas->setMatrix(transform);
-            } else {
-                canvas->translate(fLooper->fDx, fLooper->fDy);
-            }
+            canvas->translate(fLooper->fDx, fLooper->fDy);
             fState = kAfterEdge;
             return true;
         case kAfterEdge:
@@ -160,19 +130,7 @@ void SkBlurDrawLooper::toString(SkString* str) const {
     str->append(" color: ");
     str->appendHex(fBlurColor);
 
-    str->append(" flags: (");
-    if (kNone_BlurFlag == fBlurFlags) {
-        str->append("None");
-    } else {
-        bool needsSeparator = false;
-        SkAddFlagToString(str, SkToBool(kIgnoreTransform_BlurFlag & fBlurFlags), "IgnoreTransform",
-                          &needsSeparator);
-        SkAddFlagToString(str, SkToBool(kOverrideColor_BlurFlag & fBlurFlags), "OverrideColor",
-                          &needsSeparator);
-        SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "HighQuality",
-                          &needsSeparator);
-    }
-    str->append(")");
+    str->append(" flags: (None)");
 
     // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toString is added
     // alternatively we could cache the radius in SkBlurDrawLooper and just add it here
index f2c35d76bda3bd3623971f4bee972ed57f513a2b..744e2025b915c044db2527f7197268df623e7a3f 100644 (file)
@@ -383,24 +383,6 @@ static SkBlurQuality blurMaskFilterFlags_as_quality(uint32_t blurMaskFilterFlags
             kHigh_SkBlurQuality : kLow_SkBlurQuality;
 }
 
-static uint32_t blurMaskFilterFlags_to_blurDrawLooperFlags(uint32_t bmf) {
-    const struct {
-        uint32_t fBlurMaskFilterFlag;
-        uint32_t fBlurDrawLooperFlag;
-    } pairs[] = {
-        { SkBlurMaskFilter::kIgnoreTransform_BlurFlag, SkBlurDrawLooper::kIgnoreTransform_BlurFlag },
-        { SkBlurMaskFilter::kHighQuality_BlurFlag,     SkBlurDrawLooper::kHighQuality_BlurFlag },
-    };
-
-    uint32_t bdl = 0;
-    for (size_t i = 0; i < SK_ARRAY_COUNT(pairs); ++i) {
-        if (bmf & pairs[i].fBlurMaskFilterFlag) {
-            bdl |= pairs[i].fBlurDrawLooperFlag;
-        }
-    }
-    return bdl;
-}
-
 static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
                                 SkBlurStyle style, uint32_t blurMaskFilterFlags) {
     if (kNormal_SkBlurStyle != style) {
@@ -410,13 +392,8 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
     const SkColor color = 0xFF335577;
     const SkScalar dx = 10;
     const SkScalar dy = -5;
-    const SkBlurQuality quality = blurMaskFilterFlags_as_quality(blurMaskFilterFlags);
-    uint32_t flags = blurMaskFilterFlags_to_blurDrawLooperFlags(blurMaskFilterFlags);
-
-    sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy, flags));
-
-    const bool expectSuccess = sigma > 0 &&
-                               0 == (flags & SkBlurDrawLooper::kIgnoreTransform_BlurFlag);
+    sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy));
+    const bool expectSuccess = sigma > 0;
 
     if (nullptr == lp) {
         REPORTER_ASSERT(reporter, sigma <= 0);
@@ -430,7 +407,7 @@ static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma,
             REPORTER_ASSERT(reporter, rec.fOffset.y() == dy);
             REPORTER_ASSERT(reporter, rec.fColor == color);
             REPORTER_ASSERT(reporter, rec.fStyle == style);
-            REPORTER_ASSERT(reporter, rec.fQuality == quality);
+            REPORTER_ASSERT(reporter, rec.fQuality == kLow_SkBlurQuality);
         }
     }
 }