From aeadad1dfb7e4d3582d63dacd2ecbed71a5dd4ec Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 18 Jul 2017 16:43:41 -0400 Subject: Make progressive renderer default for pdfium_test. When Chrome renders PDF pages it uses the progressive renderer. The one shot renderer is used to render print preview pages. This CL changes pdfium_test to use the progressive renderer by default to better match Chrome. This also adds a --render-oneshot flag which will use the non-progressive renderer. Bug: chromium:736695 Change-Id: If79333ae10a0ed1c9bce1290caad8d531e6709aa Reviewed-on: https://pdfium-review.googlesource.com/8130 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- samples/pdfium_test.cc | 36 ++++++++++++++++++++++++++++++++++-- testing/tools/run_corpus_tests.py | 1 + testing/tools/test_runner.py | 7 +++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 223a29f1f4..719ac509aa 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -25,6 +25,7 @@ #include "public/fpdf_edit.h" #include "public/fpdf_ext.h" #include "public/fpdf_formfill.h" +#include "public/fpdf_progressive.h" #include "public/fpdf_structtree.h" #include "public/fpdf_text.h" #include "public/fpdfview.h" @@ -81,6 +82,7 @@ struct Options { : show_config(false), show_metadata(false), send_events(false), + render_oneshot(false), #ifdef ENABLE_CALLGRIND callgrind_delimiters(false), #endif // ENABLE_CALLGRIND @@ -92,6 +94,7 @@ struct Options { bool show_config; bool show_metadata; bool send_events; + bool render_oneshot; #ifdef ENABLE_CALLGRIND bool callgrind_delimiters; #endif // ENABLE_CALLGRIND @@ -696,6 +699,8 @@ bool ParseCommandLine(const std::vector& args, options->show_metadata = true; } else if (cur_arg == "--send-events") { options->send_events = true; + } else if (cur_arg == "--render-oneshot") { + options->render_oneshot = true; #ifdef ENABLE_CALLGRIND } else if (cur_arg == "--callgrind-delim") { options->callgrind_delimiters = true; @@ -973,6 +978,13 @@ void DumpPageStructure(FPDF_PAGE page, const int page_idx) { printf("\n\n"); } +// Note, for a client using progressive rendering you'd want to determine if you +// need the rendering to pause instead of always saying |true|. This is for +// testing to force the renderer to break whenever possible. +FPDF_BOOL NeedToPauseNow(IFSDK_PAUSE* p) { + return true; +} + bool RenderPage(const std::string& name, FPDF_DOCUMENT doc, FPDF_FORMHANDLE form, @@ -1007,11 +1019,30 @@ bool RenderPage(const std::string& name, if (bitmap) { FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; FPDFBitmap_FillRect(bitmap.get(), 0, 0, width, height, fill_color); - FPDF_RenderPageBitmap(bitmap.get(), page.get(), 0, 0, width, height, 0, - FPDF_ANNOT); + + if (options.render_oneshot) { + // Note, client programs probably want to use this method instead of the + // progressive calls. The progressive calls are if you need to pause the + // rendering to update the UI, the PDF renderer will break when possible. + FPDF_RenderPageBitmap(bitmap.get(), page.get(), 0, 0, width, height, 0, + FPDF_ANNOT); + } else { + IFSDK_PAUSE pause; + pause.version = 1; + pause.NeedToPauseNow = &NeedToPauseNow; + + int rv = FPDF_RenderPageBitmap_Start( + bitmap.get(), page.get(), 0, 0, width, height, 0, FPDF_ANNOT, &pause); + while (rv == FPDF_RENDER_TOBECOUNTINUED) + rv = FPDF_RenderPage_Continue(page.get(), &pause); + } FPDF_FFLDraw(form, bitmap.get(), page.get(), 0, 0, width, height, 0, FPDF_ANNOT); + + if (!options.render_oneshot) + FPDF_RenderPage_Close(page.get()); + int stride = FPDFBitmap_GetStride(bitmap.get()); const char* buffer = reinterpret_cast(FPDFBitmap_GetBuffer(bitmap.get())); @@ -1280,6 +1311,7 @@ static const char kUsageString[] = " --show-metadata - print the file metadata\n" " --show-structure - print the structure elements from the document\n" " --send-events - send input described by .evt file\n" + " --render-oneshot - render image without using progressive renderer\n" #ifdef ENABLE_CALLGRIND " --callgrind-delim - delimit interesting section when using callgrind\n" #endif // ENABLE_CALLGRIND diff --git a/testing/tools/run_corpus_tests.py b/testing/tools/run_corpus_tests.py index 5932685f32..1175de497c 100755 --- a/testing/tools/run_corpus_tests.py +++ b/testing/tools/run_corpus_tests.py @@ -10,6 +10,7 @@ import test_runner def main(): runner = test_runner.TestRunner('corpus') runner.SetEnforceExpectedImages(True) + runner.SetOneShotRenderer(True) return runner.Run() if __name__ == '__main__': diff --git a/testing/tools/test_runner.py b/testing/tools/test_runner.py index 8f0670d33b..9524b7459b 100644 --- a/testing/tools/test_runner.py +++ b/testing/tools/test_runner.py @@ -40,6 +40,7 @@ class TestRunner: def __init__(self, dirname): self.test_dir = dirname self.enforce_expected_images = False + self.oneshot_renderer = False # GenerateAndTest returns a tuple where # success is a boolean indicating whether the tests passed comparison @@ -125,6 +126,8 @@ class TestRunner: cmd_to_run = [self.pdfium_test_path, '--send-events', '--png'] if self.gold_results: cmd_to_run.append('--md5') + if self.oneshot_renderer: + cmd_to_run.append('--render-oneshot') cmd_to_run.append(pdf_path) return common.RunCommandExtractHashedFiles(cmd_to_run) @@ -302,3 +305,7 @@ class TestRunner: def SetEnforceExpectedImages(self, new_value): """Set whether to enforce that each test case provide an expected image.""" self.enforce_expected_images = new_value + + def SetOneShotRenderer(self, new_value): + """Set whether to use the oneshot renderer. """ + self.oneshot_renderer = new_value -- cgit v1.2.3