aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/tools
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-07-15 08:06:29 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-15 08:06:29 -0700
commit4524813cbc34368b640af7ad4a5ce6901d0a7388 (patch)
tree2ab3f871d7fec7019f027dd34c40fe6767a3d9a9 /experimental/tools
parentf0c84407ae12e0483af26881ec9e22de97563fef (diff)
experimental: remove old PDF benchmarking tools
Diffstat (limited to 'experimental/tools')
-rw-r--r--experimental/tools/PageCachingDocument.cpp98
-rw-r--r--experimental/tools/PageCachingDocument.h22
-rw-r--r--experimental/tools/SkDmuxWStream.cpp42
-rw-r--r--experimental/tools/SkDmuxWStream.h32
-rw-r--r--experimental/tools/multipage_pdf_profiler.cpp135
-rwxr-xr-xexperimental/tools/multipage_pdf_profiler.sh18
-rw-r--r--experimental/tools/skp_to_pdf_md5.cpp203
7 files changed, 0 insertions, 550 deletions
diff --git a/experimental/tools/PageCachingDocument.cpp b/experimental/tools/PageCachingDocument.cpp
deleted file mode 100644
index 9baf45c721..0000000000
--- a/experimental/tools/PageCachingDocument.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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 "PageCachingDocument.h"
-#include "SkCanvas.h"
-#include "SkDocument.h"
-#include "SkPictureRecorder.h"
-#include "SkRect.h"
-#include "SkTDArray.h"
-
-namespace {
-
-typedef void (*DoneProc)(SkWStream*, bool);
-typedef SkData* (*Encoder)(size_t*, const SkBitmap&);
-
-// This class allows us to compare the relative memory consumption of
-// the PDF and SkPicture backends.
-class PageCachingDocument : public SkDocument {
-public:
- PageCachingDocument(SkWStream*, DoneProc, Encoder, SkScalar rasterDpi);
- virtual ~PageCachingDocument();
- virtual SkCanvas* onBeginPage(SkScalar width,
- SkScalar height,
- const SkRect& content) override;
- void onEndPage() override;
- bool onClose(SkWStream*) override;
- void onAbort() override;
-
-private:
- struct Page {
- SkScalar fWidth;
- SkScalar fHeight;
- SkAutoTUnref<SkPicture> fPic;
- };
- SkPictureRecorder fRecorder;
- SkTDArray<Page> fPages;
- Encoder fEncoder;
- SkScalar fRasterDpi;
-};
-
-PageCachingDocument::PageCachingDocument(SkWStream* stream,
- DoneProc done,
- Encoder encoder,
- SkScalar rasterDpi)
- : SkDocument(stream, done), fEncoder(encoder), fRasterDpi(rasterDpi) {
-}
-
-PageCachingDocument::~PageCachingDocument() {
- for (Page* p = fPages.begin(); p != fPages.end(); ++p) {
- p->~Page();
- }
-}
-
-SkCanvas* PageCachingDocument::onBeginPage(SkScalar width,
- SkScalar height,
- const SkRect& content) {
- Page* page = fPages.push();
- sk_bzero(page, sizeof(*page));
- page->fWidth = width;
- page->fHeight = height;
- SkASSERT(!page->fPic.get());
- SkCanvas* canvas = fRecorder.beginRecording(content);
- return canvas;
-}
-
-void PageCachingDocument::onEndPage() {
- SkASSERT(fPages.count() > 0);
- SkASSERT(!fPages[fPages.count() - 1].fPic);
- fPages[fPages.count() - 1].fPic.reset(fRecorder.endRecording());
-}
-
-bool PageCachingDocument::onClose(SkWStream* stream) {
- SkAutoTUnref<SkDocument> doc(
- SkDocument::CreatePDF(stream, NULL, fEncoder, fRasterDpi));
- for (Page* page = fPages.begin(); page != fPages.end(); ++page) {
- SkRect cullRect = page->fPic->cullRect();
- SkCanvas* canvas =
- doc->beginPage(page->fWidth, page->fHeight, &cullRect);
- canvas->drawPicture(page->fPic);
- doc->endPage();
- }
- return doc->close();
-}
-
-void PageCachingDocument::onAbort() {
-}
-} // namespace
-
-SkDocument* CreatePageCachingDocument(SkWStream* stream,
- DoneProc done,
- Encoder encoder,
- SkScalar rasterDpi) {
- return SkNEW_ARGS(PageCachingDocument, (stream, done, encoder, rasterDpi));
-}
diff --git a/experimental/tools/PageCachingDocument.h b/experimental/tools/PageCachingDocument.h
deleted file mode 100644
index 19be1ae619..0000000000
--- a/experimental/tools/PageCachingDocument.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef PageCachingDocument_DEFINED
-#define PageCachingDocument_DEFINED
-
-#include "SkScalar.h"
-
-class SkBitmap;
-class SkData;
-class SkDocument;
-class SkWStream;
-
-SkDocument* CreatePageCachingDocument(
- SkWStream* stream,
- void (*done)(SkWStream*, bool) = NULL,
- SkData* (*encoder)(size_t*, const SkBitmap&) = NULL,
- SkScalar rasterDpi = 72.0);
-#endif // PageCachingDocument_DEFINED
diff --git a/experimental/tools/SkDmuxWStream.cpp b/experimental/tools/SkDmuxWStream.cpp
deleted file mode 100644
index 6dde5bfa3b..0000000000
--- a/experimental/tools/SkDmuxWStream.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkDmuxWStream.h"
-
-SkDmuxWStream::SkDmuxWStream(SkWStream* const streamArray[], size_t count)
- : fWStreams(streamArray, static_cast<int>(count)), fBytesWritten(0) {}
-
-SkDmuxWStream::~SkDmuxWStream() {
- for (int i = 0; i < fWStreams.count(); ++i) {
- fWStreams[i]->flush();
- }
-}
-
-bool SkDmuxWStream::write(const void* buffer, size_t size) {
- for (int i = 0; i < fWStreams.count(); ++i) {
- if (!fWStreams[i]->write(buffer, size)) {
- return false;
- }
- }
- fBytesWritten += size;
- return true;
-}
-
-void SkDmuxWStream::newline() {
- for (int i = 0; i < fWStreams.count(); ++i) {
- fWStreams[i]->newline();
- }
- fBytesWritten += 1; // This may be a lie.
-}
-
-void SkDmuxWStream::flush() {
- for (int i = 0; i < fWStreams.count(); ++i) {
- fWStreams[i]->flush();
- }
-}
-
-size_t SkDmuxWStream::bytesWritten() const { return fBytesWritten; }
diff --git a/experimental/tools/SkDmuxWStream.h b/experimental/tools/SkDmuxWStream.h
deleted file mode 100644
index aac8b18a88..0000000000
--- a/experimental/tools/SkDmuxWStream.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef SkDmuxWStream_DEFINED
-#define SkDmuxWStream_DEFINED
-
-#include "SkStream.h"
-#include "SkTDArray.h"
-
-/**
- * A SkWStream Demultiplexer. If initialized with
- * SkDmuxWStream dmuxWStream(NULL, 0);
- * then it becomes a /dev/null.
- */
-class SkDmuxWStream : public SkWStream {
-public:
- SkDmuxWStream(SkWStream* const streamArray[], size_t count);
- ~SkDmuxWStream();
- virtual bool write(const void* buffer, size_t size) override;
- virtual void newline() override;
- virtual void flush() override;
- virtual size_t bytesWritten() const override;
-
-private:
- SkTDArray<SkWStream*> fWStreams;
- size_t fBytesWritten;
-};
-
-#endif // SkDmuxWStream_DEFINED
diff --git a/experimental/tools/multipage_pdf_profiler.cpp b/experimental/tools/multipage_pdf_profiler.cpp
deleted file mode 100644
index 08a32a2436..0000000000
--- a/experimental/tools/multipage_pdf_profiler.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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 "PageCachingDocument.h"
-#include "ProcStats.h"
-#include "flags/SkCommandLineFlags.h"
-
-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(cachePages, false, "Use a PageCachingDocument.");
-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) {
- }
- bool write(const void*, size_t size) override {
- fBytesWritten += size;
- return true;
- }
- size_t bytesWritten() const override {
- return fBytesWritten;
- }
- size_t fBytesWritten;
-};
-
-SkDocument* CreatePDFDocument(SkWStream* out) {
- if (FLAGS_cachePages) {
- return CreatePageCachingDocument(out);
- } else {
- 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));
- picture->playback(canvas);
- //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
deleted file mode 100755
index d2cbdc5a3d..0000000000
--- a/experimental/tools/multipage_pdf_profiler.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/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
diff --git a/experimental/tools/skp_to_pdf_md5.cpp b/experimental/tools/skp_to_pdf_md5.cpp
deleted file mode 100644
index 87f504510f..0000000000
--- a/experimental/tools/skp_to_pdf_md5.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright 2015 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 "SkCommandLineFlags.h"
-#include "SkDocument.h"
-#include "SkForceLinking.h"
-#include "SkGraphics.h"
-#include "SkMD5.h"
-#include "SkOSFile.h"
-#include "SkPicture.h"
-#include "SkStream.h"
-#include "SkTArray.h"
-#include "SkTSort.h"
-
-#include "SkDmuxWStream.h"
-
-static const char kUsage[] =
- "This program takes a list of Skia Picture (SKP) files and renders\n"
- "each as a multipage PDF, then prints out the MD5 checksum of the\n"
- "PDF file. This can be used to verify that changes to the PDF\n"
- "backend will not change PDF output.\n";
-
-__SK_FORCE_IMAGE_DECODER_LINKING;
-
-DEFINE_string2(inputPaths,
- r,
- "",
- "A list of directories and files to use as input.\n"
- "Files are expected to have the .skp extension.");
-
-DEFINE_string2(outputDirectoryPath, w, "", "TODO: document this");
-
-static const char SKP_FILE_EXTENSION[] = ".skp";
-static const char PDF_FILE_EXTENSION[] = ".pdf";
-
-// Used by SkTQSort<SkString>()
-static bool operator<(const SkString& a, const SkString& b) {
- return strcmp(a.c_str(), b.c_str()) < 0;
-}
-
-// Process --inputPaths defined on the command line. Return false if
-// no files found.
-static bool process_input_files(SkTArray<SkString>* files) {
- for (int i = 0; i < FLAGS_inputPaths.count(); i++) {
- const char* input = FLAGS_inputPaths[i];
- if (sk_isdir(input)) {
- SkOSFile::Iter iter(input, SKP_FILE_EXTENSION);
- SkString inputFilename;
- while (iter.next(&inputFilename)) {
- files->push_back(SkOSPath::Join(input, inputFilename.c_str()));
- }
- } else {
- if (SkStrEndsWith(input, SKP_FILE_EXTENSION)) {
- if (sk_exists(input)) {
- files->push_back(SkString(input));
- } else {
- SkDebugf("file_does_not_exist %s\n", input);
- }
- } else {
- SkDebugf("skipping_file %s\n", input);
- }
- }
- }
- if (files->count() > 0) {
- SkTQSort<SkString>(files->begin(), files->end() - 1);
- return true;
- }
- return false;
-}
-
-// Print the given SkPicture to a PDF, breaking on 8.5x11 pages.
-static void picture_to_pdf(const SkPicture& picture, SkWStream* out) {
- SkAutoTUnref<SkDocument> pdfDocument(SkDocument::CreatePDF(out));
-
- 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;
-
- 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 = pdfDocument->beginPage(w, h);
- canvas->clipRect(letterRect);
- canvas->translate(SkIntToScalar(-kLetterWidth * x),
- SkIntToScalar(-kLetterHeight * y));
- canvas->drawPicture(&picture);
- canvas->flush();
- pdfDocument->endPage();
- }
- }
- pdfDocument->close();
- out->flush();
-}
-
-static bool skp_to_pdf_md5(SkStream* input, SkMD5::Digest* digest) {
- SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(input));
- if (NULL == picture.get()) {
- return false;
- }
-
- SkMD5 checksumWStream;
- picture_to_pdf(*picture, &checksumWStream);
- checksumWStream.finish(*digest);
- return true;
-}
-
-static bool skp_to_pdf_and_md5(SkStream* input,
- const char* path,
- SkMD5::Digest* digest) {
- SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(input));
- if (NULL == picture.get()) {
- return false;
- }
-
- SkMD5 checksumWStream;
- SkFILEWStream fileWStream(path);
- SkWStream* wStreamArray[] = {&checksumWStream, &fileWStream};
- SkDmuxWStream dmuxWStream(wStreamArray, SK_ARRAY_COUNT(wStreamArray));
-
- picture_to_pdf(*picture, &dmuxWStream);
- checksumWStream.finish(*digest);
- return true;
-}
-
-SkString digest_to_hex(const SkMD5::Digest& digest) {
- static const char kHex[] = "0123456789ABCDEF";
- SkString string(2 * sizeof(digest.data));
- char* p = string.writable_str();
- for (size_t i = 0; i < sizeof(digest.data); ++i) {
- uint8_t c = digest.data[i];
- *(p++) = kHex[c >> 4];
- *(p++) = kHex[c & 0xF];
- }
- return string;
-}
-
-static void str_replace_ending(SkString* str,
- const char* oldExt,
- const char* newExt) {
- SkASSERT(str->endsWith(oldExt));
- SkASSERT(str->size() >= strlen(oldExt));
- str->remove(str->size() - strlen(oldExt), strlen(oldExt));
- str->append(newExt);
-}
-
-int main(int argc, char** argv) {
- SkCommandLineFlags::SetUsage(kUsage);
- SkCommandLineFlags::Parse(argc, argv);
- const char* outputDir = FLAGS_outputDirectoryPath.count() > 0
- ? FLAGS_outputDirectoryPath[0]
- : NULL;
- if (outputDir) {
- sk_mkdir(outputDir);
- }
-
- SkAutoGraphics ag;
- int successCount = 0;
- SkTArray<SkString> files;
- if (!process_input_files(&files)) {
- SkDebugf("You need to specify a --inputPaths option.\n");
- return 1;
- }
- for (int i = 0; i < files.count(); ++i) {
- SkString basename = SkOSPath::Basename(files[i].c_str());
- SkFILEStream inputStream(files[i].c_str());
- if (!inputStream.isValid()) {
- SkDebugf("could_not_open %s\n", basename.c_str());
- continue;
- }
- SkMD5::Digest digest;
-
- if (outputDir) {
- SkString path = SkOSPath::Join(outputDir, basename.c_str());
- str_replace_ending(&path, SKP_FILE_EXTENSION, PDF_FILE_EXTENSION);
- if (!skp_to_pdf_and_md5(&inputStream, path.c_str(), &digest)) {
- SkDebugf("invalid_skp %s\n", basename.c_str());
- continue;
- }
- } else {
- if (!skp_to_pdf_md5(&inputStream, &digest)) {
- SkDebugf("invalid_skp %s\n", basename.c_str());
- continue;
- }
- }
- SkString hexDigest = digest_to_hex(digest);
- printf("%s %s\n", hexDigest.c_str(), basename.c_str());
- ++successCount;
- }
- return successCount == files.count() ? 0 : 1;
-}
-