diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-07-18 16:43:41 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-18 21:20:38 +0000 |
commit | aeadad1dfb7e4d3582d63dacd2ecbed71a5dd4ec (patch) | |
tree | df7c1d038a1843585ac5956829d31c5c4fc9bc74 /samples/pdfium_test.cc | |
parent | 7d0af80637afbc673e4bc9a34bcb556afdf3434d (diff) | |
download | pdfium-aeadad1dfb7e4d3582d63dacd2ecbed71a5dd4ec.tar.xz |
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 <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'samples/pdfium_test.cc')
-rw-r--r-- | samples/pdfium_test.cc | 36 |
1 files changed, 34 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<std::string>& 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<const char*>(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 |