aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/PdfViewer
diff options
context:
space:
mode:
authorGravatar edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-11 16:25:51 +0000
committerGravatar edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-11 16:25:51 +0000
commit6a9d436260582b9453de37877b6e00c2dd24f33a (patch)
treef054e6dc352b3f4234102e0d1018fad978a647ad /experimental/PdfViewer
parentde36b6948116a3d498ad8d808869ba182a66e206 (diff)
pdfviewer: add option to run the load or render multiple times, --benchLoad, --benchRender
Review URL: https://codereview.chromium.org/18093008 git-svn-id: http://skia.googlecode.com/svn/trunk@10013 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/PdfViewer')
-rw-r--r--experimental/PdfViewer/SkPdfRenderer.cpp5
-rw-r--r--experimental/PdfViewer/pdf_viewer_main.cpp53
2 files changed, 39 insertions, 19 deletions
diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/SkPdfRenderer.cpp
index 8502ac54b2..2a7e839d41 100644
--- a/experimental/PdfViewer/SkPdfRenderer.cpp
+++ b/experimental/PdfViewer/SkPdfRenderer.cpp
@@ -2003,6 +2003,10 @@ bool SkPdfRenderer::load(const SkString inputFileName) {
// TODO(edisonn): create static function that could return NULL if there are errors
fPdfDoc = new SkNativeParsedPDF(inputFileName.c_str());
+ if (fPdfDoc->pages() == 0) {
+ delete fPdfDoc;
+ fPdfDoc = NULL;
+ }
return fPdfDoc != NULL;
}
@@ -2024,4 +2028,3 @@ SkRect SkPdfRenderer::MediaBox(int page) const {
size_t SkPdfRenderer::bytesUsed() const {
return fPdfDoc ? fPdfDoc->bytesUsed() : 0;
}
-
diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp
index 7bff14a92e..207cd9679f 100644
--- a/experimental/PdfViewer/pdf_viewer_main.cpp
+++ b/experimental/PdfViewer/pdf_viewer_main.cpp
@@ -25,8 +25,12 @@ DEFINE_string2(pages, p, "all", "What pages to render and how:\n"
"\tnumber - a specific page number\n"
);
DEFINE_double(DPI, 72, "DPI to be used for rendering (scale).");
+DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any rendering and \n"
+ "\tminimal parsing to ensure correctness. Default 0 (disabled).");
+DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disabled)");
+
+
// TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all
-// TODO(edisonn): add ability to do the op N times, bench (either load N times, render n times or load + render n times)
/**
* Given list of directories and files to use as input, expects to find .pdf
@@ -160,31 +164,44 @@ static bool process_pdf(const SkString& inputPath, const SkString& outputDir,
bool success = false;
success = renderer.load(inputPath);
+ if (FLAGS_showMemoryUsage) {
+ SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.bytesUsed());
+ }
- if (success) {
- if (FLAGS_showMemoryUsage) {
- SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.bytesUsed());
+ // TODO(edisonn): bench timers
+ if (FLAGS_benchLoad > 0) {
+ for (int i = 0 ; i < FLAGS_benchLoad; i++) {
+ success = renderer.load(inputPath);
+ if (FLAGS_showMemoryUsage) {
+ SkDebugf("Memory usage after load %i number : %u\n", i, (unsigned int)renderer.bytesUsed());
+ }
}
+ }
+
+ if (success) {
if (!renderer.pages())
{
SkDebugf("ERROR: Empty PDF Document %s\n", inputPath.c_str());
return false;
} else {
- if (strcmp(FLAGS_pages[0], "all") == 0) {
- for (int pn = 0; pn < renderer.pages(); ++pn) {
- success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
- }
- } else if (strcmp(FLAGS_pages[0], "reverse") == 0) {
- for (int pn = renderer.pages() - 1; pn >= 0; --pn) {
- success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
+ for (int i = 0; i < FLAGS_benchRender + 1; i++) {
+ // TODO(edisonn) if (i == 1) start timer
+ if (strcmp(FLAGS_pages[0], "all") == 0) {
+ for (int pn = 0; pn < renderer.pages(); ++pn) {
+ success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
+ }
+ } else if (strcmp(FLAGS_pages[0], "reverse") == 0) {
+ for (int pn = renderer.pages() - 1; pn >= 0; --pn) {
+ success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success;
+ }
+ } else if (strcmp(FLAGS_pages[0], "first") == 0) {
+ success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success;
+ } else if (strcmp(FLAGS_pages[0], "last") == 0) {
+ success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && success;
+ } else {
+ int pn = atoi(FLAGS_pages[0]);
+ success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && pn;
}
- } else if (strcmp(FLAGS_pages[0], "first") == 0) {
- success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success;
- } else if (strcmp(FLAGS_pages[0], "last") == 0) {
- success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && success;
- } else {
- int pn = atoi(FLAGS_pages[0]);
- success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && pn;
}
}
}