Create macro for registering classes for deserialization
Review URL: https://codereview.appspot.com/5909063
git-svn-id: http://skia.googlecode.com/svn/trunk@3494 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/ClockFaceView.cpp b/samplecode/ClockFaceView.cpp
index a479d9c..fe7bb90 100644
--- a/samplecode/ClockFaceView.cpp
+++ b/samplecode/ClockFaceView.cpp
@@ -76,7 +76,8 @@
buffer.writeScalar(fRadius);
}
- virtual Factory getFactory() { return CreateProc; }
+
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Dot2DPathEffect)
protected:
virtual void begin(const SkIRect& uvBounds, SkPath* dst) {
@@ -103,11 +104,6 @@
SkScalar fRadius;
SkTDArray<SkPoint>* fPts;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
- {
- return new Dot2DPathEffect(buffer);
- }
-
typedef Sk2DPathEffect INHERITED;
};
@@ -119,13 +115,12 @@
dst->setFillType(SkPath::kInverseWinding_FillType);
return true;
}
- virtual Factory getFactory() { return Factory; }
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(InverseFillPE)
+
protected:
-// InverseFillPE(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+ InverseFillPE(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
private:
- static SkFlattenable* Factory(SkFlattenableReadBuffer& buffer) {
- return new InverseFillPE;
- }
+
typedef SkPathEffect INHERITED;
};
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index 4321532..8d2157f 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -164,7 +164,7 @@
buffer.writeScalar(fRadius);
}
- virtual Factory getFactory() { return CreateProc; }
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Dot2DPathEffect)
protected:
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) {
@@ -177,10 +177,6 @@
private:
SkScalar fRadius;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return new Dot2DPathEffect(buffer);
- }
-
typedef Sk2DPathEffect INHERITED;
};
@@ -222,11 +218,13 @@
return false;
}
- virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
+
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect)
+
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) {
if (ucount > 1) {
@@ -250,8 +248,6 @@
private:
SkScalar fWidth;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { return new Line2DPathEffect(buffer); }
-
typedef Sk2DPathEffect INHERITED;
};
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index 9b72afb..3c656e9 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -612,12 +612,13 @@
return false;
}
- virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer& buffer)
{
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
+
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst)
{
@@ -644,11 +645,6 @@
private:
SkScalar fWidth;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer)
- {
- return new Line2DPathEffect(buffer);
- }
-
typedef Sk2DPathEffect INHERITED;
};
diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp
index 6a0eba8..7ce1abe 100644
--- a/samplecode/SampleText.cpp
+++ b/samplecode/SampleText.cpp
@@ -54,12 +54,10 @@
// if (c < min) c = min;
return c;
}
- virtual Factory getFactory() { return Create; }
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(ReduceNoise)
+
private:
ReduceNoise(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
- static SkFlattenable* Create(SkFlattenableReadBuffer& rb) {
- return new ReduceNoise(rb);
- }
};
class Darken : public SkKernel33ProcMaskFilter {
@@ -78,12 +76,10 @@
SkASSERT(f >= 0 && f <= 1);
return (int)(f * 255);
}
- virtual Factory getFactory() { return Create; }
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Darken)
+
private:
Darken(SkFlattenableReadBuffer& rb) : SkKernel33ProcMaskFilter(rb) {}
- static SkFlattenable* Create(SkFlattenableReadBuffer& rb) {
- return new Darken(rb);
- }
};
static SkMaskFilter* makemf() { return new Darken(0x30); }
@@ -136,11 +132,11 @@
typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&);
// overrides for SkFlattenable
- virtual Factory getFactory() { return Create; }
virtual void flatten(SkFlattenableWriteBuffer& b) {
// this->INHERITED::flatten(b); How can we know if this is legal????
b.write32(SkScalarToFixed(fExp));
}
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPowerMode)
private:
SkScalar fExp; // user's value
@@ -151,9 +147,6 @@
// read the exponent
this->init(SkFixedToScalar(b.readS32()));
}
- static SkFlattenable* Create(SkFlattenableReadBuffer& b) {
- return SkNEW_ARGS(SkPowerMode, (b));
- }
typedef SkXfermode INHERITED;
};
diff --git a/samplecode/SampleTextEffects.cpp b/samplecode/SampleTextEffects.cpp
index 6eadffd..e6bca82 100644
--- a/samplecode/SampleTextEffects.cpp
+++ b/samplecode/SampleTextEffects.cpp
@@ -189,11 +189,11 @@
return false;
}
- virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer& buffer) {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) {
@@ -218,10 +218,6 @@
private:
SkScalar fWidth;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return new Line2DPathEffect(buffer);
- }
-
typedef Sk2DPathEffect INHERITED;
};