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