aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-08-09 18:47:40 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-08-09 18:47:40 +0000
commit18dc47731f4b37d8896b51f1b92ab31abd78b5a0 (patch)
treec6a2660aaec77bdbdf98d0230a889bbc3c40736e
parent633722ec44ad28261dfaee38a3a8acebefb3ce68 (diff)
use common subclass SkPath2DPathEffect, which can be serialized
git-svn-id: http://skia.googlecode.com/svn/trunk@2087 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/effects/Sk2DPathEffect.h34
-rw-r--r--samplecode/SampleSlides.cpp42
-rw-r--r--samplecode/SampleTextEffects.cpp38
-rw-r--r--src/effects/Sk2DPathEffect.cpp31
4 files changed, 70 insertions, 75 deletions
diff --git a/include/effects/Sk2DPathEffect.h b/include/effects/Sk2DPathEffect.h
index 22b5dd360b..f27a6b384a 100644
--- a/include/effects/Sk2DPathEffect.h
+++ b/include/effects/Sk2DPathEffect.h
@@ -10,27 +10,21 @@
#ifndef Sk2DPathEffect_DEFINED
#define Sk2DPathEffect_DEFINED
+#include "SkPath.h"
#include "SkPathEffect.h"
#include "SkMatrix.h"
-// This class is not exported to java.
class Sk2DPathEffect : public SkPathEffect {
public:
Sk2DPathEffect(const SkMatrix& mat);
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
// overrides from SkFlattenable
- // This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
-
- // This method is not exported to java.
virtual Factory getFactory();
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
-
protected:
/** New virtual, to be overridden by subclasses.
This is called once from filterPath, and provides the
@@ -59,8 +53,34 @@ private:
Sk2DPathEffect(const Sk2DPathEffect&);
Sk2DPathEffect& operator=(const Sk2DPathEffect&);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
friend class Sk2DPathEffectBlitter;
typedef SkPathEffect INHERITED;
};
+class SkPath2DPathEffect : public Sk2DPathEffect {
+public:
+ /**
+ * Stamp the specified path to fill the shape, using the matrix to define
+ * the latice.
+ */
+ SkPath2DPathEffect(const SkMatrix&, const SkPath&);
+
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
+protected:
+ SkPath2DPathEffect(SkFlattenableReadBuffer& buffer);
+
+ virtual void flatten(SkFlattenableWriteBuffer&);
+ virtual Factory getFactory();
+ virtual void next(const SkPoint& loc, int u, int v, SkPath* dst);
+
+private:
+ SkPath fPath;
+
+ typedef Sk2DPathEffect INHERITED;
+};
+
+
#endif
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index de108bae7b..5fab682545 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -570,46 +570,18 @@ static void r6(SkLayerRasterizer* rast, SkPaint& p)
#include "Sk2DPathEffect.h"
-class Dot2DPathEffect : public Sk2DPathEffect {
-public:
- Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix)
- : Sk2DPathEffect(matrix), fRadius(radius) {}
-
- virtual void flatten(SkFlattenableWriteBuffer& buffer)
- {
- this->INHERITED::flatten(buffer);
-
- buffer.writeScalar(fRadius);
- }
- virtual Factory getFactory() { return CreateProc; }
-
-protected:
- virtual void next(const SkPoint& loc, int u, int v, SkPath* dst)
- {
- dst->addCircle(loc.fX, loc.fY, fRadius);
- }
-
- Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer)
- {
- fRadius = buffer.readScalar();
- }
-private:
- SkScalar fRadius;
-
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
- {
- return new Dot2DPathEffect(buffer);
- }
-
- typedef Sk2DPathEffect INHERITED;
-};
+static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
+ SkPath path;
+ path.addCircle(0, 0, radius);
+ return new SkPath2DPathEffect(matrix, path);
+}
static void r7(SkLayerRasterizer* rast, SkPaint& p)
{
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
rast->addLayer(p);
}
@@ -620,7 +592,7 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p)
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);
diff --git a/samplecode/SampleTextEffects.cpp b/samplecode/SampleTextEffects.cpp
index 2a573f8718..6eadffd642 100644
--- a/samplecode/SampleTextEffects.cpp
+++ b/samplecode/SampleTextEffects.cpp
@@ -145,41 +145,17 @@ static void r6(SkLayerRasterizer* rast, SkPaint& p) {
#include "Sk2DPathEffect.h"
-class Dot2DPathEffect : public Sk2DPathEffect {
-public:
- Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix)
- : Sk2DPathEffect(matrix), fRadius(radius) {}
-
- virtual void flatten(SkFlattenableWriteBuffer& buffer) {
- this->INHERITED::flatten(buffer);
-
- buffer.writeScalar(fRadius);
- }
- virtual Factory getFactory() { return CreateProc; }
-
-protected:
- virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) {
- dst->addCircle(loc.fX, loc.fY, fRadius);
- }
-
- Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) {
- fRadius = buffer.readScalar();
- }
-private:
- SkScalar fRadius;
-
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return new Dot2DPathEffect(buffer);
- }
-
- typedef Sk2DPathEffect INHERITED;
-};
+static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
+ SkPath path;
+ path.addCircle(0, 0, radius);
+ return new SkPath2DPathEffect(matrix, path);
+}
static void r7(SkLayerRasterizer* rast, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
rast->addLayer(p);
}
@@ -189,7 +165,7 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);
diff --git a/src/effects/Sk2DPathEffect.cpp b/src/effects/Sk2DPathEffect.cpp
index b205f7042b..486dc47edc 100644
--- a/src/effects/Sk2DPathEffect.cpp
+++ b/src/effects/Sk2DPathEffect.cpp
@@ -101,7 +101,34 @@ SkFlattenable* Sk2DPathEffect::CreateProc(SkFlattenableReadBuffer& buffer)
}
///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+SkPath2DPathEffect::SkPath2DPathEffect(const SkMatrix& m, const SkPath& p)
+ : INHERITED(m), fPath(p) {
+}
+
+SkPath2DPathEffect::SkPath2DPathEffect(SkFlattenableReadBuffer& buffer)
+ : INHERITED(buffer) {
+ fPath.unflatten(buffer);
+}
+
+SkFlattenable* SkPath2DPathEffect::CreateProc(SkFlattenableReadBuffer& buffer) {
+ return SkNEW_ARGS(SkPath2DPathEffect, (buffer));
+}
+
+void SkPath2DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) {
+ this->INHERITED::flatten(buffer);
+ fPath.flatten(buffer);
+}
+
+SkFlattenable::Factory SkPath2DPathEffect::getFactory() {
+ return CreateProc;
+}
+
+void SkPath2DPathEffect::next(const SkPoint& loc, int u, int v, SkPath* dst) {
+ dst->addPath(fPath, loc.fX, loc.fY);
+}
-static SkFlattenable::Registrar gReg("Sk2DPathEffect",
- Sk2DPathEffect::CreateProc);
+static SkFlattenable::Registrar gReg("SkPath2DPathEffect",
+ SkPath2DPathEffect::CreateProc);