From e6a5138ec89a1235bf426fd19a0e4f61dfeafca0 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 16 Feb 2016 09:17:44 -0800 Subject: Rework progressive render loop. Migrating this off of CFX_PrtList depends on first making this saner. The tricky part is checking whether new objects have been added to a partially-parsed layer. The old code used to do this by keeping track of the last element in the list, and seeing if it changes. It's far simpler to keep track of the last element processed, and just keep looking for more objects after it with each pass. Fold together some duplicated blocks along the way. Remove unused EstimateProgress() method. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1699443002 . --- core/include/fpdfapi/fpdf_module.h | 2 - core/include/fpdfapi/fpdf_render.h | 16 +-- core/src/fpdfapi/fpdf_render/fpdf_render.cpp | 146 ++++++++------------------- 3 files changed, 49 insertions(+), 115 deletions(-) (limited to 'core') diff --git a/core/include/fpdfapi/fpdf_module.h b/core/include/fpdfapi/fpdf_module.h index 6a17a489c2..6888e81000 100644 --- a/core/include/fpdfapi/fpdf_module.h +++ b/core/include/fpdfapi/fpdf_module.h @@ -26,7 +26,6 @@ class CPDF_Image; class CPDF_Page; class CPDF_PageObjectList; class CPDF_PageRenderCache; -class CPDF_RenderConfig; class CPDF_RenderOptions; class CPDF_Stream; class ICodec_FaxModule; @@ -107,7 +106,6 @@ class IPDF_RenderModule { virtual CPDF_DocRenderData* GetRenderData() = 0; virtual CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) = 0; virtual void DestroyPageCache(CPDF_PageRenderCache*) = 0; - virtual CPDF_RenderConfig* GetConfig() = 0; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_MODULE_H_ diff --git a/core/include/fpdfapi/fpdf_render.h b/core/include/fpdfapi/fpdf_render.h index 2637dd3252..ec5d151914 100644 --- a/core/include/fpdfapi/fpdf_render.h +++ b/core/include/fpdfapi/fpdf_render.h @@ -136,11 +136,13 @@ class CPDF_ProgressiveRenderer { Status GetStatus() const { return m_Status; } void Start(IFX_Pause* pPause); void Continue(IFX_Pause* pPause); - int EstimateProgress(); private: void RenderStep(); + // Maximum page objects to render before checking for pause. + static const int kStepLimit = 100; + Status m_Status; CPDF_RenderContext* const m_pContext; CFX_RenderDevice* const m_pDevice; @@ -148,9 +150,8 @@ class CPDF_ProgressiveRenderer { std::unique_ptr m_pRenderStatus; CFX_FloatRect m_ClipRect; FX_DWORD m_LayerIndex; - FX_DWORD m_ObjectIndex; - FX_POSITION m_ObjectPos; - FX_POSITION m_PrevLastPos; + CPDF_RenderContext::Layer* m_pCurrentLayer; + FX_POSITION m_LastObjectRendered; }; class CPDF_TextRenderer { @@ -261,13 +262,6 @@ class CPDF_PageRenderCache { FX_DWORD m_nCacheSize; FX_BOOL m_bCurFindCache; }; -class CPDF_RenderConfig { - public: - CPDF_RenderConfig(); - ~CPDF_RenderConfig(); - int m_HalftoneLimit; - int m_RenderStepLimit; -}; FX_BOOL IsAvailableMatrix(const CFX_Matrix& matrix); diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp index eeee03485a..0ea941a1e6 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "render_int.h" +#include "core/src/fpdfapi/fpdf_render/render_int.h" #include "core/include/fpdfapi/fpdf_module.h" #include "core/include/fpdfapi/fpdf_render.h" @@ -87,10 +87,7 @@ class CPDF_RenderModule : public IPDF_RenderModule { void DestroyPageCache(CPDF_PageRenderCache* pCache) override; - CPDF_RenderConfig* GetConfig() override { return &m_RenderConfig; } - CPDF_DocRenderData m_RenderData; - CPDF_RenderConfig m_RenderConfig; }; CPDF_DocRenderData* CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc) { @@ -1038,10 +1035,8 @@ CPDF_ProgressiveRenderer::CPDF_ProgressiveRenderer( m_pDevice(pDevice), m_pOptions(pOptions), m_LayerIndex(0), - m_ObjectIndex(0), - m_ObjectPos(nullptr), - m_PrevLastPos(nullptr) { -} + m_pCurrentLayer(nullptr), + m_LastObjectRendered(nullptr) {} CPDF_ProgressiveRenderer::~CPDF_ProgressiveRenderer() { if (m_pRenderStatus) @@ -1058,66 +1053,41 @@ void CPDF_ProgressiveRenderer::Start(IFX_Pause* pPause) { } void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { - if (m_Status != ToBeContinued) { - return; - } - FX_DWORD nLayers = m_pContext->CountLayers(); - for (; m_LayerIndex < nLayers; m_LayerIndex++) { - CPDF_RenderContext::Layer* pLayer = m_pContext->GetLayer(m_LayerIndex); - FX_POSITION LastPos = pLayer->m_pObjectList->GetLastObjectPosition(); - if (!m_ObjectPos) { - if (LastPos == m_PrevLastPos) { - if (!pLayer->m_pObjectList->IsParsed()) { - pLayer->m_pObjectList->ContinueParse(pPause); - if (!pLayer->m_pObjectList->IsParsed()) { - return; - } - LastPos = pLayer->m_pObjectList->GetLastObjectPosition(); - } - } - if (LastPos == m_PrevLastPos) { - if (m_pRenderStatus) { - m_pRenderStatus.reset(); - m_pDevice->RestoreState(); - m_ObjectPos = NULL; - m_PrevLastPos = NULL; - } - continue; + while (m_Status == ToBeContinued) { + if (!m_pCurrentLayer) { + if (m_LayerIndex >= m_pContext->CountLayers()) { + m_Status = Done; + return; } - if (m_PrevLastPos) { - m_ObjectPos = m_PrevLastPos; - pLayer->m_pObjectList->GetNextObject(m_ObjectPos); - } else { - m_ObjectPos = pLayer->m_pObjectList->GetFirstObjectPosition(); - } - m_PrevLastPos = LastPos; - } - if (!m_pRenderStatus) { - m_ObjectPos = pLayer->m_pObjectList->GetFirstObjectPosition(); - m_ObjectIndex = 0; + m_pCurrentLayer = m_pContext->GetLayer(m_LayerIndex); + m_LastObjectRendered = nullptr; m_pRenderStatus.reset(new CPDF_RenderStatus()); m_pRenderStatus->Initialize( m_pContext, m_pDevice, NULL, NULL, NULL, NULL, m_pOptions, - pLayer->m_pObjectList->m_Transparency, FALSE, NULL); + m_pCurrentLayer->m_pObjectList->m_Transparency, FALSE, NULL); m_pDevice->SaveState(); m_ClipRect = m_pDevice->GetClipBox(); CFX_Matrix device2object; - device2object.SetReverse(pLayer->m_Matrix); + device2object.SetReverse(m_pCurrentLayer->m_Matrix); device2object.TransformRect(m_ClipRect); } - int objs_to_go = CPDF_ModuleMgr::Get() - ->GetRenderModule() - ->GetConfig() - ->m_RenderStepLimit; - while (m_ObjectPos) { + FX_POSITION pos; + if (m_LastObjectRendered) { + pos = m_LastObjectRendered; + m_pCurrentLayer->m_pObjectList->GetNextObject(pos); + } else { + pos = m_pCurrentLayer->m_pObjectList->GetFirstObjectPosition(); + } + int nObjsToGo = kStepLimit; + while (pos) { CPDF_PageObject* pCurObj = - pLayer->m_pObjectList->GetObjectAt(m_ObjectPos); + m_pCurrentLayer->m_pObjectList->GetObjectAt(pos); if (pCurObj && pCurObj->m_Left <= m_ClipRect.right && pCurObj->m_Right >= m_ClipRect.left && pCurObj->m_Bottom <= m_ClipRect.top && pCurObj->m_Top >= m_ClipRect.bottom) { - if (m_pRenderStatus->ContinueSingleObject(pCurObj, &pLayer->m_Matrix, - pPause)) { + if (m_pRenderStatus->ContinueSingleObject( + pCurObj, &m_pCurrentLayer->m_Matrix, pPause)) { return; } if (pCurObj->m_Type == CPDF_PageObject::IMAGE && @@ -1127,59 +1097,36 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { } if (pCurObj->m_Type == CPDF_PageObject::FORM || pCurObj->m_Type == CPDF_PageObject::SHADING) { - objs_to_go = 0; + nObjsToGo = 0; } else { - objs_to_go--; + --nObjsToGo; } } - m_ObjectIndex++; - pLayer->m_pObjectList->GetNextObject(m_ObjectPos); - if (objs_to_go == 0) { - if (pPause && pPause->NeedToPauseNow()) { + m_LastObjectRendered = pos; + if (nObjsToGo == 0) { + if (pPause && pPause->NeedToPauseNow()) return; - } - objs_to_go = CPDF_ModuleMgr::Get() - ->GetRenderModule() - ->GetConfig() - ->m_RenderStepLimit; + nObjsToGo = kStepLimit; } + m_pCurrentLayer->m_pObjectList->GetNextObject(pos); } - if (!pLayer->m_pObjectList->IsParsed()) { - return; - } - m_pRenderStatus.reset(); - m_pDevice->RestoreState(); - m_ObjectPos = NULL; - m_PrevLastPos = NULL; - if (pPause && pPause->NeedToPauseNow()) { + if (m_pCurrentLayer->m_pObjectList->IsParsed()) { + m_pRenderStatus.reset(); + m_pDevice->RestoreState(); + m_pCurrentLayer = nullptr; + m_LastObjectRendered = nullptr; m_LayerIndex++; - return; - } - } - m_Status = Done; -} -int CPDF_ProgressiveRenderer::EstimateProgress() { - if (!m_pContext) { - return 0; - } - FX_DWORD nLayers = m_pContext->CountLayers(); - int nTotal = 0; - int nRendered = 0; - for (FX_DWORD layer = 0; layer < nLayers; layer++) { - CPDF_RenderContext::Layer* pLayer = m_pContext->GetLayer(layer); - int nObjs = pLayer->m_pObjectList->CountObjects(); - if (layer == m_LayerIndex) { - nRendered += m_ObjectIndex; - } else if (layer < m_LayerIndex) { - nRendered += nObjs; + if (pPause && pPause->NeedToPauseNow()) { + return; + } + } else { + m_pCurrentLayer->m_pObjectList->ContinueParse(pPause); + if (!m_pCurrentLayer->m_pObjectList->IsParsed()) + return; } - nTotal += nObjs; - } - if (nTotal == 0) { - return 0; } - return 100 * nRendered / nTotal; } + CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { if (!pObj) return nullptr; @@ -1252,11 +1199,6 @@ void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj) { if (it != m_TransferFuncMap.end()) it->second->RemoveRef(); } -CPDF_RenderConfig::CPDF_RenderConfig() { - m_HalftoneLimit = 0; - m_RenderStepLimit = 100; -} -CPDF_RenderConfig::~CPDF_RenderConfig() {} CPDF_DeviceBuffer::CPDF_DeviceBuffer() : m_pDevice(nullptr), m_pContext(nullptr), m_pObject(nullptr) {} -- cgit v1.2.3