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

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

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years 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 "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"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ClearImageCache(pCACHEINFO[i++].pStream); 67 ClearImageCache(pCACHEINFO[i++].pStream);
68 nCount--; 68 nCount--;
69 } 69 }
70 while (m_nCacheSize > (FX_DWORD)dwLimitCacheSize) { 70 while (m_nCacheSize > (FX_DWORD)dwLimitCacheSize) {
71 ClearImageCache(pCACHEINFO[i++].pStream); 71 ClearImageCache(pCACHEINFO[i++].pStream);
72 } 72 }
73 FX_Free(pCACHEINFO); 73 FX_Free(pCACHEINFO);
74 } 74 }
75 void CPDF_PageRenderCache::ClearImageCache(CPDF_Stream* pStream) { 75 void CPDF_PageRenderCache::ClearImageCache(CPDF_Stream* pStream) {
76 void* value = m_ImageCaches.GetValueAt(pStream); 76 void* value = m_ImageCaches.GetValueAt(pStream);
77 if (value == NULL) { 77 if (!value) {
78 m_ImageCaches.RemoveKey(pStream); 78 m_ImageCaches.RemoveKey(pStream);
79 return; 79 return;
80 } 80 }
81 m_nCacheSize -= ((CPDF_ImageCache*)value)->EstimateSize(); 81 m_nCacheSize -= ((CPDF_ImageCache*)value)->EstimateSize();
82 delete (CPDF_ImageCache*)value; 82 delete (CPDF_ImageCache*)value;
83 m_ImageCaches.RemoveKey(pStream); 83 m_ImageCaches.RemoveKey(pStream);
84 } 84 }
85 FX_DWORD CPDF_PageRenderCache::EstimateSize() { 85 FX_DWORD CPDF_PageRenderCache::EstimateSize() {
86 FX_DWORD dwSize = 0; 86 FX_DWORD dwSize = 0;
87 FX_POSITION pos = m_ImageCaches.GetStartPosition(); 87 FX_POSITION pos = m_ImageCaches.GetStartPosition();
88 while (pos) { 88 while (pos) {
89 void* key; 89 void* key;
90 void* value; 90 void* value;
91 m_ImageCaches.GetNextAssoc(pos, key, value); 91 m_ImageCaches.GetNextAssoc(pos, key, value);
92 dwSize += ((CPDF_ImageCache*)value)->EstimateSize(); 92 dwSize += ((CPDF_ImageCache*)value)->EstimateSize();
93 } 93 }
94 m_nCacheSize = dwSize; 94 m_nCacheSize = dwSize;
95 return dwSize; 95 return dwSize;
96 } 96 }
97 FX_DWORD CPDF_PageRenderCache::GetCachedSize(CPDF_Stream* pStream) const { 97 FX_DWORD CPDF_PageRenderCache::GetCachedSize(CPDF_Stream* pStream) const {
98 if (pStream == NULL) { 98 if (!pStream) {
99 return m_nCacheSize; 99 return m_nCacheSize;
100 } 100 }
101 CPDF_ImageCache* pImageCache; 101 CPDF_ImageCache* pImageCache;
102 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { 102 if (!m_ImageCaches.Lookup(pStream, (void*&)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, 107 void CPDF_PageRenderCache::GetCachedBitmap(CPDF_Stream* pStream,
108 CFX_DIBSource*& pBitmap, 108 CFX_DIBSource*& pBitmap,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 if (!ret) { 169 if (!ret) {
170 m_nCacheSize += m_pCurImageCache->EstimateSize(); 170 m_nCacheSize += m_pCurImageCache->EstimateSize();
171 } 171 }
172 return FALSE; 172 return FALSE;
173 } 173 }
174 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream, 174 void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream,
175 const CFX_DIBitmap* pBitmap) { 175 const CFX_DIBitmap* pBitmap) {
176 CPDF_ImageCache* pImageCache; 176 CPDF_ImageCache* pImageCache;
177 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) { 177 if (!m_ImageCaches.Lookup(pStream, (void*&)pImageCache)) {
178 if (pBitmap == NULL) { 178 if (!pBitmap) {
179 return; 179 return;
180 } 180 }
181 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream); 181 pImageCache = new CPDF_ImageCache(m_pPage->m_pDocument, pStream);
182 m_ImageCaches.SetAt(pStream, pImageCache); 182 m_ImageCaches.SetAt(pStream, pImageCache);
183 } 183 }
184 int oldsize = pImageCache->EstimateSize(); 184 int oldsize = pImageCache->EstimateSize();
185 pImageCache->Reset(pBitmap); 185 pImageCache->Reset(pBitmap);
186 m_nCacheSize = pImageCache->EstimateSize() - oldsize; 186 m_nCacheSize = pImageCache->EstimateSize() - oldsize;
187 } 187 }
188 CPDF_ImageCache::CPDF_ImageCache(CPDF_Document* pDoc, CPDF_Stream* pStream) 188 CPDF_ImageCache::CPDF_ImageCache(CPDF_Document* pDoc, CPDF_Stream* pStream)
(...skipping 24 matching lines...) Expand all
213 void CPDF_PageRenderCache::ClearImageData() { 213 void CPDF_PageRenderCache::ClearImageData() {
214 FX_POSITION pos = m_ImageCaches.GetStartPosition(); 214 FX_POSITION pos = m_ImageCaches.GetStartPosition();
215 while (pos) { 215 while (pos) {
216 void* key; 216 void* key;
217 void* value; 217 void* value;
218 m_ImageCaches.GetNextAssoc(pos, key, value); 218 m_ImageCaches.GetNextAssoc(pos, key, value);
219 ((CPDF_ImageCache*)value)->ClearImageData(); 219 ((CPDF_ImageCache*)value)->ClearImageData();
220 } 220 }
221 } 221 }
222 void CPDF_ImageCache::ClearImageData() { 222 void CPDF_ImageCache::ClearImageData() {
223 if (m_pCachedBitmap && m_pCachedBitmap->GetBuffer() == NULL) { 223 if (m_pCachedBitmap && !m_pCachedBitmap->GetBuffer()) {
224 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData(); 224 ((CPDF_DIBSource*)m_pCachedBitmap)->ClearImageData();
225 } 225 }
226 } 226 }
227 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { 227 static FX_DWORD FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) {
228 return pDIB && pDIB->GetBuffer() 228 return pDIB && pDIB->GetBuffer()
229 ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPitch() + 229 ? (FX_DWORD)pDIB->GetHeight() * pDIB->GetPitch() +
230 (FX_DWORD)pDIB->GetPaletteSize() * 4 230 (FX_DWORD)pDIB->GetPaletteSize() * 4
231 : 0; 231 : 0;
232 } 232 }
233 FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, 233 FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 FPDF_ImageCache_EstimateImageSize(m_pCachedMask); 363 FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
364 } 364 }
365 void CPDF_Document::ClearRenderFont() { 365 void CPDF_Document::ClearRenderFont() {
366 if (m_pDocRender) { 366 if (m_pDocRender) {
367 CFX_FontCache* pCache = m_pDocRender->GetFontCache(); 367 CFX_FontCache* pCache = m_pDocRender->GetFontCache();
368 if (pCache) { 368 if (pCache) {
369 pCache->FreeCache(FALSE); 369 pCache->FreeCache(FALSE);
370 } 370 }
371 } 371 }
372 } 372 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render.cpp ('k') | core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698