[Tizen] Add trace log to check text performance
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / font-client-plugin-cache-handler.cpp
index acaec1d..d7fb50d 100644 (file)
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
 #include <fontconfig/fontconfig.h>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/environment-variable.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/internal/text/text-abstraction/font-client-impl.h>
 #include <dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h>
@@ -61,6 +63,31 @@ extern Dali::Integration::Log::Filter* gFontClientLogFilter;
 
 namespace
 {
+
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FONT_PERFORMANCE_MARKER, false);
+
+/**
+ * @brief Maximum size of glyph cache per each font face.
+ */
+constexpr std::size_t DEFAULT_GLYPH_CACHE_MAX         = 128;
+constexpr std::size_t MINIMUM_SIZE_OF_GLYPH_CACHE_MAX = 3u;
+
+constexpr auto MAX_NUMBER_OF_GLYPH_CACHE_ENV = "DALI_GLYPH_CACHE_MAX";
+
+/**
+ * @brief Get maximum size of glyph cache size from environment.
+ * If not settuped, default as 128.
+ * @note This value fixed when we call it first time.
+ * @return The max size of glyph cache.
+ */
+inline size_t GetMaxNumberOfGlyphCache()
+{
+  using Dali::EnvironmentVariable::GetEnvironmentVariable;
+  static auto numberString = GetEnvironmentVariable(MAX_NUMBER_OF_GLYPH_CACHE_ENV);
+  static auto number       = numberString ? std::strtoul(numberString, nullptr, 10) : DEFAULT_GLYPH_CACHE_MAX;
+  return (number < MINIMUM_SIZE_OF_GLYPH_CACHE_MAX) ? MINIMUM_SIZE_OF_GLYPH_CACHE_MAX : number;
+}
+
 } // namespace
 
 namespace Dali::TextAbstraction::Internal
@@ -249,6 +276,7 @@ FontClient::Plugin::CacheHandler::CacheHandler()
   mFontDescriptionSizeCache(),
   mEllipsisCache(),
   mEmbeddedItemCache(),
+  mGlyphCacheManager(new GlyphCacheManager(GetMaxNumberOfGlyphCache())),
   mLatestFoundFontDescription(),
   mLatestFoundFontDescriptionId(0u),
   mLatestFoundCacheKey(0, 0),
@@ -264,6 +292,9 @@ FontClient::Plugin::CacheHandler::~CacheHandler()
 
 void FontClient::Plugin::CacheHandler::ClearCache()
 {
+  // delete cached glyph informations before clear mFontFaceCache.
+  mGlyphCacheManager->ClearCache();
+
   mDefaultFontDescription = FontDescription();
 
   mSystemFonts.clear();
@@ -479,7 +510,7 @@ void FontClient::Plugin::CacheHandler::InitDefaultFontDescription()
         mFontDescriptionCache.push_back(tempFontDescription);
 
         // Set the index to the vector of paths to font file names.
-        const FontDescriptionId fontDescriptionId = mFontDescriptionCache.size();
+        const FontDescriptionId fontDescriptionId = static_cast<FontDescriptionId>(mFontDescriptionCache.size());
 
         FONT_LOG_DESCRIPTION(tempFontDescription, "default platform font");
         DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "  default font fontDescriptionId : %d\n", fontDescriptionId);
