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

Unified Diff: tools/PictureRenderer.cpp

Issue 784643002: Replace EncodeBitmap with an interface. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 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 | « tests/PictureTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/PictureRenderer.cpp
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 33766e96195c58f556e458186afb9da661138373..123cc2c5cccee9bc08a2d3486abbdd14f573a13b 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -28,6 +28,7 @@
#include "SkPictureRecorder.h"
#include "SkPictureUtils.h"
#include "SkPixelRef.h"
+#include "SkPixelSerializer.h"
#include "SkScalar.h"
#include "SkStream.h"
#include "SkString.h"
@@ -359,10 +360,22 @@ SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) {
return NULL;
}
-// the size_t* parameter is deprecated, so we ignore it
-static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) {
- return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
-}
+// Encodes to PNG, unless there is already encoded data, in which case that gets
+// used.
+// FIXME: Share with PictureTest.cpp?
+
+class PngPixelSerializer : public SkPixelSerializer {
+public:
+ virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+ virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
+ size_t rowBytes) SK_OVERRIDE {
+ SkBitmap bm;
+ if (!bm.installPixels(info, pixels, rowBytes)) {
+ return NULL;
+ }
+ return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
+ }
+};
bool RecordPictureRenderer::render(SkBitmap** out) {
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
@@ -378,7 +391,8 @@ bool RecordPictureRenderer::render(SkBitmap** out) {
// Record the new picture as a new SKP with PNG encoded bitmaps.
SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_str());
SkFILEWStream stream(skpPath.c_str());
- picture->serialize(&stream, &encode_bitmap_to_data);
+ PngPixelSerializer serializer;
+ picture->serialize(&stream, &serializer);
return true;
}
return false;
« no previous file with comments | « tests/PictureTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698