John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_progressive.h" |
| 8 | |
dsinclair | 39c62fd | 2016-09-29 12:49:17 -0700 | [diff] [blame] | 9 | #include "core/fpdfapi/cpdf_pagerendercontext.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 10 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame^] | 11 | #include "core/fpdfapi/render/cpdf_progressiverenderer.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 12 | #include "core/fxcrt/fx_memory.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 13 | #include "core/fxge/cfx_fxgedevice.h" |
| 14 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/fsdk_define.h" |
| 16 | #include "fpdfsdk/fsdk_pauseadapter.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 17 | #include "public/fpdfview.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 18 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | |
Lei Zhang | 8fec3e4 | 2015-11-04 15:32:02 -0800 | [diff] [blame] | 20 | // These checks are here because core/ and public/ cannot depend on each other. |
| 21 | static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER, |
| 22 | "CPDF_ProgressiveRenderer::Ready value mismatch"); |
| 23 | static_assert(CPDF_ProgressiveRenderer::ToBeContinued == |
| 24 | FPDF_RENDER_TOBECOUNTINUED, |
| 25 | "CPDF_ProgressiveRenderer::ToBeContinued value mismatch"); |
| 26 | static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE, |
| 27 | "CPDF_ProgressiveRenderer::Done value mismatch"); |
| 28 | static_assert(CPDF_ProgressiveRenderer::Failed == FPDF_RENDER_FAILED, |
| 29 | "CPDF_ProgressiveRenderer::Failed value mismatch"); |
| 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, |
| 32 | FPDF_PAGE page, |
| 33 | int start_x, |
| 34 | int start_y, |
| 35 | int size_x, |
| 36 | int size_y, |
| 37 | int rotate, |
| 38 | int flags, |
| 39 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 40 | if (!bitmap || !pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 43 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | if (!pPage) |
| 45 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 46 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 47 | CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 48 | pPage->SetRenderContext(pdfium::WrapUnique(pContext)); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 49 | CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 50 | pContext->m_pDevice.reset(pDevice); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 51 | CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); |
| 52 | pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 53 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 54 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 56 | rotate, flags, FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | if (pContext->m_pRenderer) { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 59 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 60 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | } |
| 62 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 66 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 67 | if (!pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 70 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | if (!pPage) |
| 72 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 74 | CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | if (pContext && pContext->m_pRenderer) { |
| 76 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 77 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 78 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 79 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | } |
| 81 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 85 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | if (!pPage) |
| 87 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 88 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 89 | CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 90 | if (!pContext) |
| 91 | return; |
| 92 | |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 93 | pContext->m_pDevice->RestoreState(false); |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 94 | pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | } |