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

Side by Side Diff: core/fpdfapi/fpdf_page/fpdf_page_doc.cpp

Issue 2368433003: Make CPDF_ColorSpace::Load() return a unique_ptr (Closed)
Patch Set: Created 4 years, 3 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_page/pageint.h" 7 #include "core/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 fontData->clear(); 69 fontData->clear();
70 } 70 }
71 } 71 }
72 72
73 for (auto& it : m_ColorSpaceMap) { 73 for (auto& it : m_ColorSpaceMap) {
74 CPDF_CountedColorSpace* csData = it.second; 74 CPDF_CountedColorSpace* csData = it.second;
75 if (!csData->get()) 75 if (!csData->get())
76 continue; 76 continue;
77 77
78 if (bForceRelease || csData->use_count() < 2) { 78 if (bForceRelease || csData->use_count() < 2) {
79 csData->get()->ReleaseCS(); 79 csData->get()->Release();
80 csData->reset(nullptr); 80 csData->reset(nullptr);
81 } 81 }
82 } 82 }
83 83
84 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end();) { 84 for (auto it = m_IccProfileMap.begin(); it != m_IccProfileMap.end();) {
85 auto curr_it = it++; 85 auto curr_it = it++;
86 CPDF_CountedIccProfile* ipData = curr_it->second; 86 CPDF_CountedIccProfile* ipData = curr_it->second;
87 if (!ipData->get()) 87 if (!ipData->get())
88 continue; 88 continue;
89 89
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 CPDF_CountedColorSpace* csData = nullptr; 288 CPDF_CountedColorSpace* csData = nullptr;
289 auto it = m_ColorSpaceMap.find(pCSObj); 289 auto it = m_ColorSpaceMap.find(pCSObj);
290 if (it != m_ColorSpaceMap.end()) { 290 if (it != m_ColorSpaceMap.end()) {
291 csData = it->second; 291 csData = it->second;
292 if (csData->get()) { 292 if (csData->get()) {
293 return csData->AddRef(); 293 return csData->AddRef();
294 } 294 }
295 } 295 }
296 296
297 CPDF_ColorSpace* pCS = CPDF_ColorSpace::Load(m_pPDFDoc, pArray); 297 std::unique_ptr<CPDF_ColorSpace> pCS =
298 CPDF_ColorSpace::Load(m_pPDFDoc, pArray);
298 if (!pCS) 299 if (!pCS)
299 return nullptr; 300 return nullptr;
300 301
301 if (!csData) { 302 if (!csData) {
302 csData = new CPDF_CountedColorSpace(pCS); 303 csData = new CPDF_CountedColorSpace(pCS.release());
303 m_ColorSpaceMap[pCSObj] = csData; 304 m_ColorSpaceMap[pCSObj] = csData;
304 } else { 305 } else {
305 csData->reset(pCS); 306 csData->reset(pCS.release());
306 } 307 }
307 return csData->AddRef(); 308 return csData->AddRef();
308 } 309 }
309 310
310 CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj) { 311 CPDF_ColorSpace* CPDF_DocPageData::GetCopiedColorSpace(CPDF_Object* pCSObj) {
311 if (!pCSObj) 312 if (!pCSObj)
312 return nullptr; 313 return nullptr;
313 314
314 auto it = m_ColorSpaceMap.find(pCSObj); 315 auto it = m_ColorSpaceMap.find(pCSObj);
315 if (it != m_ColorSpaceMap.end()) 316 if (it != m_ColorSpaceMap.end())
(...skipping 12 matching lines...) Expand all
328 329
329 CPDF_CountedColorSpace* pCountedColorSpace = it->second; 330 CPDF_CountedColorSpace* pCountedColorSpace = it->second;
330 if (!pCountedColorSpace->get()) 331 if (!pCountedColorSpace->get())
331 return; 332 return;
332 333
333 pCountedColorSpace->RemoveRef(); 334 pCountedColorSpace->RemoveRef();
334 if (pCountedColorSpace->use_count() > 1) 335 if (pCountedColorSpace->use_count() > 1)
335 return; 336 return;
336 337
337 // We have item only in m_ColorSpaceMap cache. Clean it. 338 // We have item only in m_ColorSpaceMap cache. Clean it.
338 pCountedColorSpace->get()->ReleaseCS(); 339 pCountedColorSpace->get()->Release();
339 pCountedColorSpace->reset(nullptr); 340 pCountedColorSpace->reset(nullptr);
340 } 341 }
341 342
342 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, 343 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj,
343 FX_BOOL bShading, 344 FX_BOOL bShading,
344 const CFX_Matrix& matrix) { 345 const CFX_Matrix& matrix) {
345 if (!pPatternObj) 346 if (!pPatternObj)
346 return nullptr; 347 return nullptr;
347 348
348 CPDF_CountedPattern* ptData = nullptr; 349 CPDF_CountedPattern* ptData = nullptr;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 544 }
544 545
545 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr( 546 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(
546 CPDF_Object* pPatternObj) const { 547 CPDF_Object* pPatternObj) const {
547 if (!pPatternObj) 548 if (!pPatternObj)
548 return nullptr; 549 return nullptr;
549 550
550 auto it = m_PatternMap.find(pPatternObj); 551 auto it = m_PatternMap.find(pPatternObj);
551 return it != m_PatternMap.end() ? it->second : nullptr; 552 return it != m_PatternMap.end() ? it->second : nullptr;
552 } 553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698