aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tools/PictureRenderer.cpp17
-rw-r--r--tools/render_pictures_main.cpp8
2 files changed, 21 insertions, 4 deletions
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 84b67d84f9..7030f14962 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 @@ SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) {
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;
}
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index 521bbf8209..7d6275dfa5 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -42,7 +42,7 @@ static void usage(const char* argv0) {
SkDebugf(
" outputDir: directory to write the rendered images.\n\n");
SkDebugf(
-" --mode pow2tile minWidth height[%] | simple\n"
+" --mode pow2tile minWidth height[%] | simple | rerecord\n"
" | tile width[%] height[%]: Run in the corresponding mode.\n"
" Default is simple.\n");
SkDebugf(
@@ -55,7 +55,9 @@ static void usage(const char* argv0) {
" power of two. A simple render\n"
" is done with these tiles.\n");
SkDebugf(
-" simple, Render using the default rendering method.\n");
+" simple, Render using the default rendering method.\n"
+" rerecord, Record the picture as a new skp, with the bitmaps PNG encoded.\n"
+ );
SkDebugf(
" tile width[%] height[%], Do a simple render using tiles\n"
" with the given dimensions.\n");
@@ -213,6 +215,8 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
exit(-1);
}
heightString = *argv;
+ } else if (0 == strcmp(*argv, "rerecord")) {
+ renderer = SkNEW(sk_tools::RecordPictureRenderer);
} else {
SkDebugf("%s is not a valid mode for --mode\n", *argv);
usage(argv0);