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

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

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 months 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 "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" 7 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h"
8 8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h" 10 #include "core/fpdfapi/fpdf_page/pageint.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } else { 159 } else {
160 pEntry = it->second; 160 pEntry = it->second;
161 } 161 }
162 m_nCacheSize -= pEntry->EstimateSize(); 162 m_nCacheSize -= pEntry->EstimateSize();
163 pEntry->Reset(pBitmap); 163 pEntry->Reset(pBitmap);
164 m_nCacheSize += pEntry->EstimateSize(); 164 m_nCacheSize += pEntry->EstimateSize();
165 } 165 }
166 CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc, 166 CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc,
167 CPDF_Stream* pStream) 167 CPDF_Stream* pStream)
168 : m_dwTimeCount(0), 168 : m_dwTimeCount(0),
169 m_pCurBitmap(NULL), 169 m_pCurBitmap(nullptr),
170 m_pCurMask(NULL), 170 m_pCurMask(nullptr),
171 m_MatteColor(0), 171 m_MatteColor(0),
172 m_pRenderStatus(NULL), 172 m_pRenderStatus(nullptr),
173 m_pDocument(pDoc), 173 m_pDocument(pDoc),
174 m_pStream(pStream), 174 m_pStream(pStream),
175 m_pCachedBitmap(NULL), 175 m_pCachedBitmap(nullptr),
176 m_pCachedMask(NULL), 176 m_pCachedMask(nullptr),
177 m_dwCacheSize(0) {} 177 m_dwCacheSize(0) {}
178 CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() { 178 CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {
179 delete m_pCachedBitmap; 179 delete m_pCachedBitmap;
180 delete m_pCachedMask; 180 delete m_pCachedMask;
181 } 181 }
182 void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) { 182 void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) {
183 delete m_pCachedBitmap; 183 delete m_pCachedBitmap;
184 m_pCachedBitmap = NULL; 184 m_pCachedBitmap = nullptr;
185 if (pBitmap) { 185 if (pBitmap) {
186 m_pCachedBitmap = pBitmap->Clone(); 186 m_pCachedBitmap = pBitmap->Clone();
187 } 187 }
188 CalcSize(); 188 CalcSize();
189 } 189 }
190 190
191 static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { 191 static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) {
192 return pDIB && pDIB->GetBuffer() 192 return pDIB && pDIB->GetBuffer()
193 ? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() + 193 ? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() +
194 (uint32_t)pDIB->GetPaletteSize() * 4 194 (uint32_t)pDIB->GetPaletteSize() * 4
(...skipping 15 matching lines...) Expand all
210 MatteColor = m_MatteColor; 210 MatteColor = m_MatteColor;
211 return TRUE; 211 return TRUE;
212 } 212 }
213 if (!pRenderStatus) { 213 if (!pRenderStatus) {
214 return FALSE; 214 return FALSE;
215 } 215 }
216 CPDF_RenderContext* pContext = pRenderStatus->GetContext(); 216 CPDF_RenderContext* pContext = pRenderStatus->GetContext();
217 CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); 217 CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache();
218 m_dwTimeCount = pPageRenderCache->GetTimeCount(); 218 m_dwTimeCount = pPageRenderCache->GetTimeCount();
219 CPDF_DIBSource* pSrc = new CPDF_DIBSource; 219 CPDF_DIBSource* pSrc = new CPDF_DIBSource;
220 CPDF_DIBSource* pMaskSrc = NULL; 220 CPDF_DIBSource* pMaskSrc = nullptr;
221 if (!pSrc->Load(m_pDocument, m_pStream, &pMaskSrc, &MatteColor, 221 if (!pSrc->Load(m_pDocument, m_pStream, &pMaskSrc, &MatteColor,
222 pRenderStatus->m_pFormResource, pPageResources, bStdCS, 222 pRenderStatus->m_pFormResource, pPageResources, bStdCS,
223 GroupFamily, bLoadMask)) { 223 GroupFamily, bLoadMask)) {
224 delete pSrc; 224 delete pSrc;
225 pBitmap = NULL; 225 pBitmap = nullptr;
226 return FALSE; 226 return FALSE;
227 } 227 }
228 m_MatteColor = MatteColor; 228 m_MatteColor = MatteColor;
229 if (pSrc->GetPitch() * pSrc->GetHeight() < FPDF_HUGE_IMAGE_SIZE) { 229 if (pSrc->GetPitch() * pSrc->GetHeight() < FPDF_HUGE_IMAGE_SIZE) {
230 m_pCachedBitmap = pSrc->Clone(); 230 m_pCachedBitmap = pSrc->Clone();
231 delete pSrc; 231 delete pSrc;
232 } else { 232 } else {
233 m_pCachedBitmap = pSrc; 233 m_pCachedBitmap = pSrc;
234 } 234 }
235 if (pMaskSrc) { 235 if (pMaskSrc) {
236 m_pCachedMask = pMaskSrc->Clone(); 236 m_pCachedMask = pMaskSrc->Clone();
237 delete pMaskSrc; 237 delete pMaskSrc;
238 } 238 }
239 239
240 pBitmap = m_pCachedBitmap; 240 pBitmap = m_pCachedBitmap;
241 pMask = m_pCachedMask; 241 pMask = m_pCachedMask;
242 CalcSize(); 242 CalcSize();
243 return FALSE; 243 return FALSE;
244 } 244 }
245 CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() { 245 CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() {
246 CFX_DIBSource* pDIBSource = m_pCurBitmap; 246 CFX_DIBSource* pDIBSource = m_pCurBitmap;
247 m_pCurBitmap = NULL; 247 m_pCurBitmap = nullptr;
248 return pDIBSource; 248 return pDIBSource;
249 } 249 }
250 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() { 250 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() {
251 CFX_DIBSource* pDIBSource = m_pCurMask; 251 CFX_DIBSource* pDIBSource = m_pCurMask;
252 m_pCurMask = NULL; 252 m_pCurMask = nullptr;
253 return pDIBSource; 253 return pDIBSource;
254 } 254 }
255 int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, 255 int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
256 CPDF_Dictionary* pPageResources, 256 CPDF_Dictionary* pPageResources,
257 FX_BOOL bStdCS, 257 FX_BOOL bStdCS,
258 uint32_t GroupFamily, 258 uint32_t GroupFamily,
259 FX_BOOL bLoadMask, 259 FX_BOOL bLoadMask,
260 CPDF_RenderStatus* pRenderStatus, 260 CPDF_RenderStatus* pRenderStatus,
261 int32_t downsampleWidth, 261 int32_t downsampleWidth,
262 int32_t downsampleHeight) { 262 int32_t downsampleHeight) {
263 if (m_pCachedBitmap) { 263 if (m_pCachedBitmap) {
264 m_pCurBitmap = m_pCachedBitmap; 264 m_pCurBitmap = m_pCachedBitmap;
265 m_pCurMask = m_pCachedMask; 265 m_pCurMask = m_pCachedMask;
266 return 1; 266 return 1;
267 } 267 }
268 if (!pRenderStatus) { 268 if (!pRenderStatus) {
269 return 0; 269 return 0;
270 } 270 }
271 m_pRenderStatus = pRenderStatus; 271 m_pRenderStatus = pRenderStatus;
272 m_pCurBitmap = new CPDF_DIBSource; 272 m_pCurBitmap = new CPDF_DIBSource;
273 int ret = 273 int ret =
274 ((CPDF_DIBSource*)m_pCurBitmap) 274 ((CPDF_DIBSource*)m_pCurBitmap)
275 ->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResources, 275 ->StartLoadDIBSource(m_pDocument, m_pStream, TRUE, pFormResources,
276 pPageResources, bStdCS, GroupFamily, bLoadMask); 276 pPageResources, bStdCS, GroupFamily, bLoadMask);
277 if (ret == 2) { 277 if (ret == 2) {
278 return ret; 278 return ret;
279 } 279 }
280 if (!ret) { 280 if (!ret) {
281 delete m_pCurBitmap; 281 delete m_pCurBitmap;
282 m_pCurBitmap = NULL; 282 m_pCurBitmap = nullptr;
283 return 0; 283 return 0;
284 } 284 }
285 ContinueGetCachedBitmap(); 285 ContinueGetCachedBitmap();
286 return 0; 286 return 0;
287 } 287 }
288 void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() { 288 void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() {
289 m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->GetMatteColor(); 289 m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->GetMatteColor();
290 m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask(); 290 m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask();
291 CPDF_RenderContext* pContext = m_pRenderStatus->GetContext(); 291 CPDF_RenderContext* pContext = m_pRenderStatus->GetContext();
292 CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); 292 CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache();
293 m_dwTimeCount = pPageRenderCache->GetTimeCount(); 293 m_dwTimeCount = pPageRenderCache->GetTimeCount();
294 if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() < 294 if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() <
295 FPDF_HUGE_IMAGE_SIZE) { 295 FPDF_HUGE_IMAGE_SIZE) {
296 m_pCachedBitmap = m_pCurBitmap->Clone(); 296 m_pCachedBitmap = m_pCurBitmap->Clone();
297 delete m_pCurBitmap; 297 delete m_pCurBitmap;
298 m_pCurBitmap = NULL; 298 m_pCurBitmap = nullptr;
299 } else { 299 } else {
300 m_pCachedBitmap = m_pCurBitmap; 300 m_pCachedBitmap = m_pCurBitmap;
301 } 301 }
302 if (m_pCurMask) { 302 if (m_pCurMask) {
303 m_pCachedMask = m_pCurMask->Clone(); 303 m_pCachedMask = m_pCurMask->Clone();
304 delete m_pCurMask; 304 delete m_pCurMask;
305 m_pCurMask = NULL; 305 m_pCurMask = nullptr;
306 } 306 }
307 m_pCurBitmap = m_pCachedBitmap; 307 m_pCurBitmap = m_pCachedBitmap;
308 m_pCurMask = m_pCachedMask; 308 m_pCurMask = m_pCachedMask;
309 CalcSize(); 309 CalcSize();
310 } 310 }
311 int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) { 311 int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) {
312 int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause); 312 int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause);
313 if (ret == 2) { 313 if (ret == 2) {
314 return ret; 314 return ret;
315 } 315 }
316 if (!ret) { 316 if (!ret) {
317 delete m_pCurBitmap; 317 delete m_pCurBitmap;
318 m_pCurBitmap = NULL; 318 m_pCurBitmap = nullptr;
319 return 0; 319 return 0;
320 } 320 }
321 ContinueGetCachedBitmap(); 321 ContinueGetCachedBitmap();
322 return 0; 322 return 0;
323 } 323 }
324 void CPDF_ImageCacheEntry::CalcSize() { 324 void CPDF_ImageCacheEntry::CalcSize() {
325 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + 325 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) +
326 FPDF_ImageCache_EstimateImageSize(m_pCachedMask); 326 FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
327 } 327 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_render/fpdf_render.cpp ('k') | core/fpdfapi/fpdf_render/fpdf_render_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698