blob: f47cd7dde6648839ac2b499aa2e93e63f62da98f [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
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070014DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page,
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015 int start_x, int start_y, int size_x,
16 int size_y, int rotate, int flags,
17 IFSDK_PAUSE * pause )
18{
19 if (bitmap == NULL || page == NULL)
20 return FPDF_RENDER_FAILED;
21
22 if (!pause)
23 return FPDF_RENDER_FAILED;
24
25 if (pause->version !=1)
26 return FPDF_RENDER_FAILED;
27
Bo Xufdc00a72014-10-28 23:03:33 -070028 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
29 if (!pPage)
30 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070031
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070033
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034 CRenderContext* pContext = FX_NEW CRenderContext;
35 pPage->SetPrivateData((void*)1, pContext, DropContext );
36#ifdef _SKIA_SUPPORT_
37 pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
38 if (flags & FPDF_REVERSE_BYTE_ORDER)
39 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
40 else
41 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
42#else
43 pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
44 if (flags & FPDF_REVERSE_BYTE_ORDER)
45 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
46 else
47 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
48#endif
49 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070050
Tom Sepez75f43c42015-07-15 16:35:53 -070051 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
52 rotate, flags,FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
54 if ( pContext->m_pRenderer )
55 {
56 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
57 status = pContext->m_pRenderer->GetStatus();
58 return status;
59 }
60 return FPDF_RENDER_FAILED;
61}
62
63DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)
64{
65 if (page == NULL)
66 return FPDF_RENDER_FAILED;
67
68 if (!pause)
69 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070070
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071 if (pause->version !=1)
72 return FPDF_RENDER_FAILED;
73
Bo Xufdc00a72014-10-28 23:03:33 -070074 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
75 if (!pPage)
76 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077
78// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
79
80 CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
81 if (pContext && pContext->m_pRenderer)
82 {
83 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
84 pContext->m_pRenderer->Continue(&IPauseAdapter);
85
86 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
87 status = pContext->m_pRenderer->GetStatus();
88 return status;
89 }
90 return FPDF_RENDER_FAILED;
91}
92
93
94DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
95{
96 if (page == NULL) return;
Bo Xufdc00a72014-10-28 23:03:33 -070097 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
98 if (!pPage) return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
100// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
101
102 CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
103 if (pContext)
104 {
105 pContext->m_pDevice->RestoreState();
106 delete pContext;
107 pPage->RemovePrivateData((void*)1);
108 }
109}
110