Add option in flattening to write factory names inline, as we are recording.
SkGPipe needs this, since it cannot (unlike SkPicture) see all of the factories
before it hands its data to the reader.
In this mode, the writer embedds the factory name the first time it sees it,
and then after that writes an index (referencing the fFactorySet). The reader
installs an empty array, and as it encounters names, appends them to that array
so that subsequent indices can be used to retrieve the previously named factory.
Some of the existing patheffects did not register their factory names, so those
changes are also part of this CL. Annoyingly, to register your factory using the
current scheme, it has to be in the public section of the class definition.
git-svn-id: http://skia.googlecode.com/svn/trunk@1663 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 03bcab8..fddda55 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -100,11 +100,27 @@
fTFArray = array;
fTFCount = count;
}
-
+
+ /**
+ * Call this with a pre-loaded array of Factories, in the same order as
+ * were created/written by the writer. SkPicture uses this.
+ */
void setFactoryPlayback(SkFlattenable::Factory array[], int count) {
+ fFactoryTDArray = NULL;
fFactoryArray = array;
fFactoryCount = count;
}
+
+ /**
+ * Call this with an initially empty array, so the reader can cache each
+ * factory it sees by name. Used by the pipe code in conjunction with
+ * the writer's kInlineFactoryNames_Flag.
+ */
+ void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
+ fFactoryTDArray = array;
+ fFactoryArray = NULL;
+ fFactoryCount = 0;
+ }
SkTypeface* readTypeface();
SkRefCnt* readRefCnt();
@@ -118,6 +134,7 @@
SkTypeface** fTFArray;
int fTFCount;
+ SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
SkFlattenable::Factory* fFactoryArray;
int fFactoryCount;
@@ -165,12 +182,22 @@
SkFactorySet* setFactoryRecorder(SkFactorySet*);
enum Flags {
- kCrossProcess_Flag = 0x01
+ kCrossProcess_Flag = 0x01,
+ /**
+ * Instructs the writer to inline Factory names as there are seen the
+ * first time (after that we store an index). The pipe code uses this.
+ */
+ kInlineFactoryNames_Flag = 0x02,
};
- Flags getFlags() const { return fFlags; }
+ Flags getFlags() const { return (Flags)fFlags; }
void setFlags(Flags flags) { fFlags = flags; }
- bool isCrossProcess() const { return (fFlags & kCrossProcess_Flag) != 0; }
+ bool isCrossProcess() const {
+ return SkToBool(fFlags & kCrossProcess_Flag);
+ }
+ bool inlineFactoryNames() const {
+ return SkToBool(fFlags & kInlineFactoryNames_Flag);
+ }
bool persistBitmapPixels() const {
return (fFlags & kCrossProcess_Flag) != 0;
@@ -179,10 +206,10 @@
bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
private:
- Flags fFlags;
- SkRefCntSet* fTFSet;
- SkRefCntSet* fRCSet;
- SkFactorySet* fFactorySet;
+ uint32_t fFlags;
+ SkRefCntSet* fTFSet;
+ SkRefCntSet* fRCSet;
+ SkFactorySet* fFactorySet;
typedef SkWriter32 INHERITED;
};
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index f4b325f..4e83651 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -876,7 +876,7 @@
friend class SkTextToPathIter;
};
-//////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
#include "SkPathEffect.h"
@@ -894,20 +894,18 @@
SkPaint::Cap, SkScalar miterLimit = -1);
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
// overrides for 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&);
+
private:
SkScalar fWidth, fMiter;
uint8_t fStyle, fJoin, fCap;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SkStrokePathEffect(SkFlattenableReadBuffer&);
typedef SkPathEffect INHERITED;
diff --git a/include/core/SkPathEffect.h b/include/core/SkPathEffect.h
index eb1cc23..f84e1d1 100644
--- a/include/core/SkPathEffect.h
+++ b/include/core/SkPathEffect.h
@@ -31,7 +31,6 @@
*/
class SK_API SkPathEffect : public SkFlattenable {
public:
- // This method is not exported to java.
SkPathEffect() {}
/** Given a src path and a width value, return true if the patheffect
@@ -86,16 +85,16 @@
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
+ return SkNEW_ARGS(SkComposePathEffect, (buffer));
+ }
+
protected:
virtual Factory getFactory() { return CreateProc; }
private:
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkComposePathEffect, (buffer));
- }
SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
// illegal
@@ -121,16 +120,16 @@
: INHERITED(first, second) {}
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
+ return SkNEW_ARGS(SkSumPathEffect, (buffer));
+ }
+
protected:
virtual Factory getFactory() { return CreateProc; }
private:
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkSumPathEffect, (buffer));
- }
SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
// illegal
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h
index db6c64d..fa87243 100644
--- a/include/core/SkPtrRecorder.h
+++ b/include/core/SkPtrRecorder.h
@@ -89,10 +89,13 @@
*/
template <typename T> class SkTPtrSet : public SkPtrSet {
public:
+ uint32_t find(T ptr) {
+ return this->INHERITED::find((void*)ptr);
+ }
uint32_t add(T ptr) {
return this->INHERITED::add((void*)ptr);
}
-
+
void copyToArray(T* array) const {
this->INHERITED::copyToArray((void**)array);
}
diff --git a/include/effects/SkCornerPathEffect.h b/include/effects/SkCornerPathEffect.h
index 823de3f..a44df0a 100644
--- a/include/effects/SkCornerPathEffect.h
+++ b/include/effects/SkCornerPathEffect.h
@@ -42,17 +42,13 @@
// This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
protected:
SkCornerPathEffect(SkFlattenableReadBuffer&);
private:
SkScalar fRadius;
-
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
-
- // illegal
- SkCornerPathEffect(const SkCornerPathEffect&);
- SkCornerPathEffect& operator=(const SkCornerPathEffect&);
typedef SkPathEffect INHERITED;
};
diff --git a/include/effects/SkDashPathEffect.h b/include/effects/SkDashPathEffect.h
index 145f67d..4eb5c1e 100644
--- a/include/effects/SkDashPathEffect.h
+++ b/include/effects/SkDashPathEffect.h
@@ -44,6 +44,8 @@
// This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
protected:
SkDashPathEffect(SkFlattenableReadBuffer&);
@@ -56,8 +58,6 @@
SkScalar fIntervalLength;
bool fScaleToFit;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
-
typedef SkPathEffect INHERITED;
};
diff --git a/include/effects/SkDiscretePathEffect.h b/include/effects/SkDiscretePathEffect.h
index 2950950..19b107e 100644
--- a/include/effects/SkDiscretePathEffect.h
+++ b/include/effects/SkDiscretePathEffect.h
@@ -41,13 +41,13 @@
// This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
protected:
SkDiscretePathEffect(SkFlattenableReadBuffer&);
private:
SkScalar fSegLength, fPerterb;
-
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
typedef SkPathEffect INHERITED;
};