OLD | NEW |
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 "render_int.h" | 7 #include "render_int.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_pageobj.h" | 9 #include "core/include/fpdfapi/fpdf_pageobj.h" |
10 #include "core/include/fpdfapi/fpdf_render.h" | 10 #include "core/include/fpdfapi/fpdf_render.h" |
11 #include "core/include/fxge/fx_ge.h" | 11 #include "core/include/fxge/fx_ge.h" |
12 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 12 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
13 | 13 |
14 struct CACHEINFO { | 14 struct CACHEINFO { |
15 FX_DWORD time; | 15 FX_DWORD time; |
16 CPDF_Stream* pStream; | 16 CPDF_Stream* pStream; |
17 }; | 17 }; |
| 18 |
18 extern "C" { | 19 extern "C" { |
19 static int compare(const void* data1, const void* data2) { | 20 static int compare(const void* data1, const void* data2) { |
20 return ((CACHEINFO*)data1)->time - ((CACHEINFO*)data2)->time; | 21 return ((CACHEINFO*)data1)->time - ((CACHEINFO*)data2)->time; |
21 } | 22 } |
22 }; | 23 } // extern "C" |
23 void CPDF_Page::ClearRenderCache() { | 24 |
24 if (m_pPageRender) { | 25 CPDF_PageRenderCache::~CPDF_PageRenderCache() { |
25 m_pPageRender->ClearAll(); | 26 for (const auto& it : m_ImageCache) |
26 } | 27 delete it.second; |
27 } | |
28 void CPDF_PageRenderCache::ClearAll() { | |
29 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | |
30 while (pos) { | |
31 void* key; | |
32 void* value; | |
33 m_ImageCaches.GetNextAssoc(pos, key, value); | |
34 delete (CPDF_ImageCache*)value; | |
35 } | |
36 m_ImageCaches.RemoveAll(); | |
37 m_nCacheSize = 0; | |
38 m_nTimeCount = 0; | |
39 } | 28 } |
40 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) { | 29 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) { |
41 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) { | 30 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) |
42 return; | 31 return; |
43 } | 32 |
44 int nCount = m_ImageCaches.GetCount(); | 33 size_t nCount = m_ImageCache.size(); |
45 CACHEINFO* pCACHEINFO = | 34 CACHEINFO* pCACHEINFO = FX_Alloc(CACHEINFO, nCount); |
46 (CACHEINFO*)FX_Alloc2D(uint8_t, sizeof(CACHEINFO), nCount); | 35 size_t i = 0; |
47 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 36 for (const auto& it : m_ImageCache) { |
48 int i = 0; | 37 pCACHEINFO[i].time = it.second->GetTimeCount(); |
49 while (pos) { | 38 pCACHEINFO[i++].pStream = it.second->GetStream(); |
50 void* key; | |
51 void* value; | |
52 m_ImageCaches.GetNextAssoc(pos, key, value); | |
53 pCACHEINFO[i].time = ((CPDF_ImageCache*)value)->GetTimeCount(); | |
54 pCACHEINFO[i++].pStream = ((CPDF_ImageCache*)value)->GetStream(); | |
55 } | 39 } |
56 FXSYS_qsort(pCACHEINFO, nCount, sizeof(CACHEINFO), compare); | 40 FXSYS_qsort(pCACHEINFO, nCount, sizeof(CACHEINFO), compare); |
57 FX_DWORD nTimeCount = m_nTimeCount; | 41 FX_DWORD nTimeCount = m_nTimeCount; |
| 42 |
| 43 // Check if time value is about to roll over and reset all entries. |
| 44 // The comparision is legal because FX_DWORD is an unsigned type. |
58 if (nTimeCount + 1 < nTimeCount) { | 45 if (nTimeCount + 1 < nTimeCount) { |
59 for (i = 0; i < nCount; i++) { | 46 for (i = 0; i < nCount; i++) |
60 ((CPDF_ImageCache*)(m_ImageCaches[pCACHEINFO[i].pStream])) | 47 m_ImageCache[pCACHEINFO[i].pStream]->m_dwTimeCount = i; |
61 ->m_dwTimeCount = i; | |
62 } | |
63 m_nTimeCount = nCount; | 48 m_nTimeCount = nCount; |
64 } | 49 } |
| 50 |
65 i = 0; | 51 i = 0; |
66 while (nCount > 15) { | 52 while (i + 15 < nCount) |
67 ClearImageCache(pCACHEINFO[i++].pStream); | 53 ClearImageCacheEntry(pCACHEINFO[i++].pStream); |
68 nCount--; | 54 |
69 } | 55 while (i < nCount && m_nCacheSize > (FX_DWORD)dwLimitCacheSize) |
70 while (m_nCacheSize > (FX_DWORD)dwLimitCacheSize) { | 56 ClearImageCacheEntry(pCACHEINFO[i++].pStream); |
71 ClearImageCache(pCACHEINFO[i++].pStream); | 57 |
72 } | |
73 FX_Free(pCACHEINFO); | 58 FX_Free(pCACHEINFO); |
74 } | 59 } |
75 void CPDF_PageRenderCache::ClearImageCache(CPDF_Stream* pStream) { | 60 void CPDF_PageRenderCache::ClearImageCacheEntry(CPDF_Stream* pStream) { |
76 void* value = m_ImageCaches.GetValueAt(pStream); | 61 auto it = m_ImageCache.find(pStream); |
77 if (!value) { | 62 if (it == m_ImageCache.end()) |
78 m_ImageCaches.RemoveKey(pStream); | |
79 return; | 63 return; |
80 } | 64 |
81 m_nCacheSize -= ((CPDF_ImageCache*)value)->EstimateSize(); | 65 m_nCacheSize -= it->second->EstimateSize(); |
82 delete (CPDF_ImageCache*)value; | 66 delete it->second; |
83 m_ImageCaches.RemoveKey(pStream); | 67 m_ImageCache.erase(it); |
84 } | 68 } |
85 FX_DWORD CPDF_PageRenderCache::EstimateSize() { | 69 FX_DWORD CPDF_PageRenderCache::EstimateSize() { |
86 FX_DWORD dwSize = 0; | 70 FX_DWORD dwSize = 0; |
87 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 71 for (const auto& it : m_ImageCache) |
88 while (pos) { | 72 dwSize += it.second->EstimateSize(); |
89 void* key; | 73 |
90 void* value; | |
91 m_ImageCaches.GetNextAssoc(pos, key, value); | |
92 dwSize += ((CPDF_ImageCache*)value)->EstimateSize(); | |
93 } | |
94 m_nCacheSize = dwSize; | 74 m_nCacheSize = dwSize; |
95 return dwSize; | 75 return dwSize; |
96 } | 76 } |
97 FX_DWORD CPDF_PageRenderCache::GetCachedSize(CPDF_Stream* pStream) const { | |
98 if (!pStream) { | |
99 return m_nCacheSize; | |
100 } | |
101 CPDF_ImageCache* pImageCache; | |
102 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { | |
103 return 0; | |
104 } | |
105 return pImageCache->EstimateSize(); | |
106 } | |
107 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, | 77 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, |
108 CFX_DIBSource*& pBitmap, | 78 CFX_DIBSource*& pBitmap, |
109 CFX_DIBSource*& pMask, | 79 CFX_DIBSource*& pMask, |
110 FX_DWORD& MatteColor, | 80 FX_DWORD& MatteColor, |
111 FX_BOOL bStdCS, | 81 FX_BOOL bStdCS, |
112 FX_DWORD GroupFamily, | 82 FX_DWORD GroupFamily, |
113 FX_BOOL bLoadMask, | 83 FX_BOOL bLoadMask, |
114 CPDF_RenderStatus* pRenderStatus, | 84 CPDF_RenderStatus* pRenderStatus, |
115 int32_t downsampleWidth, | 85 int32_t downsampleWidth, |
116 int32_t downsampleHeight) { | 86 int32_t downsampleHeight) { |
117 CPDF_ImageCache* pImageCache; | 87 CPDF_ImageCacheEntry* pEntry; |
118 FX_BOOL bFind = m_ImageCaches.Lookup(pStream, (void*&)pImageCache); | 88 const auto it = m_ImageCache.find(pStream); |
119 if (!bFind) { | 89 FX_BOOL bFound = it != m_ImageCache.end(); |
120 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 90 if (bFound) |
121 } | 91 pEntry = it->second; |
| 92 else |
| 93 pEntry = new CPDF_ImageCacheEntry(m_pPage->m_pDocument, pStream); |
| 94 |
122 m_nTimeCount++; | 95 m_nTimeCount++; |
123 FX_BOOL bCached = pImageCache->GetCachedBitmap( | 96 FX_BOOL bAlreadyCached = pEntry->GetCachedBitmap( |
124 pBitmap, pMask, MatteColor, m_pPage->m_pPageResources, bStdCS, | 97 pBitmap, pMask, MatteColor, m_pPage->m_pPageResources, bStdCS, |
125 GroupFamily, bLoadMask, pRenderStatus, downsampleWidth, downsampleHeight); | 98 GroupFamily, bLoadMask, pRenderStatus, downsampleWidth, downsampleHeight); |
126 if (!bFind) { | 99 |
127 m_ImageCaches.SetAt(pStream, pImageCache); | 100 if (!bFound) |
128 } | 101 m_ImageCache[pStream] = pEntry; |
129 if (!bCached) { | 102 |
130 m_nCacheSize += pImageCache->EstimateSize(); | 103 if (!bAlreadyCached) |
131 } | 104 m_nCacheSize += pEntry->EstimateSize(); |
132 } | 105 } |
133 FX_BOOL CPDF_PageRenderCache::StartGetCachedBitmap( | 106 FX_BOOL CPDF_PageRenderCache::StartGetCachedBitmap( |
134 CPDF_Stream* pStream, | 107 CPDF_Stream* pStream, |
135 FX_BOOL bStdCS, | 108 FX_BOOL bStdCS, |
136 FX_DWORD GroupFamily, | 109 FX_DWORD GroupFamily, |
137 FX_BOOL bLoadMask, | 110 FX_BOOL bLoadMask, |
138 CPDF_RenderStatus* pRenderStatus, | 111 CPDF_RenderStatus* pRenderStatus, |
139 int32_t downsampleWidth, | 112 int32_t downsampleWidth, |
140 int32_t downsampleHeight) { | 113 int32_t downsampleHeight) { |
141 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (void*&)m_pCurImageCache); | 114 const auto it = m_ImageCache.find(pStream); |
142 if (!m_bCurFindCache) { | 115 m_bCurFindCache = it != m_ImageCache.end(); |
143 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 116 if (m_bCurFindCache) { |
| 117 m_pCurImageCacheEntry = it->second; |
| 118 } else { |
| 119 m_pCurImageCacheEntry = |
| 120 new CPDF_ImageCacheEntry(m_pPage->m_pDocument, pStream); |
144 } | 121 } |
145 int ret = m_pCurImageCache->StartGetCachedBitmap( | 122 int ret = m_pCurImageCacheEntry->StartGetCachedBitmap( |
146 pRenderStatus->m_pFormResource, m_pPage->m_pPageResources, bStdCS, | 123 pRenderStatus->m_pFormResource, m_pPage->m_pPageResources, bStdCS, |
147 GroupFamily, bLoadMask, pRenderStatus, downsampleWidth, downsampleHeight); | 124 GroupFamily, bLoadMask, pRenderStatus, downsampleWidth, downsampleHeight); |
148 if (ret == 2) { | 125 if (ret == 2) |
149 return TRUE; | 126 return TRUE; |
150 } | 127 |
151 m_nTimeCount++; | 128 m_nTimeCount++; |
152 if (!m_bCurFindCache) { | 129 if (!m_bCurFindCache) |
153 m_ImageCaches.SetAt(pStream, m_pCurImageCache); | 130 m_ImageCache[pStream] = m_pCurImageCacheEntry; |
154 } | 131 |
155 if (!ret) { | 132 if (!ret) |
156 m_nCacheSize += m_pCurImageCache->EstimateSize(); | 133 m_nCacheSize += m_pCurImageCacheEntry->EstimateSize(); |
157 } | 134 |
158 return FALSE; | 135 return FALSE; |
159 } | 136 } |
160 FX_BOOL CPDF_PageRenderCache::Continue(IFX_Pause* pPause) { | 137 FX_BOOL CPDF_PageRenderCache::Continue(IFX_Pause* pPause) { |
161 int ret = m_pCurImageCache->Continue(pPause); | 138 int ret = m_pCurImageCacheEntry->Continue(pPause); |
162 if (ret == 2) { | 139 if (ret == 2) |
163 return TRUE; | 140 return TRUE; |
164 } | |
165 m_nTimeCount++; | 141 m_nTimeCount++; |
166 if (!m_bCurFindCache) { | 142 if (!m_bCurFindCache) |
167 m_ImageCaches.SetAt(m_pCurImageCache->GetStream(), m_pCurImageCache); | 143 m_ImageCache[m_pCurImageCacheEntry->GetStream()] = m_pCurImageCacheEntry; |
168 } | 144 if (!ret) |
169 if (!ret) { | 145 m_nCacheSize += m_pCurImageCacheEntry->EstimateSize(); |
170 m_nCacheSize += m_pCurImageCache->EstimateSize(); | |
171 } | |
172 return FALSE; | 146 return FALSE; |
173 } | 147 } |
174 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, | 148 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, |
175 const CFX_DIBitmap* pBitmap) { | 149 const CFX_DIBitmap* pBitmap) { |
176 CPDF_ImageCache* pImageCache; | 150 CPDF_ImageCacheEntry* pEntry; |
177 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { | 151 const auto it = m_ImageCache.find(pStream); |
178 if (!pBitmap) { | 152 if (it == m_ImageCache.end()) { |
| 153 if (!pBitmap) |
179 return; | 154 return; |
180 } | 155 pEntry = new CPDF_ImageCacheEntry(m_pPage->m_pDocument, pStream); |
181 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 156 m_ImageCache[pStream] = pEntry; |
182 m_ImageCaches.SetAt(pStream, pImageCache); | 157 } else { |
| 158 pEntry = it->second; |
183 } | 159 } |
184 int oldsize = pImageCache->EstimateSize(); | 160 m_nCacheSize -= pEntry->EstimateSize(); |
185 pImageCache->Reset(pBitmap); | 161 pEntry->Reset(pBitmap); |
186 m_nCacheSize = pImageCache->EstimateSize() - oldsize; | 162 m_nCacheSize += pEntry->EstimateSize(); |
187 } | 163 } |
188 CPDF_ImageCache::CPDF_ImageCache(CPDF_Document* pDoc, CPDF_Stream* pStream) | 164 CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc, |
| 165 CPDF_Stream* pStream) |
189 : m_dwTimeCount(0), | 166 : m_dwTimeCount(0), |
190 m_pCurBitmap(NULL), | 167 m_pCurBitmap(NULL), |
191 m_pCurMask(NULL), | 168 m_pCurMask(NULL), |
192 m_MatteColor(0), | 169 m_MatteColor(0), |
193 m_pRenderStatus(NULL), | 170 m_pRenderStatus(NULL), |
194 m_pDocument(pDoc), | 171 m_pDocument(pDoc), |
195 m_pStream(pStream), | 172 m_pStream(pStream), |
196 m_pCachedBitmap(NULL), | 173 m_pCachedBitmap(NULL), |
197 m_pCachedMask(NULL), | 174 m_pCachedMask(NULL), |
198 m_dwCacheSize(0) {} | 175 m_dwCacheSize(0) {} |
199 CPDF_ImageCache::~CPDF_ImageCache() { | 176 CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() { |
200 delete m_pCachedBitmap; | 177 delete m_pCachedBitmap; |
201 m_pCachedBitmap = NULL; | |
202 delete m_pCachedMask; | 178 delete m_pCachedMask; |
203 m_pCachedMask = NULL; | |
204 } | 179 } |
205 void CPDF_ImageCache::Reset(const CFX_DIBitmap* pBitmap) { | 180 void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) { |
206 delete m_pCachedBitmap; | 181 delete m_pCachedBitmap; |
207 m_pCachedBitmap = NULL; | 182 m_pCachedBitmap = NULL; |
208 if (pBitmap) { | 183 if (pBitmap) { |
209 m_pCachedBitmap = pBitmap->Clone(); | 184 m_pCachedBitmap = pBitmap->Clone(); |
210 } | 185 } |
211 CalcSize(); | 186 CalcSize(); |
212 } | 187 } |
213 void CPDF_PageRenderCache::ClearImageData() { | 188 void CPDF_PageRenderCache::ClearImageData() { |
214 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 189 for (const auto& it : m_ImageCache) |
215 while (pos) { | 190 it.second->ClearImageData(); |
216 void* key; | |
217 void* value; | |
218 m_ImageCaches.GetNextAssoc(pos, key, value); | |
219 ((CPDF_ImageCache*)value)->ClearImageData(); | |
220 } | |
221 } | 191 } |
222 void CPDF_ImageCache::ClearImageData() { | 192 void CPDF_ImageCacheEntry::ClearImageData() { |
223 if (m_pCachedBitmap && !m_pCachedBitmap->GetBuffer()) { | 193 if (m_pCachedBitmap && !m_pCachedBitmap->GetBuffer()) { |
224 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); | 194 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); |
225 } | 195 } |
226 } | 196 } |
227 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { | 197 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { |
228 return pDIB && pDIB->GetBuffer() | 198 return pDIB && pDIB->GetBuffer() |
229 ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPitch() + | 199 ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPitch() + |
230 (FX_DWORD)pDIB->GetPaletteSize() * 4 | 200 (FX_DWORD)pDIB->GetPaletteSize() * 4 |
231 : 0; | 201 : 0; |
232 } | 202 } |
233 FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, | 203 FX_BOOL CPDF_ImageCacheEntry::GetCachedBitmap(CFX_DIBSource*& pBitmap, |
234 CFX_DIBSource*& pMask, | 204 CFX_DIBSource*& pMask, |
235 FX_DWORD& MatteColor, | 205 FX_DWORD& MatteColor, |
236 CPDF_Dictionary* pPageResources, | 206 CPDF_Dictionary* pPageResources, |
237 FX_BOOL bStdCS, | 207 FX_BOOL bStdCS, |
238 FX_DWORD GroupFamily, | 208 FX_DWORD GroupFamily, |
239 FX_BOOL bLoadMask, | 209 FX_BOOL bLoadMask, |
240 CPDF_RenderStatus* pRenderStatus, | 210 CPDF_RenderStatus* pRenderStatus, |
241 int32_t downsampleWidth, | 211 int32_t downsampleWidth, |
242 int32_t downsampleHeight) { | 212 int32_t downsampleHeight) { |
243 if (m_pCachedBitmap) { | 213 if (m_pCachedBitmap) { |
244 pBitmap = m_pCachedBitmap; | 214 pBitmap = m_pCachedBitmap; |
245 pMask = m_pCachedMask; | 215 pMask = m_pCachedMask; |
246 MatteColor = m_MatteColor; | 216 MatteColor = m_MatteColor; |
247 return TRUE; | 217 return TRUE; |
248 } | 218 } |
249 if (!pRenderStatus) { | 219 if (!pRenderStatus) { |
250 return FALSE; | 220 return FALSE; |
251 } | 221 } |
252 CPDF_RenderContext* pContext = pRenderStatus->GetContext(); | 222 CPDF_RenderContext* pContext = pRenderStatus->GetContext(); |
(...skipping 18 matching lines...) Expand all Loading... |
271 if (pMaskSrc) { | 241 if (pMaskSrc) { |
272 m_pCachedMask = pMaskSrc->Clone(); | 242 m_pCachedMask = pMaskSrc->Clone(); |
273 delete pMaskSrc; | 243 delete pMaskSrc; |
274 } | 244 } |
275 | 245 |
276 pBitmap = m_pCachedBitmap; | 246 pBitmap = m_pCachedBitmap; |
277 pMask = m_pCachedMask; | 247 pMask = m_pCachedMask; |
278 CalcSize(); | 248 CalcSize(); |
279 return FALSE; | 249 return FALSE; |
280 } | 250 } |
281 CFX_DIBSource* CPDF_ImageCache::DetachBitmap() { | 251 CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() { |
282 CFX_DIBSource* pDIBSource = m_pCurBitmap; | 252 CFX_DIBSource* pDIBSource = m_pCurBitmap; |
283 m_pCurBitmap = NULL; | 253 m_pCurBitmap = NULL; |
284 return pDIBSource; | 254 return pDIBSource; |
285 } | 255 } |
286 CFX_DIBSource* CPDF_ImageCache::DetachMask() { | 256 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() { |
287 CFX_DIBSource* pDIBSource = m_pCurMask; | 257 CFX_DIBSource* pDIBSource = m_pCurMask; |
288 m_pCurMask = NULL; | 258 m_pCurMask = NULL; |
289 return pDIBSource; | 259 return pDIBSource; |
290 } | 260 } |
291 int CPDF_ImageCache::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, | 261 int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, |
292 CPDF_Dictionary* pPageResources, | 262 CPDF_Dictionary* pPageResources, |
293 FX_BOOL bStdCS, | 263 FX_BOOL bStdCS, |
294 FX_DWORD GroupFamily, | 264 FX_DWORD GroupFamily, |
295 FX_BOOL bLoadMask, | 265 FX_BOOL bLoadMask, |
296 CPDF_RenderStatus* pRenderStatus, | 266 CPDF_RenderStatus* pRenderStatus, |
297 int32_t downsampleWidth, | 267 int32_t downsampleWidth, |
298 int32_t downsampleHeight) { | 268 int32_t downsampleHeight) { |
299 if (m_pCachedBitmap) { | 269 if (m_pCachedBitmap) { |
300 m_pCurBitmap = m_pCachedBitmap; | 270 m_pCurBitmap = m_pCachedBitmap; |
301 m_pCurMask = m_pCachedMask; | 271 m_pCurMask = m_pCachedMask; |
302 return 1; | 272 return 1; |
303 } | 273 } |
304 if (!pRenderStatus) { | 274 if (!pRenderStatus) { |
305 return 0; | 275 return 0; |
306 } | 276 } |
307 m_pRenderStatus = pRenderStatus; | 277 m_pRenderStatus = pRenderStatus; |
308 m_pCurBitmap = new CPDF_DIBSource; | 278 m_pCurBitmap = new CPDF_DIBSource; |
309 int ret = | 279 int ret = |
310 ((CPDF_DIBSource*)m_pCurBitmap) | 280 ((CPDF_DIBSource*)m_pCurBitmap) |
311 ->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResources, | 281 ->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResources, |
312 pPageResources, bStdCS, GroupFamily, bLoadMask); | 282 pPageResources, bStdCS, GroupFamily, bLoadMask); |
313 if (ret == 2) { | 283 if (ret == 2) { |
314 return ret; | 284 return ret; |
315 } | 285 } |
316 if (!ret) { | 286 if (!ret) { |
317 delete m_pCurBitmap; | 287 delete m_pCurBitmap; |
318 m_pCurBitmap = NULL; | 288 m_pCurBitmap = NULL; |
319 return 0; | 289 return 0; |
320 } | 290 } |
321 ContinueGetCachedBitmap(); | 291 ContinueGetCachedBitmap(); |
322 return 0; | 292 return 0; |
323 } | 293 } |
324 int CPDF_ImageCache::ContinueGetCachedBitmap() { | 294 void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() { |
325 m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->m_MatteColor; | 295 m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->m_MatteColor; |
326 m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask(); | 296 m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask(); |
327 CPDF_RenderContext* pContext = m_pRenderStatus->GetContext(); | 297 CPDF_RenderContext* pContext = m_pRenderStatus->GetContext(); |
328 CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); | 298 CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); |
329 m_dwTimeCount = pPageRenderCache->GetTimeCount(); | 299 m_dwTimeCount = pPageRenderCache->GetTimeCount(); |
330 if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() < | 300 if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() < |
331 FPDF_HUGE_IMAGE_SIZE) { | 301 FPDF_HUGE_IMAGE_SIZE) { |
332 m_pCachedBitmap = m_pCurBitmap->Clone(); | 302 m_pCachedBitmap = m_pCurBitmap->Clone(); |
333 delete m_pCurBitmap; | 303 delete m_pCurBitmap; |
334 m_pCurBitmap = NULL; | 304 m_pCurBitmap = NULL; |
335 } else { | 305 } else { |
336 m_pCachedBitmap = m_pCurBitmap; | 306 m_pCachedBitmap = m_pCurBitmap; |
337 } | 307 } |
338 if (m_pCurMask) { | 308 if (m_pCurMask) { |
339 m_pCachedMask = m_pCurMask->Clone(); | 309 m_pCachedMask = m_pCurMask->Clone(); |
340 delete m_pCurMask; | 310 delete m_pCurMask; |
341 m_pCurMask = NULL; | 311 m_pCurMask = NULL; |
342 } | 312 } |
343 m_pCurBitmap = m_pCachedBitmap; | 313 m_pCurBitmap = m_pCachedBitmap; |
344 m_pCurMask = m_pCachedMask; | 314 m_pCurMask = m_pCachedMask; |
345 CalcSize(); | 315 CalcSize(); |
346 return 0; | |
347 } | 316 } |
348 int CPDF_ImageCache::Continue(IFX_Pause* pPause) { | 317 int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) { |
349 int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause); | 318 int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause); |
350 if (ret == 2) { | 319 if (ret == 2) { |
351 return ret; | 320 return ret; |
352 } | 321 } |
353 if (!ret) { | 322 if (!ret) { |
354 delete m_pCurBitmap; | 323 delete m_pCurBitmap; |
355 m_pCurBitmap = NULL; | 324 m_pCurBitmap = NULL; |
356 return 0; | 325 return 0; |
357 } | 326 } |
358 ContinueGetCachedBitmap(); | 327 ContinueGetCachedBitmap(); |
359 return 0; | 328 return 0; |
360 } | 329 } |
361 void CPDF_ImageCache::CalcSize() { | 330 void CPDF_ImageCacheEntry::CalcSize() { |
362 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + | 331 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + |
363 FPDF_ImageCache_EstimateImageSize(m_pCachedMask); | 332 FPDF_ImageCache_EstimateImageSize(m_pCachedMask); |
364 } | 333 } |
365 void CPDF_Document::ClearRenderFont() { | 334 void CPDF_Document::ClearRenderFont() { |
366 if (m_pDocRender) { | 335 if (m_pDocRender) { |
367 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); | 336 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); |
368 if (pCache) { | 337 if (pCache) { |
369 pCache->FreeCache(FALSE); | 338 pCache->FreeCache(FALSE); |
370 } | 339 } |
371 } | 340 } |
372 } | 341 } |
OLD | NEW |