Move glyph cache manager into font-client-plugin-cache-handler
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / plugin / font-face-glyph-cache-manager.h
index fd0eb05..15f5e45 100644 (file)
@@ -36,7 +36,7 @@ class GlyphCacheManager
 {
 public:
   // Constructor
-  GlyphCacheManager(FT_Face ftFace, std::size_t maxNumberOfGlyphCache);
+  GlyphCacheManager(std::size_t maxNumberOfGlyphCache);
 
   // Destructor
   ~GlyphCacheManager();
@@ -88,6 +88,7 @@ public:
   /**
    * @brief Load GlyphCacheData from face. The result will be cached.
    *
+   * @param[in] freeTypeFace The freetype face handle.
    * @param[in] index Index of glyph in this face.
    * @param[in] flag Flag when we load the glyph.
    * @param[in] isBoldRequired True if we require some software bold.
@@ -96,6 +97,7 @@ public:
    * @return True if load successfully. False if something error occured.
    */
   bool GetGlyphCacheDataFromIndex(
+    const FT_Face    freeTypeFace,
     const GlyphIndex index,
     const FT_Int32   flag,
     const bool       isBoldRequired,
@@ -106,6 +108,7 @@ public:
    * @brief Load GlyphCacheData from face. The result will not be cached.
    * @note If we call this API, We should release GlyphCacheData manually.
    *
+   * @param[in] freeTypeFace The freetype face handle.
    * @param[in] index Index of glyph in this face.
    * @param[in] flag Flag when we load the glyph.
    * @param[in] isBoldRequired True if we require some software bold.
@@ -114,6 +117,7 @@ public:
    * @return True if load successfully. False if something error occured.
    */
   bool LoadGlyphDataFromIndex(
+    const FT_Face    freeTypeFace,
     const GlyphIndex index,
     const FT_Int32   flag,
     const bool       isBoldRequired,
@@ -124,6 +128,7 @@ public:
    * @brief Resize bitmap glyph. The result will change cached glyph bitmap information.
    * If glyph is not bitmap glyph, nothing happened.
    *
+   * @param[in] freeTypeFace The freetype face handle.
    * @param[in] index Index of glyph in this face.
    * @param[in] flag Flag when we load the glyph.
    * @param[in] isBoldRequired True if we require some software bold.
@@ -131,6 +136,7 @@ public:
    * @param[in] desiredHeight Desired height of bitmap.
    */
   void ResizeBitmapGlyph(
+    const FT_Face    freeTypeFace,
     const GlyphIndex index,
     const FT_Int32   flag,
     const bool       isBoldRequired,
@@ -141,6 +147,7 @@ public:
    * @brief Cache rendered glyph bitmap. The result will change cached glyph information.
    * If glyph is not single color glyph, or we already cached buffer before, nothing happened.
    *
+   * @param[in] freeTypeFace The freetype face handle.
    * @param[in] index Index of glyph in this face.
    * @param[in] flag Flag when we load the glyph.
    * @param[in] isBoldRequired True if we require some software bold.
@@ -148,12 +155,28 @@ public:
    * @param[in] policy Compress behavior policy.
    */
   void CacheRenderedGlyphBuffer(
+    const FT_Face               freeTypeFace,
     const GlyphIndex            index,
     const FT_Int32              flag,
     const bool                  isBoldRequired,
     const FT_Bitmap&            srcBitmap,
     const CompressionPolicyType policy);
 
+  /**
+   * @brief Clear all cached glyph informations which has inputed FreeTypeFace.
+   *
+   * @note This API iterate all cached glyph. Should be called rarely.
+   * @param[in] freeTypeFace The freetype face handle.
+   */
+  void RemoveGlyphFromFace(const FT_Face freeTypeFace);
+
+  /**
+   * @brief Clear all cached glyph informations.
+   *
+   * @param[in] remainCount The number of remained cache items after call this API. Default is 0, clear all items.
+   */
+  void ClearCache(const std::size_t remainCount = 0u);
+
 private:
   // Private struct area.
   /**
@@ -162,25 +185,29 @@ private:
   struct GlyphCacheKey
   {
     GlyphCacheKey()
-    : mIndex(0u),
+    : mFreeTypeFace(nullptr),
+      mIndex(0u),
       mFlag(0),
       mIsBoldRequired(false)
     {
     }
 
-    GlyphCacheKey(const GlyphIndex index, const FT_Int32 flag, const bool boldRequired)
-    : mIndex(index),
+    GlyphCacheKey(const FT_Face freeTypeFace, const GlyphIndex index, const FT_Int32 flag, const bool boldRequired)
+    : mFreeTypeFace(freeTypeFace),
+      mIndex(index),
       mFlag(flag),
       mIsBoldRequired(boldRequired)
     {
     }
+
+    FT_Face    mFreeTypeFace;
     GlyphIndex mIndex;
     FT_Int32   mFlag;
     bool       mIsBoldRequired : 1;
 
     bool operator==(GlyphCacheKey const& rhs) const noexcept
     {
-      return mIndex == rhs.mIndex && mFlag == rhs.mFlag && mIsBoldRequired == rhs.mIsBoldRequired;
+      return mFreeTypeFace == rhs.mFreeTypeFace && mIndex == rhs.mIndex && mFlag == rhs.mFlag && mIsBoldRequired == rhs.mIsBoldRequired;
     }
   };
 
@@ -191,14 +218,15 @@ private:
   {
     std::size_t operator()(GlyphCacheKey const& key) const noexcept
     {
-      return static_cast<std::size_t>(key.mIndex) ^ static_cast<std::size_t>(key.mFlag) ^ (static_cast<std::size_t>(key.mIsBoldRequired) << 29);
+      return static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(key.mFreeTypeFace)) ^
+             static_cast<std::size_t>(key.mIndex) ^
+             static_cast<std::size_t>(key.mFlag) ^
+             (static_cast<std::size_t>(key.mIsBoldRequired) << 29);
     }
   };
 
 private:
   // Private member value area.
-  FT_Face mFreeTypeFace; ///< The FreeType face. Owned from font-face-cache-item
-
   std::size_t mGlyphCacheMaxSize; ///< The maximum capacity of glyph cache.
 
   using CacheContainer = LRUCacheContainer<GlyphCacheKey, GlyphCacheData, GlyphCacheKeyHash>;