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

Unified Diff: src/core/SkReadBuffer.h

Issue 1858323002: Enable flattening/unflattening with custom unflatten procs (Closed) Base URL: https://skia.googlesource.com/skia.git@flattenable
Patch Set: Avoid duping strings Created 4 years, 8 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 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

Powered by Google App Engine
This is Rietveld 408576698