DEPS include_rules no longer allows core/ -> fpsdfsk/ inclusion.
[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 || !pause || pause->version != 1)
22     return FPDF_RENDER_FAILED;
23
24   CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
25   if (!pPage)
26     return FPDF_RENDER_FAILED;
27
28   CRenderContext* pContext = new CRenderContext;
29   pPage->SetPrivateData((void*)1, pContext, DropContext);
30 #ifdef _SKIA_SUPPORT_
31   pContext->m_pDevice = new CFX_SkiaDevice;
32   if (flags & FPDF_REVERSE_BYTE_ORDER)
33     ((CFX_SkiaDevice*)pContext->m_pDevice)
34         ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
35   else
36     ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
37 #else
38   pContext->m_pDevice = new CFX_FxgeDevice;
39   if (flags & FPDF_REVERSE_BYTE_ORDER)
40     ((CFX_FxgeDevice*)pContext->m_pDevice)
41         ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
42   else
43     ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
44 #endif
45   IFSDK_PAUSE_Adapter IPauseAdapter(pause);
46
47   FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
48                          rotate, flags, FALSE, &IPauseAdapter);
49
50   if (pContext->m_pRenderer)
51     return CPDF_ProgressiveRenderer::ToFPDFStatus(
52         pContext->m_pRenderer->GetStatus());
53
54   return FPDF_RENDER_FAILED;
55 }
56
57 DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
58                                                IFSDK_PAUSE* pause) {
59   if (!pause || pause->version != 1)
60     return FPDF_RENDER_FAILED;
61
62   CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
63   if (!pPage)
64     return FPDF_RENDER_FAILED;
65
66   CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
67   if (pContext && pContext->m_pRenderer) {
68     IFSDK_PAUSE_Adapter IPauseAdapter(pause);
69     pContext->m_pRenderer->Continue(&IPauseAdapter);
70     return CPDF_ProgressiveRenderer::ToFPDFStatus(
71         pContext->m_pRenderer->GetStatus());
72   }
73   return FPDF_RENDER_FAILED;
74 }
75
76 DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
77   CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
78   if (!pPage)
79     return;
80
81   CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
82   if (!pContext)
83     return;
84
85   pContext->m_pDevice->RestoreState();
86   delete pContext;
87   pPage->RemovePrivateData((void*)1);
88 }