diff options
author | Lei Zhang <thestig@chromium.org> | 2017-05-18 15:51:20 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-19 01:39:40 +0000 |
commit | 76020fc9751e55661d1c01b6cd92dfcb1fd56e6a (patch) | |
tree | 59d5251b23f5acb78891bf2911a79f2c70812c1c /core/fpdfapi | |
parent | 22644731e0e46eae1f50927376e557c7d64db1d5 (diff) | |
download | pdfium-76020fc9751e55661d1c01b6cd92dfcb1fd56e6a.tar.xz |
Move CCodec_ModuleMgr ownership to CPDF_ModuleMgr.
More straight forward than CFX_GEModule owning in and CPDF_ModuleMgr
holding a pointer to it.
Remove assumptions that the codec modules may return nullptr, and do
IWYU.
Change-Id: Iba7fc3c7ec223fd6d29a1ab74ed13d35689bc5d5
Reviewed-on: https://pdfium-review.googlesource.com/5654
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/cpdf_modulemgr.cpp | 25 | ||||
-rw-r--r-- | core/fpdfapi/cpdf_modulemgr.h | 17 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/page/fpdf_page_colors.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_document_unittest.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/parser/fpdf_parser_decode.cpp | 13 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_dibsource.cpp | 21 |
7 files changed, 45 insertions, 50 deletions
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp index 8e39bdd587..678997a8c9 100644 --- a/core/fpdfapi/cpdf_modulemgr.cpp +++ b/core/fpdfapi/cpdf_modulemgr.cpp @@ -45,10 +45,17 @@ void CPDF_ModuleMgr::Destroy() { g_pDefaultMgr = nullptr; } -CPDF_ModuleMgr::CPDF_ModuleMgr() : m_pCodecModule(nullptr) {} +CPDF_ModuleMgr::CPDF_ModuleMgr() {} CPDF_ModuleMgr::~CPDF_ModuleMgr() {} +void CPDF_ModuleMgr::Init() { + InitCodecModule(); + InitPageModule(); + LoadEmbeddedMaps(); + LoadCodecModules(); +} + void CPDF_ModuleMgr::LoadEmbeddedMaps() { LoadEmbeddedGB1CMaps(); LoadEmbeddedJapan1CMaps(); @@ -74,30 +81,34 @@ void CPDF_ModuleMgr::LoadCodecModules() { #endif } +void CPDF_ModuleMgr::InitCodecModule() { + m_pCodecModule = pdfium::MakeUnique<CCodec_ModuleMgr>(); +} + void CPDF_ModuleMgr::InitPageModule() { m_pPageModule = pdfium::MakeUnique<CPDF_PageModule>(); } CCodec_FaxModule* CPDF_ModuleMgr::GetFaxModule() { - return m_pCodecModule ? m_pCodecModule->GetFaxModule() : nullptr; + return m_pCodecModule->GetFaxModule(); } CCodec_JpegModule* CPDF_ModuleMgr::GetJpegModule() { - return m_pCodecModule ? m_pCodecModule->GetJpegModule() : nullptr; + return m_pCodecModule->GetJpegModule(); } CCodec_JpxModule* CPDF_ModuleMgr::GetJpxModule() { - return m_pCodecModule ? m_pCodecModule->GetJpxModule() : nullptr; + return m_pCodecModule->GetJpxModule(); } CCodec_Jbig2Module* CPDF_ModuleMgr::GetJbig2Module() { - return m_pCodecModule ? m_pCodecModule->GetJbig2Module() : nullptr; + return m_pCodecModule->GetJbig2Module(); } CCodec_IccModule* CPDF_ModuleMgr::GetIccModule() { - return m_pCodecModule ? m_pCodecModule->GetIccModule() : nullptr; + return m_pCodecModule->GetIccModule(); } CCodec_FlateModule* CPDF_ModuleMgr::GetFlateModule() { - return m_pCodecModule ? m_pCodecModule->GetFlateModule() : nullptr; + return m_pCodecModule->GetFlateModule(); } diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h index 898b6ea0bc..82566ba282 100644 --- a/core/fpdfapi/cpdf_modulemgr.h +++ b/core/fpdfapi/cpdf_modulemgr.h @@ -38,11 +38,7 @@ class CPDF_ModuleMgr { static void Destroy(); static const int kFileBufSize = 512; - void SetCodecModule(CCodec_ModuleMgr* pModule) { m_pCodecModule = pModule; } - CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; } - - void InitPageModule(); - CPDF_PageModule* GetPageModule() const { return m_pPageModule.get(); } + void Init(); void SetUnsupportInfoAdapter( std::unique_ptr<CFSDK_UnsupportInfo_Adapter> pAdapter) { @@ -52,8 +48,8 @@ class CPDF_ModuleMgr { return m_pUnsupportInfoAdapter.get(); } - void LoadEmbeddedMaps(); - void LoadCodecModules(); + CCodec_ModuleMgr* GetCodecModule() const { return m_pCodecModule.get(); } + CPDF_PageModule* GetPageModule() const { return m_pPageModule.get(); } CCodec_FaxModule* GetFaxModule(); CCodec_JpegModule* GetJpegModule(); @@ -66,12 +62,17 @@ class CPDF_ModuleMgr { CPDF_ModuleMgr(); ~CPDF_ModuleMgr(); + void InitCodecModule(); + void InitPageModule(); + void LoadEmbeddedMaps(); + void LoadCodecModules(); + void LoadEmbeddedGB1CMaps(); void LoadEmbeddedCNS1CMaps(); void LoadEmbeddedJapan1CMaps(); void LoadEmbeddedKorea1CMaps(); - CCodec_ModuleMgr* m_pCodecModule; + std::unique_ptr<CCodec_ModuleMgr> m_pCodecModule; std::unique_ptr<CPDF_PageModule> m_pPageModule; std::unique_ptr<CFSDK_UnsupportInfo_Adapter> m_pUnsupportInfoAdapter; }; diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index b08dd8a852..1f2d216ed5 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -19,9 +19,7 @@ class CPDF_PageContentGeneratorTest : public testing::Test { protected: - void SetUp() override { - CPDF_ModuleMgr::Get()->InitPageModule(); - } + void SetUp() override { CPDF_ModuleMgr::Get()->Init(); } void TearDown() override { CPDF_ModuleMgr::Destroy(); diff --git a/core/fpdfapi/page/fpdf_page_colors.cpp b/core/fpdfapi/page/fpdf_page_colors.cpp index e30c780439..3ba833f1ef 100644 --- a/core/fpdfapi/page/fpdf_page_colors.cpp +++ b/core/fpdfapi/page/fpdf_page_colors.cpp @@ -226,13 +226,11 @@ CPDF_IccProfile::CPDF_IccProfile(CPDF_Stream* pStream, m_nSrcComponents = 3; return; } + uint32_t nSrcComps = 0; auto* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule(); - if (pIccModule) { - uint32_t nSrcComps = 0; - m_pTransform = pIccModule->CreateTransform_sRGB(pData, dwSize, nSrcComps); - if (m_pTransform) - m_nSrcComponents = nSrcComps; - } + m_pTransform = pIccModule->CreateTransform_sRGB(pData, dwSize, nSrcComps); + if (m_pTransform) + m_nSrcComponents = nSrcComps; } CPDF_IccProfile::~CPDF_IccProfile() { diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index f052af3aec..2715508015 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -153,10 +153,7 @@ class CPDF_TestDocPagesWithoutKids : public CPDF_Document { class cpdf_document_test : public testing::Test { public: - void SetUp() override { - CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); - module_mgr->InitPageModule(); - } + void SetUp() override { CPDF_ModuleMgr::Get()->Init(); } void TearDown() override { CPDF_ModuleMgr::Destroy(); } }; diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 64831e91e5..561b6627bc 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -549,8 +549,7 @@ bool FlateEncode(const uint8_t* src_buf, uint8_t** dest_buf, uint32_t* dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); - return pEncoders && - pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, + return pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); } @@ -559,8 +558,7 @@ bool PngEncode(const uint8_t* src_buf, uint8_t** dest_buf, uint32_t* dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); - return pEncoders && - pEncoders->GetFlateModule()->PngEncode(src_buf, src_size, dest_buf, + return pEncoders->GetFlateModule()->PngEncode(src_buf, src_size, dest_buf, dest_size); } @@ -569,9 +567,6 @@ uint32_t FlateDecode(const uint8_t* src_buf, uint8_t*& dest_buf, uint32_t& dest_size) { CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); - if (pEncoders) { - return pEncoders->GetFlateModule()->FlateOrLZWDecode( - false, src_buf, src_size, false, 0, 0, 0, 0, 0, dest_buf, dest_size); - } - return 0; + return pEncoders->GetFlateModule()->FlateOrLZWDecode( + false, src_buf, src_size, false, 0, 0, 0, 0, 0, dest_buf, dest_size); } diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index f1c58038e8..3bb91ecf1b 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -531,11 +531,9 @@ int CPDF_DIBSource::CreateDecoder() { m_pDecoder = FPDFAPI_CreateFlateDecoder( src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc, pParams); } else if (decoder == "RunLengthDecode") { - m_pDecoder = CPDF_ModuleMgr::Get() - ->GetCodecModule() - ->GetBasicModule() - ->CreateRunLengthDecoder(src_data, src_size, m_Width, - m_Height, m_nComponents, m_bpc); + CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); + m_pDecoder = pEncoders->GetBasicModule()->CreateRunLengthDecoder( + src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc); } else if (decoder == "DCTDecode") { if (!CreateDCTDecoder(src_data, src_size, pParams)) return 0; @@ -559,7 +557,8 @@ int CPDF_DIBSource::CreateDecoder() { bool CPDF_DIBSource::CreateDCTDecoder(const uint8_t* src_data, uint32_t src_size, const CPDF_Dictionary* pParams) { - m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( + CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); + m_pDecoder = pJpegModule->CreateDecoder( src_data, src_size, m_Width, m_Height, m_nComponents, !pParams || pParams->GetIntegerFor("ColorTransform", 1)); if (m_pDecoder) @@ -568,7 +567,6 @@ bool CPDF_DIBSource::CreateDCTDecoder(const uint8_t* src_data, bool bTransform = false; int comps; int bpc; - CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); if (!pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps, &bpc, &bTransform)) { return false; @@ -576,7 +574,7 @@ bool CPDF_DIBSource::CreateDCTDecoder(const uint8_t* src_data, if (m_nComponents == static_cast<uint32_t>(comps)) { m_bpc = bpc; - m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( + m_pDecoder = pJpegModule->CreateDecoder( src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); return true; } @@ -624,16 +622,13 @@ bool CPDF_DIBSource::CreateDCTDecoder(const uint8_t* src_data, return false; m_bpc = bpc; - m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( - src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); + m_pDecoder = pJpegModule->CreateDecoder(src_data, src_size, m_Width, m_Height, + m_nComponents, bTransform); return true; } void CPDF_DIBSource::LoadJpxBitmap() { CCodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); - if (!pJpxModule) - return; - auto context = pdfium::MakeUnique<JpxBitMapContext>(pJpxModule); context->set_decoder(pJpxModule->CreateDecoder( m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); |