Revert "[Tizen] Fix bug that DefaultFonts are infinitely cached"
authorHosang Kim <hosang12.kim@samsung.com>
Tue, 11 Jun 2024 07:49:52 +0000 (16:49 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Tue, 11 Jun 2024 07:49:52 +0000 (16:49 +0900)
This reverts commit 69f4ce91873e15def5623e1611e4a914596a065d.

automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp
dali-toolkit/internal/text/multi-language-support-impl.cpp
dali-toolkit/internal/text/multi-language-support-impl.h

index b1964fb..a81a462 100755 (executable)
@@ -1898,6 +1898,60 @@ int UtcDaliTextMultiLanguageValidateFonts01(void)
   END_TEST;
 }
 
+int UtcDaliTextMultiLanguageValidateFontsPerScriptCache(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextMultiLanguageValidateFontsPerScriptCache");
+
+  std::size_t MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE = 63u;
+  std::size_t VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT   = 8u;
+
+  Dali::Toolkit::Text::Internal::ValidateFontsPerScript* validateFontsPerScript = new Dali::Toolkit::Text::Internal::ValidateFontsPerScript();
+
+  for(std::size_t i = 0u; i < MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE; i ++)
+  {
+    FontId fontId = i;
+    validateFontsPerScript->Cache(fontId);
+  }
+
+  DALI_TEST_EQUALS(MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE, validateFontsPerScript->mValidFonts.Count(), TEST_LOCATION);
+
+  FontId fontId = MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE;
+  validateFontsPerScript->Cache(fontId);
+
+  DALI_TEST_EQUALS(VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT, validateFontsPerScript->mValidFonts.Count(), TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliTextMultiLanguageDefaultFontsCache(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextMultiLanguageDefaultFontsCache");
+
+  std::size_t MAX_DEFAULT_FONTS_CACHE_SIZE = 15;
+  std::size_t DEFAULT_FONTS_REMAIN_COUNT   = 2;
+
+  Dali::Toolkit::Text::Internal::DefaultFonts* defaultFontsPerScript = new Dali::Toolkit::Text::Internal::DefaultFonts();
+
+  for(std::size_t i = 0u; i < MAX_DEFAULT_FONTS_CACHE_SIZE; i ++)
+  {
+    TextAbstraction::FontDescription fontDescription;
+    FontId fontId = i;
+    defaultFontsPerScript->Cache(fontDescription, fontId);
+  }
+
+  DALI_TEST_EQUALS(MAX_DEFAULT_FONTS_CACHE_SIZE, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);
+
+  TextAbstraction::FontDescription fontDescription;
+  FontId fontId = MAX_DEFAULT_FONTS_CACHE_SIZE;
+  defaultFontsPerScript->Cache(fontDescription, fontId);
+
+  DALI_TEST_EQUALS(DEFAULT_FONTS_REMAIN_COUNT, defaultFontsPerScript->mFonts.size(), TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliTextMultiLanguageLocaleChange(void)
 {
   ToolkitTestApplication application;
index 1b3d0ce..41ba5ac 100644 (file)
@@ -42,6 +42,13 @@ Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_MULT
 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FONT_PERFORMANCE_MARKER, false);
 
 const Dali::Toolkit::Text::Character UTF32_A = 0x0041;
+
+// TODO : Customization required for these values.
+constexpr std::size_t MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE = 63;
+constexpr std::size_t MAX_DEFAULT_FONTS_CACHE_SIZE             = 15;
+
+constexpr int VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT = 8;
+constexpr int DEFAULT_FONTS_REMAIN_COUNT             = 2;
 } // namespace
 
 namespace Text
@@ -166,13 +173,7 @@ void CheckFontSupportsCharacter(
                 *(defaultFontPerScriptCacheBuffer + script) = defaultFontsPerScript;
               }
             }
-
-            // the fontId is cached only if it has not been cached before.
-            if(!isValidCachedDefaultFont)
-            {
-              defaultFontsPerScript->Cache(currentFontDescription, fontId);
-            }
-
+            defaultFontsPerScript->Cache(currentFontDescription, fontId);
             isValidFont = true;
           }
         }
@@ -200,14 +201,21 @@ bool ValidateFontsPerScript::IsValidFont(FontId fontId) const
 void ValidateFontsPerScript::Cache(FontId fontId)
 {
   mValidFonts.PushBack(fontId);
-
-  return;
+  if(MAX_VALIDATE_FONTS_PER_SCRIPT_CACHE_SIZE < mValidFonts.Count())
+  {
+    // Clear cache but remaind some last items.
+    const auto offset = mValidFonts.Count() - VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT;
+    for(int i = 0; i < VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT; ++i)
+    {
+      mValidFonts[i] = std::move(mValidFonts[offset + i]);
+    }
+    mValidFonts.Resize(VALIDATE_FONTS_PER_SCRIPT_REMAIN_COUNT);
+  }
 }
 
 FontId DefaultFonts::FindFont(TextAbstraction::FontClient&            fontClient,
                               const TextAbstraction::FontDescription& description,
-                              PointSize26Dot6                         size,
-                              Character                               character) const
+                              PointSize26Dot6                         size) const
 {
   for(std::vector<CacheItem>::const_iterator it    = mFonts.begin(),
                                              endIt = mFonts.end();
@@ -220,8 +228,7 @@ FontId DefaultFonts::FindFont(TextAbstraction::FontClient&            fontClient
        ((TextAbstraction::FontWidth::NONE == description.width) || (description.width == item.description.width)) &&
        ((TextAbstraction::FontSlant::NONE == description.slant) || (description.slant == item.description.slant)) &&
        (size == fontClient.GetPointSize(item.fontId)) &&
-       (description.family.empty() || (description.family == item.description.family)) &&
-       fontClient.IsCharacterSupportedByFont(item.fontId, character))
+       (description.family.empty() || (description.family == item.description.family)))
     {
       return item.fontId;
     }
@@ -236,8 +243,16 @@ void DefaultFonts::Cache(const TextAbstraction::FontDescription& description, Fo
   item.description = description;
   item.fontId      = fontId;
   mFonts.push_back(item);
-
-  return;
+  if(MAX_DEFAULT_FONTS_CACHE_SIZE < mFonts.size())
+  {
+    // Clear cache but remaind some last items.
+    const auto offset = mFonts.size() - DEFAULT_FONTS_REMAIN_COUNT;
+    for(int i = 0; i < DEFAULT_FONTS_REMAIN_COUNT; ++i)
+    {
+      mFonts[i] = std::move(mFonts[offset + i]);
+    }
+    mFonts.resize(DEFAULT_FONTS_REMAIN_COUNT);
+  }
 }
 
 MultilanguageSupport::MultilanguageSupport()
@@ -709,8 +724,7 @@ void MultilanguageSupport::ValidateFonts(const Vector<Character>&
       // This cache stores fall-back fonts.
       cachedDefaultFontId = defaultFonts->FindFont(fontClient,
                                                    currentFontDescription,
-                                                   currentFontPointSize,
-                                                   character);
+                                                   currentFontPointSize);
     }
 
     // Whether the cached default font is valid.
index 71014e2..2f0a904 100644 (file)
@@ -116,8 +116,7 @@ struct DefaultFonts
    */
   FontId FindFont(TextAbstraction::FontClient&            fontClient,
                   const TextAbstraction::FontDescription& description,
-                  PointSize26Dot6                         size,
-                  Character                               character) const;
+                  PointSize26Dot6                         size) const;
 
   /**
    * @brief Cache a default font for the given @p size.