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

Unified Diff: src/image/SkImage.cpp

Issue 1507123002: default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-10 (Thursday) 13:15:57 EST Created 5 years 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 | « include/core/SkImageEncoder.h ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « include/core/SkImageEncoder.h ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698