Chromium Code Reviews| Index: src/core/SkReadBuffer.h |
| diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h |
| index faf853aef5430124c7f916636804c88fa6eb4df1..2bca7936843ce6ed8196b37d0385526d17a4c2f9 100644 |
| --- a/src/core/SkReadBuffer.h |
| +++ b/src/core/SkReadBuffer.h |
| @@ -22,6 +22,7 @@ |
| #include "SkReader32.h" |
| #include "SkRefCnt.h" |
| #include "SkShader.h" |
| +#include "SkTHash.h" |
| #include "SkWriteBuffer.h" |
| #include "SkXfermode.h" |
| @@ -194,6 +195,20 @@ public: |
| } |
| /** |
| + * For an input flattenable (specified by name), set a custom factory proc |
| + * to use when unflattening. Will make a copy of |name|. |
| + * |
| + * If the global registry already has a default factory for the flattenable, |
| + * this will override that factory. If a custom factory has already been |
| + * set for the flattenable, this will override that factory. |
| + * |
| + * Custom factories cannot be removed. |
| + */ |
| + void setCustomFactory(const SkString& name, SkFlattenable::Factory factory) { |
|
mtklein
2016/04/19 18:14:55
Seems like calling setCustomFactory("...", nullptr
msarett
2016/04/19 18:55:51
Oh yeah of course. Will change the comment to ref
|
| + fCustomFactory.set(name, factory); |
| + } |
| + |
| + /** |
| * 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 +225,15 @@ 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 SkString& name) { |
| + SkFlattenable::Factory* factoryPtr = fCustomFactory.find(name); |
| + return factoryPtr ? *factoryPtr : nullptr; |
| + } |
| + |
| private: |
| bool readArray(void* value, size_t size, size_t elementSize); |
| @@ -225,6 +249,10 @@ private: |
| SkFlattenable::Factory* fFactoryArray; |
| int fFactoryCount; |
| + // Only used if we do not have an fFactoryArray. |
| + SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory; |
| + SkTHashMap<uint32_t, SkString> fFlattenableDict; |
| + |
| SkPicture::InstallPixelRefProc fBitmapDecoder; |
| #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |