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

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: 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 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

Powered by Google App Engine
This is Rietveld 408576698