Index: src/core/SkReadBuffer.h |
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h |
index 7b12194fc03558a70dba98c2b36c4aae2bcf3bbe..195d421f181a0416044a35466f8fb9f8dcc7542d 100644 |
--- a/src/core/SkReadBuffer.h |
+++ b/src/core/SkReadBuffer.h |
@@ -194,6 +194,17 @@ public: |
} |
/** |
+ * For an input flattenable (specified by name), set a custom factory proc |
reed1
2016/04/11 15:07:48
Dox comments:
1. Does the name get copied, or mus
msarett
2016/04/19 18:03:50
Done.
|
+ * to use when unflattening. |
+ */ |
+ void setCustomFactory(const char* name, SkFlattenable::Factory factory) { |
+ NameFactoryEntry entry; |
+ entry.fName = name; |
+ entry.fFactory = factory; |
+ fCustomFactory.push_back(entry); |
+ } |
+ |
+ /** |
* Provide a function to decode an SkBitmap from encoded data. Only used if the writer |
* encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the |
* appropriate size will be used. |
@@ -210,6 +221,20 @@ public: |
protected: |
SkReader32 fReader; |
+ /** |
+ * Checks if a custom factory has been set for a given flattenable. |
+ * Returns the custom factory if it exists, or nullptr otherwise. |
+ */ |
+ SkFlattenable::Factory getCustomFactory(const char* name) { |
+ for (int i = 0; i < fCustomFactory.count(); i++) { |
+ if (!strcmp(fCustomFactory[i].fName, name)) { |
+ return fCustomFactory[i].fFactory; |
+ } |
+ } |
+ |
+ return nullptr; |
+ } |
+ |
private: |
bool readArray(void* value, size_t size, size_t elementSize); |
@@ -225,6 +250,14 @@ private: |
SkFlattenable::Factory* fFactoryArray; |
int fFactoryCount; |
+ // Maps the flattenable name to a custom factory that should be used to |
+ // create the flattenable. |
+ struct NameFactoryEntry { |
+ const char* fName; |
+ SkFlattenable::Factory fFactory; |
+ }; |
+ SkTArray<NameFactoryEntry> fCustomFactory; |
+ |
SkPicture::InstallPixelRefProc fBitmapDecoder; |
#ifdef DEBUG_NON_DETERMINISTIC_ASSERT |