change SkDrawFilter::filter to return a bool, where false means don't-draw
Review URL: https://codereview.appspot.com/6851111

git-svn-id: http://skia.googlecode.com/svn/trunk@6551 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index d4d2154..ebafb8d 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -155,12 +155,13 @@
 
 class BWTextDrawFilter : public SkDrawFilter {
 public:
-    virtual void filter(SkPaint*, Type) SK_OVERRIDE;
+    virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
 };
-void BWTextDrawFilter::filter(SkPaint* p, Type t) {
+bool BWTextDrawFilter::filter(SkPaint* p, Type t) {
     if (kText_Type == t) {
         p->setAntiAlias(false);
     }
+    return true;
 }
 
 struct PipeFlagComboData {
diff --git a/include/core/SkDrawFilter.h b/include/core/SkDrawFilter.h
index 79decef..3944257 100644
--- a/include/core/SkDrawFilter.h
+++ b/include/core/SkDrawFilter.h
@@ -33,15 +33,18 @@
         kRect_Type,
         kPath_Type,
         kText_Type,
+    };
 
-        kTypeCount
+    enum {
+        kTypeCount = kText_Type + 1
     };
 
     /**
      *  Called with the paint that will be used to draw the specified type.
-     *  The implementation may modify the paint as they wish.
+     *  The implementation may modify the paint as they wish. If filter()
+     *  returns false, the draw will be skipped.
      */
-    virtual void filter(SkPaint*, Type) = 0;
+    virtual bool filter(SkPaint*, Type) = 0;
 
 private:
     typedef SkRefCnt INHERITED;
diff --git a/include/effects/SkPaintFlagsDrawFilter.h b/include/effects/SkPaintFlagsDrawFilter.h
index fbf1807..cb2a8b7 100644
--- a/include/effects/SkPaintFlagsDrawFilter.h
+++ b/include/effects/SkPaintFlagsDrawFilter.h
@@ -14,8 +14,7 @@
 public:
     SkPaintFlagsDrawFilter(uint32_t clearFlags, uint32_t setFlags);
 
-    // overrides
-    virtual void filter(SkPaint*, Type);
+    virtual bool filter(SkPaint*, Type) SK_OVERRIDE;
 
 private:
     uint16_t    fClearFlags;    // user specified
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index c94a772..0943d77 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -491,7 +491,7 @@
                     SkOSMenu::TriState hinting) :
         fLCDState(lcd), fAAState(aa), fFilterState(filter), fHintingState(hinting) {}
 
-    virtual void filter(SkPaint* paint, Type t) {
+    virtual bool filter(SkPaint* paint, Type t) {
         if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) {
             paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState);
         }
@@ -506,6 +506,7 @@
                               SkPaint::kNormal_Hinting :
                               SkPaint::kSlight_Hinting);
         }
+        return true;
     }
 
 private:
diff --git a/samplecode/SampleLayers.cpp b/samplecode/SampleLayers.cpp
index 6d57c2a..cf6b009 100644
--- a/samplecode/SampleLayers.cpp
+++ b/samplecode/SampleLayers.cpp
@@ -125,11 +125,12 @@
 
 class RedFilter : public SkDrawFilter {
 public:
-    virtual void filter(SkPaint* p, SkDrawFilter::Type) SK_OVERRIDE {
+    virtual bool filter(SkPaint* p, SkDrawFilter::Type) SK_OVERRIDE {
         fColor = p->getColor();
         if (fColor == SK_ColorRED) {
             p->setColor(SK_ColorGREEN);
         }
+        return true;
     }
 
 private:
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index a2354d5..c38ed76 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -354,7 +354,10 @@
         return false;
     }
     if (fFilter) {
-        fFilter->filter(paint, drawType);
+        if (!fFilter->filter(paint, drawType)) {
+            fDone = true;
+            return false;
+        }
         if (NULL == fLooper) {
             // no looper means we only draw once
             fDone = true;
diff --git a/src/effects/SkPaintFlagsDrawFilter.cpp b/src/effects/SkPaintFlagsDrawFilter.cpp
index 1fe4402..92d6f64 100644
--- a/src/effects/SkPaintFlagsDrawFilter.cpp
+++ b/src/effects/SkPaintFlagsDrawFilter.cpp
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkPaintFlagsDrawFilter.h"
 #include "SkPaint.h"
 
@@ -16,7 +14,8 @@
     fSetFlags = SkToU16(setFlags & SkPaint::kAllFlags);
 }
 
-void SkPaintFlagsDrawFilter::filter(SkPaint* paint, Type) {
+bool SkPaintFlagsDrawFilter::filter(SkPaint* paint, Type) {
     paint->setFlags((paint->getFlags() & ~fClearFlags) | fSetFlags);
+    return true;
 }
 
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 7030f14..132f88d 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -58,7 +58,7 @@
     FlagsDrawFilter(PictureRenderer::DrawFilterFlags* flags) :
         fFlags(flags) {}
 
-    virtual void filter(SkPaint* paint, Type t) {
+    virtual bool filter(SkPaint* paint, Type t) {
         paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags);
         if ((PictureRenderer::kBlur_DrawFilterFlag | PictureRenderer::kLowBlur_DrawFilterFlag)
                 & fFlags[t]) {
@@ -78,6 +78,7 @@
         } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) {
             paint->setHinting(SkPaint::kSlight_Hinting);
         }
+        return true;
     }
 
 private: