Fix build broken at 506df426d5d6.
[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,
13                                                   FPDF_PAGE page,
14                                                   int start_x,
15                                                   int start_y,
16                                                   int size_x,
17                                                   int size_y,
18                                                   int rotate,
19                                                   int flags,
20                                                   IFSDK_PAUSE* pause) {
21   if (bitmap == NULL || page == NULL)
22     return FPDF_RENDER_FAILED;
23
24   if (!pause)
25     return FPDF_RENDER_FAILED;
26
27   if (pause->version != 1)
28     return FPDF_RENDER_FAILED;
29
30   CPDF_Page* pPage = (CPDF_Page*)page;
31   CRenderContext* pContext = new CRenderContext;
32   pPage->SetPrivateData((void*)1, pContext, DropContext);
33 #ifdef _SKIA_SUPPORT_
34   pContext->m_pDevice = new CFX_SkiaDevice;
35   if (flags & FPDF_REVERSE_BYTE_ORDER)
36     ((CFX_SkiaDevice*)pContext->m_pDevice)
37         ->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)
44         ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
45   else
46     ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
47 #endif
48   IFSDK_PAUSE_Adapter IPauseAdapter(pause);
49
50   FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
51                          rotate, flags, FALSE, &IPauseAdapter);
52
53   if (pContext->m_pRenderer)
54     return CPDF_ProgressiveRenderer::ToFPDFStatus(
55         pContext->m_pRenderer->GetStatus());
56
57   return FPDF_RENDER_FAILED;
58 }
59
60 DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
61                                                IFSDK_PAUSE* pause) {
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   CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
73   if (pContext && pContext->m_pRenderer) {
74     IFSDK_PAUSE_Adapter IPauseAdapter(pause);
75     pContext->m_pRenderer->Continue(&IPauseAdapter);
76     return CPDF_ProgressiveRenderer::ToFPDFStatus(
77         pContext->m_pRenderer->GetStatus());
78   }
79   return FPDF_RENDER_FAILED;
80 }
81
82 DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
83   if (!page)
84     return;
85
86   CPDF_Page* pPage = (CPDF_Page*)page;
87   CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
88   if (!pContext)
89     return;
90
91   pContext->m_pDevice->RestoreState();
92   delete pContext;
93   pPage->RemovePrivateData((void*)1);
94 }