Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render_cache.cpp

Issue 1832173003: Remove FX_DWORD from core/ and delete definition (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" 7 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h"
8 8
9 #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h" 9 #include "core/fpdfapi/fpdf_page/cpdf_parseoptions.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
11 #include "core/fpdfapi/fpdf_page/pageint.h" 11 #include "core/fpdfapi/fpdf_page/pageint.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
13 #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" 13 #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h"
14 #include "core/fpdfapi/fpdf_render/render_int.h" 14 #include "core/fpdfapi/fpdf_render/render_int.h"
15 #include "core/include/fxge/fx_ge.h" 15 #include "core/include/fxge/fx_ge.h"
16 16
17 struct CACHEINFO { 17 struct CACHEINFO {
18 FX_DWORD time; 18 uint32_t time;
19 CPDF_Stream* pStream; 19 CPDF_Stream* pStream;
20 }; 20 };
21 21
22 extern "C" { 22 extern "C" {
23 static int compare(const void* data1, const void* data2) { 23 static int compare(const void* data1, const void* data2) {
24 return ((CACHEINFO*)data1)->time - ((CACHEINFO*)data2)->time; 24 return ((CACHEINFO*)data1)->time - ((CACHEINFO*)data2)->time;
25 } 25 }
26 } // extern "C" 26 } // extern "C"
27 27
28 CPDF_PageRenderCache::~CPDF_PageRenderCache() { 28 CPDF_PageRenderCache::~CPDF_PageRenderCache() {
29 for (const auto& it : m_ImageCache) 29 for (const auto& it : m_ImageCache)
30 delete it.second; 30 delete it.second;
31 } 31 }
32 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) { 32 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) {
33 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) 33 if (m_nCacheSize <= (uint32_t)dwLimitCacheSize)
34 return; 34 return;
35 35
36 size_t nCount = m_ImageCache.size(); 36 size_t nCount = m_ImageCache.size();
37 CACHEINFO* pCACHEINFO = FX_Alloc(CACHEINFO, nCount); 37 CACHEINFO* pCACHEINFO = FX_Alloc(CACHEINFO, nCount);
38 size_t i = 0; 38 size_t i = 0;
39 for (const auto& it : m_ImageCache) { 39 for (const auto& it : m_ImageCache) {
40 pCACHEINFO[i].time = it.second->GetTimeCount(); 40 pCACHEINFO[i].time = it.second->GetTimeCount();
41 pCACHEINFO[i++].pStream = it.second->GetStream(); 41 pCACHEINFO[i++].pStream = it.second->GetStream();
42 } 42 }
43 FXSYS_qsort(pCACHEINFO, nCount, sizeof(CACHEINFO), compare); 43 FXSYS_qsort(pCACHEINFO, nCount, sizeof(CACHEINFO), compare);
44 FX_DWORD nTimeCount = m_nTimeCount; 44 uint32_t nTimeCount = m_nTimeCount;
45 45
46 // Check if time value is about to roll over and reset all entries. 46 // Check if time value is about to roll over and reset all entries.
47 // The comparision is legal because FX_DWORD is an unsigned type. 47 // The comparision is legal because uint32_t is an unsigned type.
48 if (nTimeCount + 1 < nTimeCount) { 48 if (nTimeCount + 1 < nTimeCount) {
49 for (i = 0; i < nCount; i++) 49 for (i = 0; i < nCount; i++)
50 m_ImageCache[pCACHEINFO[i].pStream]->m_dwTimeCount = i; 50 m_ImageCache[pCACHEINFO[i].pStream]->m_dwTimeCount = i;
51 m_nTimeCount = nCount; 51 m_nTimeCount = nCount;
52 } 52 }
53 53
54 i = 0; 54 i = 0;
55 while (i + 15 < nCount) 55 while (i + 15 < nCount)
56 ClearImageCacheEntry(pCACHEINFO[i++].pStream); 56 ClearImageCacheEntry(pCACHEINFO[i++].pStream);
57 57
58 while (i < nCount && m_nCacheSize > (FX_DWORD)dwLimitCacheSize) 58 while (i < nCount && m_nCacheSize > (uint32_t)dwLimitCacheSize)
59 ClearImageCacheEntry(pCACHEINFO[i++].pStream); 59 ClearImageCacheEntry(pCACHEINFO[i++].pStream);
60 60
61 FX_Free(pCACHEINFO); 61 FX_Free(pCACHEINFO);
62 } 62 }
63 void CPDF_PageRenderCache::ClearImageCacheEntry(CPDF_Stream* pStream) { 63 void CPDF_PageRenderCache::ClearImageCacheEntry(CPDF_Stream* pStream) {
64 auto it = m_ImageCache.find(pStream); 64 auto it = m_ImageCache.find(pStream);
65 if (it == m_ImageCache.end()) 65 if (it == m_ImageCache.end())
66 return; 66 return;
67 67
68 m_nCacheSize -= it->second->EstimateSize(); 68 m_nCacheSize -= it->second->EstimateSize();
69 delete it->second; 69 delete it->second;
70 m_ImageCache.erase(it); 70 m_ImageCache.erase(it);
71 } 71 }
72 FX_DWORD CPDF_PageRenderCache::EstimateSize() { 72 uint32_t CPDF_PageRenderCache::EstimateSize() {
73 FX_DWORD dwSize = 0; 73 uint32_t dwSize = 0;
74 for (const auto& it : m_ImageCache) 74 for (const auto& it : m_ImageCache)
75 dwSize += it.second->EstimateSize(); 75 dwSize += it.second->EstimateSize();
76 76
77 m_nCacheSize = dwSize; 77 m_nCacheSize = dwSize;
78 return dwSize; 78 return dwSize;
79 } 79 }
80 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, 80 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream,
81 CFX_DIBSource*& pBitmap, 81 CFX_DIBSource*& pBitmap,
82 CFX_DIBSource*& pMask, 82 CFX_DIBSource*& pMask,
83 FX_DWORD& MatteColor, 83 uint32_t& MatteColor,
84 FX_BOOL bStdCS, 84 FX_BOOL bStdCS,
85 FX_DWORD GroupFamily, 85 uint32_t GroupFamily,
86 FX_BOOL bLoadMask, 86 FX_BOOL bLoadMask,
87 CPDF_RenderStatus* pRenderStatus, 87 CPDF_RenderStatus* pRenderStatus,
88 int32_t downsampleWidth, 88 int32_t downsampleWidth,
89 int32_t downsampleHeight) { 89 int32_t downsampleHeight) {
90 CPDF_ImageCacheEntry* pEntry; 90 CPDF_ImageCacheEntry* pEntry;
91 const auto it = m_ImageCache.find(pStream); 91 const auto it = m_ImageCache.find(pStream);
92 FX_BOOL bFound = it != m_ImageCache.end(); 92 FX_BOOL bFound = it != m_ImageCache.end();
93 if (bFound) 93 if (bFound)
94 pEntry = it->second; 94 pEntry = it->second;
95 else 95 else
96 pEntry = new CPDF_ImageCacheEntry(m_pPage->m_pDocument, pStream); 96 pEntry = new CPDF_ImageCacheEntry(m_pPage->m_pDocument, pStream);
97 97
98 m_nTimeCount++; 98 m_nTimeCount++;
99 FX_BOOL bAlreadyCached = pEntry->GetCachedBitmap( 99 FX_BOOL bAlreadyCached = pEntry->GetCachedBitmap(
100 pBitmap, pMask, MatteColor, m_pPage->m_pPageResources, bStdCS, 100 pBitmap, pMask, MatteColor, m_pPage->m_pPageResources, bStdCS,
101 GroupFamily, bLoadMask, pRenderStatus, downsampleWidth, downsampleHeight); 101 GroupFamily, bLoadMask, pRenderStatus, downsampleWidth, downsampleHeight);
102 102
103 if (!bFound) 103 if (!bFound)
104 m_ImageCache[pStream] = pEntry; 104 m_ImageCache[pStream] = pEntry;
105 105
106 if (!bAlreadyCached) 106 if (!bAlreadyCached)
107 m_nCacheSize += pEntry->EstimateSize(); 107 m_nCacheSize += pEntry->EstimateSize();
108 } 108 }
109 FX_BOOL CPDF_PageRenderCache::StartGetCachedBitmap( 109 FX_BOOL CPDF_PageRenderCache::StartGetCachedBitmap(
110 CPDF_Stream* pStream, 110 CPDF_Stream* pStream,
111 FX_BOOL bStdCS, 111 FX_BOOL bStdCS,
112 FX_DWORD GroupFamily, 112 uint32_t GroupFamily,
113 FX_BOOL bLoadMask, 113 FX_BOOL bLoadMask,
114 CPDF_RenderStatus* pRenderStatus, 114 CPDF_RenderStatus* pRenderStatus,
115 int32_t downsampleWidth, 115 int32_t downsampleWidth,
116 int32_t downsampleHeight) { 116 int32_t downsampleHeight) {
117 const auto it = m_ImageCache.find(pStream); 117 const auto it = m_ImageCache.find(pStream);
118 m_bCurFindCache = it != m_ImageCache.end(); 118 m_bCurFindCache = it != m_ImageCache.end();
119 if (m_bCurFindCache) { 119 if (m_bCurFindCache) {
120 m_pCurImageCacheEntry = it->second; 120 m_pCurImageCacheEntry = it->second;
121 } else { 121 } else {
122 m_pCurImageCacheEntry = 122 m_pCurImageCacheEntry =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 void CPDF_PageRenderCache::ClearImageData() { 191 void CPDF_PageRenderCache::ClearImageData() {
192 for (const auto& it : m_ImageCache) 192 for (const auto& it : m_ImageCache)
193 it.second->ClearImageData(); 193 it.second->ClearImageData();
194 } 194 }
195 void CPDF_ImageCacheEntry::ClearImageData() { 195 void CPDF_ImageCacheEntry::ClearImageData() {
196 if (m_pCachedBitmap && !m_pCachedBitmap->GetBuffer()) { 196 if (m_pCachedBitmap && !m_pCachedBitmap->GetBuffer()) {
197 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); 197 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData();
198 } 198 }
199 } 199 }
200 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { 200 static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) {
201 return pDIB && pDIB->GetBuffer() 201 return pDIB && pDIB->GetBuffer()
202 ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPitch() + 202 ? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() +
203 (FX_DWORD)pDIB->GetPaletteSize() * 4 203 (uint32_t)pDIB->GetPaletteSize() * 4
204 : 0; 204 : 0;
205 } 205 }
206 FX_BOOL CPDF_ImageCacheEntry::GetCachedBitmap(CFX_DIBSource*& pBitmap, 206 FX_BOOL CPDF_ImageCacheEntry::GetCachedBitmap(CFX_DIBSource*& pBitmap,
207 CFX_DIBSource*& pMask, 207 CFX_DIBSource*& pMask,
208 FX_DWORD& MatteColor, 208 uint32_t& MatteColor,
209 CPDF_Dictionary* pPageResources, 209 CPDF_Dictionary* pPageResources,
210 FX_BOOL bStdCS, 210 FX_BOOL bStdCS,
211 FX_DWORD GroupFamily, 211 uint32_t GroupFamily,
212 FX_BOOL bLoadMask, 212 FX_BOOL bLoadMask,
213 CPDF_RenderStatus* pRenderStatus, 213 CPDF_RenderStatus* pRenderStatus,
214 int32_t downsampleWidth, 214 int32_t downsampleWidth,
215 int32_t downsampleHeight) { 215 int32_t downsampleHeight) {
216 if (m_pCachedBitmap) { 216 if (m_pCachedBitmap) {
217 pBitmap = m_pCachedBitmap; 217 pBitmap = m_pCachedBitmap;
218 pMask = m_pCachedMask; 218 pMask = m_pCachedMask;
219 MatteColor = m_MatteColor; 219 MatteColor = m_MatteColor;
220 return TRUE; 220 return TRUE;
221 } 221 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return pDIBSource; 257 return pDIBSource;
258 } 258 }
259 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() { 259 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() {
260 CFX_DIBSource* pDIBSource = m_pCurMask; 260 CFX_DIBSource* pDIBSource = m_pCurMask;
261 m_pCurMask = NULL; 261 m_pCurMask = NULL;
262 return pDIBSource; 262 return pDIBSource;
263 } 263 }
264 int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, 264 int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
265 CPDF_Dictionary* pPageResources, 265 CPDF_Dictionary* pPageResources,
266 FX_BOOL bStdCS, 266 FX_BOOL bStdCS,
267 FX_DWORD GroupFamily, 267 uint32_t GroupFamily,
268 FX_BOOL bLoadMask, 268 FX_BOOL bLoadMask,
269 CPDF_RenderStatus* pRenderStatus, 269 CPDF_RenderStatus* pRenderStatus,
270 int32_t downsampleWidth, 270 int32_t downsampleWidth,
271 int32_t downsampleHeight) { 271 int32_t downsampleHeight) {
272 if (m_pCachedBitmap) { 272 if (m_pCachedBitmap) {
273 m_pCurBitmap = m_pCachedBitmap; 273 m_pCurBitmap = m_pCachedBitmap;
274 m_pCurMask = m_pCachedMask; 274 m_pCurMask = m_pCachedMask;
275 return 1; 275 return 1;
276 } 276 }
277 if (!pRenderStatus) { 277 if (!pRenderStatus) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 m_pCurBitmap = NULL; 327 m_pCurBitmap = NULL;
328 return 0; 328 return 0;
329 } 329 }
330 ContinueGetCachedBitmap(); 330 ContinueGetCachedBitmap();
331 return 0; 331 return 0;
332 } 332 }
333 void CPDF_ImageCacheEntry::CalcSize() { 333 void CPDF_ImageCacheEntry::CalcSize() {
334 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + 334 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) +
335 FPDF_ImageCache_EstimateImageSize(m_pCachedMask); 335 FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
336 } 336 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_render/fpdf_render.cpp ('k') | core/fpdfapi/fpdf_render/fpdf_render_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698