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 | |
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>
35 files changed, 93 insertions, 146 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)); diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp index 4cbae5cc75..84ab6a14c8 100644 --- a/core/fxcodec/codec/fx_codec_progress.cpp +++ b/core/fxcodec/codec/fx_codec_progress.cpp @@ -1068,10 +1068,6 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, } case FXCODEC_IMAGE_JPG: { CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); - if (!pJpegModule) { - m_status = FXCODEC_STATUS_ERR_MEMORY; - return false; - } m_pJpegContext = pJpegModule->Start(); if (!m_pJpegContext) { m_status = FXCODEC_STATUS_ERR_MEMORY; @@ -1873,9 +1869,9 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode( } switch (m_imagType) { case FXCODEC_IMAGE_JPG: { - CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); int down_scale = 1; GetDownScale(down_scale); + CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule(); bool bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale); while (!bStart) { FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR; diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index 08a6e09324..6174f6e18f 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -11,7 +11,6 @@ #include "core/fxcodec/fx_codec.h" #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/dib/cfx_imagerenderer.h" diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index 5151b02d8b..ad09f91f61 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -11,7 +11,6 @@ #endif #include "core/fxcrt/fx_memory.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" diff --git a/core/fxge/cfx_gemodule.h b/core/fxge/cfx_gemodule.h index 429f7d9a39..2816ca9b22 100644 --- a/core/fxge/cfx_gemodule.h +++ b/core/fxge/cfx_gemodule.h @@ -12,7 +12,6 @@ #include "core/fxge/cfx_fontmgr.h" #include "core/fxge/fx_font.h" -class CCodec_ModuleMgr; class CFX_FontCache; class CFX_FontMgr; @@ -25,7 +24,6 @@ class CFX_GEModule { CFX_FontCache* GetFontCache(); CFX_FontMgr* GetFontMgr() { return m_pFontMgr.get(); } - CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule.get(); } void* GetPlatformData() { return m_pPlatformData; } private: @@ -37,7 +35,6 @@ class CFX_GEModule { std::unique_ptr<CFX_FontCache> m_pFontCache; std::unique_ptr<CFX_FontMgr> m_pFontMgr; - std::unique_ptr<CCodec_ModuleMgr> m_pCodecModule; void* m_pPlatformData; const char** m_pUserFontPaths; }; diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h index 6aa4528f05..4d8b407b35 100644 --- a/core/fxge/cfx_renderdevice.h +++ b/core/fxge/cfx_renderdevice.h @@ -9,7 +9,6 @@ #include <memory> -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/fx_dib.h" #include "core/fxge/fx_font.h" diff --git a/core/fxge/dib/cfx_bitmapcomposer.cpp b/core/fxge/dib/cfx_bitmapcomposer.cpp index 604c0c2ce0..3f75fae1b6 100644 --- a/core/fxge/dib/cfx_bitmapcomposer.cpp +++ b/core/fxge/dib/cfx_bitmapcomposer.cpp @@ -7,7 +7,6 @@ #include "core/fxge/dib/cfx_bitmapcomposer.h" #include "core/fxcodec/fx_codec.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/ge/cfx_cliprgn.h" diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 4cba073321..48cbc3291c 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp @@ -11,7 +11,6 @@ #include <utility> #include "core/fxcodec/fx_codec.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/dib/cfx_scanlinecompositor.h" #include "core/fxge/ge/cfx_cliprgn.h" #include "third_party/base/ptr_util.h" diff --git a/core/fxge/dib/cfx_scanlinecompositor.cpp b/core/fxge/dib/cfx_scanlinecompositor.cpp index 8a0185ffe1..5bd654b3e6 100644 --- a/core/fxge/dib/cfx_scanlinecompositor.cpp +++ b/core/fxge/dib/cfx_scanlinecompositor.cpp @@ -9,7 +9,6 @@ #include <algorithm> #include "core/fxcodec/fx_codec.h" -#include "core/fxge/cfx_gemodule.h" #define FX_CCOLOR(val) (255 - (val)) #define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest) * (src) / 255) diff --git a/core/fxge/ge/cfx_gemodule.cpp b/core/fxge/ge/cfx_gemodule.cpp index d7ae098f31..4516d61e27 100644 --- a/core/fxge/ge/cfx_gemodule.cpp +++ b/core/fxge/ge/cfx_gemodule.cpp @@ -6,7 +6,6 @@ #include "core/fxge/cfx_gemodule.h" -#include "core/fxcodec/fx_codec.h" #include "core/fxge/cfx_fontcache.h" #include "core/fxge/cfx_fontmgr.h" #include "core/fxge/ge/cfx_folderfontinfo.h" @@ -21,7 +20,6 @@ CFX_GEModule* g_pGEModule = nullptr; CFX_GEModule::CFX_GEModule() : m_pFontMgr(pdfium::MakeUnique<CFX_FontMgr>()), - m_pCodecModule(pdfium::MakeUnique<CCodec_ModuleMgr>()), m_pPlatformData(nullptr), m_pUserFontPaths(nullptr) {} diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index d2924bb13c..3949837982 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -14,6 +14,7 @@ #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/cfx_defaultrenderdevice.h" #include "core/fxge/cfx_facecache.h" +#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/dib/cfx_imagerenderer.h" diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index ca5a98ca32..dd48045ce1 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -15,7 +15,6 @@ #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_memory.h" #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index ba027ba6dc..400babd16b 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -8,10 +8,12 @@ #include <memory> +#include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/cfx_maybe_owned.h" #include "core/fxge/cfx_facecache.h" #include "core/fxge/cfx_fontcache.h" +#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/dib/cfx_dibextractor.h" @@ -48,17 +50,17 @@ void PSCompressData(int PSLevel, if (src_size < 1024) return; - CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); + CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); uint8_t* dest_buf = nullptr; uint32_t dest_size = src_size; if (PSLevel >= 3) { - if (pEncoders && pEncoders->GetFlateModule()->Encode( - src_buf, src_size, &dest_buf, &dest_size)) { + if (pEncoders->GetFlateModule()->Encode(src_buf, src_size, &dest_buf, + &dest_size)) { *filter = "/FlateDecode filter "; } } else { - if (pEncoders && pEncoders->GetBasicModule()->RunLengthEncode( - src_buf, src_size, &dest_buf, &dest_size)) { + if (pEncoders->GetBasicModule()->RunLengthEncode(src_buf, src_size, + &dest_buf, &dest_size)) { *filter = "/RunLengthDecode filter "; } } @@ -681,9 +683,8 @@ bool CFX_PSRenderer::DrawText(int nChars, void CFX_PSRenderer::WritePSBinary(const uint8_t* data, int len) { uint8_t* dest_buf; uint32_t dest_size; - CCodec_ModuleMgr* pEncoders = CFX_GEModule::Get()->GetCodecModule(); - if (pEncoders && - pEncoders->GetBasicModule()->A85Encode(data, len, &dest_buf, + CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); + if (pEncoders->GetBasicModule()->A85Encode(data, len, &dest_buf, &dest_size)) { m_pStream->WriteBlock(dest_buf, dest_size); FX_Free(dest_buf); diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 2747339b1d..b495251dee 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -15,6 +15,7 @@ #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_system.h" +#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_windowsrenderdevice.h" #include "core/fxge/dib/cfx_dibextractor.h" #include "core/fxge/dib/cfx_imagerenderer.h" diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp index c63d6c2e77..449121d351 100644 --- a/fpdfsdk/fpdfdoc_unittest.cpp +++ b/fpdfsdk/fpdfdoc_unittest.cpp @@ -58,10 +58,7 @@ class PDFDocTest : public testing::Test { }; void SetUp() override { - // We don't need page module or render module, but - // initialize them to keep the code sane. - CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); - module_mgr->InitPageModule(); + CPDF_ModuleMgr::Get()->Init(); m_pDoc = pdfium::MakeUnique<CPDF_TestPdfDocument>(); m_pIndirectObjs = m_pDoc->GetHolder(); diff --git a/fpdfsdk/fpdfeditimg_unittest.cpp b/fpdfsdk/fpdfeditimg_unittest.cpp index da6930caed..0ff3db8e2d 100644 --- a/fpdfsdk/fpdfeditimg_unittest.cpp +++ b/fpdfsdk/fpdfeditimg_unittest.cpp @@ -8,10 +8,7 @@ #include "testing/gtest/include/gtest/gtest.h" class PDFEditTest : public testing::Test { - 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/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 2bf6dfca74..76913cee4f 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -360,10 +360,7 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr); CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); - pModuleMgr->SetCodecModule(pModule->GetCodecModule()); - pModuleMgr->InitPageModule(); - pModuleMgr->LoadEmbeddedMaps(); - pModuleMgr->LoadCodecModules(); + pModuleMgr->Init(); #ifdef PDF_ENABLE_XFA FXJSE_Initialize(); diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp index 66d62ca885..a7539e4897 100644 --- a/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/fxbarcode/oned/BC_OneDimWriter.cpp @@ -27,7 +27,6 @@ #include <vector> #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp index 054d7a1337..bae43b464e 100644 --- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp @@ -28,7 +28,6 @@ #include <vector> #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "fxbarcode/BC_Writer.h" #include "fxbarcode/oned/BC_OneDimWriter.h" diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp index 3eb1ff8587..49d77b72c4 100644 --- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp @@ -28,7 +28,6 @@ #include <vector> #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "fxbarcode/BC_Writer.h" #include "fxbarcode/common/BC_CommonBitMatrix.h" #include "fxbarcode/oned/BC_OneDimWriter.h" diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp index aaf0c523a7..614268e742 100644 --- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp +++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp @@ -25,7 +25,6 @@ #include <vector> #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "fxbarcode/BC_Writer.h" #include "fxbarcode/oned/BC_OneDimWriter.h" #include "fxbarcode/oned/BC_OnedEAN13Writer.h" @@ -1,7 +1,5 @@ include_rules = [ - '+core/fpdfapi/parser', - '+core/fxcrt', - '+core/fxge', + '+core', '+fxbarcode', '+third_party/bigint' ] diff --git a/xfa/fde/cfde_renderdevice.cpp b/xfa/fde/cfde_renderdevice.cpp index 9236dc7800..ec1fc2fed1 100644 --- a/xfa/fde/cfde_renderdevice.cpp +++ b/xfa/fde/cfde_renderdevice.cpp @@ -10,7 +10,6 @@ #include <memory> #include <utility> -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/cfx_substfont.h" diff --git a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp index c8ffc4eb33..cef215fe2a 100644 --- a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp +++ b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp @@ -8,6 +8,7 @@ #include <memory> +#include "core/fxge/cfx_gemodule.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" #include "third_party/base/ptr_util.h" diff --git a/xfa/fxfa/DEPS b/xfa/fxfa/DEPS index 97e9f52afa..886ee8e2b7 100644 --- a/xfa/fxfa/DEPS +++ b/xfa/fxfa/DEPS @@ -1,8 +1,3 @@ include_rules = [ - '+core/fdrm/crypto', - '+core/fpdfapi/font', - '+core/fpdfapi/page', - '+core/fpdfdoc', - '+core/fxcodec', '+fxjs', ] diff --git a/xfa/fxfa/app/DEPS b/xfa/fxfa/app/DEPS deleted file mode 100644 index f722184c91..0000000000 --- a/xfa/fxfa/app/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - '+core/fdrm/crypto', -] diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 7bbb8c8265..2ea30b59e5 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -10,12 +10,12 @@ #include <memory> #include <vector> +#include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/page/cpdf_pageobjectholder.h" #include "core/fxcodec/codec/ccodec_progressivedecoder.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/cfx_maybe_owned.h" #include "core/fxcrt/cfx_memorystream.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/dib/cfx_imagerenderer.h" @@ -1120,18 +1120,11 @@ CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer( FXCODEC_IMAGE_TYPE type, int32_t& iImageXDpi, int32_t& iImageYDpi) { - CFX_GEModule* pGeModule = CFX_GEModule::Get(); - if (!pGeModule) - return nullptr; - - CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); - if (!pCodecMgr) - return nullptr; - - CFX_DIBAttribute dibAttr; - CFX_RetainPtr<CFX_DIBitmap> pBitmap; + CCodec_ModuleMgr* pCodecMgr = CPDF_ModuleMgr::Get()->GetCodecModule(); std::unique_ptr<CCodec_ProgressiveDecoder> pProgressiveDecoder = pCodecMgr->CreateProgressiveDecoder(); + + CFX_DIBAttribute dibAttr; pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false); switch (dibAttr.m_wDPIUnit) { case FXCODEC_RESUNIT_CENTIMETER: @@ -1147,24 +1140,26 @@ CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer( } iImageXDpi = dibAttr.m_nXDPI > 1 ? dibAttr.m_nXDPI : (96); iImageYDpi = dibAttr.m_nYDPI > 1 ? dibAttr.m_nYDPI : (96); - if (pProgressiveDecoder->GetWidth() > 0 && - pProgressiveDecoder->GetHeight() > 0) { - type = pProgressiveDecoder->GetType(); - int32_t iComponents = pProgressiveDecoder->GetNumComponents(); - int32_t iBpc = pProgressiveDecoder->GetBPC(); - FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc); - pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - pBitmap->Create(pProgressiveDecoder->GetWidth(), - pProgressiveDecoder->GetHeight(), dibFormat); - pBitmap->Clear(0xffffffff); - int32_t nFrames; - if ((pProgressiveDecoder->GetFrames(nFrames) == - FXCODEC_STATUS_DECODE_READY) && - (nFrames > 0)) { - pProgressiveDecoder->StartDecode(pBitmap, 0, 0, pBitmap->GetWidth(), - pBitmap->GetHeight()); - pProgressiveDecoder->ContinueDecode(); - } + if (pProgressiveDecoder->GetWidth() <= 0 || + pProgressiveDecoder->GetHeight() <= 0) { + return nullptr; + } + + type = pProgressiveDecoder->GetType(); + int32_t iComponents = pProgressiveDecoder->GetNumComponents(); + int32_t iBpc = pProgressiveDecoder->GetBPC(); + FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc); + CFX_RetainPtr<CFX_DIBitmap> pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + pBitmap->Create(pProgressiveDecoder->GetWidth(), + pProgressiveDecoder->GetHeight(), dibFormat); + pBitmap->Clear(0xffffffff); + int32_t nFrames; + if ((pProgressiveDecoder->GetFrames(nFrames) == + FXCODEC_STATUS_DECODE_READY) && + (nFrames > 0)) { + pProgressiveDecoder->StartDecode(pBitmap, 0, 0, pBitmap->GetWidth(), + pBitmap->GetHeight()); + pProgressiveDecoder->ContinueDecode(); } return pBitmap; } diff --git a/xfa/fxfa/parser/cxfa_localemgr.cpp b/xfa/fxfa/parser/cxfa_localemgr.cpp index 0a691a6ceb..fbb12e2b48 100644 --- a/xfa/fxfa/parser/cxfa_localemgr.cpp +++ b/xfa/fxfa/parser/cxfa_localemgr.cpp @@ -11,9 +11,9 @@ #include <memory> #include <utility> +#include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/xml/cxml_element.h" -#include "core/fxge/cfx_gemodule.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodelocale.h" @@ -1056,23 +1056,17 @@ static std::unique_ptr<IFX_Locale> XFA_GetLocaleFromBuffer(const uint8_t* pBuf, int nBufLen) { if (!pBuf || nBufLen <= 0) return nullptr; - CFX_GEModule* pGeModule = CFX_GEModule::Get(); - if (!pGeModule) - return nullptr; - - CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); - if (!pCodecMgr) - return nullptr; - std::unique_ptr<CXML_Element> pLocale; uint8_t* pOut = nullptr; uint32_t dwSize; + CCodec_ModuleMgr* pCodecMgr = CPDF_ModuleMgr::Get()->GetCodecModule(); pCodecMgr->GetFlateModule()->FlateOrLZWDecode(false, pBuf, nBufLen, true, 0, 0, 0, 0, 0, pOut, dwSize); - if (pOut) { - pLocale = CXML_Element::Parse(pOut, dwSize); - FX_Free(pOut); - } + if (!pOut) + return nullptr; + + std::unique_ptr<CXML_Element> pLocale = CXML_Element::Parse(pOut, dwSize); + FX_Free(pOut); return pLocale ? pdfium::MakeUnique<CXFA_XMLLocale>(std::move(pLocale)) : nullptr; } diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp index 79e4b7a6cc..a67932f052 100644 --- a/xfa/fxgraphics/cfx_graphics.cpp +++ b/xfa/fxgraphics/cfx_graphics.cpp @@ -9,7 +9,6 @@ #include <memory> #include "core/fxge/cfx_defaultrenderdevice.h" -#include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/cfx_unicodeencoding.h" #include "third_party/base/ptr_util.h" |