From 5ce09684216ed6b74836de9bd056b8f15bd66a4e Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 25 May 2016 16:16:32 -0700 Subject: Remove CFX_PrivateData from CPDF_Document Replace it with two generic slots for Links and Codec usage. Since the codec is at a lower layer than the document, we don't provide separate get/set methods, since having a document upon which to call these would be a layering violation. Do the same for the Links for simplicity. Review-Url: https://codereview.chromium.org/2005193003 --- core/fpdfapi/fpdf_parser/include/cpdf_document.h | 9 ++++-- core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 6 ++-- core/fxcodec/codec/ccodec_jbig2module.h | 6 ++-- core/fxcodec/codec/fx_codec_jbig.cpp | 37 ++++++++++------------ fpdfsdk/fpdfdoc.cpp | 17 +++------- 5 files changed, 34 insertions(+), 41 deletions(-) diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_document.h b/core/fpdfapi/fpdf_parser/include/cpdf_document.h index f7a7f9f183..e1d1c77a12 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_document.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_document.h @@ -11,6 +11,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" +#include "core/fpdfdoc/include/fpdf_doc.h" #include "core/fxcrt/include/fx_basic.h" class CFX_Font; @@ -35,7 +36,7 @@ class CPDF_StreamAcc; #define FPDFPERM_PRINT_HIGH 0x0800 #define FPDF_PAGE_MAX_NUM 0xFFFFF -class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjectHolder { +class CPDF_Document : public CPDF_IndirectObjectHolder { public: explicit CPDF_Document(CPDF_Parser* pParser); ~CPDF_Document(); @@ -57,6 +58,9 @@ class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjectHolder { void ClearPageData(); void RemoveColorSpaceFromPageData(CPDF_Object* pObject); + std::unique_ptr* CodecContext() { return &m_pCodecContext; } + std::unique_ptr* LinksContext() { return &m_pLinksContext; } + CPDF_DocRenderData* GetRenderData() const { return m_pDocRender.get(); } void ClearRenderData(); void ClearRenderFont(); @@ -107,7 +111,6 @@ class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjectHolder { friend class CPDF_OCContext; // Retrieve page count information by getting count value from the tree nodes - // or walking through the tree nodes to calculate it. int RetrievePageCount() const; CPDF_Dictionary* FindPDFPage(CPDF_Dictionary* pPages, int iPage, @@ -131,6 +134,8 @@ class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjectHolder { // TODO(thestig): Figure out why this cannot be a std::unique_ptr. CPDF_DocPageData* m_pDocPage; std::unique_ptr m_pDocRender; + std::unique_ptr m_pCodecContext; + std::unique_ptr m_pLinksContext; }; #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DOCUMENT_H_ diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 19aeb71e9a..75f6a231a4 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -355,9 +355,9 @@ int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { } } ret = pJbig2Module->StartDecode( - m_pJbig2Context, m_pDocument, m_Width, m_Height, m_pStreamAcc.get(), - m_pGlobalStream.get(), m_pCachedBitmap->GetBuffer(), - m_pCachedBitmap->GetPitch(), pPause); + m_pJbig2Context, m_pDocument->CodecContext(), m_Width, m_Height, + m_pStreamAcc.get(), m_pGlobalStream.get(), + m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause); if (ret < 0) { m_pCachedBitmap.reset(); m_pGlobalStream.reset(); diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h index 20578c8cdb..a967e0b997 100644 --- a/core/fxcodec/codec/ccodec_jbig2module.h +++ b/core/fxcodec/codec/ccodec_jbig2module.h @@ -7,7 +7,9 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_JBIG2MODULE_H_ -#include "core/fxcrt/include/fx_system.h" +#include + +#include "core/fxcrt/include/fx_basic.h" class CPDF_StreamAcc; class IFX_Pause; @@ -19,7 +21,7 @@ class CCodec_Jbig2Module { void* CreateJbig2Context(); FXCODEC_STATUS StartDecode(void* pJbig2Context, - CFX_PrivateData* pPrivateData, + std::unique_ptr* pContextHolder, uint32_t width, uint32_t height, CPDF_StreamAcc* src_stream, diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp index 99cf2ec82f..2b0be1070e 100644 --- a/core/fxcodec/codec/fx_codec_jbig.cpp +++ b/core/fxcodec/codec/fx_codec_jbig.cpp @@ -46,17 +46,11 @@ class JBig2DocumentContext : public CFX_Deletable { std::list m_SymbolDictCache; }; -JBig2DocumentContext* GetJBig2DocumentContext(CCodec_Jbig2Module* pModule, - CFX_PrivateData* pPrivateData) { - void* pModulePrivateData = pPrivateData->GetPrivateData(pModule); - if (pModulePrivateData) { - CFX_Deletable* pDeletable = - reinterpret_cast(pModulePrivateData); - return static_cast(pDeletable); - } - JBig2DocumentContext* pJBig2DocumentContext = new JBig2DocumentContext(); - pPrivateData->SetPrivateObj(pModule, pJBig2DocumentContext); - return pJBig2DocumentContext; +JBig2DocumentContext* GetJBig2DocumentContext( + std::unique_ptr* pContextHolder) { + if (!pContextHolder->get()) + pContextHolder->reset(new JBig2DocumentContext()); + return static_cast(pContextHolder->get()); } CCodec_Jbig2Context::CCodec_Jbig2Context() { @@ -76,20 +70,21 @@ void CCodec_Jbig2Module::DestroyJbig2Context(void* pJbig2Content) { } pJbig2Content = NULL; } -FXCODEC_STATUS CCodec_Jbig2Module::StartDecode(void* pJbig2Context, - CFX_PrivateData* pPrivateData, - uint32_t width, - uint32_t height, - CPDF_StreamAcc* src_stream, - CPDF_StreamAcc* global_stream, - uint8_t* dest_buf, - uint32_t dest_pitch, - IFX_Pause* pPause) { +FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( + void* pJbig2Context, + std::unique_ptr* pContextHolder, + uint32_t width, + uint32_t height, + CPDF_StreamAcc* src_stream, + CPDF_StreamAcc* global_stream, + uint8_t* dest_buf, + uint32_t dest_pitch, + IFX_Pause* pPause) { if (!pJbig2Context) { return FXCODEC_STATUS_ERR_PARAMS; } JBig2DocumentContext* pJBig2DocumentContext = - GetJBig2DocumentContext(this, pPrivateData); + GetJBig2DocumentContext(pContextHolder); CCodec_Jbig2Context* m_pJbig2Context = (CCodec_Jbig2Context*)pJbig2Context; m_pJbig2Context->m_width = width; m_pJbig2Context->m_height = height; diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp index 7473cb0671..0f69340821 100644 --- a/fpdfsdk/fpdfdoc.cpp +++ b/fpdfsdk/fpdfdoc.cpp @@ -16,8 +16,6 @@ namespace { -int THISMODULE = 0; - CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark bookmark, const CFX_WideString& title, @@ -45,22 +43,15 @@ CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, return CPDF_Bookmark(); } -void ReleaseLinkList(void* data) { - delete (CPDF_LinkList*)data; -} - CPDF_LinkList* GetLinkList(CPDF_Page* page) { if (!page) return nullptr; - // Link list is stored with the document CPDF_Document* pDoc = page->m_pDocument; - CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); - if (!pLinkList) { - pLinkList = new CPDF_LinkList; - pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); - } - return pLinkList; + std::unique_ptr* pHolder = pDoc->LinksContext(); + if (!pHolder->get()) + pHolder->reset(new CPDF_LinkList); + return pHolder->get(); } } // namespace -- cgit v1.2.3