Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Unified Diff: src/core/SkWriteBuffer.cpp

Issue 1199473002: change old picture serialization to really handle images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix check in new_array function Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698