aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-01 19:34:20 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-01 19:34:20 +0000
commit0c3e5fe728ce4b8606819ee919a4b82f4d9efc85 (patch)
tree137ba2eb2fa061cfc29e737f1d98de8605675c3f /include
parent4605a3f3ff8fa2072f98e6bcb71bc43d4c6196d6 (diff)
Pipe factory names independently from the flattenables using them.
Avoids an issue where a flattenable written twice might be written differently (the first time the flat data may have a name, whereas the second time it will have an index). Also add a test which confirms that identical flattenables will have the same SkFlatData representation. BUG=https://code.google.com/p/skia/issues/detail?id=721 TEST=FlatDataTest.cpp Review URL: https://codereview.appspot.com/6431057 git-svn-id: http://skia.googlecode.com/svn/trunk@4896 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkFlattenable.h52
-rw-r--r--include/pipe/SkGPipe.h1
2 files changed, 38 insertions, 15 deletions
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 1828b42a45..bbd4a80edf 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -191,8 +191,8 @@ public:
/**
* 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.
+ * factory it sees by name. Used by the pipe code in combination with
+ * setNamedFactoryRecorder.
*/
void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
fFactoryTDArray = array;
@@ -241,6 +241,33 @@ protected:
class SkFactorySet : public SkTPtrSet<SkFlattenable::Factory> {};
+/**
+ * Similar to SkFactorySet, but only allows Factorys that have registered names.
+ * Also has a function to return the next added Factory's name.
+ */
+class SkNamedFactorySet : public SkRefCnt {
+public:
+ SkNamedFactorySet();
+
+ /**
+ * Find the specified Factory in the set. If it is not already in the set,
+ * and has registered its name, add it to the set, and return its index.
+ * If the Factory has no registered name, return 0.
+ */
+ uint32_t find(SkFlattenable::Factory);
+
+ /**
+ * If new Factorys have been added to the set, return the name of the first
+ * Factory added after the Factory name returned by the last call to this
+ * function.
+ */
+ const char* getNextAddedFactoryName();
+private:
+ int fNextAddedFactory;
+ SkFactorySet fFactorySet;
+ SkTDArray<const char*> fNames;
+};
+
class SkFlattenableWriteBuffer {
public:
SkFlattenableWriteBuffer();
@@ -285,14 +312,12 @@ public:
SkFactorySet* getFactoryRecorder() const { return fFactorySet; }
SkFactorySet* setFactoryRecorder(SkFactorySet*);
+ SkNamedFactorySet* getNamedFactoryRecorder() const { return fNamedFactorySet; }
+ SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
+
enum Flags {
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,
- /**
* Instructs the writer to always serialize bitmap pixel data.
*/
kForceFlattenBitmapPixels_Flag = 0x04
@@ -304,9 +329,6 @@ public:
bool isCrossProcess() const {
return SkToBool(fFlags & kCrossProcess_Flag);
}
- bool inlineFactoryNames() const {
- return SkToBool(fFlags & kInlineFactoryNames_Flag);
- }
bool persistBitmapPixels() const {
return (fFlags & (kCrossProcess_Flag | kForceFlattenBitmapPixels_Flag)) != 0;
@@ -322,10 +344,12 @@ protected:
obj->flatten(buffer);
}
- uint32_t fFlags;
- SkRefCntSet* fTFSet;
- SkRefCntSet* fRCSet;
- SkFactorySet* fFactorySet;
+ uint32_t fFlags;
+ SkRefCntSet* fTFSet;
+ SkRefCntSet* fRCSet;
+ SkFactorySet* fFactorySet;
+ SkNamedFactorySet* fNamedFactorySet;
+
};
#endif
diff --git a/include/pipe/SkGPipe.h b/include/pipe/SkGPipe.h
index a1f425c699..0a908d0480 100644
--- a/include/pipe/SkGPipe.h
+++ b/include/pipe/SkGPipe.h
@@ -128,7 +128,6 @@ public:
private:
SkGPipeCanvas* fCanvas;
- SkFactorySet* fFactorySet;
SkWriter32 fWriter;
};