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

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

Issue 2536903004: Do not clone in CPDF_ImageCacheEntry::GetCachedBitmap (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/render/cpdf_pagerendercache.h" 7 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
8 8
9 #include "core/fpdfapi/page/cpdf_page.h" 9 #include "core/fpdfapi/page/cpdf_page.h"
10 #include "core/fpdfapi/page/pageint.h" 10 #include "core/fpdfapi/page/pageint.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 m_pCurBitmap(nullptr), 176 m_pCurBitmap(nullptr),
177 m_pCurMask(nullptr), 177 m_pCurMask(nullptr),
178 m_MatteColor(0), 178 m_MatteColor(0),
179 m_pRenderStatus(nullptr), 179 m_pRenderStatus(nullptr),
180 m_pDocument(pDoc), 180 m_pDocument(pDoc),
181 m_pStream(pStream), 181 m_pStream(pStream),
182 m_pCachedBitmap(nullptr), 182 m_pCachedBitmap(nullptr),
183 m_pCachedMask(nullptr), 183 m_pCachedMask(nullptr),
184 m_dwCacheSize(0) {} 184 m_dwCacheSize(0) {}
185 CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() { 185 CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {
186 delete m_pCachedBitmap; 186 delete m_pCachedBitmap;
Tom Sepez 2016/11/29 17:00:53 Can we make these two unique_ptr's first? Similar
npm 2016/11/29 17:05:31 Sure I can do that. But in this particular case, y
npm 2016/11/29 17:06:27 s/about/after
187 delete m_pCachedMask; 187 delete m_pCachedMask;
188 } 188 }
189 void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) { 189 void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) {
190 delete m_pCachedBitmap; 190 delete m_pCachedBitmap;
191 m_pCachedBitmap = nullptr; 191 m_pCachedBitmap = nullptr;
192 if (pBitmap) { 192 if (pBitmap) {
193 m_pCachedBitmap = pBitmap->Clone(); 193 m_pCachedBitmap = pBitmap->Clone();
194 } 194 }
195 CalcSize(); 195 CalcSize();
196 } 196 }
(...skipping 29 matching lines...) Expand all
226 CPDF_DIBSource* pSrc = new CPDF_DIBSource; 226 CPDF_DIBSource* pSrc = new CPDF_DIBSource;
227 CPDF_DIBSource* pMaskSrc = nullptr; 227 CPDF_DIBSource* pMaskSrc = nullptr;
228 if (!pSrc->Load(m_pDocument, m_pStream, &pMaskSrc, &MatteColor, 228 if (!pSrc->Load(m_pDocument, m_pStream, &pMaskSrc, &MatteColor,
229 pRenderStatus->m_pFormResource, pPageResources, bStdCS, 229 pRenderStatus->m_pFormResource, pPageResources, bStdCS,
230 GroupFamily, bLoadMask)) { 230 GroupFamily, bLoadMask)) {
231 delete pSrc; 231 delete pSrc;
232 pBitmap = nullptr; 232 pBitmap = nullptr;
233 return false; 233 return false;
234 } 234 }
235 m_MatteColor = MatteColor; 235 m_MatteColor = MatteColor;
236 if (pSrc->GetPitch() * pSrc->GetHeight() < FPDF_HUGE_IMAGE_SIZE) { 236 m_pCachedBitmap = pSrc;
237 m_pCachedBitmap = pSrc->Clone(); 237 if (pMaskSrc)
238 delete pSrc; 238 m_pCachedMask = pMaskSrc;
239 } else {
240 m_pCachedBitmap = pSrc;
241 }
242 if (pMaskSrc) {
243 m_pCachedMask = pMaskSrc->Clone();
244 delete pMaskSrc;
245 }
246 239
247 pBitmap = m_pCachedBitmap; 240 pBitmap = m_pCachedBitmap;
248 pMask = m_pCachedMask; 241 pMask = m_pCachedMask;
249 CalcSize(); 242 CalcSize();
250 return false; 243 return false;
251 } 244 }
245
252 CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() { 246 CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() {
253 CFX_DIBSource* pDIBSource = m_pCurBitmap; 247 CFX_DIBSource* pDIBSource = m_pCurBitmap;
254 m_pCurBitmap = nullptr; 248 m_pCurBitmap = nullptr;
255 return pDIBSource; 249 return pDIBSource;
256 } 250 }
257 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() { 251 CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() {
258 CFX_DIBSource* pDIBSource = m_pCurMask; 252 CFX_DIBSource* pDIBSource = m_pCurMask;
259 m_pCurMask = nullptr; 253 m_pCurMask = nullptr;
260 return pDIBSource; 254 return pDIBSource;
261 } 255 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 m_pCurBitmap = nullptr; 311 m_pCurBitmap = nullptr;
318 return 0; 312 return 0;
319 } 313 }
320 ContinueGetCachedBitmap(); 314 ContinueGetCachedBitmap();
321 return 0; 315 return 0;
322 } 316 }
323 void CPDF_ImageCacheEntry::CalcSize() { 317 void CPDF_ImageCacheEntry::CalcSize() {
324 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + 318 m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) +
325 FPDF_ImageCache_EstimateImageSize(m_pCachedMask); 319 FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
326 } 320 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698