diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_document.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/include/cpdf_document.h | 7 | ||||
-rw-r--r-- | core/fxcodec/codec/ccodec_jbig2module.h | 20 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jbig.cpp | 32 | ||||
-rw-r--r-- | core/fxcodec/include/JBig2_DocumentContext.h | 34 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.cpp | 6 | ||||
-rw-r--r-- | core/fxcodec/jbig2/JBig2_Context.h | 4 | ||||
-rw-r--r-- | core/fxcrt/include/fx_memory.h | 5 |
8 files changed, 66 insertions, 43 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index 485d538832..605fb6e878 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -18,6 +18,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" #include "core/fpdfapi/fpdf_render/render_int.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" +#include "core/fxcodec/include/JBig2_DocumentContext.h" #include "core/fxge/include/fx_font.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_document.h b/core/fpdfapi/fpdf_parser/include/cpdf_document.h index 24d400fcd7..63141bf297 100644 --- a/core/fpdfapi/fpdf_parser/include/cpdf_document.h +++ b/core/fpdfapi/fpdf_parser/include/cpdf_document.h @@ -25,6 +25,7 @@ class CPDF_IccProfile; class CPDF_Image; class CPDF_Pattern; class CPDF_StreamAcc; +class JBig2_DocumentContext; #define FPDFPERM_PRINT 0x0004 #define FPDFPERM_MODIFY 0x0008 @@ -58,7 +59,9 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { void ClearPageData(); void RemoveColorSpaceFromPageData(CPDF_Object* pObject); - std::unique_ptr<CFX_Deletable>* CodecContext() { return &m_pCodecContext; } + std::unique_ptr<JBig2_DocumentContext>* CodecContext() { + return &m_pCodecContext; + } std::unique_ptr<CPDF_LinkList>* LinksContext() { return &m_pLinksContext; } CPDF_DocRenderData* GetRenderData() const { return m_pDocRender.get(); } @@ -134,7 +137,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder { // TODO(thestig): Figure out why this cannot be a std::unique_ptr. CPDF_DocPageData* m_pDocPage; std::unique_ptr<CPDF_DocRenderData> m_pDocRender; - std::unique_ptr<CFX_Deletable> m_pCodecContext; + std::unique_ptr<JBig2_DocumentContext> m_pCodecContext; std::unique_ptr<CPDF_LinkList> m_pLinksContext; }; diff --git a/core/fxcodec/codec/ccodec_jbig2module.h b/core/fxcodec/codec/ccodec_jbig2module.h index 5d77d53619..765a11fcb4 100644 --- a/core/fxcodec/codec/ccodec_jbig2module.h +++ b/core/fxcodec/codec/ccodec_jbig2module.h @@ -16,6 +16,7 @@ class CJBig2_Context; class CJBig2_Image; class CPDF_StreamAcc; class IFX_Pause; +class JBig2_DocumentContext; class CCodec_Jbig2Context { public: @@ -37,15 +38,16 @@ class CCodec_Jbig2Module { CCodec_Jbig2Module() {} ~CCodec_Jbig2Module(); - FXCODEC_STATUS StartDecode(CCodec_Jbig2Context* pJbig2Context, - std::unique_ptr<CFX_Deletable>* 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); + FXCODEC_STATUS StartDecode( + CCodec_Jbig2Context* pJbig2Context, + std::unique_ptr<JBig2_DocumentContext>* 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); FXCODEC_STATUS ContinueDecode(CCodec_Jbig2Context* pJbig2Context, IFX_Pause* pPause); }; diff --git a/core/fxcodec/codec/fx_codec_jbig.cpp b/core/fxcodec/codec/fx_codec_jbig.cpp index 8f2d07f490..adc57fd1ad 100644 --- a/core/fxcodec/codec/fx_codec_jbig.cpp +++ b/core/fxcodec/codec/fx_codec_jbig.cpp @@ -9,32 +9,20 @@ #include <list> #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fxcodec/include/JBig2_DocumentContext.h" #include "core/fxcodec/jbig2/JBig2_Context.h" #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/include/fx_memory.h" -// Holds per-document JBig2 related data. -class JBig2DocumentContext : public CFX_Deletable { - public: - std::list<CJBig2_CachePair>* GetSymbolDictCache() { - return &m_SymbolDictCache; - } - - ~JBig2DocumentContext() override { - for (auto it : m_SymbolDictCache) { - delete it.second; - } - } +JBig2_DocumentContext::JBig2_DocumentContext() {} - private: - std::list<CJBig2_CachePair> m_SymbolDictCache; -}; +JBig2_DocumentContext::~JBig2_DocumentContext() {} -JBig2DocumentContext* GetJBig2DocumentContext( - std::unique_ptr<CFX_Deletable>* pContextHolder) { - if (!pContextHolder->get()) - pContextHolder->reset(new JBig2DocumentContext()); - return static_cast<JBig2DocumentContext*>(pContextHolder->get()); +JBig2_DocumentContext* GetJBig2DocumentContext( + std::unique_ptr<JBig2_DocumentContext>* pContextHolder) { + if (!pContextHolder) + pContextHolder->reset(new JBig2_DocumentContext()); + return pContextHolder->get(); } CCodec_Jbig2Context::CCodec_Jbig2Context() @@ -52,7 +40,7 @@ CCodec_Jbig2Module::~CCodec_Jbig2Module() {} FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( CCodec_Jbig2Context* pJbig2Context, - std::unique_ptr<CFX_Deletable>* pContextHolder, + std::unique_ptr<JBig2_DocumentContext>* pContextHolder, uint32_t width, uint32_t height, CPDF_StreamAcc* src_stream, @@ -63,7 +51,7 @@ FXCODEC_STATUS CCodec_Jbig2Module::StartDecode( if (!pJbig2Context) return FXCODEC_STATUS_ERR_PARAMS; - JBig2DocumentContext* pJBig2DocumentContext = + JBig2_DocumentContext* pJBig2DocumentContext = GetJBig2DocumentContext(pContextHolder); pJbig2Context->m_width = width; pJbig2Context->m_height = height; diff --git a/core/fxcodec/include/JBig2_DocumentContext.h b/core/fxcodec/include/JBig2_DocumentContext.h new file mode 100644 index 0000000000..d49bdfab8e --- /dev/null +++ b/core/fxcodec/include/JBig2_DocumentContext.h @@ -0,0 +1,34 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXCODEC_INCLUDE_JBIG2_DOCUMENTCONTEXT_H_ +#define CORE_FXCODEC_INCLUDE_JBIG2_DOCUMENTCONTEXT_H_ + +#include <list> +#include <memory> +#include <utility> + +class CJBig2_SymbolDict; + +using CJBig2_CacheKey = std::pair<uint32_t, uint32_t>; +using CJBig2_CachePair = + std::pair<CJBig2_CacheKey, std::unique_ptr<CJBig2_SymbolDict>>; + +// Holds per-document JBig2 related data. +class JBig2_DocumentContext { + public: + JBig2_DocumentContext(); + ~JBig2_DocumentContext(); + + std::list<CJBig2_CachePair>* GetSymbolDictCache() { + return &m_SymbolDictCache; + } + + private: + std::list<CJBig2_CachePair> m_SymbolDictCache; +}; + +#endif // CORE_FXCODEC_INCLUDE_JBIG2_DOCUMENTCONTEXT_H_ diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 1e4c35a625..256ce3910a 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -591,7 +591,8 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, if (it->first == key) { std::unique_ptr<CJBig2_SymbolDict> copy(it->second->DeepCopy()); pSegment->m_Result.sd = copy.release(); - m_pSymbolDictCache->push_front(*it); + m_pSymbolDictCache->push_front( + CJBig2_CachePair(key, std::move(it->second))); m_pSymbolDictCache->erase(it); cache_hit = true; break; @@ -621,11 +622,10 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, pSegment->m_Result.sd->DeepCopy(); int size = pdfium::CollectionSize<int>(*m_pSymbolDictCache); while (size >= kSymbolDictCacheMaxSize) { - delete m_pSymbolDictCache->back().second; m_pSymbolDictCache->pop_back(); --size; } - m_pSymbolDictCache->push_front(CJBig2_CachePair(key, value.release())); + m_pSymbolDictCache->push_front(CJBig2_CachePair(key, std::move(value))); } } if (wFlags & 0x0200) { diff --git a/core/fxcodec/jbig2/JBig2_Context.h b/core/fxcodec/jbig2/JBig2_Context.h index 1577b22d37..a0e1a8fcac 100644 --- a/core/fxcodec/jbig2/JBig2_Context.h +++ b/core/fxcodec/jbig2/JBig2_Context.h @@ -25,8 +25,8 @@ class IFX_Pause; // Cache is keyed by the ObjNum of a stream and an index within the stream. using CJBig2_CacheKey = std::pair<uint32_t, uint32_t>; -// NB: CJBig2_SymbolDict* is owned. -using CJBig2_CachePair = std::pair<CJBig2_CacheKey, CJBig2_SymbolDict*>; +using CJBig2_CachePair = + std::pair<CJBig2_CacheKey, std::unique_ptr<CJBig2_SymbolDict>>; #define JBIG2_SUCCESS 0 #define JBIG2_FAILED -1 diff --git a/core/fxcrt/include/fx_memory.h b/core/fxcrt/include/fx_memory.h index 53e6b9d1eb..a3eba2fd79 100644 --- a/core/fxcrt/include/fx_memory.h +++ b/core/fxcrt/include/fx_memory.h @@ -107,11 +107,6 @@ std::unique_ptr<T> WrapUnique(T* ptr) { return std::unique_ptr<T>(ptr); } -class CFX_Deletable { - public: - virtual ~CFX_Deletable() {} -}; - #endif // __cplusplus #endif // CORE_FXCRT_INCLUDE_FX_MEMORY_H_ |