Index: src/core/SkOrderedReadBuffer.cpp |
diff --git a/src/core/SkOrderedReadBuffer.cpp b/src/core/SkOrderedReadBuffer.cpp |
index 2c83ce0ac56d89f4475b0c78c68adef7c13b3068..68642c214b261dc955aa185b9977f5ac8168f59a 100644 |
--- a/src/core/SkOrderedReadBuffer.cpp |
+++ b/src/core/SkOrderedReadBuffer.cpp |
@@ -7,6 +7,7 @@ |
*/ |
#include "SkBitmap.h" |
+#include "SkErrorInternals.h" |
#include "SkOrderedReadBuffer.h" |
#include "SkStream.h" |
#include "SkTypeface.h" |
@@ -168,32 +169,46 @@ uint32_t SkOrderedReadBuffer::getArrayCount() { |
} |
void SkOrderedReadBuffer::readBitmap(SkBitmap* bitmap) { |
+ const int width = this->readInt(); |
+ const int height = this->readInt(); |
const size_t length = this->readUInt(); |
if (length > 0) { |
// Bitmap was encoded. |
const void* data = this->skip(length); |
- const int width = this->readInt(); |
- const int height = this->readInt(); |
if (fBitmapDecoder != NULL && fBitmapDecoder(data, length, bitmap)) { |
SkASSERT(bitmap->width() == width && bitmap->height() == height); |
- } else { |
- // This bitmap was encoded when written, but we are unable to decode, possibly due to |
- // not having a decoder. Use a placeholder bitmap. |
- SkDebugf("Could not decode bitmap. Resulting bitmap will be red.\n"); |
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
- bitmap->allocPixels(); |
- bitmap->eraseColor(SK_ColorRED); |
+ return; |
} |
+ // This bitmap was encoded when written, but we are unable to decode, possibly due to |
+ // not having a decoder. |
+ SkDebugf("Could not decode bitmap. Resulting bitmap will be red.\n"); |
} else { |
- if (fBitmapStorage) { |
+ // The writer stored a boolean value to determine whether an SkBitmapHeap was used during |
+ // writing. |
+ if (this->readBool()) { |
const uint32_t index = fReader.readU32(); |
fReader.readU32(); // bitmap generation ID (see SkOrderedWriteBuffer::writeBitmap) |
- *bitmap = *fBitmapStorage->getBitmap(index); |
- fBitmapStorage->releaseRef(index); |
+ if (fBitmapStorage) { |
+ *bitmap = *fBitmapStorage->getBitmap(index); |
+ fBitmapStorage->releaseRef(index); |
+ return; |
+ } else { |
+ // Throw an error. |
+ SkErrorInternals::SetError(kParseError_SkError, "SkOrderedWriteBuffer::writeBitmap " |
+ "stored the SkBitmap in an SkBitmapHeap, but " |
+ "SkOrderedReadBuffer has no SkBitmapHeapReader to " |
+ "retrieve the SkBitmap."); |
+ } |
} else { |
+ // The SkBitmap was simply flattened. |
bitmap->unflatten(*this); |
+ return; |
} |
} |
+ // Could not read the SkBitmap. Use a placeholder bitmap. |
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
+ bitmap->allocPixels(); |
+ bitmap->eraseColor(SK_ColorRED); |
} |
SkTypeface* SkOrderedReadBuffer::readTypeface() { |