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

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: Fix test 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
« no previous file with comments | « src/core/SkFlattenableSerialization.cpp ('k') | src/core/SkReadBuffer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkReadBuffer.h
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index faf853aef5430124c7f916636804c88fa6eb4df1..b18505453e7edfbc898664f97085e99084f65a79 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"
@@ -111,6 +112,9 @@ public:
virtual uint32_t readUInt();
virtual int32_t read32();
+ // peek
+ virtual uint8_t peekByte();
+
// strings -- the caller is responsible for freeing the string contents
virtual void readString(SkString* string);
virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding);
@@ -194,6 +198,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 can be removed by calling setCustomFactory("...", nullptr).
+ */
+ void setCustomFactory(const SkString& name, SkFlattenable::Factory factory) {
+ 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.
@@ -208,8 +226,27 @@ public:
virtual bool validateAvailable(size_t size) { return true; }
protected:
+ /**
+ * Allows subclass to check if we are using factories for expansion
+ * of flattenables.
+ */
+ int factoryCount() { return fFactoryCount; }
+
+
+ /**
+ * 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;
+ }
+
SkReader32 fReader;
+ // Only used if we do not have an fFactoryArray.
+ SkTHashMap<uint32_t, SkString> fFlattenableDict;
+
private:
bool readArray(void* value, size_t size, size_t elementSize);
@@ -225,6 +262,9 @@ private:
SkFlattenable::Factory* fFactoryArray;
int fFactoryCount;
+ // Only used if we do not have an fFactoryArray.
+ SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory;
+
SkPicture::InstallPixelRefProc fBitmapDecoder;
#ifdef DEBUG_NON_DETERMINISTIC_ASSERT
« no previous file with comments | « src/core/SkFlattenableSerialization.cpp ('k') | src/core/SkReadBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698