aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2014-12-01 12:21:25 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-01 12:21:25 -0800
commit742cacdd20034c70f826b60eb416f7cc0a81d587 (patch)
treea03ef229607d16436e0b4d8a28f62e28e147bd6c /experimental
parent435eba7e1eb6f6622ebe171274a8d595d947a9cd (diff)
multipage_pdf_profiler, gmtoskp
Diffstat (limited to 'experimental')
-rw-r--r--experimental/tools/gmtoskp.cpp78
-rw-r--r--experimental/tools/multipage_pdf_profiler.cpp138
-rwxr-xr-xexperimental/tools/multipage_pdf_profiler.sh18
3 files changed, 234 insertions, 0 deletions
diff --git a/experimental/tools/gmtoskp.cpp b/experimental/tools/gmtoskp.cpp
new file mode 100644
index 0000000000..bafd3d3679
--- /dev/null
+++ b/experimental/tools/gmtoskp.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCanvas.h"
+#include "SkForceLinking.h"
+#include "SkGraphics.h"
+#include "SkOSFile.h"
+#include "SkPicture.h"
+#include "SkPictureRecorder.h"
+#include "SkStream.h"
+#include "SkTemplates.h"
+#include "flags/SkCommandLineFlags.h"
+#include "gm.h"
+
+DEFINE_string2(match,
+ m,
+ NULL,
+ "[~][^]substring[$] [...] of GM name to run.\n"
+ "Multiple matches may be separated by spaces.\n"
+ "~ causes a matching GM to always be skipped\n"
+ "^ requires the start of the GM to match\n"
+ "$ requires the end of the GM to match\n"
+ "^ and $ requires an exact match\n"
+ "If a GM does not match any list entry,\n"
+ "it is skipped unless some list entry starts with ~");
+
+DEFINE_string2(writePath, w, "", "Write output here as .skps.");
+
+__SK_FORCE_IMAGE_DECODER_LINKING;
+
+static void gmtoskp(skiagm::GM* gm, SkWStream* outputStream) {
+ SkPictureRecorder pictureRecorder;
+ SkRect bounds = SkRect::MakeWH(SkIntToScalar(gm->getISize().width()),
+ SkIntToScalar(gm->getISize().height()));
+ SkCanvas* canvas = pictureRecorder.beginRecording(bounds, NULL, 0);
+ canvas->concat(gm->getInitialTransform());
+ gm->draw(canvas);
+ canvas->flush();
+ SkAutoTUnref<SkPicture> pict(pictureRecorder.endRecordingAsPicture());
+ pict->serialize(outputStream, NULL);
+}
+
+int main(int argc, char** argv) {
+ SkAutoGraphics ag;
+ SkCommandLineFlags::SetUsage("");
+ SkCommandLineFlags::Parse(argc, argv);
+ if (FLAGS_writePath.isEmpty()) {
+ return 1;
+ }
+ const char* writePath = FLAGS_writePath[0];
+ if (!sk_mkdir(writePath)) {
+ return 1;
+ }
+ for (const skiagm::GMRegistry* reg = skiagm::GMRegistry::Head();
+ reg != NULL;
+ reg = reg->next()) {
+ SkAutoTDelete<skiagm::GM> gm(reg->factory()(NULL));
+ if (!gm.get()) {
+ continue;
+ }
+ const char* name = gm->getName();
+ if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, name)) {
+ SkString path = SkOSPath::Join(writePath, name);
+ path.append(".skp");
+ SkFILEWStream outputStream(path.c_str());
+ if (!outputStream.isValid()) {
+ SkDebugf("Could not open file %s\n", path.c_str());
+ return 1;
+ }
+ gmtoskp(gm, &outputStream);
+ }
+ }
+ return 0;
+}
diff --git a/experimental/tools/multipage_pdf_profiler.cpp b/experimental/tools/multipage_pdf_profiler.cpp
new file mode 100644
index 0000000000..93c8df9fb4
--- /dev/null
+++ b/experimental/tools/multipage_pdf_profiler.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkCanvas.h"
+#include "SkDocument.h"
+#include "SkForceLinking.h"
+#include "SkGraphics.h"
+#include "SkNullCanvas.h"
+#include "SkPicture.h"
+#include "SkStream.h"
+#include "SkTemplates.h"
+#include "ProcStats.h"
+#include "flags/SkCommandLineFlags.h"
+
+#ifdef SK_ENABLE_NEW_SKPDF_BACKEND
+#include "skpdf.h"
+#endif
+
+DEFINE_string2(readPath,
+ r,
+ "",
+ "(Required) The path to a .skp Skia Picture file.");
+DEFINE_string2(writePath, w, "", "If set, write PDF output to this file.");
+DEFINE_bool(newPdf, false, "Use the new PDF backend.");
+DEFINE_bool(nullCanvas, true, "Render to a SkNullCanvas as a control.");
+
+__SK_FORCE_IMAGE_DECODER_LINKING;
+
+namespace {
+class NullWStream : public SkWStream {
+public:
+ NullWStream() : fBytesWritten(0) {
+ }
+ virtual bool write(const void*, size_t size) SK_OVERRIDE {
+ fBytesWritten += size;
+ return true;
+ }
+ virtual size_t bytesWritten() const SK_OVERRIDE {
+ return fBytesWritten;
+ }
+ size_t fBytesWritten;
+};
+
+SkDocument* CreatePDFDocument(SkWStream* out) {
+#ifdef SK_ENABLE_NEW_SKPDF_BACKEND
+ if (FLAGS_newPdf) {
+ return skpdf::CreatePDFDocument(out);
+ }
+#endif
+ return SkDocument::CreatePDF(out);
+}
+} // namespace
+
+int main(int argc, char** argv) {
+ SkCommandLineFlags::Parse(argc, argv);
+ if (FLAGS_readPath.isEmpty()) {
+ SkDebugf("Error: missing requires --readPath option\n");
+ return 1;
+ }
+ const char* path = FLAGS_readPath[0];
+ SkFILEStream inputStream(path);
+
+ if (!inputStream.isValid()) {
+ SkDebugf("Could not open file %s\n", path);
+ return 2;
+ }
+ SkAutoGraphics ag;
+ SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream));
+ if (NULL == picture.get()) {
+ SkDebugf("Could not read an SkPicture from %s\n", path);
+ return 3;
+ }
+
+ int width = picture->cullRect().width();
+ int height = picture->cullRect().height();
+
+ const int kLetterWidth = 612; // 8.5 * 72
+ const int kLetterHeight = 792; // 11 * 72
+ SkRect letterRect = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
+ SkIntToScalar(kLetterHeight));
+
+ int xPages = ((width - 1) / kLetterWidth) + 1;
+ int yPages = ((height - 1) / kLetterHeight) + 1;
+
+ SkAutoTDelete<SkWStream> out(SkNEW(NullWStream));
+
+ if (!FLAGS_writePath.isEmpty()) {
+ SkAutoTDelete<SkFILEWStream> fileStream(
+ SkNEW_ARGS(SkFILEWStream, (FLAGS_writePath[0])));
+ if (!fileStream->isValid()) {
+ SkDebugf("Can't open file \"%s\" for writing.", FLAGS_writePath[0]);
+ return 1;
+ }
+ out.reset(fileStream.detach());
+ }
+
+ SkCanvas* nullCanvas = SkCreateNullCanvas();
+
+ SkAutoTUnref<SkDocument> pdfDocument;
+ if (!FLAGS_nullCanvas) {
+ pdfDocument.reset(CreatePDFDocument(out.get()));
+ }
+
+ for (int y = 0; y < yPages; ++y) {
+ for (int x = 0; x < xPages; ++x) {
+ SkCanvas* canvas;
+ if (FLAGS_nullCanvas) {
+ canvas = nullCanvas;
+ } else {
+ int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
+ int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
+ canvas = pdfDocument->beginPage(w, h);
+ }
+ {
+ SkAutoCanvasRestore autoCanvasRestore(canvas, true);
+ canvas->clipRect(letterRect);
+ canvas->translate(SkIntToScalar(-kLetterWidth * x),
+ SkIntToScalar(-kLetterHeight * y));
+ canvas->drawPicture(picture);
+ }
+ canvas->flush();
+ if (!FLAGS_nullCanvas) {
+ pdfDocument->endPage();
+ }
+ }
+ }
+ if (!FLAGS_nullCanvas) {
+ pdfDocument->close();
+ pdfDocument.reset(NULL);
+ }
+ printf(SK_SIZE_T_SPECIFIER "\t%4d\n",
+ inputStream.getLength(),
+ sk_tools::getMaxResidentSetSizeMB());
+ return 0;
+}
diff --git a/experimental/tools/multipage_pdf_profiler.sh b/experimental/tools/multipage_pdf_profiler.sh
new file mode 100755
index 0000000000..d2cbdc5a3d
--- /dev/null
+++ b/experimental/tools/multipage_pdf_profiler.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "usage: $0 SKP_DIRECTORY MULTIPAGE_PDF_PROFILER_EXE" >&2
+ exit 1
+fi
+
+SKP_DIRECTORY="$1"
+MULTIPAGE_PDF_PROFILER_EXE="$2"
+
+printf '"FILE","SKP SIZE (BYTES)","MEMORY USE (MB)"\n' >&2
+for skp in "$SKP_DIRECTORY"/*.skp; do
+ r=$("$MULTIPAGE_PDF_PROFILER_EXE" 0 "$skp")
+ skp_size=$(echo $r | awk '{ print $1 }')
+ mem0=$(echo $r | awk '{ print $2 }')
+ mem1=$("$MULTIPAGE_PDF_PROFILER_EXE" 1 "$skp" | awk '{ print $2 }')
+ printf '"%s",%d,%d\n' $(basename "$skp") $skp_size $(($mem1 - $mem0))
+done