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