aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-21 19:24:00 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-21 19:24:00 +0000
commit6bac947cd5bc460dd9166ada6310d678fd2e39f8 (patch)
tree4f0adb7306dc1738f7e935ad84aac16ea1cc5d4d /include/core
parent25fb21f5df904c6f111bbf8f07e6a6c339416d09 (diff)
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
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkFlattenable.h43
-rw-r--r--include/core/SkPaint.h8
-rw-r--r--include/core/SkPathEffect.h17
-rw-r--r--include/core/SkPtrRecorder.h5
4 files changed, 50 insertions, 23 deletions
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 03bcab86e2..fddda551cd 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -100,11 +100,27 @@ public:
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 @@ private:
SkTypeface** fTFArray;
int fTFCount;
+ SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
SkFlattenable::Factory* fFactoryArray;
int fFactoryCount;
@@ -165,12 +182,22 @@ public:
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 @@ public:
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 f4b325fea5..4e83651927 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -876,7 +876,7 @@ private:
friend class SkTextToPathIter;
};
-//////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
#include "SkPathEffect.h"
@@ -894,20 +894,18 @@ public:
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 eb1cc23833..f84e1d1b12 100644
--- a/include/core/SkPathEffect.h
+++ b/include/core/SkPathEffect.h
@@ -31,7 +31,6 @@ class SkPath;
*/
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 @@ public:
// 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 @@ public:
: 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 db6c64dfdf..fa87243e52 100644
--- a/include/core/SkPtrRecorder.h
+++ b/include/core/SkPtrRecorder.h
@@ -89,10 +89,13 @@ private:
*/
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);
}