Index: src/image/SkImage.cpp |
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp |
index 338ab0913090da08bb1a030eaec9d20bea99c6c8..7db5b4e0a8e66b7bd477844d46b4b8830a5237f6 100644 |
--- a/src/image/SkImage.cpp |
+++ b/src/image/SkImage.cpp |
@@ -9,7 +9,6 @@ |
#include "SkBitmapCache.h" |
#include "SkCanvas.h" |
#include "SkData.h" |
-#include "SkImageEncoder.h" |
#include "SkImageGenerator.h" |
#include "SkImagePriv.h" |
#include "SkImageShader.h" |
@@ -179,14 +178,32 @@ |
return nullptr; |
} |
+namespace { |
+ |
+class DefaultSerializer : public SkPixelSerializer { |
+protected: |
+ bool onUseEncodedData(const void *data, size_t len) override { |
+ return true; |
+ } |
+ SkData* onEncode(const SkPixmap& pixmap) override { |
+ SkBitmap bm; |
+ if (!bm.installPixels(pixmap.info(), |
+ const_cast<void*>(pixmap.addr()), |
+ pixmap.rowBytes(), |
+ pixmap.ctable(), |
+ nullptr, nullptr)) { |
+ return nullptr; |
+ } |
+ return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
+ } |
+}; |
+ |
+} // anonymous namespace |
+ |
SkData* SkImage::encode(SkPixelSerializer* serializer) const { |
- SkAutoTUnref<SkPixelSerializer> defaultSerializer; |
- SkPixelSerializer* effectiveSerializer = serializer; |
- if (!effectiveSerializer) { |
- defaultSerializer.reset(SkImageEncoder::CreatePixelSerializer()); |
- SkASSERT(defaultSerializer.get()); |
- effectiveSerializer = defaultSerializer.get(); |
- } |
+ DefaultSerializer defaultSerializer; |
+ SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultSerializer; |
+ |
SkAutoTUnref<SkData> encoded(this->refEncoded()); |
if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded->size())) { |
return encoded.detach(); |