summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_render/cpdf_pagerendercache.h
blob: 4e47e019b40c83acd2bc55b39aa3515bf4c85570 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FPDFAPI_FPDF_RENDER_CPDF_PAGERENDERCACHE_H_
#define CORE_FPDFAPI_FPDF_RENDER_CPDF_PAGERENDERCACHE_H_

#include <map>

#include "core/fxcrt/include/fx_system.h"

class CPDF_Stream;
class CPDF_ImageCacheEntry;
class CPDF_Page;
class CPDF_RenderStatus;
class CFX_DIBitmap;
class CFX_DIBSource;
class IFX_Pause;

class CPDF_PageRenderCache {
 public:
  explicit CPDF_PageRenderCache(CPDF_Page* pPage)
      : m_pPage(pPage),
        m_pCurImageCacheEntry(nullptr),
        m_nTimeCount(0),
        m_nCacheSize(0),
        m_bCurFindCache(FALSE) {}
  ~CPDF_PageRenderCache();
  void ClearImageData();

  uint32_t EstimateSize();
  void CacheOptimization(int32_t dwLimitCacheSize);
  uint32_t GetTimeCount() const { return m_nTimeCount; }
  void SetTimeCount(uint32_t dwTimeCount) { m_nTimeCount = dwTimeCount; }

  void GetCachedBitmap(CPDF_Stream* pStream,
                       CFX_DIBSource*& pBitmap,
                       CFX_DIBSource*& pMask,
                       uint32_t& MatteColor,
                       FX_BOOL bStdCS = FALSE,
                       uint32_t GroupFamily = 0,
                       FX_BOOL bLoadMask = FALSE,
                       CPDF_RenderStatus* pRenderStatus = NULL,
                       int32_t downsampleWidth = 0,
                       int32_t downsampleHeight = 0);

  void ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap);
  void ClearImageCacheEntry(CPDF_Stream* pStream);
  CPDF_Page* GetPage() const { return m_pPage; }
  CPDF_ImageCacheEntry* GetCurImageCacheEntry() const {
    return m_pCurImageCacheEntry;
  }

  FX_BOOL StartGetCachedBitmap(CPDF_Stream* pStream,
                               FX_BOOL bStdCS = FALSE,
                               uint32_t GroupFamily = 0,
                               FX_BOOL bLoadMask = FALSE,
                               CPDF_RenderStatus* pRenderStatus = NULL,
                               int32_t downsampleWidth = 0,
                               int32_t downsampleHeight = 0);

  FX_BOOL Continue(IFX_Pause* pPause);

 protected:
  friend class CPDF_Page;

  CPDF_Page* const m_pPage;
  CPDF_ImageCacheEntry* m_pCurImageCacheEntry;
  std::map<CPDF_Stream*, CPDF_ImageCacheEntry*> m_ImageCache;
  uint32_t m_nTimeCount;
  uint32_t m_nCacheSize;
  FX_BOOL m_bCurFindCache;
};

#endif  // CORE_FPDFAPI_FPDF_RENDER_CPDF_PAGERENDERCACHE_H_