Factory methods for heap-allocated SkPathEffect and SkXfermode objects.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 20 Feb 2014 20:40:19 +0000 (20:40 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 20 Feb 2014 20:40:19 +0000 (20:40 +0000)
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 SkPathEffect, SkXfermode and
their subclasses non-public and instead provides factory methods for
creating these objects on the heap. We temporarily keep the constructors
of the following classes public to not break Chrome/Blink:

SkXfermode
SkCornerPathEffect
SkDashPathEffect

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

Author: dominikg@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13519 2bbb7eff-a529-9590-31e7-b0007b416f81

29 files changed:
bench/DashBench.cpp
experimental/PdfViewer/SkPdfGraphicsState.cpp
gm/dashcubics.cpp
gm/dashing.cpp
gm/patheffects.cpp
gm/texteffects.cpp
include/core/SkPathEffect.h
include/core/SkXfermode.h
include/effects/Sk1DPathEffect.h
include/effects/Sk2DPathEffect.h
include/effects/SkAvoidXfermode.h
include/effects/SkCornerPathEffect.h
include/effects/SkDashPathEffect.h
include/effects/SkDiscretePathEffect.h
include/effects/SkPixelXorXfermode.h
samplecode/SampleAll.cpp
samplecode/SampleAvoid.cpp
samplecode/SamplePathEffects.cpp
samplecode/SamplePathUtils.cpp
samplecode/SampleSlides.cpp
src/animator/SkDrawDash.cpp
src/animator/SkDrawDiscrete.cpp
src/animator/SkDrawExtraPathEffect.cpp
src/core/SkXfermode.cpp
src/core/SkXfermode_proccoeff.h
src/effects/SkArithmeticMode.cpp
src/utils/debugger/SkDebugCanvas.cpp
tests/DrawPathTest.cpp
tests/XfermodeTest.cpp

index 2e4bc376bc7d8afa1d65a5efb331c0ea1b5833da..365eee984102af545cbec6ec5d3c4a0de6ac8b70 100644 (file)
@@ -71,8 +71,8 @@ protected:
         SkPath path;
         this->makePath(&path);
 
-        paint.setPathEffect(new SkDashPathEffect(fIntervals.begin(),
-                                                 fIntervals.count(), 0))->unref();
+        paint.setPathEffect(SkDashPathEffect::Create(fIntervals.begin(),
+                                                     fIntervals.count(), 0))->unref();
 
         if (fDoClip) {
             SkRect r = path.getBounds();
@@ -186,7 +186,7 @@ public:
         proc(&fPath);
 
         SkScalar vals[] = { SkIntToScalar(4), SkIntToScalar(4) };
-        fPE.reset(new SkDashPathEffect(vals, 2, 0));
+        fPE.reset(SkDashPathEffect::Create(vals, 2, 0));
     }
 
 protected:
@@ -224,7 +224,7 @@ public:
         fIsRound = isRound;
 
         SkScalar vals[] = { SK_Scalar1, SK_Scalar1 };
-        fPE.reset(new SkDashPathEffect(vals, 2, 0));
+        fPE.reset(SkDashPathEffect::Create(vals, 2, 0));
     }
 
 protected:
@@ -263,7 +263,7 @@ public:
         fDoAA = doAA;
 
         SkScalar vals[] = { SkIntToScalar(dashLength), SkIntToScalar(dashLength) };
-        fPathEffect.reset(new SkDashPathEffect(vals, 2, SK_Scalar1, false));
+        fPathEffect.reset(SkDashPathEffect::Create(vals, 2, SK_Scalar1, false));
     }
 
 protected:
@@ -323,8 +323,8 @@ public:
         // deliberately pick intervals that won't be caught by asPoints(), so
         // we can test the filterPath code-path.
         const SkScalar intervals[] = { 2, 1, 1, 1 };
-        fPathEffect.reset(new SkDashPathEffect(intervals,
-                                               SK_ARRAY_COUNT(intervals), 0));
+        fPathEffect.reset(SkDashPathEffect::Create(intervals,
+                                                   SK_ARRAY_COUNT(intervals), 0));
 
         SkScalar cx = 640 / 2;  // center X
         SkScalar cy = 480 / 2;  // center Y
index b52f22ccc71c340e2e880eec2a6500b4798aedb8..76c4120fa33998f36449235c1228eacf3cbf827a 100644 (file)
@@ -25,9 +25,9 @@ void SkPdfGraphicsState::applyGraphicsState(SkPaint* paint, bool stroking) {
         paint->setStrokeWidth(SkDoubleToScalar(fLineWidth));
         // TODO(edisonn): perf, avoid allocs of the intervals
         if (fDashArrayLength > 0) {
-            paint->setPathEffect(new SkDashPathEffect(fDashArray,
-                                                      fDashArrayLength,
-                                                      fDashPhase))->unref();
+            paint->setPathEffect(SkDashPathEffect::Create(fDashArray,
+                                                          fDashArrayLength,
+                                                          fDashPhase))->unref();
         }
     }
 
index 5d874d4dc64482c06b5c6ca268958b32b7cabcb1..f99c0c34f4544975a0649a544a58adef7f1ea6c2 100644 (file)
@@ -43,7 +43,7 @@ protected:
         SkParsePath::FromSVGString(d, &path);
 
         SkScalar intervals[] = { 5, 10 };
-        SkPathEffect* pe = new SkDashPathEffect(intervals, 2, 0);
+        SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0);
 
         SkPaint paint;
         paint.setAntiAlias(true);
index fa88e9e0abae4a7795d1cbdea729dc9081264e97..f690852fbda2a9a1215f56499d368956650f4656 100644 (file)
@@ -19,7 +19,7 @@ static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint,
         SkIntToScalar(off),
     };
 
-    p.setPathEffect(new SkDashPathEffect(intervals, 2, 0))->unref();
+    p.setPathEffect(SkDashPathEffect::Create(intervals, 2, 0))->unref();
     canvas->drawLine(0, 0, finalX, 0, p);
 }
 
@@ -155,7 +155,7 @@ protected:
                 vals[i] = SkIntToScalar(*intervals++);
             }
             SkScalar phase = vals[0] / 2;
-            paint.setPathEffect(new SkDashPathEffect(vals, count, phase))->unref();
+            paint.setPathEffect(SkDashPathEffect::Create(vals, count, phase))->unref();
 
             for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) {
                 SkPath path;
@@ -202,7 +202,7 @@ protected:
 
         SkScalar intervals[2] = { dashLength, dashLength };
 
-        p.setPathEffect(new SkDashPathEffect(intervals, 2, phase, false))->unref();
+        p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase, false))->unref();
 
         SkPoint pts[2];
 
