Initial commit.
[pdfium.git] / fpdfsdk / src / fpdf_progressive.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../include/fpdf_progressive.h"\r
8 #include "../include/fsdk_define.h"\r
9 #include "../include/fpdfview.h"\r
10 #include "../include/fsdk_rendercontext.h"\r
11 \r
12 extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,\r
13                                                 int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );\r
14 \r
15 extern void DropContext(void* data);\r
16 \r
17 DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page, \r
18                                                                                                         int start_x, int start_y, int size_x,\r
19                                                                                                     int size_y, int rotate, int flags,\r
20                                                                                                         IFSDK_PAUSE * pause )\r
21 {\r
22         if (bitmap == NULL || page == NULL)\r
23                 return FPDF_RENDER_FAILED;\r
24 \r
25         if (!pause)\r
26                 return FPDF_RENDER_FAILED;\r
27 \r
28         if (pause->version !=1)\r
29                 return FPDF_RENDER_FAILED;\r
30 \r
31         CPDF_Page* pPage = (CPDF_Page*)page;\r
32         \r
33 //      FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
34         \r
35         CRenderContext* pContext = FX_NEW CRenderContext;\r
36         pPage->SetPrivateData((void*)1, pContext, DropContext );\r
37 #ifdef _SKIA_SUPPORT_\r
38         pContext->m_pDevice = FX_NEW CFX_SkiaDevice;\r
39         if (flags & FPDF_REVERSE_BYTE_ORDER)\r
40                 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);\r
41         else\r
42                 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);\r
43 #else\r
44         pContext->m_pDevice = FX_NEW CFX_FxgeDevice;\r
45         if (flags & FPDF_REVERSE_BYTE_ORDER)\r
46                 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE);\r
47         else\r
48                 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);\r
49 #endif\r
50         IFSDK_PAUSE_Adapter IPauseAdapter(pause);\r
51         \r
52         if (flags & FPDF_NO_CATCH)\r
53                 Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);\r
54         else {\r
55                 try {\r
56                         Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter);\r
57                         }\r
58                 catch (...){}\r
59         }\r
60 \r
61         if ( pContext->m_pRenderer )\r
62         {\r
63                 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;\r
64                 status = pContext->m_pRenderer->GetStatus();\r
65                 return status;\r
66         }\r
67         return FPDF_RENDER_FAILED;\r
68 }\r
69 \r
70 DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)\r
71 {\r
72         if (page == NULL)\r
73                 return FPDF_RENDER_FAILED;\r
74 \r
75         if (!pause)\r
76                 return FPDF_RENDER_FAILED;\r
77         \r
78         if (pause->version !=1)\r
79                 return FPDF_RENDER_FAILED;\r
80 \r
81         CPDF_Page* pPage = (CPDF_Page*)page;\r
82 \r
83 //      FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
84 \r
85         CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);\r
86         if (pContext && pContext->m_pRenderer)\r
87         {\r
88                 IFSDK_PAUSE_Adapter IPauseAdapter(pause);\r
89                 pContext->m_pRenderer->Continue(&IPauseAdapter);\r
90 \r
91                 CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed;\r
92                 status = pContext->m_pRenderer->GetStatus();\r
93                 return status;\r
94         }\r
95         return FPDF_RENDER_FAILED;\r
96 }\r
97 \r
98 \r
99 DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)\r
100 {\r
101         if (page == NULL) return;\r
102         CPDF_Page* pPage = (CPDF_Page*)page;\r
103 \r
104 //      FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
105 \r
106         CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);\r
107         if (pContext)\r
108         {\r
109                 pContext->m_pDevice->RestoreState();\r
110                 delete pContext;\r
111                 pPage->RemovePrivateData((void*)1);\r
112         }\r
113 }\r
114 \r