Index: src/core/SkWriteBuffer.cpp |
diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp |
index 6baea3794691bb4e78bf2a8066c7bd361e208a1f..66737424e388720d6dd8cf32af4e6865d06ea057 100644 |
--- a/src/core/SkWriteBuffer.cpp |
+++ b/src/core/SkWriteBuffer.cpp |
@@ -287,24 +287,31 @@ void SkWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) { |
* The distinction is important, since 0-index is 32bits (always), but a |
* 0-functionptr might be 32 or 64 bits. |
*/ |
+ bool useString = (fFactorySet == nullptr && fNamedFactorySet == nullptr) || |
+ this->isValidating(); |
if (nullptr == flattenable) { |
- if (this->isValidating()) { |
+ if (useString) { |
this->writeString(""); |
- } else if (fFactorySet != nullptr || fNamedFactorySet != nullptr) { |
- this->write32(0); |
} else { |
- this->writeFunctionPtr(nullptr); |
+ this->write32(0); |
} |
return; |
} |
- SkFlattenable::Factory factory = flattenable->getFactory(); |
- SkASSERT(factory != nullptr); |
+ const char* name; |
+ SkFlattenable::Factory factory; |
+ if (useString) { |
+ name = flattenable->getTypeName(); |
+ SkASSERT(name != nullptr); |
+ } else { |
+ factory = flattenable->getFactory(); |
+ SkASSERT(factory); |
+ } |
/* |
* We can write 1 of 3 versions of the flattenable: |
- * 1. function-ptr : this is the fastest for the reader, but assumes that |
- * the writer and reader are in the same process. |
+ * 1. string : this allows us flatten even if the flattenable is not in |
+ * the global registry (as long as it overrides getTypeName()). |
* 2. index into fFactorySet : This is assumes the writer will later |
* resolve the function-ptrs into strings for its reader. SkPicture |
* does exactly this, by writing a table of names (matching the indices) |
@@ -313,18 +320,17 @@ void SkWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) { |
* name. SkGPipe uses this technique so it can write the name to its |
* stream before writing the flattenable. |
*/ |
- if (this->isValidating()) { |
+ if (useString) { |
this->writeString(flattenable->getTypeName()); |
} else if (fFactorySet) { |
this->write32(fFactorySet->add(factory)); |
- } else if (fNamedFactorySet) { |
+ } else { |
+ SkASSERT(fNamedFactorySet); |
int32_t index = fNamedFactorySet->find(factory); |
this->write32(index); |
if (0 == index) { |
return; |
} |
- } else { |
- this->writeFunctionPtr((void*)factory); |
} |
// make room for the size of the flattened object |