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 11 matching lines...) Expand all Loading... |
22 void CPDF_Page::ClearRenderCache() | 22 void CPDF_Page::ClearRenderCache() |
23 { | 23 { |
24 if (m_pPageRender) { | 24 if (m_pPageRender) { |
25 m_pPageRender->ClearAll(); | 25 m_pPageRender->ClearAll(); |
26 } | 26 } |
27 } | 27 } |
28 void CPDF_PageRenderCache::ClearAll() | 28 void CPDF_PageRenderCache::ClearAll() |
29 { | 29 { |
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 void* key; |
| 33 void* value; |
33 m_ImageCaches.GetNextAssoc(pos, key, value); | 34 m_ImageCaches.GetNextAssoc(pos, key, value); |
34 delete (CPDF_ImageCache*)value; | 35 delete (CPDF_ImageCache*)value; |
35 } | 36 } |
36 m_ImageCaches.RemoveAll(); | 37 m_ImageCaches.RemoveAll(); |
37 m_nCacheSize = 0; | 38 m_nCacheSize = 0; |
38 m_nTimeCount = 0; | 39 m_nTimeCount = 0; |
39 } | 40 } |
40 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) | 41 void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) |
41 { | 42 { |
42 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) { | 43 if (m_nCacheSize <= (FX_DWORD)dwLimitCacheSize) { |
43 return; | 44 return; |
44 } | 45 } |
45 int nCount = m_ImageCaches.GetCount(); | 46 int nCount = m_ImageCaches.GetCount(); |
46 CACHEINFO* pCACHEINFO = (CACHEINFO*)FX_Alloc2D(uint8_t, sizeof(CACHEINFO), n
Count); | 47 CACHEINFO* pCACHEINFO = (CACHEINFO*)FX_Alloc2D(uint8_t, sizeof(CACHEINFO), n
Count); |
47 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 48 FX_POSITION pos = m_ImageCaches.GetStartPosition(); |
48 int i = 0; | 49 int i = 0; |
49 while (pos) { | 50 while (pos) { |
50 FX_LPVOID key, value; | 51 void* key; |
| 52 void* value; |
51 m_ImageCaches.GetNextAssoc(pos, key, value); | 53 m_ImageCaches.GetNextAssoc(pos, key, value); |
52 pCACHEINFO[i].time = ((CPDF_ImageCache*)value)->GetTimeCount(); | 54 pCACHEINFO[i].time = ((CPDF_ImageCache*)value)->GetTimeCount(); |
53 pCACHEINFO[i++].pStream = ((CPDF_ImageCache*)value)->GetStream(); | 55 pCACHEINFO[i++].pStream = ((CPDF_ImageCache*)value)->GetStream(); |
54 } | 56 } |
55 FXSYS_qsort(pCACHEINFO, nCount, sizeof (CACHEINFO), compare); | 57 FXSYS_qsort(pCACHEINFO, nCount, sizeof (CACHEINFO), compare); |
56 FX_DWORD nTimeCount = m_nTimeCount; | 58 FX_DWORD nTimeCount = m_nTimeCount; |
57 if (nTimeCount + 1 < nTimeCount) { | 59 if (nTimeCount + 1 < nTimeCount) { |
58 for (i = 0; i < nCount; i ++) { | 60 for (i = 0; i < nCount; i ++) { |
59 ((CPDF_ImageCache*)(m_ImageCaches[pCACHEINFO[i].pStream]))->m_dwTime
Count = i; | 61 ((CPDF_ImageCache*)(m_ImageCaches[pCACHEINFO[i].pStream]))->m_dwTime
Count = i; |
60 } | 62 } |
61 m_nTimeCount = nCount; | 63 m_nTimeCount = nCount; |
62 } | 64 } |
63 i = 0; | 65 i = 0; |
64 while(nCount > 15) { | 66 while(nCount > 15) { |
65 ClearImageCache(pCACHEINFO[i++].pStream); | 67 ClearImageCache(pCACHEINFO[i++].pStream); |
66 nCount--; | 68 nCount--; |
67 } | 69 } |
68 while (m_nCacheSize > (FX_DWORD)dwLimitCacheSize) { | 70 while (m_nCacheSize > (FX_DWORD)dwLimitCacheSize) { |
69 ClearImageCache(pCACHEINFO[i++].pStream); | 71 ClearImageCache(pCACHEINFO[i++].pStream); |
70 } | 72 } |
71 FX_Free(pCACHEINFO); | 73 FX_Free(pCACHEINFO); |
72 } | 74 } |
73 void CPDF_PageRenderCache::ClearImageCache(CPDF_Stream* pStream) | 75 void CPDF_PageRenderCache::ClearImageCache(CPDF_Stream* pStream) |
74 { | 76 { |
75 FX_LPVOID value = m_ImageCaches.GetValueAt(pStream); | 77 void* value = m_ImageCaches.GetValueAt(pStream); |
76 if (value == NULL) { | 78 if (value == NULL) { |
77 m_ImageCaches.RemoveKey(pStream); | 79 m_ImageCaches.RemoveKey(pStream); |
78 return; | 80 return; |
79 } | 81 } |
80 m_nCacheSize -= ((CPDF_ImageCache*)value)->EstimateSize(); | 82 m_nCacheSize -= ((CPDF_ImageCache*)value)->EstimateSize(); |
81 delete (CPDF_ImageCache*)value; | 83 delete (CPDF_ImageCache*)value; |
82 m_ImageCaches.RemoveKey(pStream); | 84 m_ImageCaches.RemoveKey(pStream); |
83 } | 85 } |
84 FX_DWORD CPDF_PageRenderCache::EstimateSize() | 86 FX_DWORD CPDF_PageRenderCache::EstimateSize() |
85 { | 87 { |
86 FX_DWORD dwSize = 0; | 88 FX_DWORD dwSize = 0; |
87 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 89 FX_POSITION pos = m_ImageCaches.GetStartPosition(); |
88 while (pos) { | 90 while (pos) { |
89 FX_LPVOID key, value; | 91 void* key; |
| 92 void* value; |
90 m_ImageCaches.GetNextAssoc(pos, key, value); | 93 m_ImageCaches.GetNextAssoc(pos, key, value); |
91 dwSize += ((CPDF_ImageCache*)value)->EstimateSize(); | 94 dwSize += ((CPDF_ImageCache*)value)->EstimateSize(); |
92 } | 95 } |
93 m_nCacheSize = dwSize; | 96 m_nCacheSize = dwSize; |
94 return dwSize; | 97 return dwSize; |
95 } | 98 } |
96 FX_DWORD CPDF_PageRenderCache::GetCachedSize(CPDF_Stream* pStream) const | 99 FX_DWORD CPDF_PageRenderCache::GetCachedSize(CPDF_Stream* pStream) const |
97 { | 100 { |
98 if (pStream == NULL) { | 101 if (pStream == NULL) { |
99 return m_nCacheSize; | 102 return m_nCacheSize; |
100 } | 103 } |
101 CPDF_ImageCache* pImageCache; | 104 CPDF_ImageCache* pImageCache; |
102 if (!m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache)) { | 105 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { |
103 return 0; | 106 return 0; |
104 } | 107 } |
105 return pImageCache->EstimateSize(); | 108 return pImageCache->EstimateSize(); |
106 } | 109 } |
107 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, |
108 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, | 111 FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_BOOL bLoadMask, CPDF_RenderStat
us* pRenderStatus, |
109 int32_t downsampleWidth, int32_t downsampleHeight) | 112 int32_t downsampleWidth, int32_t downsampleHeight) |
110 { | 113 { |
111 CPDF_ImageCache* pImageCache; | 114 CPDF_ImageCache* pImageCache; |
112 FX_BOOL bFind = m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache); | 115 FX_BOOL bFind = m_ImageCaches.Lookup(pStream, (void*&)pImageCache); |
113 if (!bFind) { | 116 if (!bFind) { |
114 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 117 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
115 } | 118 } |
116 m_nTimeCount ++; | 119 m_nTimeCount ++; |
117 FX_BOOL bCached = pImageCache->GetCachedBitmap(pBitmap, pMask, MatteColor, m
_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, downsam
pleWidth, downsampleHeight); | 120 FX_BOOL bCached = pImageCache->GetCachedBitmap(pBitmap, pMask, MatteColor, m
_pPage->m_pPageResources, bStdCS, GroupFamily, bLoadMask, pRenderStatus, downsam
pleWidth, downsampleHeight); |
118 if (!bFind) { | 121 if (!bFind) { |
119 m_ImageCaches.SetAt(pStream, pImageCache); | 122 m_ImageCaches.SetAt(pStream, pImageCache); |
120 } | 123 } |
121 if (!bCached) { | 124 if (!bCached) { |
122 m_nCacheSize += pImageCache->EstimateSize(); | 125 m_nCacheSize += pImageCache->EstimateSize(); |
123 } | 126 } |
124 } | 127 } |
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) | 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) |
126 { | 129 { |
127 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (FX_LPVOID&)m_pCurImageCache
); | 130 m_bCurFindCache = m_ImageCaches.Lookup(pStream, (void*&)m_pCurImageCache); |
128 if (!m_bCurFindCache) { | 131 if (!m_bCurFindCache) { |
129 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 132 m_pCurImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
130 } | 133 } |
131 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); |
132 if (ret == 2) { | 135 if (ret == 2) { |
133 return TRUE; | 136 return TRUE; |
134 } | 137 } |
135 m_nTimeCount ++; | 138 m_nTimeCount ++; |
136 if (!m_bCurFindCache) { | 139 if (!m_bCurFindCache) { |
137 m_ImageCaches.SetAt(pStream, m_pCurImageCache); | 140 m_ImageCaches.SetAt(pStream, m_pCurImageCache); |
(...skipping 14 matching lines...) Expand all Loading... |
152 m_ImageCaches.SetAt(m_pCurImageCache->GetStream(), m_pCurImageCache); | 155 m_ImageCaches.SetAt(m_pCurImageCache->GetStream(), m_pCurImageCache); |
153 } | 156 } |
154 if (!ret) { | 157 if (!ret) { |
155 m_nCacheSize += m_pCurImageCache->EstimateSize(); | 158 m_nCacheSize += m_pCurImageCache->EstimateSize(); |
156 } | 159 } |
157 return FALSE; | 160 return FALSE; |
158 } | 161 } |
159 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap*
pBitmap) | 162 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap*
pBitmap) |
160 { | 163 { |
161 CPDF_ImageCache* pImageCache; | 164 CPDF_ImageCache* pImageCache; |
162 if (!m_ImageCaches.Lookup(pStream, (FX_LPVOID&)pImageCache)) { | 165 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { |
163 if (pBitmap == NULL) { | 166 if (pBitmap == NULL) { |
164 return; | 167 return; |
165 } | 168 } |
166 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); | 169 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); |
167 m_ImageCaches.SetAt(pStream, pImageCache); | 170 m_ImageCaches.SetAt(pStream, pImageCache); |
168 } | 171 } |
169 int oldsize = pImageCache->EstimateSize(); | 172 int oldsize = pImageCache->EstimateSize(); |
170 pImageCache->Reset(pBitmap); | 173 pImageCache->Reset(pBitmap); |
171 m_nCacheSize = pImageCache->EstimateSize() - oldsize; | 174 m_nCacheSize = pImageCache->EstimateSize() - oldsize; |
172 } | 175 } |
(...skipping 29 matching lines...) Expand all Loading... |
202 m_pCachedBitmap = NULL; | 205 m_pCachedBitmap = NULL; |
203 if (pBitmap) { | 206 if (pBitmap) { |
204 m_pCachedBitmap = pBitmap->Clone(); | 207 m_pCachedBitmap = pBitmap->Clone(); |
205 } | 208 } |
206 CalcSize(); | 209 CalcSize(); |
207 } | 210 } |
208 void CPDF_PageRenderCache::ClearImageData() | 211 void CPDF_PageRenderCache::ClearImageData() |
209 { | 212 { |
210 FX_POSITION pos = m_ImageCaches.GetStartPosition(); | 213 FX_POSITION pos = m_ImageCaches.GetStartPosition(); |
211 while (pos) { | 214 while (pos) { |
212 FX_LPVOID key, value; | 215 void* key; |
| 216 void* value; |
213 m_ImageCaches.GetNextAssoc(pos, key, value); | 217 m_ImageCaches.GetNextAssoc(pos, key, value); |
214 ((CPDF_ImageCache*)value)->ClearImageData(); | 218 ((CPDF_ImageCache*)value)->ClearImageData(); |
215 } | 219 } |
216 } | 220 } |
217 void CPDF_ImageCache::ClearImageData() | 221 void CPDF_ImageCache::ClearImageData() |
218 { | 222 { |
219 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { | 223 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { |
220 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); | 224 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); |
221 } | 225 } |
222 } | 226 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 350 } |
347 void CPDF_Document::ClearRenderFont() | 351 void CPDF_Document::ClearRenderFont() |
348 { | 352 { |
349 if (m_pDocRender) { | 353 if (m_pDocRender) { |
350 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); | 354 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); |
351 if (pCache) { | 355 if (pCache) { |
352 pCache->FreeCache(FALSE); | 356 pCache->FreeCache(FALSE); |
353 } | 357 } |
354 } | 358 } |
355 } | 359 } |
OLD | NEW |