| 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 19 matching lines...) Expand all Loading... |
| 30 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 30 FX_POSITION pos = m_ImageCaches.GetStartPosition(); |
| 31 while (pos) { | 31 while (pos) { |
| 32 FX_LPVOID key, value; | 32 FX_LPVOID key, value; |
| 33 m_ImageCaches.GetNextAssoc(pos, key, value); | 33 m_ImageCaches.GetNextAssoc(pos, key, value); |
| 34 delete (CPDF_ImageCache*)value; | 34 delete (CPDF_ImageCache*)value; |
| 35 } | 35 } |
| 36 m_ImageCaches.RemoveAll(); | 36 m_ImageCaches.RemoveAll(); |
| 37 m_nCacheSize = 0; | 37 m_nCacheSize = 0; |
| 38 m_nTimeCount = 0; | 38 m_nTimeCount = 0; |
| 39 } | 39 } |
| 40 void CPDF_PageRenderCache::CacheOptimization(FX_INT32 dwLimitCacheSize) | 40 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) |
| 41 { | 41 { |
| 42 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) { | 42 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) { |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 int nCount = m_ImageCaches.GetCount(); | 45 int nCount = m_ImageCaches.GetCount(); |
| 46 CACHEINFO* pCACHEINFO = (CACHEINFO*)FX_Alloc2D(FX_BYTE, sizeof(CACHEINFO), n
Count); | 46 CACHEINFO* pCACHEINFO = (CACHEINFO*)FX_Alloc2D(uint8_t, sizeof(CACHEINFO), n
Count); |
| 47 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 47 FX_POSITION pos = m_ImageCaches.GetStartPosition(); |
| 48 int i = 0; | 48 int i = 0; |
| 49 while (pos) { | 49 while (pos) { |
| 50 FX_LPVOID key, value; | 50 FX_LPVOID key, value; |
| 51 m_ImageCaches.GetNextAssoc(pos, key, value); | 51 m_ImageCaches.GetNextAssoc(pos, key, value); |
| 52 pCACHEINFO[i].time = ((CPDF_ImageCache*)value)->GetTimeCount(); | 52 pCACHEINFO[i].time = ((CPDF_ImageCache*)value)->GetTimeCount(); |
| 53 pCACHEINFO[i++].pStream = ((CPDF_ImageCache*)value)->GetStream(); | 53 pCACHEINFO[i++].pStream = ((CPDF_ImageCache*)value)->GetStream(); |
| 54 } | 54 } |
| 55 FXSYS_qsort(pCACHEINFO, nCount, sizeof (CACHEINFO), compare); | 55 FXSYS_qsort(pCACHEINFO, nCount, sizeof (CACHEINFO), compare); |
| 56 FX_DWORD nTimeCount = m_nTimeCount; | 56 FX_DWORD nTimeCount = m_nTimeCount; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return m_nCacheSize; | 99 return m_nCacheSize; |
| 100 } | 100 } |
| 101 CPDF_ImageCache* pImageCache; | 101 CPDF_ImageCache* pImageCache; |
| 102 if (!m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache)) { | 102 if (!m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache)) { |
| 103 return 0; | 103 return 0; |
| 104 } | 104 } |
| 105 return pImageCache->EstimateSize(); | 105 return pImageCache->EstimateSize(); |
| 106 } | 106 } |
| 107 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*&
pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor, | 107 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*&
pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor, |
| 108 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, | 108 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, |
| 109 FX_INT32 downsampleWidth, FX_INT32 downsampleHeight) | 109 int32_t downsampleWidth, int32_t downsampleHeight) |
| 110 { | 110 { |
| 111 CPDF_ImageCache* pImageCache; | 111 CPDF_ImageCache* pImageCache; |
| 112 FX_BOOL bFind = m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache); | 112 FX_BOOL bFind = m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache); |
| 113 if (!bFind) { | 113 if (!bFind) { |
| 114 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 114 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
| 115 } | 115 } |
| 116 m_nTimeCount ++; | 116 m_nTimeCount ++; |
| 117 FX_BOOL bCached = pImageCache->GetCachedBitmap(pBitmap, pMask, MatteColor, m
_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, downsam
pleWidth, downsampleHeight); | 117 FX_BOOL bCached = pImageCache->GetCachedBitmap(pBitmap, pMask, MatteColor, m
_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, downsam
pleWidth, downsampleHeight); |
| 118 if (!bFind) { | 118 if (!bFind) { |
| 119 m_ImageCaches.SetAt(pStream, pImageCache); | 119 m_ImageCaches.SetAt(pStream, pImageCache); |
| 120 } | 120 } |
| 121 if (!bCached) { | 121 if (!bCached) { |
| 122 m_nCacheSize += pImageCache->EstimateSize(); | 122 m_nCacheSize += pImageCache->EstimateSize(); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 FX_BOOL»CPDF_PageRenderCache::StartGetCachedBitmap(CPDF_Stream* pStream, FX_BOOL
bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStat
us, FX_INT32 downsampleWidth, FX_INT32 downsampleHeight) | 125 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) |
| 126 { | 126 { |
| 127 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (FX_LPVOID&)m_pCurImageCache
); | 127 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (FX_LPVOID&)m_pCurImageCache
); |
| 128 if (!m_bCurFindCache) { | 128 if (!m_bCurFindCache) { |
| 129 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 129 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
| 130 } | 130 } |
| 131 int ret = m_pCurImageCache->StartGetCachedBitmap(pRenderStatus->m_pFormResou
rce, m_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, d
ownsampleWidth, downsampleHeight); | 131 int ret = m_pCurImageCache->StartGetCachedBitmap(pRenderStatus->m_pFormResou
rce, m_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, d
ownsampleWidth, downsampleHeight); |
| 132 if (ret == 2) { | 132 if (ret == 2) { |
| 133 return TRUE; | 133 return TRUE; |
| 134 } | 134 } |
| 135 m_nTimeCount ++; | 135 m_nTimeCount ++; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { | 219 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { |
| 220 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); | 220 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) | 223 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) |
| 224 { | 224 { |
| 225 return pDIB && pDIB->GetBuffer() ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPi
tch() + (FX_DWORD)pDIB->GetPaletteSize() * 4 : 0; | 225 return pDIB && pDIB->GetBuffer() ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPi
tch() + (FX_DWORD)pDIB->GetPaletteSize() * 4 : 0; |
| 226 } | 226 } |
| 227 FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, CFX_DIBSource*
& pMask, FX_DWORD& MatteColor, CPDF_Dictionary* pPageResources, | 227 FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, CFX_DIBSource*
& pMask, FX_DWORD& MatteColor, CPDF_Dictionary* pPageResources, |
| 228 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, | 228 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, |
| 229 FX_INT32 downsampleWidth, FX_INT32 downsampleHeight) | 229 int32_t downsampleWidth, int32_t downsampleHeight) |
| 230 { | 230 { |
| 231 if (m_pCachedBitmap) { | 231 if (m_pCachedBitmap) { |
| 232 pBitmap = m_pCachedBitmap; | 232 pBitmap = m_pCachedBitmap; |
| 233 pMask = m_pCachedMask; | 233 pMask = m_pCachedMask; |
| 234 MatteColor = m_MatteColor; | 234 MatteColor = m_MatteColor; |
| 235 return TRUE; | 235 return TRUE; |
| 236 } | 236 } |
| 237 if (!pRenderStatus) { | 237 if (!pRenderStatus) { |
| 238 return FALSE; | 238 return FALSE; |
| 239 } | 239 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return pDIBSource; | 271 return pDIBSource; |
| 272 } | 272 } |
| 273 CFX_DIBSource* CPDF_ImageCache::DetachMask() | 273 CFX_DIBSource* CPDF_ImageCache::DetachMask() |
| 274 { | 274 { |
| 275 CFX_DIBSource* pDIBSource = m_pCurMask; | 275 CFX_DIBSource* pDIBSource = m_pCurMask; |
| 276 m_pCurMask = NULL; | 276 m_pCurMask = NULL; |
| 277 return pDIBSource; | 277 return pDIBSource; |
| 278 } | 278 } |
| 279 int CPDF_ImageCache::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, C
PDF_Dictionary* pPageResources, FX_BOOL bStdCS, | 279 int CPDF_ImageCache::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, C
PDF_Dictionary* pPageResources, FX_BOOL bStdCS, |
| 280 FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStatu
s, | 280 FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStatus* pRenderStatu
s, |
| 281 FX_INT32 downsampleWidth, FX_INT32 downsampleHeight) | 281 int32_t downsampleWidth, int32_t downsampleHeight) |
| 282 { | 282 { |
| 283 if (m_pCachedBitmap) { | 283 if (m_pCachedBitmap) { |
| 284 m_pCurBitmap = m_pCachedBitmap; | 284 m_pCurBitmap = m_pCachedBitmap; |
| 285 m_pCurMask = m_pCachedMask; | 285 m_pCurMask = m_pCachedMask; |
| 286 return 1; | 286 return 1; |
| 287 } | 287 } |
| 288 if (!pRenderStatus) { | 288 if (!pRenderStatus) { |
| 289 return 0; | 289 return 0; |
| 290 } | 290 } |
| 291 m_pRenderStatus = pRenderStatus; | 291 m_pRenderStatus = pRenderStatus; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 346 } |
| 347 void CPDF_Document::ClearRenderFont() | 347 void CPDF_Document::ClearRenderFont() |
| 348 { | 348 { |
| 349 if (m_pDocRender) { | 349 if (m_pDocRender) { |
| 350 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); | 350 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); |
| 351 if (pCache) { | 351 if (pCache) { |
| 352 pCache->FreeCache(FALSE); | 352 pCache->FreeCache(FALSE); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 } | 355 } |
| OLD | NEW |