1 // Copyright 2016 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 #ifndef CORE_FPDFAPI_RENDER_CPDF_PROGRESSIVERENDERER_H_
8 #define CORE_FPDFAPI_RENDER_CPDF_PROGRESSIVERENDERER_H_
9 
10 #include <memory>
11 
12 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
13 #include "core/fpdfapi/render/cpdf_rendercontext.h"
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/fx_system.h"
16 #include "core/fxcrt/unowned_ptr.h"
17 
18 class CPDF_RenderOptions;
19 class CPDF_RenderStatus;
20 class CFX_RenderDevice;
21 class PauseIndicatorIface;
22 
23 class CPDF_ProgressiveRenderer {
24  public:
25   // Must match FDF_RENDER_* definitions in public/fpdf_progressive.h, but
26   // cannot #include that header. fpdfsdk/fpdf_progressive.cpp has
27   // static_asserts to make sure the two sets of values match.
28   enum Status {
29     kReady,          // FPDF_RENDER_READY
30     kToBeContinued,  // FPDF_RENDER_TOBECONTINUED
31     kDone,           // FPDF_RENDER_DONE
32     kFailed          // FPDF_RENDER_FAILED
33   };
34 
35   CPDF_ProgressiveRenderer(CPDF_RenderContext* pContext,
36                            CFX_RenderDevice* pDevice,
37                            const CPDF_RenderOptions* pOptions);
38   ~CPDF_ProgressiveRenderer();
39 
GetStatus()40   Status GetStatus() const { return m_Status; }
41   void Start(PauseIndicatorIface* pPause);
42   void Continue(PauseIndicatorIface* pPause);
43 
44  private:
45   // Maximum page objects to render before checking for pause.
46   static constexpr int kStepLimit = 100;
47 
48   Status m_Status = kReady;
49   UnownedPtr<CPDF_RenderContext> const m_pContext;
50   UnownedPtr<CFX_RenderDevice> const m_pDevice;
51   const CPDF_RenderOptions* const m_pOptions;
52   std::unique_ptr<CPDF_RenderStatus> m_pRenderStatus;
53   CFX_FloatRect m_ClipRect;
54   uint32_t m_LayerIndex = 0;
55   CPDF_RenderContext::Layer* m_pCurrentLayer = nullptr;
56   CPDF_PageObjectHolder::const_iterator m_LastObjectRendered;
57 };
58 
59 #endif  // CORE_FPDFAPI_RENDER_CPDF_PROGRESSIVERENDERER_H_
60