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