Index: src/image/SkImage.cpp |
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp |
index ee76a7ea39ed825e357227fe812cb12c5f3b4e67..240c06e63be94fe3a5c0e6e680dd65105868b2a0 100644 |
--- a/src/image/SkImage.cpp |
+++ b/src/image/SkImage.cpp |
@@ -74,6 +74,14 @@ SkShader* SkImage::newShader(SkShader::TileMode tileX, |
} |
SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { |
+ SkAutoDataUnref encoded(this->refEncoded()); |
+ if (encoded) { |
+ SkAutoDataUnref reencoded(SkImageEncoder::ReencodeData(encoded, type)); |
+ if (reencoded) { |
+ return reencoded.detach(); |
+ } |
+ } |
+ |
SkBitmap bm; |
if (as_IB(this)->getROPixels(&bm)) { |
return SkImageEncoder::EncodeData(bm, type, quality); |
@@ -85,10 +93,6 @@ namespace { |
class DefaultSerializer : public SkPixelSerializer { |
protected: |
- bool onUseEncodedData(const void *data, size_t len) override { |
- return true; |
- } |
- |
SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes) override { |
return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100); |
} |
@@ -101,15 +105,17 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const { |
SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultSerializer; |
SkAutoTUnref<SkData> encoded(this->refEncoded()); |
- if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded->size())) { |
- return encoded.detach(); |
+ if (encoded) { |
+ encoded.reset(effectiveSerializer->reencodeData(encoded)); |
+ if (encoded) { |
+ return encoded.detach(); |
+ } |
} |
SkBitmap bm; |
SkAutoPixmapUnlock apu; |
if (as_IB(this)->getROPixels(&bm) && bm.requestLock(&apu)) { |
- const SkPixmap& pmap = apu.pixmap(); |
- return effectiveSerializer->encodePixels(pmap.info(), pmap.addr(), pmap.rowBytes()); |
+ return effectiveSerializer->encodePixels(apu.pixmap()); |
} |
return nullptr; |