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

Unified Diff: src/image/SkImage.cpp

Issue 1511183002: Revert of default SkPixelSerializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 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();
« 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