Index: src/core/SkWriteBuffer.cpp |
diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp |
index d2eb8c5d8d234c7aaaf7b491b7e8a78d93c8628e..faa7f00b08d35d9523d2381127b68b8937fd67d7 100644 |
--- a/src/core/SkWriteBuffer.cpp |
+++ b/src/core/SkWriteBuffer.cpp |
@@ -218,6 +218,34 @@ void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) { |
SkBitmap::WriteRawPixels(this, bitmap); |
} |
+static bool try_write_encoded(SkWriteBuffer* buffer, SkData* encoded) { |
+ SkPixelSerializer* ps = buffer->getPixelSerializer(); |
+ // Assumes that if the client did not set a serializer, they are |
+ // happy to get the encoded data. |
+ if (!ps || ps->useEncodedData(encoded->data(), encoded->size())) { |
+ write_encoded_bitmap(buffer, encoded, SkIPoint::Make(0, 0)); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+void SkWriteBuffer::writeImage(const SkImage* image) { |
+ this->writeInt(image->width()); |
+ this->writeInt(image->height()); |
+ |
+ SkAutoTUnref<SkData> encoded(image->refEncoded()); |
+ if (encoded && try_write_encoded(this, encoded)) { |
+ return; |
+ } |
+ |
+ encoded.reset(image->encode(SkImageEncoder::kPNG_Type, 100)); |
+ if (encoded && try_write_encoded(this, encoded)) { |
+ return; |
+ } |
+ |
+ this->writeUInt(0); // signal no pixels (in place of the size of the encoded data) |
+} |
+ |
void SkWriteBuffer::writeTypeface(SkTypeface* obj) { |
if (NULL == obj || NULL == fTFSet) { |
fWriter.write32(0); |