Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: src/core/SkReadBuffer.h

Issue 1837913003: Add support for serializing/deserializing of SkDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add ability to specify custom flattenable factories on SkReadBuffer Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkReadBuffer.h
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index 48edcfe7620e1018e940b68ac17e73724d85f35a..babd276dad0002f8f26262c8debb14b30adb8370 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"
@@ -202,6 +203,15 @@ public:
}
/**
+ * For an input flattenable (specified by name), set custom factory proc
+ * to use when unflattening.
+ */
+ void setCustomFactory(const char* name, SkFlattenable::Factory factory) {
+ SkFlattenable::Factory defaultFactory = SkFlattenable::NameToFactory(name);
+ fCustomFactory->set(defaultFactory, 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.
@@ -218,6 +228,14 @@ 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(SkFlattenable::Factory factory) {
+ return fCustomFactory->find(factory);
+ }
+
private:
bool readArray(void* value, size_t size, size_t elementSize);
@@ -233,6 +251,10 @@ private:
SkFlattenable::Factory* fFactoryArray;
int fFactoryCount;
+ // Maps the default Factory to any custom Factory that was specified for
+ // this SkReadBuffer.
+ SkAutoTDelete<SkTHashMap<SkFlattenable::Factory, SkFlattenable::Factory>> fCustomFactory;
+
SkPicture::InstallPixelRefProc fBitmapDecoder;
#ifdef DEBUG_NON_DETERMINISTIC_ASSERT

Powered by Google App Engine
This is Rietveld 408576698