aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-20 20:40:19 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-20 20:40:19 +0000
commit0a2bf90dccba3bde188e0386a7f0c60e6dde1ae9 (patch)
treeaa5c4198b4a200d6efe87d1a81964c8c219c1091 /include
parent4012ba51a218883daef6c9be142f970b8ef5d0d2 (diff)
Factory methods for heap-allocated SkPathEffect and SkXfermode 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 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
Diffstat (limited to 'include')
-rw-r--r--include/core/SkPathEffect.h27
-rw-r--r--include/core/SkXfermode.h16
-rw-r--r--include/effects/Sk1DPathEffect.h10
-rw-r--r--include/effects/Sk2DPathEffect.h29
-rw-r--r--include/effects/SkAvoidXfermode.h9
-rw-r--r--include/effects/SkCornerPathEffect.h9
-rw-r--r--include/effects/SkDashPathEffect.h12
-rw-r--r--include/effects/SkDiscretePathEffect.h9
-rw-r--r--include/effects/SkPixelXorXfermode.h9
9 files changed, 109 insertions, 21 deletions
diff --git a/include/core/SkPathEffect.h b/include/core/SkPathEffect.h
index 3f38f3a101..86ccf86a92 100644
--- a/include/core/SkPathEffect.h
+++ b/include/core/SkPathEffect.h
@@ -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&);
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 31b8081f85..86c08dd6b7 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -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;
diff --git a/include/effects/Sk1DPathEffect.h b/include/effects/Sk1DPathEffect.h
index 4ac8f73b26..ce49460e65 100644
--- a/include/effects/Sk1DPathEffect.h
+++ b/include/effects/Sk1DPathEffect.h
@@ -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
diff --git a/include/effects/Sk2DPathEffect.h b/include/effects/Sk2DPathEffect.h
index 859b5cd952..f037e33508 100644
--- a/include/effects/Sk2DPathEffect.h
+++ b/include/effects/Sk2DPathEffect.h
@@ -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;
diff --git a/include/effects/SkAvoidXfermode.h b/include/effects/SkAvoidXfermode.h
index afc3fc9d70..2fa20b9834 100644
--- a/include/effects/SkAvoidXfermode.h
+++ b/include/effects/SkAvoidXfermode.h
@@ -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
diff --git a/include/effects/SkCornerPathEffect.h b/include/effects/SkCornerPathEffect.h
index dcb7c9f736..c77505be39 100644
--- a/include/effects/SkCornerPathEffect.h
+++ b/include/effects/SkCornerPathEffect.h
@@ -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;
diff --git a/include/effects/SkDashPathEffect.h b/include/effects/SkDashPathEffect.h
index 818e073924..a1c5482653 100644
--- a/include/effects/SkDashPathEffect.h
+++ b/include/effects/SkDashPathEffect.h
@@ -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;
diff --git a/include/effects/SkDiscretePathEffect.h b/include/effects/SkDiscretePathEffect.h
index 60eb85274c..126b408218 100644
--- a/include/effects/SkDiscretePathEffect.h
+++ b/include/effects/SkDiscretePathEffect.h
@@ -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;
diff --git a/include/effects/SkPixelXorXfermode.h b/include/effects/SkPixelXorXfermode.h
index 9472d9426e..cfd59ecce0 100644
--- a/include/effects/SkPixelXorXfermode.h
+++ b/include/effects/SkPixelXorXfermode.h
@@ -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;