Index: src/image/SkImage.cpp |
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp |
index 7db5b4e0a8e66b7bd477844d46b4b8830a5237f6..338ab0913090da08bb1a030eaec9d20bea99c6c8 100644 |
--- a/src/image/SkImage.cpp |
+++ b/src/image/SkImage.cpp |
@@ -9,6 +9,7 @@ |
#include "SkBitmapCache.h" |
#include "SkCanvas.h" |
#include "SkData.h" |
+#include "SkImageEncoder.h" |
#include "SkImageGenerator.h" |
#include "SkImagePriv.h" |
#include "SkImageShader.h" |
@@ -178,32 +179,14 @@ SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { |
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 { |
- DefaultSerializer defaultSerializer; |
- SkPixelSerializer* effectiveSerializer = serializer ? serializer : &defaultSerializer; |
- |
+ SkAutoTUnref<SkPixelSerializer> defaultSerializer; |
+ SkPixelSerializer* effectiveSerializer = serializer; |
+ if (!effectiveSerializer) { |
+ defaultSerializer.reset(SkImageEncoder::CreatePixelSerializer()); |
+ SkASSERT(defaultSerializer.get()); |
+ effectiveSerializer = defaultSerializer.get(); |
+ } |
SkAutoTUnref<SkData> encoded(this->refEncoded()); |
if (encoded && effectiveSerializer->useEncodedData(encoded->data(), encoded->size())) { |
return encoded.detach(); |