blob: 9167a77c46a8f77bba0570b1fc19baeda6fc2750 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez1ed8a212015-05-11 15:25:39 -07007#include "../../public/fpdf_progressive.h"
8#include "../../public/fpdfview.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010#include "../include/fsdk_rendercontext.h"
Bo Xufdc00a72014-10-28 23:03:33 -070011#include "../include/fpdfxfa/fpdfxfa_doc.h"
12#include "../include/fpdfxfa/fpdfxfa_page.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Nico Weber9d8ec5a2015-08-04 13:00:21 -070014DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
15 FPDF_PAGE page,
16 int start_x,
17 int start_y,
18 int size_x,
19 int size_y,
20 int rotate,
21 int flags,
22 IFSDK_PAUSE* pause) {
23 if (bitmap == NULL || page == NULL)
24 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 if (!pause)
27 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 if (pause->version != 1)
30 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
33 if (!pPage)
34 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070035
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036 // FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070037
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038 CRenderContext* pContext = FX_NEW CRenderContext;
39 pPage->SetPrivateData((void*)1, pContext, DropContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040#ifdef _SKIA_SUPPORT_
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
42 if (flags & FPDF_REVERSE_BYTE_ORDER)
43 ((CFX_SkiaDevice*)pContext->m_pDevice)
44 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
45 else
46 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
49 if (flags & FPDF_REVERSE_BYTE_ORDER)
50 ((CFX_FxgeDevice*)pContext->m_pDevice)
51 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
52 else
53 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
58 rotate, flags, FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 if (pContext->m_pRenderer) {
61 CPDF_ProgressiveRenderer::RenderStatus status =
62 CPDF_ProgressiveRenderer::Failed;
63 status = pContext->m_pRenderer->GetStatus();
64 return status;
65 }
66 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067}
68
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
70 IFSDK_PAUSE* pause) {
71 if (page == NULL)
72 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 if (!pause)
75 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070076
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 if (pause->version != 1)
78 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
81 if (!pPage)
82 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 // FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
87 if (pContext && pContext->m_pRenderer) {
88 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
89 pContext->m_pRenderer->Continue(&IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 CPDF_ProgressiveRenderer::RenderStatus status =
92 CPDF_ProgressiveRenderer::Failed;
93 status = pContext->m_pRenderer->GetStatus();
94 return status;
95 }
96 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097}
98
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
100 if (page == NULL)
101 return;
102 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
103 if (!pPage)
104 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 // FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
109 if (pContext) {
110 pContext->m_pDevice->RestoreState();
111 delete pContext;
112 pPage->RemovePrivateData((void*)1);
113 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114}