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

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: Send only the index or the string - never both 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..44d948dcb04606d8368d31c39dd8a7f5cb513dac 100644
--- a/src/core/SkReadBuffer.cpp
+++ b/src/core/SkReadBuffer.cpp
@@ -6,6 +6,7 @@
*/
#include "SkBitmap.h"
+#include "SkEndian.h"
#include "SkErrorInternals.h"
#include "SkImage.h"
#include "SkImageGenerator.h"
@@ -106,6 +107,11 @@ int32_t SkReadBuffer::read32() {
return fReader.readInt();
}
+uint8_t SkReadBuffer::peekByte() {
+ SkASSERT(fReader.available() > 0);
+ return *((uint8_t*) fReader.peek());
+}
+
void SkReadBuffer::readString(SkString* string) {
size_t len;
const char* strContents = fReader.readString(&len);
@@ -344,9 +350,32 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
}
factory = fFactoryArray[index];
} else {
- factory = (SkFlattenable::Factory)readFunctionPtr();
- if (nullptr == factory) {
- return nullptr; // writer failed to give us the flattenable
+ SkString name;
+ if (this->peekByte()) {
+ // If the first byte is non-zero, the flattenable is specified by a string.
+ this->readString(&name);
+
+ // Add the string to the dictionary.
+ fFlattenableDict.set(fFlattenableDict.count() + 1, name);
+ } else {
+ // Read the index. We are guaranteed that the first and last bytes
+ // are zeroed, so we must shift down a byte.
+ uint32_t index = fReader.readU32() >> 8;
+ if (0 == index) {
+ return nullptr; // writer failed to give us the flattenable
+ }
+
+ SkString* namePtr = fFlattenableDict.find(index);
+ SkASSERT(namePtr);
+ name = *namePtr;
+ }
+
+ // Check if a custom Factory has been specified for this flattenable.
+ if (!(factory = this->getCustomFactory(name))) {
+ // If there is no custom Factory, check for a default.
+ if (!(factory = SkFlattenable::NameToFactory(name.c_str()))) {
+ return nullptr; // writer failed to give us the flattenable
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698