From af0d918ebdabb6d160a1a6ab58910a1668886410 Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Thu, 17 May 2018 20:39:53 +0900 Subject: [PATCH] [4.0] Caching FcPattern object when using FcCharSetHasChar The result of FcCharSetHasChar can be destroyed when destroying FcPattern object. Caching FcPattern object when using FcCharSetHasChar function and destroying it later. Change-Id: I5cf69c5948d935e5ec2748fcc9580830cc4a697b --- .../text-abstraction/font-client-plugin-impl.cpp | 19 +++++++++++++++---- .../text-abstraction/font-client-plugin-impl.h | 14 ++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp index 09193c0..0239bc1 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp @@ -256,7 +256,7 @@ FontClient::Plugin::~Plugin() #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING delete mVectorFontCache; #endif - + DestroyMatchedPatterns(); FT_Done_FreeType( mFreeTypeLibrary ); } @@ -279,6 +279,7 @@ void FontClient::Plugin::ClearCache() mDefaultFontDescriptionCached = false; mDefaultFontCharacterSets.Clear(); mDefaultFontDescription = FontDescription(); + DestroyMatchedPatterns(); } void FontClient::Plugin::SetDpi( unsigned int horizontalDpi, @@ -1991,9 +1992,10 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do FcCharSet* characterSet = NULL; FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet ); - FcPatternDestroy( match ); FcPatternDestroy( pattern ); + mMatchedFcPatternCache.PushBack( match ); + mFontCache[id-1u].mCharacterSet = characterSet; // Add the path to the cache. @@ -2013,7 +2015,7 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do } } -FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) const +FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) { FcCharSet* characterSet = NULL; @@ -2026,13 +2028,22 @@ FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDesc FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet ); - FcPatternDestroy( match ); + mMatchedFcPatternCache.PushBack( match ); + FcPatternDestroy( pattern ); } return characterSet; } +void FontClient::Plugin::DestroyMatchedPatterns() +{ + for (auto & object : mMatchedFcPatternCache) { + FcPatternDestroy(reinterpret_cast(object)); + } + mMatchedFcPatternCache.Clear(); +} + } // namespace Internal } // namespace TextAbstraction diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.h b/text/dali/internal/text-abstraction/font-client-plugin-impl.h index 5cc45d3..150560f 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.h +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.h @@ -495,7 +495,13 @@ private: * * @return A character set. */ - _FcCharSet* CreateCharacterSetFromDescription( const FontDescription& description ) const; + _FcCharSet* CreateCharacterSetFromDescription( const FontDescription& description ); + + /** + * @brief Destroy all matched Patterns. + * + */ + void DestroyMatchedPatterns(); private: @@ -525,9 +531,9 @@ private: CharacterSetList mCharacterSetCache; ///< Caches character set lists for the validated font. std::vector mFontIdCache; ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts. - VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc. - - Vector mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size. + VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc. + Vector mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size. + Vector<_FcPattern*> mMatchedFcPatternCache; ///< Contain matched FcPattern pointer. bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not }; -- 2.7.4