@@ -514,7 +545,7 @@ bool FontClient::Plugin::CacheHandler::FindValidatedFont(const FontDescription&
                                                          FontDescriptionId&     fontDescriptionId)
 {
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
-  DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  number of validated fonts in the cache : %d\n", mValidatedFontCache.size());
+  DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  number of validated fonts in the cache : %zu\n", mValidatedFontCache.size());
 
   fontDescriptionId = 0u;
 
@@ -564,6 +595,8 @@ void FontClient::Plugin::CacheHandler::ValidateFont(const FontDescription& fontD
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
   FONT_LOG_DESCRIPTION(fontDescription, "");
 
+  DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_VALIDATE_FONT");
+
   // Create a font pattern.
   FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription);
 
@@ -575,12 +608,19 @@ void FontClient::Plugin::CacheHandler::ValidateFont(const FontDescription& fontD
 
   if(matched && (nullptr != characterSet))
   {
+    #if defined(TRACE_ENABLED)
+    if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+    {
+      DALI_LOG_DEBUG_INFO("DALI_TEXT_VALIDATE_FONT : FcFontMatch : %s, style : %s, %s, %s\n", fontDescription.family.c_str(), FontWidth::Name[fontDescription.width], FontWeight::Name[fontDescription.weight], FontSlant::Name[fontDescription.slant]);
+    }
+    #endif
+
     // Add the path to the cache.
     description.type = FontDescription::FACE_FONT;
     mFontDescriptionCache.push_back(description);
 
     // Set the index to the vector of paths to font file names.
-    fontDescriptionId = mFontDescriptionCache.size();
+    fontDescriptionId = static_cast<FontDescriptionId>(mFontDescriptionCache.size());
 
     FONT_LOG_DESCRIPTION(description, "matched");
     DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "  fontDescriptionId : %d\n", fontDescriptionId);
@@ -619,7 +659,7 @@ bool FontClient::Plugin::CacheHandler::FindFallbackFontList(const FontDescriptio
                                                             CharacterSetList*&     characterSetList) const
 {
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
-  DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  number of fallback font lists in the cache : %d\n", mFallbackCache.size());
+  DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  number of fallback font lists in the cache : %zu\n", mFallbackCache.size());
 
   fontList = nullptr;
 
@@ -649,6 +689,15 @@ void FontClient::Plugin::CacheHandler::CacheFallbackFontList(FontDescription&&
 {
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
 
+  DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_FALLBACK_FONTLIST");
+
+  #if defined(TRACE_ENABLED)
+  if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+  {
+    DALI_LOG_DEBUG_INFO("DALI_TEXT_FALLBACK_FONTLIST : FcFontSort : %s\n", fontDescription.family.c_str());
+  }
+  #endif
+
   fontList         = new FontList;
   characterSetList = new CharacterSetList;
 
@@ -683,7 +732,7 @@ bool FontClient::Plugin::CacheHandler::FindFontByPath(const FontPath& path,
   DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
   DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "                path : [%s]\n", path.c_str());
   DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "  requestedPointSize : %d\n", requestedPointSize);
-  DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  number of fonts in the cache : %d\n", mFontFaceCache.size());
+  DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, "  number of fonts in the cache : %zu\n", mFontFaceCache.size());
 
   fontId = 0u;
   for(const auto& cacheItem : mFontFaceCache)
@@ -800,7 +849,7 @@ void FontClient::Plugin::CacheHandler::CacheFontPath(FT_Face ftFace, FontId font
     mFontDescriptionCache.push_back(description);
 
     // Set the index to the vector of paths to font file names.
-    fontDescriptionId = mFontDescriptionCache.size();
+    fontDescriptionId = static_cast<FontDescriptionId>(mFontDescriptionCache.size());
 
     // Increase the reference counter and add the character set to the cache.
     mCharacterSetCache.PushBack(FcCharSetCopy(characterSet));
@@ -816,21 +865,21 @@ void FontClient::Plugin::CacheHandler::CacheFontPath(FT_Face ftFace, FontId font
 FontId FontClient::Plugin::CacheHandler::CacheFontFaceCacheItem(FontFaceCacheItem&& fontFaceCacheItem)
 {
   // Set the index to the font's id cache.
-  fontFaceCacheItem.mFontId = mFontIdCache.size();
+  fontFaceCacheItem.mFontId = static_cast<FontId>(mFontIdCache.size());
 
   // Create the font id item to cache.
   FontIdCacheItem fontIdCacheItem;
   fontIdCacheItem.type = FontDescription::FACE_FONT;
 
   // Set the index to the FreeType font face cache.
-  fontIdCacheItem.index = mFontFaceCache.size();
+  fontIdCacheItem.index = static_cast<FontCacheIndex>(mFontFaceCache.size());
 
   // Cache the items.
   mFontFaceCache.emplace_back(std::move(fontFaceCacheItem));
   mFontIdCache.emplace_back(std::move(fontIdCacheItem));
 
   // Set the font id to be returned.
-  FontId fontId = mFontIdCache.size();
+  FontId fontId = static_cast<FontId>(mFontIdCache.size());
 
   return fontId;
 }
@@ -861,7 +910,7 @@ bool FontClient::Plugin::CacheHandler::FindEllipsis(PointSize26Dot6 requestedPoi
 
 FontClient::Plugin::CacheHandler::EllipsisCacheIndex FontClient::Plugin::CacheHandler::CacheEllipsis(EllipsisItem&& ellipsisItem)
 {
-  EllipsisCacheIndex ellipsisCacheIndex = mEllipsisCache.size();
+  EllipsisCacheIndex ellipsisCacheIndex = static_cast<EllipsisCacheIndex>(mEllipsisCache.size());
 
   mEllipsisCache.emplace_back(std::move(ellipsisItem));
 
@@ -889,21 +938,21 @@ bool FontClient::Plugin::CacheHandler::FindBitmapFont(const FontFamily& bitmapFo
 FontId FontClient::Plugin::CacheHandler::CacheBitmapFontCacheItem(BitmapFontCacheItem&& bitmapFontCacheItem)
 {
   // Set the index to the font's id cache.
-  bitmapFontCacheItem.id = mFontIdCache.size();
+  bitmapFontCacheItem.id = static_cast<FontId>(mFontIdCache.size());
 
   // Create the font id item to cache.
   CacheHandler::FontIdCacheItem fontIdCacheItem;
   fontIdCacheItem.type = FontDescription::BITMAP_FONT;
 
   // Set the index to the Bitmap font face cache.
-  fontIdCacheItem.index = mBitmapFontCache.size();
+  fontIdCacheItem.index = static_cast<FontCacheIndex>(mBitmapFontCache.size());
 
   // Cache the items.
   mBitmapFontCache.emplace_back(std::move(bitmapFontCacheItem));
   mFontIdCache.emplace_back(std::move(fontIdCacheItem));
 
   // Set the font id to be returned.
-  FontId fontId = mFontIdCache.size();
+  FontId fontId = static_cast<FontId>(mFontIdCache.size());
 
   return fontId;
 }
@@ -939,13 +988,13 @@ PixelBufferId FontClient::Plugin::CacheHandler::CacheEmbeddedPixelBuffer(const s
     PixelBufferCacheItem pixelBufferCacheItem;
     pixelBufferCacheItem.pixelBuffer = pixelBuffer;
     pixelBufferCacheItem.url         = url;
-    pixelBufferCacheItem.id          = mPixelBufferCache.size() + 1u;
+    pixelBufferCacheItem.id          = static_cast<PixelBufferId>(mPixelBufferCache.size() + 1u);
 
     // Store the cache item in the cache.
     mPixelBufferCache.emplace_back(std::move(pixelBufferCacheItem));
 
     // Set the pixel buffer id to be returned.
-    pixelBufferId = mPixelBufferCache.size();
+    pixelBufferId = static_cast<PixelBufferId>(mPixelBufferCache.size());
   }
   return pixelBufferId;
 }
@@ -970,13 +1019,13 @@ bool FontClient::Plugin::CacheHandler::FindEmbeddedItem(PixelBufferId pixelBuffe
 
 GlyphIndex FontClient::Plugin::CacheHandler::CacheEmbeddedItem(EmbeddedItem&& embeddedItem)
 {
-  embeddedItem.index = mEmbeddedItemCache.size() + 1u;
+  embeddedItem.index = static_cast<GlyphIndex>(mEmbeddedItemCache.size() + 1u);
 
   // Cache the embedded item.
   mEmbeddedItemCache.emplace_back(std::move(embeddedItem));
 
   // Set the font id to be returned.
-  GlyphIndex index = mEmbeddedItemCache.size();
+  GlyphIndex index = static_cast<GlyphIndex>(mEmbeddedItemCache.size());
 
   return index;
 }