Pipe factory names independently from the flattenables using them.
Avoids an issue where a flattenable written twice might be written
differently (the first time the flat data may have a name, whereas
the second time it will have an index).
Also add a test which confirms that identical flattenables will have
the same SkFlatData representation.
BUG=https://code.google.com/p/skia/issues/detail?id=721
TEST=FlatDataTest.cpp
Review URL: https://codereview.appspot.com/6431057
git-svn-id: http://skia.googlecode.com/svn/trunk@4896 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkOrderedReadBuffer.cpp b/src/core/SkOrderedReadBuffer.cpp
index f3ba485..df94907 100644
--- a/src/core/SkOrderedReadBuffer.cpp
+++ b/src/core/SkOrderedReadBuffer.cpp
@@ -45,32 +45,16 @@
if (0 == index) {
return NULL; // writer failed to give us the flattenable
}
- index = -index; // we stored the negative of the index
index -= 1; // we stored the index-base-1
SkASSERT(index < fFactoryCount);
factory = fFactoryArray[index];
} else if (fFactoryTDArray) {
- const int32_t* peek = (const int32_t*)fReader.peek();
- if (*peek <= 0) {
- int32_t index = fReader.readU32();
- if (0 == index) {
- return NULL; // writer failed to give us the flattenable
- }
- index = -index; // we stored the negative of the index
- index -= 1; // we stored the index-base-1
- factory = (*fFactoryTDArray)[index];
- } else {
- const char* name = fReader.readString();
- factory = SkFlattenable::NameToFactory(name);
- if (factory) {
- SkASSERT(fFactoryTDArray->find(factory) < 0);
- *fFactoryTDArray->append() = factory;
- } else {
-// SkDebugf("can't find factory for [%s]\n", name);
- }
- // if we didn't find a factory, that's our failure, not the writer's,
- // so we fall through, so we can skip the sizeRecorded data.
+ int32_t index = fReader.readU32();
+ if (0 == index) {
+ return NULL; // writer failed to give us the flattenable
}
+ index -= 1; // we stored the index-base-1
+ factory = (*fFactoryTDArray)[index];
} else {
factory = (SkFlattenable::Factory)readFunctionPtr();
if (NULL == factory) {