Chromium Code Reviews| 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 |
| + } |
| } |
| } |