John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame^] | 11 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 12 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
| 14 | extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, |
| 15 | int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause ); |
| 16 | |
| 17 | extern void DropContext(void* data); |
| 18 | |
| 19 | DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page, |
| 20 | int start_x, int start_y, int size_x, |
| 21 | int size_y, int rotate, int flags, |
| 22 | IFSDK_PAUSE * pause ) |
| 23 | { |
| 24 | if (bitmap == NULL || page == NULL) |
| 25 | return FPDF_RENDER_FAILED; |
| 26 | |
| 27 | if (!pause) |
| 28 | return FPDF_RENDER_FAILED; |
| 29 | |
| 30 | if (pause->version !=1) |
| 31 | return FPDF_RENDER_FAILED; |
| 32 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame^] | 33 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 34 | if (!pPage) |
| 35 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
| 37 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
| 38 | |
| 39 | CRenderContext* pContext = FX_NEW CRenderContext; |
| 40 | pPage->SetPrivateData((void*)1, pContext, DropContext ); |
| 41 | #ifdef _SKIA_SUPPORT_ |
| 42 | pContext->m_pDevice = FX_NEW CFX_SkiaDevice; |
| 43 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 44 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); |
| 45 | else |
| 46 | ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| 47 | #else |
| 48 | pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
| 49 | if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 50 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); |
| 51 | else |
| 52 | ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| 53 | #endif |
| 54 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 55 | |
Bo Xu | d4e406e | 2014-08-13 11:03:19 -0700 | [diff] [blame] | 56 | Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | |
| 58 | if ( pContext->m_pRenderer ) |
| 59 | { |
| 60 | CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed; |
| 61 | status = pContext->m_pRenderer->GetStatus(); |
| 62 | return status; |
| 63 | } |
| 64 | return FPDF_RENDER_FAILED; |
| 65 | } |
| 66 | |
| 67 | DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * pause) |
| 68 | { |
| 69 | if (page == NULL) |
| 70 | return FPDF_RENDER_FAILED; |
| 71 | |
| 72 | if (!pause) |
| 73 | return FPDF_RENDER_FAILED; |
| 74 | |
| 75 | if (pause->version !=1) |
| 76 | return FPDF_RENDER_FAILED; |
| 77 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame^] | 78 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 79 | if (!pPage) |
| 80 | return FPDF_RENDER_FAILED; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | |
| 82 | // FXMT_CSLOCK_OBJ(&pPage->m_PageLock); |
| 83 | |
| 84 | CRenderContext * pContext = (CRenderContext*)pPage->GetPrivateData((void*)1); |
| 85 | if (pContext && pContext->m_pRenderer) |
| 86 | { |
| 87 | IFSDK_PAUSE_Adapter IPauseAdapter(pause); |
| 88 | pContext->m_pRenderer->Continue(&IPauseAdapter); |
| 89 | |
| 90 | CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed; |
| 91 | status = pContext->m_pRenderer->GetStatus(); |
| 92 | return status; |
| 93 | } |
| 94 | return FPDF_RENDER_FAILED; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page) |
| 99 | { |
| 100 | if (page == NULL) return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame^] | 101 | CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 102 | if (!pPage) return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | |