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 | |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 9 | #include "core/fpdfapi/fpdf_render/include/cpdf_progressiverenderer.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 10 | #include "fpdfsdk/include/fsdk_define.h" |
| 11 | #include "fpdfsdk/include/fsdk_rendercontext.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 12 | #include "public/fpdfview.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Lei Zhang | 8fec3e4 | 2015-11-04 15:32:02 -0800 | [diff] [blame] | 14 | // These checks are here because core/ and public/ cannot depend on each other. |
| 15 | static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER, |
| 16 | "CPDF_ProgressiveRenderer::Ready value mismatch"); |
| 17 | static_assert(CPDF_ProgressiveRenderer::ToBeContinued == |
| 18 | FPDF_RENDER_TOBECOUNTINUED, |
| 19 | "CPDF_ProgressiveRenderer::ToBeContinued value mismatch"); |
| 20 | static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE, |
| 21 | "CPDF_ProgressiveRenderer::Done value mismatch"); |
| 22 | static_assert(CPDF_ProgressiveRenderer::Failed == FPDF_RENDER_FAILED, |
| 23 | "CPDF_ProgressiveRenderer::Failed value mismatch"); |
| 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, |
| 26 | FPDF_PAGE page, |
| 27 | int start_x, |
| 28 | int start_y, |
| 29 | int size_x, |
| 30 | int size_y, |
| 31 | int rotate, |
| 32 | int flags, |
| 33 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 34 | if (!bitmap || !pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 37 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | if (!pPage) |
| 39 | return FPDF_RENDER_FAILED; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 40 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 41 | CRenderContext* pContext = new CRenderContext; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | pPage->SetPrivateData((void*)1, pContext, DropContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | #ifdef _SKIA_SUPPORT_ |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 44 | pContext->m_pDevice = new CFX_SkiaDevice; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 46 | ((CFX_SkiaDevice*)pContext->m_pDevice) |
| 47 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 48 | else |
| 49 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | #else |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 51 | pContext->m_pDevice = new CFX_FxgeDevice; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 53 | ((CFX_FxgeDevice*)pContext->m_pDevice) |
| 54 | ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| 55 | else |
| 56 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 59 | |
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, |
| 61 | rotate, flags, FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | if (pContext->m_pRenderer) { |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 64 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 65 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | } |
| 67 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page, |
| 71 | IFSDK_PAUSE* pause) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 72 | if (!pause || pause->version != 1) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 75 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | if (!pPage) |
| 77 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 80 | if (pContext && pContext->m_pRenderer) { |
| 81 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 82 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
Tom Sepez | b3b6762 | 2015-10-19 16:20:03 -0700 | [diff] [blame] | 83 | return CPDF_ProgressiveRenderer::ToFPDFStatus( |
| 84 | pContext->m_pRenderer->GetStatus()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | } |
| 86 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 90 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | if (!pPage) |
| 92 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 95 | if (!pContext) |
| 96 | return; |
| 97 | |
| 98 | pContext->m_pDevice->RestoreState(); |
| 99 | delete pContext; |
| 100 | pPage->RemovePrivateData((void*)1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | } |