Add an option to render_pictures to rerecord the pictures with PNG encoded bitmaps.
Review URL: https://codereview.appspot.com/6821092
git-svn-id: http://skia.googlecode.com/svn/trunk@6332 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 84b67d8..7030f14 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -21,6 +21,7 @@
#include "SkPicture.h"
#include "SkRTree.h"
#include "SkScalar.h"
+#include "SkStream.h"
#include "SkString.h"
#include "SkTemplates.h"
#include "SkTileGrid.h"
@@ -213,13 +214,25 @@
return NULL;
}
-bool RecordPictureRenderer::render(const SkString*) {
+static bool PNGEncodeBitmapToStream(SkWStream* wStream, const SkBitmap& bm) {
+ return SkImageEncoder::EncodeStream(wStream, bm, SkImageEncoder::kPNG_Type, 100);
+}
+
+bool RecordPictureRenderer::render(const SkString* path) {
SkAutoTUnref<SkPicture> replayer(this->createPicture());
SkCanvas* recorder = replayer->beginRecording(fPicture->width(), fPicture->height(),
this->recordFlags());
fPicture->draw(recorder);
replayer->endRecording();
- // Since this class does not actually render, return false.
+ if (path != NULL) {
+ // Record the new picture as a new SKP with PNG encoded bitmaps.
+ SkString skpPath(*path);
+ // ".skp" was removed from 'path' before being passed in here.
+ skpPath.append(".skp");
+ SkFILEWStream stream(skpPath.c_str());
+ replayer->serialize(&stream, &PNGEncodeBitmapToStream);
+ return true;
+ }
return false;
}