blob: 0628c6268ea20460c0c156473f9c29b72c11033d [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_progressive.h"
8
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010#include "../include/fsdk_rendercontext.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080011#include "public/fpdfview.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
Lei Zhang8fec3e42015-11-04 15:32:02 -080013// These checks are here because core/ and public/ cannot depend on each other.
14static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER,
15 "CPDF_ProgressiveRenderer::Ready value mismatch");
16static_assert(CPDF_ProgressiveRenderer::ToBeContinued ==
17 FPDF_RENDER_TOBECOUNTINUED,
18 "CPDF_ProgressiveRenderer::ToBeContinued value mismatch");
19static_assert(CPDF_ProgressiveRenderer::Done == FPDF_RENDER_DONE,
20 "CPDF_ProgressiveRenderer::Done value mismatch");
21static_assert(CPDF_ProgressiveRenderer::Failed == FPDF_RENDER_FAILED,
22 "CPDF_ProgressiveRenderer::Failed value mismatch");
23
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
25 FPDF_PAGE page,
26 int start_x,
27 int start_y,
28 int size_x,
29 int size_y,
30 int rotate,
31 int flags,
32 IFSDK_PAUSE* pause) {
Tom Sepezdb0be962015-10-16 14:00:21 -070033 if (!bitmap || !pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035
Tom Sepezdb0be962015-10-16 14:00:21 -070036 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 if (!pPage)
38 return FPDF_RENDER_FAILED;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070039
Tom Sepezae51c812015-08-05 12:34:06 -070040 CRenderContext* pContext = new CRenderContext;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 pPage->SetPrivateData((void*)1, pContext, DropContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042#ifdef _SKIA_SUPPORT_
Tom Sepezae51c812015-08-05 12:34:06 -070043 pContext->m_pDevice = new CFX_SkiaDevice;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 if (flags & FPDF_REVERSE_BYTE_ORDER)
45 ((CFX_SkiaDevice*)pContext->m_pDevice)
46 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
47 else
48 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049#else
Tom Sepezae51c812015-08-05 12:34:06 -070050 pContext->m_pDevice = new CFX_FxgeDevice;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 if (flags & FPDF_REVERSE_BYTE_ORDER)
52 ((CFX_FxgeDevice*)pContext->m_pDevice)
53 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE);
54 else
55 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070058
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
60 rotate, flags, FALSE, &IPauseAdapter);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 if (pContext->m_pRenderer) {
Tom Sepezb3b67622015-10-19 16:20:03 -070063 return CPDF_ProgressiveRenderer::ToFPDFStatus(
64 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 }
66 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067}
68
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,
70 IFSDK_PAUSE* pause) {
Tom Sepezdb0be962015-10-16 14:00:21 -070071 if (!pause || pause->version != 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073
Tom Sepezdb0be962015-10-16 14:00:21 -070074 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 if (!pPage)
76 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
79 if (pContext && pContext->m_pRenderer) {
80 IFSDK_PAUSE_Adapter IPauseAdapter(pause);
81 pContext->m_pRenderer->Continue(&IPauseAdapter);
Tom Sepezb3b67622015-10-19 16:20:03 -070082 return CPDF_ProgressiveRenderer::ToFPDFStatus(
83 pContext->m_pRenderer->GetStatus());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 }
85 return FPDF_RENDER_FAILED;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086}
87
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) {
Tom Sepezdb0be962015-10-16 14:00:21 -070089 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 if (!pPage)
91 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 CRenderContext* pContext = (CRenderContext*)pPage->GetPrivateData((void*)1);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070094 if (!pContext)
95 return;
96
97 pContext->m_pDevice->RestoreState();
98 delete pContext;
99 pPage->RemovePrivateData((void*)1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}