summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp6
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp13
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.h5
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp52
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.h7
-rw-r--r--core/fpdfapi/page/cpdf_meshstream.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_meshstream.h3
-rw-r--r--core/fpdfapi/page/fpdf_page_func.cpp12
-rw-r--r--core/fpdfapi/page/pageint.h9
9 files changed, 48 insertions, 68 deletions
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 500de26c56..400b7a9150 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -1084,9 +1084,9 @@ bool CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
if (CPDF_String* pString = pTableObj->AsString()) {
m_Table = pString->GetString();
} else if (CPDF_Stream* pStream = pTableObj->AsStream()) {
- CPDF_StreamAcc acc;
- acc.LoadAllData(pStream, false);
- m_Table = CFX_ByteStringC(acc.GetData(), acc.GetSize());
+ auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
+ pAcc->LoadAllData(false);
+ m_Table = CFX_ByteStringC(pAcc->GetData(), pAcc->GetSize());
}
return true;
}
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 46e2c52c75..96bc7a2221 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -55,8 +55,8 @@ void CPDF_ContentParser::Start(CPDF_Page* pPage) {
}
if (CPDF_Stream* pStream = pContent->AsStream()) {
m_nStreams = 0;
- m_pSingleStream = pdfium::MakeUnique<CPDF_StreamAcc>();
- m_pSingleStream->LoadAllData(pStream, false);
+ m_pSingleStream = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
+ m_pSingleStream->LoadAllData(false);
} else if (CPDF_Array* pArray = pContent->AsArray()) {
m_nStreams = pArray->GetCount();
if (m_nStreams)
@@ -114,8 +114,8 @@ void CPDF_ContentParser::Start(CPDF_Form* pForm,
pState->SetSoftMask(nullptr);
}
m_nStreams = 0;
- m_pSingleStream = pdfium::MakeUnique<CPDF_StreamAcc>();
- m_pSingleStream->LoadAllData(pForm->m_pFormStream, false);
+ m_pSingleStream = pdfium::MakeRetain<CPDF_StreamAcc>(pForm->m_pFormStream);
+ m_pSingleStream->LoadAllData(false);
m_pData = (uint8_t*)m_pSingleStream->GetData();
m_Size = m_pSingleStream->GetSize();
m_Status = ToBeContinued;
@@ -156,10 +156,11 @@ void CPDF_ContentParser::Continue(IFX_Pause* pPause) {
} else {
CPDF_Array* pContent =
m_pObjectHolder->m_pFormDict->GetArrayFor("Contents");
- m_StreamArray[m_CurrentOffset] = pdfium::MakeUnique<CPDF_StreamAcc>();
CPDF_Stream* pStreamObj = ToStream(
pContent ? pContent->GetDirectObjectAt(m_CurrentOffset) : nullptr);
- m_StreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, false);
+ m_StreamArray[m_CurrentOffset] =
+ pdfium::MakeRetain<CPDF_StreamAcc>(pStreamObj);
+ m_StreamArray[m_CurrentOffset]->LoadAllData(false);
m_CurrentOffset++;
}
}
diff --git a/core/fpdfapi/page/cpdf_contentparser.h b/core/fpdfapi/page/cpdf_contentparser.h
index 5fd11f6c0b..402fd2fdd0 100644
--- a/core/fpdfapi/page/cpdf_contentparser.h
+++ b/core/fpdfapi/page/cpdf_contentparser.h
@@ -12,6 +12,7 @@
#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
#include "core/fpdfapi/page/cpdf_streamcontentparser.h"
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
class CPDF_AllStates;
class CPDF_Form;
@@ -48,8 +49,8 @@ class CPDF_ContentParser {
bool m_bForm;
CPDF_Type3Char* m_pType3Char;
uint32_t m_nStreams;
- std::unique_ptr<CPDF_StreamAcc> m_pSingleStream;
- std::vector<std::unique_ptr<CPDF_StreamAcc>> m_StreamArray;
+ CFX_RetainPtr<CPDF_StreamAcc> m_pSingleStream;
+ std::vector<CFX_RetainPtr<CPDF_StreamAcc>> m_StreamArray;
uint8_t* m_pData;
uint32_t m_Size;
uint32_t m_CurrentOffset;
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index a57c42d3cd..5e13740c21 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -96,15 +96,8 @@ void CPDF_DocPageData::Clear(bool bForceRelease) {
for (auto it = m_FontFileMap.begin(); it != m_FontFileMap.end();) {
auto curr_it = it++;
- CPDF_CountedStreamAcc* pCountedFont = curr_it->second;
- if (!pCountedFont->get())
- continue;
-
- if (bForceRelease || pCountedFont->use_count() < 2) {
- delete pCountedFont->get();
- delete pCountedFont;
+ if (bForceRelease || curr_it->second->HasOneRef())
m_FontFileMap.erase(curr_it);
- }
}
m_ImageMap.clear();
@@ -408,11 +401,11 @@ CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
if (it != m_IccProfileMap.end())
return it->second;
- CPDF_StreamAcc accessor;
- accessor.LoadAllData(pProfileStream, false);
+ auto pAccessor = pdfium::MakeRetain<CPDF_StreamAcc>(pProfileStream);
+ pAccessor->LoadAllData(false);
uint8_t digest[20];
- CRYPT_SHA1Generate(accessor.GetData(), accessor.GetSize(), digest);
+ CRYPT_SHA1Generate(pAccessor->GetData(), pAccessor->GetSize(), digest);
CFX_ByteString bsDigest(digest, 20);
auto hash_it = m_HashProfileMap.find(bsDigest);
@@ -422,7 +415,7 @@ CFX_RetainPtr<CPDF_IccProfile> CPDF_DocPageData::GetIccProfile(
return it_copied_stream->second;
}
auto pProfile = pdfium::MakeRetain<CPDF_IccProfile>(
- pProfileStream, accessor.GetData(), accessor.GetSize());
+ pProfileStream, pAccessor->GetData(), pAccessor->GetSize());
m_IccProfileMap[pProfileStream] = pProfile;
m_HashProfileMap[bsDigest] = pProfileStream;
return pProfile;
@@ -435,13 +428,12 @@ void CPDF_DocPageData::MaybePurgeIccProfile(CPDF_Stream* pProfileStream) {
m_IccProfileMap.erase(it);
}
-CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
+CFX_RetainPtr<CPDF_StreamAcc> CPDF_DocPageData::GetFontFileStreamAcc(
CPDF_Stream* pFontStream) {
ASSERT(pFontStream);
-
auto it = m_FontFileMap.find(pFontStream);
if (it != m_FontFileMap.end())
- return it->second->AddRef();
+ return it->second;
CPDF_Dictionary* pFontDict = pFontStream->GetDict();
int32_t org_size = pFontDict->GetIntegerFor("Length1") +
@@ -449,36 +441,20 @@ CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(
pFontDict->GetIntegerFor("Length3");
org_size = std::max(org_size, 0);
- auto pFontAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
- pFontAcc->LoadAllData(pFontStream, false, org_size);
-
- CPDF_CountedStreamAcc* pCountedFont =
- new CPDF_CountedStreamAcc(std::move(pFontAcc));
- m_FontFileMap[pFontStream] = pCountedFont;
- return pCountedFont->AddRef();
+ auto pFontAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pFontStream);
+ pFontAcc->LoadAllData(false, org_size);
+ m_FontFileMap[pFontStream] = pFontAcc;
+ return pFontAcc;
}
-void CPDF_DocPageData::ReleaseFontFileStreamAcc(
+void CPDF_DocPageData::MaybePurgeFontFileStreamAcc(
const CPDF_Stream* pFontStream) {
if (!pFontStream)
return;
auto it = m_FontFileMap.find(pFontStream);
- if (it == m_FontFileMap.end())
- return;
-
- CPDF_CountedStreamAcc* pCountedStream = it->second;
- if (!pCountedStream)
- return;
-
- pCountedStream->RemoveRef();
- if (pCountedStream->use_count() > 1)
- return;
-
- // We have item only in m_FontFileMap cache. Clean it.
- delete pCountedStream->get();
- delete pCountedStream;
- m_FontFileMap.erase(it);
+ if (it != m_FontFileMap.end() && it->second->HasOneRef())
+ m_FontFileMap.erase(it);
}
CPDF_CountedColorSpace* CPDF_DocPageData::FindColorSpacePtr(
diff --git a/core/fpdfapi/page/cpdf_docpagedata.h b/core/fpdfapi/page/cpdf_docpagedata.h
index 24e0006efd..f5ac303290 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.h
+++ b/core/fpdfapi/page/cpdf_docpagedata.h
@@ -53,15 +53,14 @@ class CPDF_DocPageData {
CFX_RetainPtr<CPDF_IccProfile> GetIccProfile(CPDF_Stream* pProfileStream);
void MaybePurgeIccProfile(CPDF_Stream* pProfileStream);
- CPDF_StreamAcc* GetFontFileStreamAcc(CPDF_Stream* pFontStream);
- void ReleaseFontFileStreamAcc(const CPDF_Stream* pFontStream);
+ CFX_RetainPtr<CPDF_StreamAcc> GetFontFileStreamAcc(CPDF_Stream* pFontStream);
+ void MaybePurgeFontFileStreamAcc(const CPDF_Stream* pFontStream);
CPDF_CountedColorSpace* FindColorSpacePtr(CPDF_Object* pCSObj) const;
CPDF_CountedPattern* FindPatternPtr(CPDF_Object* pPatternObj) const;
private:
using CPDF_CountedFont = CPDF_CountedObject<CPDF_Font>;
- using CPDF_CountedStreamAcc = CPDF_CountedObject<CPDF_StreamAcc>;
CPDF_ColorSpace* GetColorSpaceImpl(CPDF_Object* pCSObj,
const CPDF_Dictionary* pResources,
@@ -71,7 +70,7 @@ class CPDF_DocPageData {
bool m_bForceClear;
std::map<CFX_ByteString, CPDF_Stream*> m_HashProfileMap;
std::map<const CPDF_Object*, CPDF_CountedColorSpace*> m_ColorSpaceMap;
- std::map<const CPDF_Stream*, CPDF_CountedStreamAcc*> m_FontFileMap;
+ std::map<const CPDF_Stream*, CFX_RetainPtr<CPDF_StreamAcc>> m_FontFileMap;
std::map<const CPDF_Dictionary*, CPDF_CountedFont*> m_FontMap;
std::map<const CPDF_Stream*, CFX_RetainPtr<CPDF_IccProfile>> m_IccProfileMap;
std::map<uint32_t, CFX_RetainPtr<CPDF_Image>> m_ImageMap;
diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp
index b0a21c627a..c173bc633a 100644
--- a/core/fpdfapi/page/cpdf_meshstream.cpp
+++ b/core/fpdfapi/page/cpdf_meshstream.cpp
@@ -107,14 +107,17 @@ CPDF_MeshStream::CPDF_MeshStream(
m_xmin(0),
m_xmax(0),
m_ymin(0),
- m_ymax(0) {
+ m_ymax(0),
+ m_pStream(pdfium::MakeRetain<CPDF_StreamAcc>(pShadingStream)) {
memset(&m_ColorMin, 0, sizeof(m_ColorMin));
memset(&m_ColorMax, 0, sizeof(m_ColorMax));
}
+CPDF_MeshStream::~CPDF_MeshStream() {}
+
bool CPDF_MeshStream::Load() {
- m_Stream.LoadAllData(m_pShadingStream);
- m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize());
+ m_pStream->LoadAllData();
+ m_BitStream.Init(m_pStream->GetData(), m_pStream->GetSize());
CPDF_Dictionary* pDict = m_pShadingStream->GetDict();
m_nCoordBits = pDict->GetIntegerFor("BitsPerCoordinate");
m_nComponentBits = pDict->GetIntegerFor("BitsPerComponent");
diff --git a/core/fpdfapi/page/cpdf_meshstream.h b/core/fpdfapi/page/cpdf_meshstream.h
index e58e354b35..e02c3bb4e8 100644
--- a/core/fpdfapi/page/cpdf_meshstream.h
+++ b/core/fpdfapi/page/cpdf_meshstream.h
@@ -39,6 +39,7 @@ class CPDF_MeshStream {
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
CPDF_Stream* pShadingStream,
CPDF_ColorSpace* pCS);
+ ~CPDF_MeshStream();
bool Load();
@@ -80,7 +81,7 @@ class CPDF_MeshStream {
float m_ymax;
float m_ColorMin[kMaxComponents];
float m_ColorMax[kMaxComponents];
- CPDF_StreamAcc m_Stream;
+ CFX_RetainPtr<CPDF_StreamAcc> m_pStream;
CFX_BitStream m_BitStream;
};
diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp
index 9be1edb7ff..bc66adf726 100644
--- a/core/fpdfapi/page/fpdf_page_func.cpp
+++ b/core/fpdfapi/page/fpdf_page_func.cpp
@@ -90,10 +90,10 @@ class CPDF_PSFunc : public CPDF_Function {
};
bool CPDF_PSFunc::v_Init(CPDF_Object* pObj) {
- CPDF_StreamAcc acc;
- acc.LoadAllData(pObj->AsStream(), false);
- return m_PS.Parse(reinterpret_cast<const char*>(acc.GetData()),
- acc.GetSize());
+ auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pObj->AsStream());
+ pAcc->LoadAllData(false);
+ return m_PS.Parse(reinterpret_cast<const char*>(pAcc->GetData()),
+ pAcc->GetSize());
}
bool CPDF_PSFunc::v_Call(float* inputs, float* results) const {
@@ -487,8 +487,8 @@ bool CPDF_SampledFunc::v_Init(CPDF_Object* pObj) {
return false;
m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample);
- m_pSampleStream = pdfium::MakeUnique<CPDF_StreamAcc>();
- m_pSampleStream->LoadAllData(pStream, false);
+ m_pSampleStream = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
+ m_pSampleStream->LoadAllData(false);
FX_SAFE_UINT32 nTotalSampleBits = 1;
m_EncodeInfo.resize(m_nInputs);
for (uint32_t i = 0; i < m_nInputs; i++) {
diff --git a/core/fpdfapi/page/pageint.h b/core/fpdfapi/page/pageint.h
index a7a00f02ee..05865ca58e 100644
--- a/core/fpdfapi/page/pageint.h
+++ b/core/fpdfapi/page/pageint.h
@@ -12,14 +12,13 @@
#include "core/fpdfapi/page/cpdf_colorspace.h"
#include "core/fpdfapi/page/cpdf_countedobject.h"
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/cfx_retain_ptr.h"
class CPDF_ExpIntFunc;
class CPDF_Pattern;
class CPDF_SampledFunc;
class CPDF_StitchFunc;
-class CPDF_Stream;
-class CPDF_StreamAcc;
class CPDF_Function {
public:
@@ -102,8 +101,8 @@ class CPDF_SampledFunc : public CPDF_Function {
return m_EncodeInfo;
}
uint32_t GetBitsPerSample() const { return m_nBitsPerSample; }
- const CPDF_StreamAcc* GetSampleStream() const {
- return m_pSampleStream.get();
+ CFX_RetainPtr<CPDF_StreamAcc> GetSampleStream() const {
+ return m_pSampleStream;
}
private:
@@ -111,7 +110,7 @@ class CPDF_SampledFunc : public CPDF_Function {
std::vector<SampleDecodeInfo> m_DecodeInfo;
uint32_t m_nBitsPerSample;
uint32_t m_SampleMax;
- std::unique_ptr<CPDF_StreamAcc> m_pSampleStream;
+ CFX_RetainPtr<CPDF_StreamAcc> m_pSampleStream;
};
class CPDF_StitchFunc : public CPDF_Function {