index a1fb675a3ce36d4f7c5a0a57ee4360fae1835fe8..4c5cd4512a29785b06165dbd5567c771e7781d23 100644 (file)
@@ -17,10 +17,10 @@ namespace skiagm {
 
 static void compose_pe(SkPaint* paint) {
     SkPathEffect* pe = paint->getPathEffect();
-    SkPathEffect* corner = new SkCornerPathEffect(25);
+    SkPathEffect* corner = SkCornerPathEffect::Create(25);
     SkPathEffect* compose;
     if (pe) {
-        compose = new SkComposePathEffect(pe, corner);
+        compose = SkComposePathEffect::Create(pe, corner);
         corner->unref();
     } else {
         compose = corner;
@@ -45,8 +45,8 @@ static void stroke_pe(SkPaint* paint) {
 static void dash_pe(SkPaint* paint) {
     SkScalar inter[] = { 20, 10, 10, 10 };
     paint->setStrokeWidth(12);
-    paint->setPathEffect(new SkDashPathEffect(inter, SK_ARRAY_COUNT(inter),
-                                              0))->unref();
+    paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter),
+                                                  0))->unref();
     compose_pe(paint);
 }
 
@@ -69,7 +69,7 @@ static void one_d_pe(SkPaint* paint) {
     path.offset(SkIntToScalar(-6), 0);
     scale(&path, 1.5f);
 
-    paint->setPathEffect(new SkPath1DPathEffect(path, SkIntToScalar(21), 0,
+    paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0,
                                 SkPath1DPathEffect::kRotate_Style))->unref();
     compose_pe(paint);
 }
@@ -83,7 +83,7 @@ static void fill_pe(SkPaint* paint) {
 }
 
 static void discrete_pe(SkPaint* paint) {
-    paint->setPathEffect(new SkDiscretePathEffect(10, 4))->unref();
+    paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref();
 }
 
 static SkPathEffect* MakeTileEffect() {
@@ -93,7 +93,7 @@ static SkPathEffect* MakeTileEffect() {
     SkPath path;
     path.addCircle(0, 0, SkIntToScalar(5));
 
-    return new SkPath2DPathEffect(m, path);
+    return SkPath2DPathEffect::Create(m, path);
 }
 
 static void tile_pe(SkPaint* paint) {
index 094fe7b8a175681c2e39cdf91eac47d5d33c02a9..cf9ec5accc3308be438e3c01bce8e1bd9d44d47e 100644 (file)
@@ -77,7 +77,7 @@ static void r4(SkLayerRasterizer* rast, SkPaint& p) {
 static void r5(SkLayerRasterizer* rast, SkPaint& p) {
     rast->addLayer(p);
 
-    p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref();
+    p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
     p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
     rast->addLayer(p);
 }
@@ -98,7 +98,7 @@ static void r6(SkLayerRasterizer* rast, SkPaint& p) {
 static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
     SkPath path;
     path.addCircle(0, 0, radius);
-    return new SkPath2DPathEffect(matrix, path);
+    return SkPath2DPathEffect::Create(matrix, path);
 }
 
 static void r7(SkLayerRasterizer* rast, SkPaint& p) {
@@ -132,7 +132,7 @@ static void r9(SkLayerRasterizer* rast, SkPaint& p) {
     SkMatrix    lattice;
     lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
     lattice.postRotate(SkIntToScalar(30), 0, 0);
-    p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref();
+    p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
     p.setXfermodeMode(SkXfermode::kClear_Mode);
     rast->addLayer(p);
 
index 3f38f3a101a52e0889662f8ed38ab192ae0b99be..86ccf86a9223eedb59dfb7361102bfb067177868 100644 (file)
@@ -31,8 +31,6 @@ class SK_API SkPathEffect : public SkFlattenable {
 public:
     SK_DECLARE_INST_COUNT(SkPathEffect)
 
-    SkPathEffect() {}
-
     /**
      *  Given a src path (input) and a stroke-rec (input and output), apply
      *  this effect to the src path, returning the new path in dst, and return
@@ -109,6 +107,7 @@ public:
     SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
 
 protected:
+    SkPathEffect() {}
     SkPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
 
 private:
@@ -127,10 +126,10 @@ private:
 */
 class SkPairPathEffect : public SkPathEffect {
 public:
-    SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
     virtual ~SkPairPathEffect();
 
 protected:
+    SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
     SkPairPathEffect(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
@@ -153,8 +152,9 @@ public:
         The reference counts for outer and inner are both incremented in the constructor,
         and decremented in the destructor.
     */
-    SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
-        : INHERITED(outer, inner) {}
+    static SkComposePathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) {
+        return SkNEW_ARGS(SkComposePathEffect, (outer, inner));
+    }
 
     virtual bool filterPath(SkPath* dst, const SkPath& src,
                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@@ -164,6 +164,12 @@ public:
 protected:
     SkComposePathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
+        : INHERITED(outer, inner) {}
+
 private:
     // illegal
     SkComposePathEffect(const SkComposePathEffect&);
@@ -184,8 +190,9 @@ public:
         The reference counts for first and second are both incremented in the constructor,
         and decremented in the destructor.
     */
-    SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
-        : INHERITED(first, second) {}
+    static SkSumPathEffect* Create(SkPathEffect* first, SkPathEffect* second) {
+        return SkNEW_ARGS(SkSumPathEffect, (first, second));
+    }
 
     virtual bool filterPath(SkPath* dst, const SkPath& src,
                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@@ -195,6 +202,12 @@ public:
 protected:
     SkSumPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {}
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
+        : INHERITED(first, second) {}
+
 private:
     // illegal
     SkSumPathEffect(const SkSumPathEffect&);
index 31b8081f85b0f05a2904f20d9ae22f07900634cd..86c08dd6b7bb43d86731b85def691248a7d515b8 100644 (file)
@@ -32,8 +32,6 @@ class SK_API SkXfermode : public SkFlattenable {
 public:
     SK_DECLARE_INST_COUNT(SkXfermode)
 
-    SkXfermode() {}
-
     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
                         const SkAlpha aa[]) const;
     virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
@@ -230,6 +228,11 @@ protected:
     */
     virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkXfermode() {}
+
 private:
     enum {
         kModeCount = kLastMode + 1
@@ -250,7 +253,9 @@ private:
 */
 class SkProcXfermode : public SkXfermode {
 public:
-    SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {}
+    static SkProcXfermode* Create(SkXfermodeProc proc) {
+        return SkNEW_ARGS(SkProcXfermode, (proc));
+    }
 
     // overrides from SkXfermode
     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
@@ -276,6 +281,11 @@ protected:
         return fProc;
     }
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {}
+
 private:
     SkXfermodeProc  fProc;
 
index 4ac8f73b266bb5e80cd19950742b2a4a3ca0fa25..ce49460e653733836b8b27441c86adf0a827d185 100644 (file)
@@ -52,7 +52,10 @@ public:
         @param style how to transform path at each point (based on the current
                      position and tangent)
     */
-    SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
+    static SkPath1DPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase,
+                                      Style style) {
+        return SkNEW_ARGS(SkPath1DPathEffect, (path, advance, phase, style));
+    }
 
     virtual bool filterPath(SkPath*, const SkPath&,
                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@@ -67,6 +70,11 @@ protected:
     virtual SkScalar begin(SkScalar contourLength) const SK_OVERRIDE;
     virtual SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
+
 private:
     SkPath      fPath;          // copied from constructor
     SkScalar    fAdvance;       // copied from constructor
index 859b5cd95292f96f6ec5021e344b22b8071553a9..f037e335085674ae3108d8626e563b1e30056ccb 100644 (file)
@@ -14,7 +14,9 @@
 
 class SK_API Sk2DPathEffect : public SkPathEffect {
 public:
-    Sk2DPathEffect(const SkMatrix& mat);
+    static Sk2DPathEffect* Create(const SkMatrix& mat) {
+        return SkNEW_ARGS(Sk2DPathEffect, (mat));
+    }
 
     virtual bool filterPath(SkPath*, const SkPath&,
                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@@ -44,6 +46,11 @@ protected:
     Sk2DPathEffect(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    Sk2DPathEffect(const SkMatrix& mat);
+
 private:
     SkMatrix    fMatrix, fInverse;
     bool        fMatrixIsInvertible;
@@ -58,8 +65,9 @@ private:
 
 class SK_API SkLine2DPathEffect : public Sk2DPathEffect {
 public:
-    SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
-    : Sk2DPathEffect(matrix), fWidth(width) {}
+    static SkLine2DPathEffect* Create(SkScalar width, const SkMatrix& matrix) {
+        return SkNEW_ARGS(SkLine2DPathEffect, (width, matrix));
+    }
 
     virtual bool filterPath(SkPath* dst, const SkPath& src,
                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@@ -73,6 +81,12 @@ protected:
 
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
+    : Sk2DPathEffect(matrix), fWidth(width) {}
+
 private:
     SkScalar fWidth;
 
@@ -85,7 +99,9 @@ public:
      *  Stamp the specified path to fill the shape, using the matrix to define
      *  the latice.
      */
-    SkPath2DPathEffect(const SkMatrix&, const SkPath&);
+    static SkPath2DPathEffect* Create(const SkMatrix& matrix, const SkPath& path) {
+        return SkNEW_ARGS(SkPath2DPathEffect, (matrix, path));
+    }
 
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath2DPathEffect)
 
@@ -95,6 +111,11 @@ protected:
 
     virtual void next(const SkPoint&, int u, int v, SkPath*) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkPath2DPathEffect(const SkMatrix&, const SkPath&);
+
 private:
     SkPath  fPath;
 
index afc3fc9d7009e572537d3aa5410bd29a2edb4c84..2fa20b98346781c370af9faaaa256d76053435f4 100644 (file)
@@ -37,7 +37,9 @@ public:
                 Tolerance near 0: draw only on colors that are nearly identical to the op-color
                 Tolerance near 255: draw on any colors even remotely similar to the op-color
      */
-    SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
+    static SkAvoidXfermode* Create(SkColor opColor, U8CPU tolerance, Mode mode) {
+        return SkNEW_ARGS(SkAvoidXfermode, (opColor, tolerance, mode));
+    }
 
     // overrides from SkXfermode
     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
@@ -54,6 +56,11 @@ protected:
     SkAvoidXfermode(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkAvoidXfermode(SkColor opColor, U8CPU tolerance, Mode mode);
+
 private:
     SkColor     fOpColor;
     uint32_t    fDistMul;   // x.14
index dcb7c9f736c34c571cdf30e0e6b56b536ee22125..c77505be3911512f9478e52e54ea83a70f9f0762 100644 (file)
@@ -20,7 +20,9 @@ public:
     /** radius must be > 0 to have an effect. It specifies the distance from each corner
         that should be "rounded".
     */
-    SkCornerPathEffect(SkScalar radius);
+    static SkCornerPathEffect* Create(SkScalar radius) {
+        return SkNEW_ARGS(SkCornerPathEffect, (radius));
+    }
     virtual ~SkCornerPathEffect();
 
     virtual bool filterPath(SkPath* dst, const SkPath& src,
@@ -32,6 +34,11 @@ protected:
     SkCornerPathEffect(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkCornerPathEffect(SkScalar radius);
+
 private:
     SkScalar    fRadius;
 
index 818e0739246fa31928dddc3faa4775104afb000f..a1c548265367cd0b0eac1d963070799ac6652b5d 100644 (file)
@@ -36,8 +36,10 @@ public:
 
         Note: only affects stroked paths.
     */
-    SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase,
-                     bool scaleToFit = false);
+    static SkDashPathEffect* Create(const SkScalar intervals[], int count,
+                                    SkScalar phase, bool scaleToFit = false) {
+        return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase, scaleToFit));
+    }
     virtual ~SkDashPathEffect();
 
     virtual bool filterPath(SkPath* dst, const SkPath& src,
@@ -55,6 +57,12 @@ protected:
     SkDashPathEffect(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase,
+                     bool scaleToFit = false);
+
 private:
     SkScalar*   fIntervals;
     int32_t     fCount;
index 60eb85274c1736967d848d9b2fa05f1c04e48760..126b40821899531c0f7117f6c20f77db99ca0c87 100644 (file)
@@ -20,7 +20,9 @@ public:
         away from the original path by a maximum of deviation.
         Note: works on filled or framed paths
     */
-    SkDiscretePathEffect(SkScalar segLength, SkScalar deviation);
+    static SkDiscretePathEffect* Create(SkScalar segLength, SkScalar deviation) {
+        return SkNEW_ARGS(SkDiscretePathEffect, (segLength, deviation));
+    }
 
     virtual bool filterPath(SkPath* dst, const SkPath& src,
                             SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
@@ -31,6 +33,11 @@ protected:
     SkDiscretePathEffect(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkDiscretePathEffect(SkScalar segLength, SkScalar deviation);
+
 private:
     SkScalar fSegLength, fPerterb;
 
index 9472d9426e3ba00e83585a725129034d6eb0a5f3..cfd59ecce010d1395b60208f9d3ed0345454e0b8 100644 (file)
@@ -17,7 +17,9 @@
 */
 class SK_API SkPixelXorXfermode : public SkXfermode {
 public:
-    SkPixelXorXfermode(SkColor opColor) : fOpColor(opColor) {}
+    static SkPixelXorXfermode* Create(SkColor opColor) {
+        return SkNEW_ARGS(SkPixelXorXfermode, (opColor));
+    }
 
     SK_DEVELOPER_TO_STRING()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPixelXorXfermode)
@@ -29,6 +31,11 @@ protected:
     // override from SkXfermode
     virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
 
+#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
+public:
+#endif
+    SkPixelXorXfermode(SkColor opColor) : fOpColor(opColor) {}
+
 private:
     SkColor fOpColor;
 
index 6410670fedbf4758a3d24787ceacb7eccb320189..bb5aadd1d8d01490a7cc427d39f21ad911c9d4b6 100644 (file)
@@ -144,7 +144,7 @@ static void r4(SkLayerRasterizer* rast, SkPaint& p) {
 static void r5(SkLayerRasterizer* rast, SkPaint& p) {
     rast->addLayer(p);
 
-    p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref();
+    p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
     p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
     rast->addLayer(p);
 }
@@ -217,7 +217,7 @@ static void r9(SkLayerRasterizer* rast, SkPaint& p) {
     SkMatrix    lattice;
     lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
     lattice.postRotate(SkIntToScalar(30), 0, 0);
-    p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref();
+    p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
     p.setXfermodeMode(SkXfermode::kClear_Mode);
     rast->addLayer(p);
 
@@ -550,11 +550,11 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect {
             path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
         path.close();
         path.offset(SkIntToScalar(-6), 0);
-        SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12),
+        SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12),
             gPhase, SkPath1DPathEffect::kRotate_Style);
-        SkPathEffect* inner = new SkDiscretePathEffect(SkIntToScalar(2),
+        SkPathEffect* inner = SkDiscretePathEffect::Create(SkIntToScalar(2),
             SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2));
-        SkPathEffect* result = new SkComposePathEffect(outer, inner);
+        SkPathEffect* result = SkComposePathEffect::Create(outer, inner);
         outer->unref();
         inner->unref();
         return result;
@@ -627,12 +627,12 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect {
         canvas->restore();
 
         if (1) {
-            SkAvoidXfermode   mode(SK_ColorWHITE, 0xFF,
-                                   SkAvoidXfermode::kTargetColor_Mode);
+            SkAutoTUnref<SkAvoidXfermode> mode(SkAvoidXfermode::Create(SK_ColorWHITE, 0xFF,
+                                   SkAvoidXfermode::kTargetColor_Mode));
             SkPaint paint;
             x += SkIntToScalar(20);
             SkRect  r = { x, 0, x + SkIntToScalar(360), SkIntToScalar(700) };
-            paint.setXfermode(&mode);
+            paint.setXfermode(mode);
             paint.setColor(SK_ColorGREEN);
             paint.setAntiAlias(true);
             canvas->drawOval(r, paint);
index 879481b41c07234d02fe085228b07d0bce2e059d..aa7ca0e8ef4a19d6fa730edcd85b6791387254c7 100644 (file)
@@ -78,9 +78,9 @@ protected:
         frameP.setStyle(SkPaint::kStroke_Style);
 
         for (size_t i = 0; i < SK_ARRAY_COUNT(gData); i++) {
-            SkAvoidXfermode mode(SK_ColorGREEN, gData[i].fTolerance,
-                                 gData[i].fMode);
-            paint.setXfermode(&mode);
+            SkAutoTUnref<SkAvoidXfermode> mode(SkAvoidXfermode::Create(
+                SK_ColorGREEN, gData[i].fTolerance, gData[i].fMode));
+            paint.setXfermode(mode);
             int div = 3;
             SkRect rr = { 0, 0, r.width()/div, r.height()/div };
             rr.offset(r.width()/4 - rr.width()/2, r.height()/4 - rr.height()/2);
index ac77f210de911160b5a00f28b657753e725ea37e..2a1a49b9495bd15ffc555f764df00bfd4cf686d7 100644 (file)
@@ -29,7 +29,7 @@ static const int gXY[] = {
 
 static SkPathEffect* make_pe(int flags) {
     if (flags == 1)
-        return new SkCornerPathEffect(SkIntToScalar(CORNER_RADIUS));
+        return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
 
     SkPath  path;
     path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
@@ -38,14 +38,14 @@ static SkPathEffect* make_pe(int flags) {
     path.close();
     path.offset(SkIntToScalar(-6), 0);
 
-    SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kRotate_Style);
+    SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kRotate_Style);
 
     if (flags == 2)
         return outer;
 
-    SkPathEffect* inner = new SkCornerPathEffect(SkIntToScalar(CORNER_RADIUS));
+    SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
 
-    SkPathEffect* pe = new SkComposePathEffect(outer, inner);
+    SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
     outer->unref();
     inner->unref();
     return pe;
@@ -59,10 +59,11 @@ static SkPathEffect* make_warp_pe() {
     path.close();
     path.offset(SkIntToScalar(-6), 0);
 
-    SkPathEffect* outer = new SkPath1DPathEffect(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kMorph_Style);
-    SkPathEffect* inner = new SkCornerPathEffect(SkIntToScalar(CORNER_RADIUS));
+    SkPathEffect* outer = SkPath1DPathEffect::Create(
+        path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kMorph_Style);
+    SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
 
-    SkPathEffect* pe = new SkComposePathEffect(outer, inner);
+    SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
     outer->unref();
     inner->unref();
     return pe;
index 09ab7738e976dd732b365c6369002f90b018c471..503a6eaa25ae6cef22dae3c5f93087a2df78aa91 100644 (file)
@@ -65,14 +65,14 @@ protected:
 
     virtual void onDrawContent(SkCanvas* canvas) {
         SkScalar intervals[8] = { .5f, .3f, .5f, .3f, .5f, .3f, .5f, .3f };
-        SkDashPathEffect dash(intervals, 2, fPhase);
-        SkCornerPathEffect corner(.25f);
-        SkComposePathEffect compose(&dash, &corner);
+        SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, fPhase));
+        SkAutoTUnref<SkCornerPathEffect> corner(SkCornerPathEffect::Create(.25f));
+        SkAutoTUnref<SkComposePathEffect> compose(SkComposePathEffect::Create(dash, corner));
 
         SkPaint outlinePaint;
         outlinePaint.setAntiAlias(true);  // dashed paint for bitmap
         outlinePaint.setStyle(SkPaint::kStroke_Style);
-        outlinePaint.setPathEffect(&compose);
+        outlinePaint.setPathEffect(compose);
 
         canvas->scale(10.0f, 10.0f);  // scales up
 
index 26cfc7d1a36bfb6fefae6fe18c4bb0884215bb45..914283aab022c7b95dc2d468a1991f0ae8c0ed88 100644 (file)
@@ -31,10 +31,10 @@ typedef void (*SlideProc)(SkCanvas*);
 
 static void compose_pe(SkPaint* paint) {
     SkPathEffect* pe = paint->getPathEffect();
-    SkPathEffect* corner = new SkCornerPathEffect(25);
+    SkPathEffect* corner = SkCornerPathEffect::Create(25);
     SkPathEffect* compose;
     if (pe) {
-        compose = new SkComposePathEffect(pe, corner);
+        compose = SkComposePathEffect::Create(pe, corner);
         corner->unref();
     } else {
         compose = corner;
@@ -59,8 +59,8 @@ static void stroke_pe(SkPaint* paint) {
 static void dash_pe(SkPaint* paint) {
     SkScalar inter[] = { 20, 10, 10, 10 };
     paint->setStrokeWidth(12);
-    paint->setPathEffect(new SkDashPathEffect(inter, SK_ARRAY_COUNT(inter),
-                                              0))->unref();
+    paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter),
+                                                  0))->unref();
     compose_pe(paint);
 }
 
@@ -83,8 +83,8 @@ static void one_d_pe(SkPaint* paint) {
     path.offset(SkIntToScalar(-6), 0);
     scale(&path, 1.5f);
 
-    paint->setPathEffect(new SkPath1DPathEffect(path, SkIntToScalar(21), 0,
-                                SkPath1DPathEffect::kRotate_Style))->unref();
+    paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0,
+                                                    SkPath1DPathEffect::kRotate_Style))->unref();
     compose_pe(paint);
 }
 
@@ -97,7 +97,7 @@ static void fill_pe(SkPaint* paint) {
 }
 
 static void discrete_pe(SkPaint* paint) {
-    paint->setPathEffect(new SkDiscretePathEffect(10, 4))->unref();
+    paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref();
 }
 
 static SkPathEffect* MakeTileEffect() {
@@ -107,7 +107,7 @@ static SkPathEffect* MakeTileEffect() {
     SkPath path;
     path.addCircle(0, 0, SkIntToScalar(5));
 
-    return new SkPath2DPathEffect(m, path);
+    return SkPath2DPathEffect::Create(m, path);
 }
 
 static void tile_pe(SkPaint* paint) {
@@ -547,7 +547,7 @@ static void r5(SkLayerRasterizer* rast, SkPaint& p)
 {
     rast->addLayer(p);
 
-    p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref();
+    p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->unref();
     p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
     rast->addLayer(p);
 }
@@ -569,7 +569,7 @@ static void r6(SkLayerRasterizer* rast, SkPaint& p)
 static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
     SkPath path;
     path.addCircle(0, 0, radius);
-    return new SkPath2DPathEffect(matrix, path);
+    return SkPath2DPathEffect::Create(matrix, path);
 }
 
 static void r7(SkLayerRasterizer* rast, SkPaint& p)
@@ -606,7 +606,7 @@ static void r9(SkLayerRasterizer* rast, SkPaint& p)
     SkMatrix    lattice;
     lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
     lattice.postRotate(SkIntToScalar(30), 0, 0);
-    p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref();
+    p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
     p.setXfermodeMode(SkXfermode::kClear_Mode);
     rast->addLayer(p);
 
index 8e73aa1c2deec4064ab26fa55ace950d90d19fc9..cfef30335b90f19969a91d37e28bace46914de66 100644 (file)
@@ -31,5 +31,5 @@ SkPathEffect* SkDash::getPathEffect() {
     int count = intervals.count();
     if (count == 0)
         return NULL;
-    return new SkDashPathEffect(intervals.begin(), count, phase);
+    return SkDashPathEffect::Create(intervals.begin(), count, phase);
 }
index 18c3ee0f61b7229ecf5ad16bc39f44a8a1ea1df7..9376435950d771295c478aea2809e48051a7a41b 100644 (file)
@@ -30,5 +30,5 @@ SkPathEffect* SkDiscrete::getPathEffect() {
     if (deviation <= 0 || segLength <= 0)
         return NULL;
     else
-        return new SkDiscretePathEffect(segLength, deviation);
+        return SkDiscretePathEffect::Create(segLength, deviation);
 }
index 7b991d251ef072d6f55479937fd5a6a6cffaaa37..4b911d11c4ffb2871da2613a37a79175acd7c1f3 100644 (file)
@@ -371,7 +371,7 @@ bool SkDrawComposePathEffect::addChild(SkAnimateMaker& , SkDisplayable* child) {
 SkPathEffect* SkDrawComposePathEffect::getPathEffect() {
     SkPathEffect* e1 = effect1->getPathEffect();
     SkPathEffect* e2 = effect2->getPathEffect();
-    SkPathEffect* composite = new SkComposePathEffect(e1, e2);
+    SkPathEffect* composite = SkComposePathEffect::Create(e1, e2);
     e1->unref();
     e2->unref();
     return composite;
@@ -401,7 +401,7 @@ SkDrawCornerPathEffect::~SkDrawCornerPathEffect() {
 }
 
 SkPathEffect* SkDrawCornerPathEffect::getPathEffect() {
-    return new SkCornerPathEffect(radius);
+    return SkCornerPathEffect::Create(radius);
 }
 
 /////////
index 66e0dea2f552c00153a6a3c3c3962a3d63663c9f..f5ac20b2825ad91601ebe4fe4c146e4570be70c4 100644 (file)
@@ -1444,7 +1444,9 @@ void SkProcCoeffXfermode::toString(SkString* str) const {
 
 class SkClearXfermode : public SkProcCoeffXfermode {
 public:
-    SkClearXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kClear_Mode) {}
+    static SkClearXfermode* Create(const ProcCoeff& rec) {
+        return SkNEW_ARGS(SkClearXfermode, (rec));
+    }
 
     virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
     virtual void xferA8(SkAlpha*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
@@ -1453,6 +1455,7 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkClearXfermode)
 
 private:
+    SkClearXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kClear_Mode) {}
     SkClearXfermode(SkReadBuffer& buffer)
         : SkProcCoeffXfermode(buffer) {}
 
@@ -1506,7 +1509,9 @@ void SkClearXfermode::toString(SkString* str) const {
 
 class SkSrcXfermode : public SkProcCoeffXfermode {
 public:
-    SkSrcXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kSrc_Mode) {}
+    static SkSrcXfermode* Create(const ProcCoeff& rec) {
+        return SkNEW_ARGS(SkSrcXfermode, (rec));
+    }
 
     virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
     virtual void xferA8(SkAlpha*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
@@ -1515,6 +1520,7 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSrcXfermode)
 
 private:
+    SkSrcXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kSrc_Mode) {}
     SkSrcXfermode(SkReadBuffer& buffer)
         : SkProcCoeffXfermode(buffer) {}
 
@@ -1573,7 +1579,9 @@ void SkSrcXfermode::toString(SkString* str) const {
 
 class SkDstInXfermode : public SkProcCoeffXfermode {
 public:
-    SkDstInXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstIn_Mode) {}
+    static SkDstInXfermode* Create(const ProcCoeff& rec) {
+        return SkNEW_ARGS(SkDstInXfermode, (rec));
+    }
 
     virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
 
@@ -1581,6 +1589,7 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDstInXfermode)
 
 private:
+    SkDstInXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstIn_Mode) {}
     SkDstInXfermode(SkReadBuffer& buffer) : INHERITED(buffer) {}
 
     typedef SkProcCoeffXfermode INHERITED;
@@ -1616,7 +1625,9 @@ void SkDstInXfermode::toString(SkString* str) const {
 
 class SkDstOutXfermode : public SkProcCoeffXfermode {
 public:
-    SkDstOutXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstOut_Mode) {}
+    static SkDstOutXfermode* Create(const ProcCoeff& rec) {
+        return SkNEW_ARGS(SkDstOutXfermode, (rec));
+    }
 
     virtual void xfer32(SkPMColor*, const SkPMColor*, int, const SkAlpha*) const SK_OVERRIDE;
 
@@ -1624,6 +1635,7 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDstOutXfermode)
 
 private:
+    SkDstOutXfermode(const ProcCoeff& rec) : SkProcCoeffXfermode(rec, kDstOut_Mode) {}
     SkDstOutXfermode(SkReadBuffer& buffer)
         : INHERITED(buffer) {}
 
@@ -1712,23 +1724,23 @@ SkXfermode* SkXfermode::Create(Mode mode) {
             // commonly used, so we call those out for their own subclasses here.
             switch (mode) {
                 case kClear_Mode:
-                    xfer = SkNEW_ARGS(SkClearXfermode, (rec));
+                    xfer = SkClearXfermode::Create(rec);
                     break;
                 case kSrc_Mode:
-                    xfer = SkNEW_ARGS(SkSrcXfermode, (rec));
+                    xfer = SkSrcXfermode::Create(rec);
                     break;
                 case kSrcOver_Mode:
                     SkASSERT(false);    // should not land here
                     break;
                 case kDstIn_Mode:
-                    xfer = SkNEW_ARGS(SkDstInXfermode, (rec));
+                    xfer = SkDstInXfermode::Create(rec);
                     break;
                 case kDstOut_Mode:
-                    xfer = SkNEW_ARGS(SkDstOutXfermode, (rec));
+                    xfer = SkDstOutXfermode::Create(rec);
                     break;
                 default:
                     // no special-case, just rely in the rec and its function-ptrs
-                    xfer = SkNEW_ARGS(SkProcCoeffXfermode, (rec, mode));
+                    xfer = SkProcCoeffXfermode::Create(rec, mode);
                     break;
             }
         }
index 1a2f7fcc7f35b3c685aca1db0de378b31afaa717..11121115f178393a6a1463246bf8c33f7033915e 100644 (file)
@@ -15,12 +15,8 @@ struct ProcCoeff {
 
 class SkProcCoeffXfermode : public SkProcXfermode {
 public:
-    SkProcCoeffXfermode(const ProcCoeff& rec, Mode mode)
-            : INHERITED(rec.fProc) {
-        fMode = mode;
-        // these may be valid, or may be CANNOT_USE_COEFF
-        fSrcCoeff = rec.fSC;
-        fDstCoeff = rec.fDC;
+    static SkProcCoeffXfermode* Create(const ProcCoeff& rec, Mode mode) {
+        return SkNEW_ARGS(SkProcCoeffXfermode, (rec, mode));
     }
 
     virtual bool asMode(Mode* mode) const SK_OVERRIDE;
@@ -36,6 +32,14 @@ public:
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkProcCoeffXfermode)
 
 protected:
+    SkProcCoeffXfermode(const ProcCoeff& rec, Mode mode)
+            : INHERITED(rec.fProc) {
+        fMode = mode;
+        // these may be valid, or may be CANNOT_USE_COEFF
+        fSrcCoeff = rec.fSC;
+        fDstCoeff = rec.fDC;
+    }
+
     SkProcCoeffXfermode(SkReadBuffer& buffer);
 
     virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
index 052b06507c26a364d4c735c13a94718736ebdd7b..2121e3a81dadea597b4f21018e189152a8615425 100644 (file)
@@ -23,11 +23,8 @@ static const bool gUseUnpremul = false;
 
 class SkArithmeticMode_scalar : public SkXfermode {
 public:
-    SkArithmeticMode_scalar(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4) {
-        fK[0] = k1;
-        fK[1] = k2;
-        fK[2] = k3;
-        fK[3] = k4;
+    static SkArithmeticMode_scalar* Create(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4) {
+        return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4));
     }
 
     virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
@@ -41,6 +38,13 @@ public:
 #endif
 
 private:
+    SkArithmeticMode_scalar(SkScalar k1, SkScalar k2, SkScalar k3, SkScalar k4) {
+        fK[0] = k1;
+        fK[1] = k2;
+        fK[2] = k3;
+        fK[3] = k4;
+    }
+
     SkArithmeticMode_scalar(SkReadBuffer& buffer) : INHERITED(buffer) {
         fK[0] = buffer.readScalar();
         fK[1] = buffer.readScalar();
@@ -216,7 +220,7 @@ SkXfermode* SkArithmeticMode::Create(SkScalar k1, SkScalar k2,
         return SkNEW_ARGS(SkArithmeticMode_linear, (i2, i3, i4));
 #endif
     }
-    return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4));
+    return SkArithmeticMode_scalar::Create(k1, k2, k3, k4);
 }
 
 
index 32a65709546258c03ac6443a1923b9e1b661a441..07cb09f381252b96c7ad229af03ef52995df814c 100644 (file)
@@ -118,7 +118,7 @@ static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) {
 class SkOverdrawFilter : public SkDrawFilter {
 public:
     SkOverdrawFilter() {
-        fXferMode = new SkProcXfermode(OverdrawXferModeProc);
+        fXferMode = SkProcXfermode::Create(OverdrawXferModeProc);
     }
 
     virtual ~SkOverdrawFilter() {
index e7f70057b9a8be01aa2b48afdd5bc0e615996d16..f7f7367983a8c7f57ed4beb2e47743c48ff2a265 100644 (file)
@@ -202,7 +202,7 @@ static void test_crbug_140642() {
      */
 
     const SkScalar vals[] = { 27734, 35660, 2157846850.0f, 247 };
-    SkDashPathEffect dontAssert(vals, 4, -248.135982067f);
+    SkAutoTUnref<SkDashPathEffect> dontAssert(SkDashPathEffect::Create(vals, 4, -248.135982067f));
 }
 
 static void test_crbug_124652() {
@@ -212,8 +212,7 @@ static void test_crbug_124652() {
         large values can "swamp" small ones.
      */
     SkScalar intervals[2] = {837099584, 33450};
-    SkAutoTUnref<SkDashPathEffect> dash(
-        new SkDashPathEffect(intervals, 2, -10, false));
+    SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, -10, false));
 }
 
 static void test_bigcubic() {
@@ -254,12 +253,12 @@ static void test_infinite_dash(skiatest::Reporter* reporter) {
     path.lineTo(5000000, 0);
 
     SkScalar intervals[] = { 0.2f, 0.2f };
-    SkDashPathEffect dash(intervals, 2, 0);
+    SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0));
 
     SkPath filteredPath;
     SkPaint paint;
     paint.setStyle(SkPaint::kStroke_Style);
-    paint.setPathEffect(&dash);
+    paint.setPathEffect(dash);
 
     paint.getFillPath(path, &filteredPath);
     // If we reach this, we passed.
@@ -274,15 +273,15 @@ static void test_crbug_165432(skiatest::Reporter* reporter) {
     path.lineTo(10000000, 0);
 
     SkScalar intervals[] = { 0.5f, 0.5f };
-    SkDashPathEffect dash(intervals, 2, 0);
+    SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0));
 
     SkPaint paint;
     paint.setStyle(SkPaint::kStroke_Style);
-    paint.setPathEffect(&dash);
+    paint.setPathEffect(dash);
 
     SkPath filteredPath;
     SkStrokeRec rec(paint);
-    REPORTER_ASSERT(reporter, !dash.filterPath(&filteredPath, path, &rec, NULL));
+    REPORTER_ASSERT(reporter, !dash->filterPath(&filteredPath, path, &rec, NULL));
     REPORTER_ASSERT(reporter, filteredPath.isEmpty());
 }
 
index 7ac12fb089597671b4ec5c9547c6fa81ac48aa3e..4afa522de7af06aefc7b92f63e1a1e36aab57f6a 100644 (file)
@@ -37,7 +37,7 @@ static void test_asMode(skiatest::Reporter* reporter) {
         }
     }
 
-    SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc);
+    SkXfermode* bogusXfer = SkProcXfermode::Create(bogusXfermodeProc);
     SkXfermode::Mode reportedMode = ILLEGAL_MODE;
     REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode));
     REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE);