Skip to content

Commit

Permalink
Create fallback font manager to solve performance drops (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
HakkyuKim authored Apr 29, 2021
1 parent 94bd946 commit 6e859d7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions third_party/txt/src/txt/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkFontMgr> font_manager) {
Expand Down Expand Up @@ -144,6 +145,8 @@ std::vector<sk_sp<SkFontMgr>> 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;
}

Expand Down
1 change: 1 addition & 0 deletions third_party/txt/src/txt/font_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
};

sk_sp<SkFontMgr> default_font_manager_;
sk_sp<SkFontMgr> fallback_font_manager_;
sk_sp<SkFontMgr> asset_font_manager_;
sk_sp<SkFontMgr> dynamic_font_manager_;
sk_sp<SkFontMgr> test_font_manager_;
Expand Down
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ sk_sp<SkFontMgr> GetDefaultFontManager() {
return SkFontMgr::RefDefault();
}

sk_sp<SkFontMgr> GetFallbackFontManager() {
return nullptr;
}

} // namespace txt
2 changes: 2 additions & 0 deletions third_party/txt/src/txt/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ std::vector<std::string> GetDefaultFontFamilies();

sk_sp<SkFontMgr> GetDefaultFontManager();

sk_sp<SkFontMgr> GetFallbackFontManager();

} // namespace txt

#endif // TXT_PLATFORM_H_
10 changes: 9 additions & 1 deletion third_party/txt/src/txt/platform_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ sk_sp<SkFontMgr> 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<SkFontMgr> GetFallbackFontManager() {
#ifdef FLUTTER_USE_FONTCONFIG
return nullptr;
#else
return SkFontMgr_New_Custom_Directory("/usr/share/fallback_fonts");
#endif
}

Expand Down

0 comments on commit 6e859d7

Please sign in to comment.