summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_imageobject.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-31 17:10:34 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-01 02:37:29 +0000
commit7d4f6a89d7e2c5d13b7d630d6348950044a5465e (patch)
tree3e0d95ba83fb471ef6d5a9cfde5a4d8bfd103471 /core/fpdfapi/page/cpdf_imageobject.cpp
parent984f1d877ac59315f4c070b1d63c9f651221760b (diff)
downloadpdfium-7d4f6a89d7e2c5d13b7d630d6348950044a5465e.tar.xz
Refcount CPDF_Image all the time.chromium/3061chromium/3060
Remove the old externally-counted CPDF_CountedImage type. Change-Id: Ia0b288586272da3f2daf7dfc153f08e62794321a Reviewed-on: https://pdfium-review.googlesource.com/3553 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_imageobject.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_imageobject.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp
index 01d2df7421..1c2cc6ba7e 100644
--- a/core/fpdfapi/page/cpdf_imageobject.cpp
+++ b/core/fpdfapi/page/cpdf_imageobject.cpp
@@ -12,11 +12,10 @@
#include "core/fpdfapi/page/cpdf_image.h"
#include "core/fpdfapi/parser/cpdf_document.h"
-CPDF_ImageObject::CPDF_ImageObject()
- : m_pImage(nullptr), m_pImageOwned(false) {}
+CPDF_ImageObject::CPDF_ImageObject() {}
CPDF_ImageObject::~CPDF_ImageObject() {
- Release();
+ MaybePurgeCache();
}
CPDF_PageObject::Type CPDF_ImageObject::GetType() const {
@@ -48,30 +47,31 @@ void CPDF_ImageObject::CalcBoundingBox() {
m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
}
-void CPDF_ImageObject::SetOwnedImage(std::unique_ptr<CPDF_Image> pImage) {
- Release();
- m_pImage = pImage.release();
- m_pImageOwned = true;
-}
-
-void CPDF_ImageObject::SetUnownedImage(CPDF_Image* pImage) {
- Release();
+void CPDF_ImageObject::SetImage(const CFX_RetainPtr<CPDF_Image>& pImage) {
+ MaybePurgeCache();
m_pImage = pImage;
- m_pImageOwned = false;
}
-void CPDF_ImageObject::Release() {
- if (m_pImageOwned) {
- delete m_pImage;
- m_pImage = nullptr;
- m_pImageOwned = false;
+void CPDF_ImageObject::MaybePurgeCache() {
+ if (!m_pImage)
return;
- }
- if (!m_pImage)
+ CPDF_Document* pDocument = m_pImage->GetDocument();
+ if (!pDocument)
+ return;
+
+ CPDF_DocPageData* pPageData = pDocument->GetPageData();
+ if (pPageData)
+ return;
+
+ CPDF_Stream* pStream = m_pImage->GetStream();
+ if (!pStream)
+ return;
+
+ uint32_t objnum = pStream->GetObjNum();
+ if (!objnum)
return;
- CPDF_DocPageData* pPageData = m_pImage->GetDocument()->GetPageData();
- pPageData->ReleaseImage(m_pImage->GetStream()->GetObjNum());
- m_pImage = nullptr;
+ m_pImage.Reset(); // Clear my reference before asking the cache.
+ pPageData->MaybePurgeImage(objnum);
}