2490df8c2f3dbe94bb6832dd9133443fb80b1228
[pdfium.git] / fpdfsdk / src / fpdf_progressive.cpp
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 "../include/fpdf_progressive.h"
8 #include "../include/fsdk_define.h"
9 #include "../include/fpdfview.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
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         
33 //      FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
34         
35         CRenderContext* pContext = FX_NEW CRenderContext;
36         pPage->SetPrivateData((void*)1, pContext, DropContext );
37 #ifdef _SKIA_SUPPORT_
38         pContext->m_pDevice = FX_NEW CFX_SkiaDevice;
39         if (flags & FPDF_REVERSE_BYTE_ORDER)
40                 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
41         else
42                 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
43 #else
44         pContext->m_pDevice = FX_NEW CFX_FxgeDevice;
45         if (flags & FPDF_REVERSE_BYTE_ORDER)
46                 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);
47         else
48                 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
49 #endif
50         IFSDK_PAUSE_Adapter IPauseAdapter(pause);
51         
52         Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);
53
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
63 DLLEXPORT 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;
70         
71         if (pause->version !=1)
72                 return FPDF_RENDER_FAILED;
73
74         CPDF_Page* pPage = (CPDF_Page*)page;
75
76 //      FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
77
78         CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
79         if (pContext && pContext->m_pRenderer)
80         {
81                 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
82                 pContext->m_pRenderer->Continue(&IPauseAdapter);
83
84                 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;
85                 status = pContext->m_pRenderer->GetStatus();
86                 return status;
87         }
88         return FPDF_RENDER_FAILED;
89 }
90
91
92 DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
93 {
94         if (page == NULL) return;
95         CPDF_Page* pPage = (CPDF_Page*)page;
96
97 //      FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
98
99         CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
100         if (pContext)
101         {
102                 pContext->m_pDevice->RestoreState();
103                 delete pContext;
104                 pPage->RemovePrivateData((void*)1);
105         }
106 }
107