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 "../../../include/fpdfapi/fpdf_render.h" | 7 #include "../../../include/fpdfapi/fpdf_render.h" |
8 #include "../../../include/fpdfapi/fpdf_pageobj.h" | 8 #include "../../../include/fpdfapi/fpdf_pageobj.h" |
9 #include "../../../include/fxge/fx_ge.h" | 9 #include "../../../include/fxge/fx_ge.h" |
10 #include "../fpdf_page/pageint.h" | 10 #include "../fpdf_page/pageint.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (pStream == NULL) { | 101 if (pStream == NULL) { |
102 return m_nCacheSize; | 102 return m_nCacheSize; |
103 } | 103 } |
104 CPDF_ImageCache* pImageCache; | 104 CPDF_ImageCache* pImageCache; |
105 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { | 105 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { |
106 return 0; | 106 return 0; |
107 } | 107 } |
108 return pImageCache->EstimateSize(); | 108 return pImageCache->EstimateSize(); |
109 } | 109 } |
110 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*&
pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor, | 110 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*&
pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor, |
111 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, | 111 bool bStdCS, FX_DWORD GroupFamily, bool bLoadMask, CPDF_RenderStatus* pR
enderStatus, |
112 int32_t downsampleWidth, int32_t downsampleHeight) | 112 int32_t downsampleWidth, int32_t downsampleHeight) |
113 { | 113 { |
114 CPDF_ImageCache* pImageCache; | 114 CPDF_ImageCache* pImageCache; |
115 FX_BOOL bFind = m_ImageCaches.Lookup(pStream, (void*&)pImageCache); | 115 bool bFind = m_ImageCaches.Lookup(pStream, (void*&)pImageCache); |
116 if (!bFind) { | 116 if (!bFind) { |
117 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 117 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
118 } | 118 } |
119 m_nTimeCount ++; | 119 m_nTimeCount ++; |
120 FX_BOOL bCached = pImageCache->GetCachedBitmap(pBitmap, pMask, MatteColor, m
_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, downsam
pleWidth, downsampleHeight); | 120 bool bCached = pImageCache->GetCachedBitmap(pBitmap, pMask, MatteColor, m_pP
age->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, downsample
Width, downsampleHeight); |
121 if (!bFind) { | 121 if (!bFind) { |
122 m_ImageCaches.SetAt(pStream, pImageCache); | 122 m_ImageCaches.SetAt(pStream, pImageCache); |
123 } | 123 } |
124 if (!bCached) { | 124 if (!bCached) { |
125 m_nCacheSize += pImageCache->EstimateSize(); | 125 m_nCacheSize += pImageCache->EstimateSize(); |
126 } | 126 } |
127 } | 127 } |
128 FX_BOOL»CPDF_PageRenderCache::StartGetCachedBitmap(CPDF_Stream* pStream, FX_BOOL
bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStat
us, int32_t downsampleWidth, int32_t downsampleHeight) | 128 bool» CPDF_PageRenderCache::StartGetCachedBitmap(CPDF_Stream* pStream, bool bS
tdCS, FX_DWORD GroupFamily, bool bLoadMask, CPDF_RenderStatus* pRenderStatus, in
t32_t downsampleWidth, int32_t downsampleHeight) |
129 { | 129 { |
130 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (void*&)m_pCurImageCache); | 130 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (void*&)m_pCurImageCache); |
131 if (!m_bCurFindCache) { | 131 if (!m_bCurFindCache) { |
132 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 132 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
133 } | 133 } |
134 int ret = m_pCurImageCache->StartGetCachedBitmap(pRenderStatus->m_pFormResou
rce, m_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, d
ownsampleWidth, downsampleHeight); | 134 int ret = m_pCurImageCache->StartGetCachedBitmap(pRenderStatus->m_pFormResou
rce, m_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, d
ownsampleWidth, downsampleHeight); |
135 if (ret == 2) { | 135 if (ret == 2) { |
136 return TRUE; | 136 return true; |
137 } | 137 } |
138 m_nTimeCount ++; | 138 m_nTimeCount ++; |
139 if (!m_bCurFindCache) { | 139 if (!m_bCurFindCache) { |
140 m_ImageCaches.SetAt(pStream, m_pCurImageCache); | 140 m_ImageCaches.SetAt(pStream, m_pCurImageCache); |
141 } | 141 } |
142 if (!ret) { | 142 if (!ret) { |
143 m_nCacheSize += m_pCurImageCache->EstimateSize(); | 143 m_nCacheSize += m_pCurImageCache->EstimateSize(); |
144 } | 144 } |
145 return FALSE; | 145 return false; |
146 } | 146 } |
147 FX_BOOL»CPDF_PageRenderCache::Continue(IFX_Pause* pPause) | 147 bool» CPDF_PageRenderCache::Continue(IFX_Pause* pPause) |
148 { | 148 { |
149 int ret = m_pCurImageCache->Continue(pPause); | 149 int ret = m_pCurImageCache->Continue(pPause); |
150 if (ret == 2) { | 150 if (ret == 2) { |
151 return TRUE; | 151 return true; |
152 } | 152 } |
153 m_nTimeCount ++; | 153 m_nTimeCount ++; |
154 if (!m_bCurFindCache) { | 154 if (!m_bCurFindCache) { |
155 m_ImageCaches.SetAt(m_pCurImageCache->GetStream(), m_pCurImageCache); | 155 m_ImageCaches.SetAt(m_pCurImageCache->GetStream(), m_pCurImageCache); |
156 } | 156 } |
157 if (!ret) { | 157 if (!ret) { |
158 m_nCacheSize += m_pCurImageCache->EstimateSize(); | 158 m_nCacheSize += m_pCurImageCache->EstimateSize(); |
159 } | 159 } |
160 return FALSE; | 160 return false; |
161 } | 161 } |
162 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap*
pBitmap) | 162 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap*
pBitmap) |
163 { | 163 { |
164 CPDF_ImageCache* pImageCache; | 164 CPDF_ImageCache* pImageCache; |
165 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { | 165 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { |
166 if (pBitmap == NULL) { | 166 if (pBitmap == NULL) { |
167 return; | 167 return; |
168 } | 168 } |
169 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 169 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
170 m_ImageCaches.SetAt(pStream, pImageCache); | 170 m_ImageCaches.SetAt(pStream, pImageCache); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 void CPDF_ImageCache::ClearImageData() | 215 void CPDF_ImageCache::ClearImageData() |
216 { | 216 { |
217 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { | 217 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { |
218 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); | 218 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); |
219 } | 219 } |
220 } | 220 } |
221 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) | 221 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) |
222 { | 222 { |
223 return pDIB && pDIB->GetBuffer() ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPi
tch() + (FX_DWORD)pDIB->GetPaletteSize() * 4 : 0; | 223 return pDIB && pDIB->GetBuffer() ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPi
tch() + (FX_DWORD)pDIB->GetPaletteSize() * 4 : 0; |
224 } | 224 } |
225 FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, CFX_DIBSource*
& pMask, FX_DWORD& MatteColor, CPDF_Dictionary* pPageResources, | 225 bool CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, CFX_DIBSource*& p
Mask, FX_DWORD& MatteColor, CPDF_Dictionary* pPageResources, |
226 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, | 226 bool bStdCS, FX_DWORD GroupFamily, bool bLoadMask, CPDF_RenderStatus* pR
enderStatus, |
227 int32_t downsampleWidth, int32_t downsampleHeight) | 227 int32_t downsampleWidth, int32_t downsampleHeight) |
228 { | 228 { |
229 if (m_pCachedBitmap) { | 229 if (m_pCachedBitmap) { |
230 pBitmap = m_pCachedBitmap; | 230 pBitmap = m_pCachedBitmap; |
231 pMask = m_pCachedMask; | 231 pMask = m_pCachedMask; |
232 MatteColor = m_MatteColor; | 232 MatteColor = m_MatteColor; |
233 return TRUE; | 233 return true; |
234 } | 234 } |
235 if (!pRenderStatus) { | 235 if (!pRenderStatus) { |
236 return FALSE; | 236 return false; |
237 } | 237 } |
238 CPDF_RenderContext*pContext = pRenderStatus->GetContext(); | 238 CPDF_RenderContext*pContext = pRenderStatus->GetContext(); |
239 CPDF_PageRenderCache* pPageRenderCache = pContext->m_pPageCache; | 239 CPDF_PageRenderCache* pPageRenderCache = pContext->m_pPageCache; |
240 m_dwTimeCount = pPageRenderCache->GetTimeCount(); | 240 m_dwTimeCount = pPageRenderCache->GetTimeCount(); |
241 CPDF_DIBSource* pSrc = new CPDF_DIBSource; | 241 CPDF_DIBSource* pSrc = new CPDF_DIBSource; |
242 CPDF_DIBSource* pMaskSrc = NULL; | 242 CPDF_DIBSource* pMaskSrc = NULL; |
243 if (!pSrc->Load(m_pDocument, m_pStream, &pMaskSrc, &MatteColor, pRenderStatu
s->m_pFormResource, pPageResources, bStdCS, GroupFamily, bLoadMask)) { | 243 if (!pSrc->Load(m_pDocument, m_pStream, &pMaskSrc, &MatteColor, pRenderStatu
s->m_pFormResource, pPageResources, bStdCS, GroupFamily, bLoadMask)) { |
244 delete pSrc; | 244 delete pSrc; |
245 pBitmap = NULL; | 245 pBitmap = NULL; |
246 return FALSE; | 246 return false; |
247 } | 247 } |
248 m_MatteColor = MatteColor; | 248 m_MatteColor = MatteColor; |
249 if (pSrc->GetPitch() * pSrc->GetHeight() < FPDF_HUGE_IMAGE_SIZE) { | 249 if (pSrc->GetPitch() * pSrc->GetHeight() < FPDF_HUGE_IMAGE_SIZE) { |
250 m_pCachedBitmap = pSrc->Clone(); | 250 m_pCachedBitmap = pSrc->Clone(); |
251 delete pSrc; | 251 delete pSrc; |
252 } else { | 252 } else { |
253 m_pCachedBitmap = pSrc; | 253 m_pCachedBitmap = pSrc; |
254 } | 254 } |
255 if (pMaskSrc) { | 255 if (pMaskSrc) { |
256 m_pCachedMask = pMaskSrc->Clone(); | 256 m_pCachedMask = pMaskSrc->Clone(); |
257 delete pMaskSrc; | 257 delete pMaskSrc; |
258 } | 258 } |
259 | 259 |
260 pBitmap = m_pCachedBitmap; | 260 pBitmap = m_pCachedBitmap; |
261 pMask = m_pCachedMask; | 261 pMask = m_pCachedMask; |
262 CalcSize(); | 262 CalcSize(); |
263 return FALSE; | 263 return false; |
264 } | 264 } |
265 CFX_DIBSource* CPDF_ImageCache::DetachBitmap() | 265 CFX_DIBSource* CPDF_ImageCache::DetachBitmap() |
266 { | 266 { |
267 CFX_DIBSource* pDIBSource = m_pCurBitmap; | 267 CFX_DIBSource* pDIBSource = m_pCurBitmap; |
268 m_pCurBitmap = NULL; | 268 m_pCurBitmap = NULL; |
269 return pDIBSource; | 269 return pDIBSource; |
270 } | 270 } |
271 CFX_DIBSource* CPDF_ImageCache::DetachMask() | 271 CFX_DIBSource* CPDF_ImageCache::DetachMask() |
272 { | 272 { |
273 CFX_DIBSource* pDIBSource = m_pCurMask; | 273 CFX_DIBSource* pDIBSource = m_pCurMask; |
274 m_pCurMask = NULL; | 274 m_pCurMask = NULL; |
275 return pDIBSource; | 275 return pDIBSource; |
276 } | 276 } |
277 int» CPDF_ImageCache::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, C
PDF_Dictionary* pPageResources, FX_BOOL bStdCS, | 277 int» CPDF_ImageCache::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, C
PDF_Dictionary* pPageResources, bool bStdCS, |
278 FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStatu
s, | 278 FX_DWORD GroupFamily, bool bLoadMask, CPDF_RenderStatus* pRenderStatus, |
279 int32_t downsampleWidth, int32_t downsampleHeight) | 279 int32_t downsampleWidth, int32_t downsampleHeight) |
280 { | 280 { |
281 if (m_pCachedBitmap) { | 281 if (m_pCachedBitmap) { |
282 m_pCurBitmap = m_pCachedBitmap; | 282 m_pCurBitmap = m_pCachedBitmap; |
283 m_pCurMask = m_pCachedMask; | 283 m_pCurMask = m_pCachedMask; |
284 return 1; | 284 return 1; |
285 } | 285 } |
286 if (!pRenderStatus) { | 286 if (!pRenderStatus) { |
287 return 0; | 287 return 0; |
288 } | 288 } |
289 m_pRenderStatus = pRenderStatus; | 289 m_pRenderStatus = pRenderStatus; |
290 m_pCurBitmap = new CPDF_DIBSource; | 290 m_pCurBitmap = new CPDF_DIBSource; |
291 int ret = ((CPDF_DIBSource*)m_pCurBitmap)->StartLoadDIBSource(m_pDocument, m
_pStream, TRUE, pFormResources, pPageResources, bStdCS, GroupFamily, bLoadMask); | 291 int ret = ((CPDF_DIBSource*)m_pCurBitmap)->StartLoadDIBSource(m_pDocument, m
_pStream, true, pFormResources, pPageResources, bStdCS, GroupFamily, bLoadMask); |
292 if (ret == 2) { | 292 if (ret == 2) { |
293 return ret; | 293 return ret; |
294 } | 294 } |
295 if (!ret) { | 295 if (!ret) { |
296 delete m_pCurBitmap; | 296 delete m_pCurBitmap; |
297 m_pCurBitmap = NULL; | 297 m_pCurBitmap = NULL; |
298 return 0; | 298 return 0; |
299 } | 299 } |
300 ContinueGetCachedBitmap(); | 300 ContinueGetCachedBitmap(); |
301 return 0; | 301 return 0; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 } | 340 } |
341 void CPDF_ImageCache::CalcSize() | 341 void CPDF_ImageCache::CalcSize() |
342 { | 342 { |
343 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + FPDF_Im
ageCache_EstimateImageSize(m_pCachedMask); | 343 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + FPDF_Im
ageCache_EstimateImageSize(m_pCachedMask); |
344 } | 344 } |
345 void CPDF_Document::ClearRenderFont() | 345 void CPDF_Document::ClearRenderFont() |
346 { | 346 { |
347 if (m_pDocRender) { | 347 if (m_pDocRender) { |
348 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); | 348 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); |
349 if (pCache) { | 349 if (pCache) { |
350 pCache->FreeCache(FALSE); | 350 pCache->FreeCache(false); |
351 } | 351 } |
352 } | 352 } |
353 } | 353 } |
OLD | NEW |