diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-10-19 16:20:03 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-10-19 16:20:03 -0700 |
commit | b3b67620b9db518558f2912357581b600645ce68 (patch) | |
tree | a54ffe1f3d15d492278fc53d7bd52e52af3a708b /core | |
parent | d831dc7147e9895185740f551fed7abe246e2adf (diff) | |
download | pdfium-b3b67620b9db518558f2912357581b600645ce68.tar.xz |
Merge to XFA: Refactor progressive renderer.
Hand-application of diffs from https://codereview.chromium.org/1233453014/.
This was an oversight, and was too old (pre-reformat) to apply cleanly.
Checked against origin/master, only diffs are xfa related.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1416793002 .
Diffstat (limited to 'core')
-rw-r--r-- | core/include/fpdfapi/fpdf_render.h | 80 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render.cpp | 76 |
2 files changed, 68 insertions, 88 deletions
diff --git a/core/include/fpdfapi/fpdf_render.h b/core/include/fpdfapi/fpdf_render.h index 58883a01f1..3c1d95aa8a 100644 --- a/core/include/fpdfapi/fpdf_render.h +++ b/core/include/fpdfapi/fpdf_render.h @@ -7,22 +7,26 @@ #ifndef CORE_INCLUDE_FPDFAPI_FPDF_RENDER_H_ #define CORE_INCLUDE_FPDFAPI_FPDF_RENDER_H_ +#include "../../../third_party/base/nonstd_unique_ptr.h" +#include "../../../public/fpdf_progressive.h" #include "../fxge/fx_ge.h" #include "fpdf_page.h" -class CPDF_RenderContext; -class CPDF_RenderOptions; -class CPDF_ImageCache; -class IPDF_OCContext; -class CPDF_QuickStretcher; -class CFX_PathData; class CFX_GraphStateData; +class CFX_PathData; class CFX_RenderDevice; -class CPDF_TextObject; -class CPDF_PathObject; +class CPDF_FormObject; +class CPDF_ImageCache; class CPDF_ImageObject; +class CPDF_PathObject; +class CPDF_QuickStretcher; +class CPDF_RenderContext; +class CPDF_RenderOptions; +class CPDF_RenderStatus; class CPDF_ShadingObject; -class CPDF_FormObject; +class CPDF_TextObject; +class IFX_Pause; + class IPDF_OCContext { public: virtual ~IPDF_OCContext() {} @@ -127,53 +131,43 @@ class CPDF_RenderContext { friend class CPDF_RenderStatus; friend class CPDF_ProgressiveRenderer; }; + class CPDF_ProgressiveRenderer { public: - CPDF_ProgressiveRenderer(); - + // Must match FDF_RENDER_* definitions in fpdf_progressive.h. + enum Status { + Ready = FPDF_RENDER_READER, + ToBeContinued = FPDF_RENDER_TOBECOUNTINUED, + Done = FPDF_RENDER_DONE, + Failed = FPDF_RENDER_FAILED + }; + static int ToFPDFStatus(Status status) { return static_cast<int>(status); } + + CPDF_ProgressiveRenderer(CPDF_RenderContext* pContext, + CFX_RenderDevice* pDevice, + const CPDF_RenderOptions* pOptions); ~CPDF_ProgressiveRenderer(); - typedef enum { Ready, ToBeContinued, Done, Failed } RenderStatus; - - RenderStatus GetStatus() { return m_Status; } - - void Start(CPDF_RenderContext* pContext, - CFX_RenderDevice* pDevice, - const CPDF_RenderOptions* pOptions, - class IFX_Pause* pPause, - FX_BOOL bDropObjects = FALSE); - - void Continue(class IFX_Pause* pPause); - + Status GetStatus() const { return m_Status; } + void Start(IFX_Pause* pPause); + void Continue(IFX_Pause* pPause); int EstimateProgress(); - void Clear(); - - protected: - RenderStatus m_Status; - - CPDF_RenderContext* m_pContext; - - CFX_RenderDevice* m_pDevice; - - const CPDF_RenderOptions* m_pOptions; - - FX_BOOL m_bDropObjects; - - class CPDF_RenderStatus* m_pRenderer; + private: + void RenderStep(); + Status m_Status; + CPDF_RenderContext* const m_pContext; + CFX_RenderDevice* const m_pDevice; + const CPDF_RenderOptions* const m_pOptions; + nonstd::unique_ptr<CPDF_RenderStatus> m_pRenderStatus; CFX_FloatRect m_ClipRect; - FX_DWORD m_LayerIndex; - FX_DWORD m_ObjectIndex; - FX_POSITION m_ObjectPos; - FX_POSITION m_PrevLastPos; - - void RenderStep(); }; + class CPDF_TextRenderer { public: static void DrawTextString(CFX_RenderDevice* pDevice, diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp index be6483fc31..9db35068f9 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp @@ -1061,47 +1061,35 @@ void CPDF_RenderContext::DrawObjectList(CFX_RenderDevice* pDevice, AppendObjectList(pObjs, pObject2Device); Render(pDevice, pOptions); } -CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer() { - m_pRenderer = NULL; - m_pContext = NULL; - m_pDevice = NULL; - m_Status = Ready; + +CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer( + CPDF_RenderContext* pContext, + CFX_RenderDevice* pDevice, + const CPDF_RenderOptions* pOptions) + : m_Status(Ready), + m_pContext(pContext), + m_pDevice(pDevice), + m_pOptions(pOptions), + m_LayerIndex(0), + m_ObjectIndex(0), + m_ObjectPos(nullptr), + m_PrevLastPos(nullptr) { } + CPDF_ProgressiveRenderer::~CPDF_ProgressiveRenderer() { - Clear(); -} -void CPDF_ProgressiveRenderer::Clear() { - if (m_pRenderer) { - delete m_pRenderer; + if (m_pRenderStatus) m_pDevice->RestoreState(); - m_pRenderer = NULL; - } - m_Status = Ready; } -void CPDF_ProgressiveRenderer::Start(CPDF_RenderContext* pContext, - CFX_RenderDevice* pDevice, - const CPDF_RenderOptions* pOptions, - IFX_Pause* pPause, - FX_BOOL bDropObjects) { - if (m_Status != Ready) { - m_Status = Failed; - return; - } - m_pContext = pContext; - m_pDevice = pDevice; - m_pOptions = pOptions; - m_bDropObjects = bDropObjects; - if (pContext == NULL || pDevice == NULL) { + +void CPDF_ProgressiveRenderer::Start(IFX_Pause* pPause) { + if (!m_pContext || !m_pDevice || m_Status != Ready) { m_Status = Failed; return; } m_Status = ToBeContinued; - m_ObjectPos = NULL; - m_LayerIndex = 0; - m_ObjectIndex = 0; - m_PrevLastPos = NULL; Continue(pPause); } + #define RENDER_STEP_LIMIT 100 void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { if (m_Status != ToBeContinued) { @@ -1122,9 +1110,8 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { } } if (LastPos == m_PrevLastPos) { - if (m_pRenderer) { - delete m_pRenderer; - m_pRenderer = NULL; + if (m_pRenderStatus) { + m_pRenderStatus.reset(); m_pDevice->RestoreState(); m_ObjectPos = NULL; m_PrevLastPos = NULL; @@ -1139,13 +1126,13 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { } m_PrevLastPos = LastPos; } - if (m_pRenderer == NULL) { + if (!m_pRenderStatus) { m_ObjectPos = pItem->m_pObjectList->GetFirstObjectPosition(); m_ObjectIndex = 0; - m_pRenderer = new CPDF_RenderStatus(); - m_pRenderer->Initialize(m_pContext, m_pDevice, NULL, NULL, NULL, NULL, - m_pOptions, pItem->m_pObjectList->m_Transparency, - m_bDropObjects, NULL); + m_pRenderStatus.reset(new CPDF_RenderStatus()); + m_pRenderStatus->Initialize( + m_pContext, m_pDevice, NULL, NULL, NULL, NULL, m_pOptions, + pItem->m_pObjectList->m_Transparency, FALSE, NULL); m_pDevice->SaveState(); m_ClipRect = m_pDevice->GetClipBox(); CFX_AffineMatrix device2object; @@ -1162,14 +1149,14 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { pCurObj->m_Right >= m_ClipRect.left && pCurObj->m_Bottom <= m_ClipRect.top && pCurObj->m_Top >= m_ClipRect.bottom) { - if (m_pRenderer->ContinueSingleObject(pCurObj, &pItem->m_Matrix, - pPause)) { + if (m_pRenderStatus->ContinueSingleObject(pCurObj, &pItem->m_Matrix, + pPause)) { return; } if (pCurObj->m_Type == PDFPAGE_IMAGE && - m_pRenderer->m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { + m_pRenderStatus->m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { m_pContext->GetPageCache()->CacheOptimization( - m_pRenderer->m_Options.m_dwLimitCacheSize); + m_pRenderStatus->m_Options.m_dwLimitCacheSize); } if (pCurObj->m_Type == PDFPAGE_FORM || pCurObj->m_Type == PDFPAGE_SHADING) { @@ -1193,8 +1180,7 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { if (!pItem->m_pObjectList->IsParsed()) { return; } - delete m_pRenderer; - m_pRenderer = NULL; + m_pRenderStatus.reset(); m_pDevice->RestoreState(); m_ObjectPos = NULL; m_PrevLastPos = NULL; |