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

Unified Diff: src/core/SkReadBuffer.cpp

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.cpp
diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp
index abd46312f747e80e744f636d15cadb7672fa925d..752b83a3f5d22d96faa0ab1ae7e623236c1d0b7e 100644
--- a/src/core/SkReadBuffer.cpp
+++ b/src/core/SkReadBuffer.cpp
@@ -332,21 +332,40 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
SkFlattenable::Factory factory = nullptr;
+ uint32_t index = fReader.readU32();
+ if (0 == index) {
+ return nullptr; // writer failed to give us the flattenable
+ }
+
if (fFactoryCount > 0) {
- int32_t index = fReader.readU32();
- if (0 == index) {
- return nullptr; // writer failed to give us the flattenable
- }
index -= 1; // we stored the index-base-1
- if ((unsigned)index >= (unsigned)fFactoryCount) {
+ if (index >= (uint32_t) fFactoryCount) {
this->validate(false);
return nullptr;
}
factory = fFactoryArray[index];
} else {
- factory = (SkFlattenable::Factory)readFunctionPtr();
- if (nullptr == factory) {
- return nullptr; // writer failed to give us the flattenable
+ SkString name;
+ SkString* namePtr = fFlattenableDict.find(index);
+ if (namePtr) {
+ // Assume we have already seen this name and saved it to the dict.
+ name = *namePtr;
+ } else {
+ // The string must be passed after the index.
+ this->readString(&name);
+
+ // Add the string to the dictionary.
+ fFlattenableDict.set(index, name);
+ }
+
+ // Check if a custom Factory has been specified for this flattenable.
+ factory = getCustomFactory(name);
mtklein 2016/04/19 18:14:55 this->
msarett 2016/04/19 18:55:51 Done.
+ if (!factory) {
+ // If there is no custom Factory, check for a default.
+ factory = SkFlattenable::NameToFactory(name.c_str());
+ if (!factory) {
+ return nullptr; // writer failed to give us the flattenable
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698