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 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
dsinclair | 39c62fd | 2016-09-29 12:49:17 -0700 | [diff] [blame] | 11 | #include "core/fpdfapi/cpdf_pagerendercontext.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/render/cpdf_progressiverenderer.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 14 | #include "core/fxcrt/fx_memory.h" |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 15 | #include "core/fxge/cfx_defaultrenderdevice.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 16 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/fsdk_define.h" |
| 18 | #include "fpdfsdk/fsdk_pauseadapter.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 19 | #include "public/fpdfview.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 20 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | |
Lei Zhang | 8fec3e4 | 2015-11-04 15:32:02 -0800 | [diff] [blame] | 22 | // These checks are here because core/ and public/ cannot depend on each other. |
Dan Sinclair | 72cc6c6 | 2017-07-24 09:16:19 -0400 | [diff] [blame] | 23 | static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READY, |
Lei Zhang | 8fec3e4 | 2015-11-04 15:32:02 -0800 | [diff] [blame] | 24 | "CPDF_ProgressiveRenderer::Ready value mismatch"); |
| 25 | static_assert(CPDF_ProgressiveRenderer::ToBeContinued == |
Dan Sinclair | 5672524 | 2017-07-18 12:05:33 -0400 | [diff] [blame] | 26 | FPDF_RENDER_TOBECONTINUED, |
Lei Zhang | 8fec3e4 | 2015-11-04 15:32:02 -0800 | [diff] [blame] | 27 | "CPDF_ProgressiveRenderer::ToBeContinued value mismatch"); |
| 28 | static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE, |
| 29 | "CPDF_ProgressiveRenderer::Done value mismatch"); |
| 30 | static_assert(CPDF_ProgressiveRenderer::Failed == FPDF_RENDER_FAILED, |
| 31 | "CPDF_ProgressiveRenderer::Failed value mismatch"); |
| 32 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame^] | 33 | FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, |
| 34 | FPDF_PAGE page, |
| 35 | int start_x, |
| 36 | int start_y, |
| 37 | int size_x, |
| 38 | int size_y, |
| 39 | int rotate, |
| 40 | int flags, |
| 41 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 42 | if (!bitmap || !pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 45 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | if (!pPage) |
| 47 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 48 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 49 | auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>(); |
| 50 | CPDF_PageRenderContext* pContext = pOwnedContext.get(); |
| 51 | pPage->SetRenderContext(std::move(pOwnedContext)); |
| 52 | |
| 53 | CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 54 | auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); |
| 55 | CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get(); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 56 | pContext->m_pDevice = std::move(pOwnedDevice); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 57 | pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 58 | |
tsepez | 1e2c557 | 2016-05-25 14:58:09 -0700 | [diff] [blame] | 59 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 61 | rotate, flags, false, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | |
Cary Clark | 88f4743 | 2017-07-19 13:07:35 -0400 | [diff] [blame] | 63 | #ifdef _SKIA_SUPPORT_PATHS_ |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 64 | pDevice->Flush(false); |
Cary Clark | 88f4743 | 2017-07-19 13:07:35 -0400 | [diff] [blame] | 65 | pBitmap->UnPreMultiply(); |
| 66 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | if (pContext->m_pRenderer) { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 68 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 69 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | } |
| 71 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame^] | 74 | FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 75 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 76 | if (!pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 79 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | if (!pPage) |
| 81 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 83 | CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | if (pContext && pContext->m_pRenderer) { |
| 85 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 86 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
Cary Clark | 88f4743 | 2017-07-19 13:07:35 -0400 | [diff] [blame] | 87 | #ifdef _SKIA_SUPPORT_PATHS_ |
Cary Clark | d4c4011 | 2017-07-19 15:33:34 -0400 | [diff] [blame] | 88 | CFX_RenderDevice* pDevice = pContext->m_pDevice.get(); |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 89 | pDevice->Flush(false); |
Cary Clark | d4c4011 | 2017-07-19 15:33:34 -0400 | [diff] [blame] | 90 | pDevice->GetBitmap()->UnPreMultiply(); |
Cary Clark | 88f4743 | 2017-07-19 13:07:35 -0400 | [diff] [blame] | 91 | #endif |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 92 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 93 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | } |
| 95 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame^] | 98 | FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage_Close(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 99 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 100 | if (pPage) { |
| 101 | #ifdef _SKIA_SUPPORT_PATHS_ |
| 102 | CPDF_PageRenderContext* pContext = pPage->GetRenderContext(); |
| 103 | if (pContext && pContext->m_pRenderer) { |
| 104 | CFX_RenderDevice* pDevice = pContext->m_pDevice.get(); |
| 105 | pDevice->Flush(true); |
| 106 | pDevice->GetBitmap()->UnPreMultiply(); |
| 107 | } |
| 108 | #endif |
Tom Sepez | 385d32f | 2017-05-26 13:08:36 -0700 | [diff] [blame] | 109 | pPage->SetRenderContext(nullptr); |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 110 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 111 | } |