Factory methods for heap-allocated SkMaskFilter objects.

This is part of an effort to ensure that all SkPaint effects can only be
allocated on the heap.

This patch makes the constructors of SkMaskFilter and its subclasses non-public
and instead provides factory methods for  creating these objects on the heap. We
temporarily keep constructor of publicly visible classes public behind a flag.

BUG=skia:2187
R=scroggo@google.com, mtklein@google.com, reed@google.com

Author: dominikg@chromium.org

Review URL: https://codereview.chromium.org/173633003

git-svn-id: http://skia.googlecode.com/svn/trunk@13527 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/samplerstress.cpp b/gm/samplerstress.cpp
index 2ddac3a..4303118 100644
--- a/gm/samplerstress.cpp
+++ b/gm/samplerstress.cpp
@@ -83,7 +83,7 @@
             return;
         }
 
-        fMaskFilter.reset(SkNEW(SkStippleMaskFilter));
+        fMaskFilter.reset(SkStippleMaskFilter::Create());
     }
 
     virtual void onDraw(SkCanvas* canvas) {
diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h
index b47e034..33e4555 100644
--- a/include/core/SkMaskFilter.h
+++ b/include/core/SkMaskFilter.h
@@ -40,8 +40,6 @@
 public:
     SK_DECLARE_INST_COUNT(SkMaskFilter)
 
-    SkMaskFilter() {}
-
     /** Returns the format of the resulting mask that this subclass will return
         when its filterMask() method is called.
     */
@@ -136,6 +134,7 @@
     SK_DEFINE_FLATTENABLE_TYPE(SkMaskFilter)
 
 protected:
+    SkMaskFilter() {}
     // empty for now, but lets get our subclass to remember to init us for the future
     SkMaskFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}
 
diff --git a/include/effects/SkEmbossMaskFilter.h b/include/effects/SkEmbossMaskFilter.h
index 263c5e0..0843911 100644
--- a/include/effects/SkEmbossMaskFilter.h
+++ b/include/effects/SkEmbossMaskFilter.h
@@ -23,10 +23,9 @@
         uint8_t     fSpecular;      // exponent, 4.4 right now
     };
 
-    SkEmbossMaskFilter(SkScalar blurSigma, const Light& light);
-
-    SK_ATTR_DEPRECATED("use sigma version")
-    SkEmbossMaskFilter(const Light& light, SkScalar blurRadius);
+    static SkEmbossMaskFilter* Create(SkScalar blurSigma, const Light& light) {
+        return SkNEW_ARGS(SkEmbossMaskFilter, (blurSigma, light));
+    }
 
     // overrides from SkMaskFilter
     //  This method is not exported to java.
