From da65a8ea74d2748c93015fb5521da678e29e6548 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 30 Apr 2018 21:02:03 +0000 Subject: Saner memory managment in cttfontdesc, part 1. A subsequent patch will tackle the ad-hoc ref counting, but we can tidy this before going down that hole. Decouple CTTFontDesc creation from face setting. Remove union and treat single-entry case as vector's first element. Pass unique_ptr to prove memory ownership. Change-Id: Ic427798da04f3afbb65a56ee10045b9f22457a73 Reviewed-on: https://pdfium-review.googlesource.com/31730 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- core/fxge/cttfontdesc.h | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'core/fxge/cttfontdesc.h') diff --git a/core/fxge/cttfontdesc.h b/core/fxge/cttfontdesc.h index bc0ea1737f..e73b03f6ec 100644 --- a/core/fxge/cttfontdesc.h +++ b/core/fxge/cttfontdesc.h @@ -7,6 +7,9 @@ #ifndef CORE_FXGE_CTTFONTDESC_H_ #define CORE_FXGE_CTTFONTDESC_H_ +#include + +#include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/fx_font.h" @@ -18,34 +21,23 @@ class CTTFontDesc { kNotReleased // Object still alive. }; - // Single face ctor. - CTTFontDesc(uint8_t* pData, FXFT_Face face); - - // TTC face ctor. - CTTFontDesc(uint8_t* pData, size_t index, FXFT_Face face); - + explicit CTTFontDesc(std::unique_ptr pData); ~CTTFontDesc(); - void SetTTCFace(size_t index, FXFT_Face face); + void SetFace(size_t index, FXFT_Face face); void AddRef(); // May not decrement refcount, depending on the value of |face|. ReleaseStatus ReleaseFace(FXFT_Face face); - uint8_t* FontData() const { return m_pFontData; } - - FXFT_Face SingleFace() const; - FXFT_Face TTCFace(size_t index) const; + uint8_t* FontData() const { return m_pFontData.get(); } + FXFT_Face GetFace(size_t index) const; private: - const bool m_bIsTTC; int m_RefCount = 1; - uint8_t* const m_pFontData; - union { - const FXFT_Face m_SingleFace; - FXFT_Face m_TTCFaces[16]; - }; + std::unique_ptr const m_pFontData; + FXFT_Face m_TTCFaces[16]; }; #endif // CORE_FXGE_CTTFONTDESC_H_ -- cgit v1.2.3