From 6e859d7ce4cbcefdceb4e6cfd944bfe2ef9b36cb Mon Sep 17 00:00:00 2001 From: Hakkyu Kim <43136596+HakkyuKim@users.noreply.github.com> Date: Thu, 29 Apr 2021 15:41:49 +0900 Subject: [PATCH] Create fallback font manager to solve performance drops (#78) --- third_party/txt/src/txt/font_collection.cc | 3 +++ third_party/txt/src/txt/font_collection.h | 1 + third_party/txt/src/txt/platform.cc | 4 ++++ third_party/txt/src/txt/platform.h | 2 ++ third_party/txt/src/txt/platform_linux.cc | 10 +++++++++- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/third_party/txt/src/txt/font_collection.cc b/third_party/txt/src/txt/font_collection.cc index 62978d03b80eb..d3cb84e9aa666 100644 --- a/third_party/txt/src/txt/font_collection.cc +++ b/third_party/txt/src/txt/font_collection.cc @@ -99,6 +99,7 @@ size_t FontCollection::GetFontManagersCount() const { void FontCollection::SetupDefaultFontManager() { default_font_manager_ = GetDefaultFontManager(); + fallback_font_manager_ = GetFallbackFontManager(); } void FontCollection::SetDefaultFontManager(sk_sp font_manager) { @@ -144,6 +145,8 @@ std::vector> FontCollection::GetFontManagerOrder() const { order.push_back(test_font_manager_); if (default_font_manager_) order.push_back(default_font_manager_); + if (fallback_font_manager_) + order.push_back(fallback_font_manager_); return order; } diff --git a/third_party/txt/src/txt/font_collection.h b/third_party/txt/src/txt/font_collection.h index 315734c74d3da..f185c53298d67 100644 --- a/third_party/txt/src/txt/font_collection.h +++ b/third_party/txt/src/txt/font_collection.h @@ -91,6 +91,7 @@ class FontCollection : public std::enable_shared_from_this { }; sk_sp default_font_manager_; + sk_sp fallback_font_manager_; sk_sp asset_font_manager_; sk_sp dynamic_font_manager_; sk_sp test_font_manager_; diff --git a/third_party/txt/src/txt/platform.cc b/third_party/txt/src/txt/platform.cc index c60731b3758b5..689174e8e9431 100644 --- a/third_party/txt/src/txt/platform.cc +++ b/third_party/txt/src/txt/platform.cc @@ -14,4 +14,8 @@ sk_sp GetDefaultFontManager() { return SkFontMgr::RefDefault(); } +sk_sp GetFallbackFontManager() { + return nullptr; +} + } // namespace txt diff --git a/third_party/txt/src/txt/platform.h b/third_party/txt/src/txt/platform.h index cffe9280ea5c9..35a33a3d8553c 100644 --- a/third_party/txt/src/txt/platform.h +++ b/third_party/txt/src/txt/platform.h @@ -17,6 +17,8 @@ std::vector GetDefaultFontFamilies(); sk_sp GetDefaultFontManager(); +sk_sp GetFallbackFontManager(); + } // namespace txt #endif // TXT_PLATFORM_H_ diff --git a/third_party/txt/src/txt/platform_linux.cc b/third_party/txt/src/txt/platform_linux.cc index 56bdc1a2cac6b..b2e83a67d7967 100644 --- a/third_party/txt/src/txt/platform_linux.cc +++ b/third_party/txt/src/txt/platform_linux.cc @@ -78,7 +78,15 @@ sk_sp GetDefaultFontManager() { #ifdef FLUTTER_USE_FONTCONFIG return SkFontMgr_New_FontConfig(nullptr); #else - return SkFontMgr_New_Custom_Directory("/usr/share/"); + return SkFontMgr_New_Custom_Directory("/usr/share/fonts"); +#endif +} + +sk_sp GetFallbackFontManager() { +#ifdef FLUTTER_USE_FONTCONFIG + return nullptr; +#else + return SkFontMgr_New_Custom_Directory("/usr/share/fallback_fonts"); #endif }