Revert "FX_BOOL considered harmful, part 2."
[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         return CPDF_ProgressiveRenderer::ToFPDFStatus(pContext->m_pRenderer->GetStatus());
49
50     return FPDF_RENDER_FAILED;
51 }
52
53 DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause)
54 {
55     if (page == NULL)
56         return FPDF_RENDER_FAILED;
57
58     if (!pause)
59         return FPDF_RENDER_FAILED;
60
61     if (pause->version !=1)
62         return FPDF_RENDER_FAILED;
63
64     CPDF_Page* pPage = (CPDF_Page*)page;
65     CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
66     if (pContext && pContext->m_pRenderer)
67     {
68         IFSDK_PAUSE_Adapter IPauseAdapter(pause);
69         pContext->m_pRenderer->Continue(&IPauseAdapter);
70         return CPDF_ProgressiveRenderer::ToFPDFStatus(pContext->m_pRenderer->GetStatus());
71     }
72     return FPDF_RENDER_FAILED;
73 }
74
75
76 DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
77 {
78     if (!page)
79         return;
80
81     CPDF_Page* pPage = (CPDF_Page*)page;
82     CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
83     if (!pContext)
84         return;
85
86     pContext->m_pDevice->RestoreState();
87     delete pContext;
88     pPage->RemovePrivateData((void*)1);
89 }
90