@@ -42,6 +41,11 @@
     SkEmbossMaskFilter(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkEmbossMaskFilter(SkScalar blurSigma, const Light& light);
+
 private:
     Light       fLight;
     SkScalar    fBlurSigma;
diff --git a/include/effects/SkKernel33MaskFilter.h b/include/effects/SkKernel33MaskFilter.h
index bcd9b26..5530094 100644
--- a/include/effects/SkKernel33MaskFilter.h
+++ b/include/effects/SkKernel33MaskFilter.h
@@ -12,9 +12,6 @@
 
 class SK_API SkKernel33ProcMaskFilter : public SkMaskFilter {
 public:
-    SkKernel33ProcMaskFilter(unsigned percent256 = 256)
-        : fPercent256(percent256) {}
-
     virtual uint8_t computeValue(uint8_t* const* srcRows) const = 0;
 
     virtual SkMask::Format getFormat() const SK_OVERRIDE;
@@ -24,6 +21,8 @@
     SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
 
 protected:
+    SkKernel33ProcMaskFilter(unsigned percent256 = 256)
+        : fPercent256(percent256) {}
     SkKernel33ProcMaskFilter(SkReadBuffer& rb);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
@@ -37,10 +36,8 @@
 
 class SK_API SkKernel33MaskFilter : public SkKernel33ProcMaskFilter {
 public:
-    SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256)
-            : SkKernel33ProcMaskFilter(percent256) {
-        memcpy(fKernel, coeff, 9 * sizeof(int));
-        fShift = shift;
+    static SkKernel33MaskFilter* Create(const int coeff[3][3], int shift, int percent256 = 256) {
+        return SkNEW_ARGS(SkKernel33MaskFilter, (coeff, shift, percent256));
     }
 
     // override from SkKernel33ProcMaskFilter
@@ -49,6 +46,16 @@
     SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkKernel33MaskFilter)
 
+protected:
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256)
+            : SkKernel33ProcMaskFilter(percent256) {
+        memcpy(fKernel, coeff, 9 * sizeof(int));
+        fShift = shift;
+    }
+
 private:
     int fKernel[3][3];
     int fShift;
diff --git a/include/effects/SkStippleMaskFilter.h b/include/effects/SkStippleMaskFilter.h
index ee32ae1..ad7f767 100644
--- a/include/effects/SkStippleMaskFilter.h
+++ b/include/effects/SkStippleMaskFilter.h
@@ -15,7 +15,8 @@
  */
 class SK_API SkStippleMaskFilter : public SkMaskFilter {
 public:
-    SkStippleMaskFilter() : INHERITED() {
+    static SkStippleMaskFilter* Create() {
+        return SkNEW(SkStippleMaskFilter);
     }
 
     virtual bool filterMask(SkMask* dst, const SkMask& src,
@@ -35,6 +36,12 @@
     : SkMaskFilter(buffer) {
     }
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkStippleMaskFilter() : INHERITED() {
+    }
+
 private:
     typedef SkMaskFilter INHERITED;
 };
diff --git a/include/effects/SkTableMaskFilter.h b/include/effects/SkTableMaskFilter.h
index 1c2bbd7..63b32b2 100644
--- a/include/effects/SkTableMaskFilter.h
+++ b/include/effects/SkTableMaskFilter.h
@@ -18,8 +18,6 @@
  */
 class SK_API SkTableMaskFilter : public SkMaskFilter {
 public:
-    SkTableMaskFilter();
-    SkTableMaskFilter(const uint8_t table[256]);
     virtual ~SkTableMaskFilter();
 
     /** Utility that sets the gamma table
@@ -31,6 +29,10 @@
      */
     static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max);
 
+    static SkTableMaskFilter* Create(const uint8_t table[256]) {
+        return SkNEW_ARGS(SkTableMaskFilter, (table));
+    }
+
     static SkTableMaskFilter* CreateGamma(SkScalar gamma) {
         uint8_t table[256];
         MakeGammaTable(table, gamma);
@@ -54,6 +56,12 @@
     SkTableMaskFilter(SkReadBuffer& rb);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkTableMaskFilter();
+    SkTableMaskFilter(const uint8_t table[256]);
+
 private:
     uint8_t fTable[256];
 
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index bb5aadd..eb988f1 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -388,7 +388,7 @@
         light.fAmbient        = 0x48;
         light.fSpecular        = 0x80;
         SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(12)/5);
-        SkEmbossMaskFilter* embossFilter = new SkEmbossMaskFilter(sigma, light);
+        SkEmbossMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light);
 
         SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode);
         SkColorFilter* lightingFilter = SkColorFilter::CreateLightingFilter(
diff --git a/samplecode/SampleEmboss.cpp b/samplecode/SampleEmboss.cpp
index dacd4bf..1810a09 100644
--- a/samplecode/SampleEmboss.cpp
+++ b/samplecode/SampleEmboss.cpp
@@ -53,7 +53,7 @@
         paint.setAntiAlias(true);
         paint.setStyle(SkPaint::kStroke_Style);
         paint.setStrokeWidth(SkIntToScalar(10));
-        paint.setMaskFilter(new SkEmbossMaskFilter(
+        paint.setMaskFilter(SkEmbossMaskFilter::Create(
             SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
         paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
         paint.setDither(true);
diff --git a/src/effects/SkEmbossMaskFilter.cpp b/src/effects/SkEmbossMaskFilter.cpp
index 6747bf5..ab549cc 100644
--- a/src/effects/SkEmbossMaskFilter.cpp
+++ b/src/effects/SkEmbossMaskFilter.cpp
@@ -49,7 +49,7 @@
     light.fAmbient = SkToU8(am);
     light.fSpecular = SkToU8(sp);
 
-    return SkNEW_ARGS(SkEmbossMaskFilter, (blurSigma, light));
+    return SkEmbossMaskFilter::Create(blurSigma, light);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -68,13 +68,6 @@
     normalize(fLight.fDirection);
 }
 
-SkEmbossMaskFilter::SkEmbossMaskFilter(const Light& light, SkScalar blurRadius)
-        : fLight(light) {
-    normalize(fLight.fDirection);
-
-    fBlurSigma = SkBlurMask::ConvertRadiusToSigma(blurRadius);
-}
-
 SkMask::Format SkEmbossMaskFilter::getFormat() const {
     return SkMask::k3D_Format;
 }
diff --git a/src/views/SkWidgets.cpp b/src/views/SkWidgets.cpp
index fb16f1e..cde2b42 100644
--- a/src/views/SkWidgets.cpp
+++ b/src/views/SkWidgets.cpp
@@ -234,6 +234,7 @@
     return "enabled";
 }
 
+#include "SkBlurMask.h"
 #include "SkBlurMaskFilter.h"
 #include "SkEmbossMaskFilter.h"
 
@@ -255,7 +256,8 @@
     if (focus)
         light.fDirection[2] += SK_Scalar1/4;
 
-    paint->setMaskFilter(new SkEmbossMaskFilter(light, radius))->unref();
+    SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(radius);
+    paint->setMaskFilter(new SkEmbossMaskFilter(sigma, light))->unref();
 }
 
 void SkPushButtonWidget::onDraw(SkCanvas* canvas)