aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-04-14 14:06:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-14 14:06:18 -0700
commit7e79818137f2173302d6476a6127525b11684ec2 (patch)
treef7e28b12a168d6b98fe0480d58fd0cc28cd5a6e5 /dm
parent115acee9386e685f9a5938fb2cf13fd5a475012a (diff)
DM: add --multiPage option
Motivation: I want to switch back to single-page output by default for direct comparison to raster backends in Gold. I can still test the multi-page option via a command-line switch. BUG=skia:3721 Review URL: https://codereview.chromium.org/1063873004
Diffstat (limited to 'dm')
-rw-r--r--dm/DMSrcSink.cpp66
1 files changed, 42 insertions, 24 deletions
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 9e9a77c271..e70dd3e2b0 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -24,6 +24,9 @@
#include "SkStream.h"
#include "SkXMLWriter.h"
+DEFINE_bool(multiPage, false, "For document-type backends, render the source"
+ " into multiple pages");
+
static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
return encoded && SkInstallDiscardablePixelRef(encoded, dst);
@@ -377,33 +380,48 @@ static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
int width = src.size().width(),
height = src.size().height();
- const int kLetterWidth = 612, // 8.5 * 72
- kLetterHeight = 792; // 11 * 72
- const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
- SkIntToScalar(kLetterHeight));
-
- int xPages = ((width - 1) / kLetterWidth) + 1;
- int yPages = ((height - 1) / kLetterHeight) + 1;
-
- for (int y = 0; y < yPages; ++y) {
- for (int x = 0; x < xPages; ++x) {
- int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
- int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
- SkCanvas* canvas =
- doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
- if (!canvas) {
- return "SkDocument::beginPage(w,h) returned NULL";
- }
- canvas->clipRect(letter);
- canvas->translate(-letter.width() * x, -letter.height() * y);
- Error err = src.draw(canvas);
- if (!err.isEmpty()) {
- return err;
+ if (FLAGS_multiPage) {
+ const int kLetterWidth = 612, // 8.5 * 72
+ kLetterHeight = 792; // 11 * 72
+ const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
+ SkIntToScalar(kLetterHeight));
+
+ int xPages = ((width - 1) / kLetterWidth) + 1;
+ int yPages = ((height - 1) / kLetterHeight) + 1;
+
+ for (int y = 0; y < yPages; ++y) {
+ for (int x = 0; x < xPages; ++x) {
+ int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
+ int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
+ SkCanvas* canvas =
+ doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
+ if (!canvas) {
+ return "SkDocument::beginPage(w,h) returned NULL";
+ }
+ canvas->clipRect(letter);
+ canvas->translate(-letter.width() * x, -letter.height() * y);
+ Error err = src.draw(canvas);
+ if (!err.isEmpty()) {
+ return err;
+ }
+ doc->endPage();
}
- doc->endPage();
}
+ } else {
+ SkCanvas* canvas =
+ doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
+ if (!canvas) {
+ return "SkDocument::beginPage(w,h) returned NULL";
+ }
+ Error err = src.draw(canvas);
+ if (!err.isEmpty()) {
+ return err;
+ }
+ doc->endPage();
+ }
+ if (!doc->close()) {
+ return "SkDocument::close() returned false";
}
- doc->close();
dst->flush();
return "";
}