blob: 5226770d488832561dffd843d05cc77267912f49 [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.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../include/fpdf_progressive.h"
8#include "../include/fsdk_define.h"
9#include "../include/fpdfview.h"
10#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
14extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
15 int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );
16
17extern void DropContext(void* data);
18
19DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page,
20 int start_x, int start_y, int size_x,
21 int size_y, int rotate, int flags,
22 IFSDK_PAUSE * pause )
23{
24 if (bitmap == NULL || page == NULL)
25 return FPDF_RENDER_FAILED;
26
27 if (!pause)
28 return FPDF_RENDER_FAILED;
29
30 if (pause->version !=1)
31 return FPDF_RENDER_FAILED;
32
Bo Xufdc00a72014-10-28 23:03:33 -070033 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
34 if (!pPage)
35 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
37// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
38
39 CRenderContext* pContext = FX_NEW CRenderContext;
40 pPage->SetPrivateData((void*)1, pContext, DropContext );
41#ifdef _SKIA_SUPPORT_
42 pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
43 if (flags & FPDF_REVERSE_BYTE_ORDER)
44 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
45 else
46 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
47#else
48 pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
49 if (flags & FPDF_REVERSE_BYTE_ORDER)
50 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
51 else
52 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
53#endif
54 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
55
Bo Xud4e406e2014-08-13 11:03:19 -070056 Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057
58 if ( pContext->m_pRenderer )
59 {
60 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
61 status = pContext->m_pRenderer->GetStatus();
62 return status;
63 }
64 return FPDF_RENDER_FAILED;
65}
66
67DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)
68{
69 if (page == NULL)
70 return FPDF_RENDER_FAILED;
71
72 if (!pause)
73 return FPDF_RENDER_FAILED;
74
75 if (pause->version !=1)
76 return FPDF_RENDER_FAILED;
77
Bo Xufdc00a72014-10-28 23:03:33 -070078 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
79 if (!pPage)
80 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
82// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
83
84 CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
85 if (pContext && pContext->m_pRenderer)
86 {
87 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
88 pContext->m_pRenderer->Continue(&IPauseAdapter);
89
90 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
91 status = pContext->m_pRenderer->GetStatus();
92 return status;
93 }
94 return FPDF_RENDER_FAILED;
95}
96
97
98DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
99{
100 if (page == NULL) return;
Bo Xufdc00a72014-10-28 23:03:33 -0700101 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
102 if (!pPage) return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700103
104// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
105
106 CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
107 if (pContext)
108 {
109 pContext->m_pDevice->RestoreState();
110 delete pContext;
111 pPage->RemovePrivateData((void*)1);
112 }
113}
114