-
Notifications
You must be signed in to change notification settings - Fork 6k
Optimize loading fallback font-family performance #13257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,9 @@ const uint32_t TEXT_STYLE_VS = 0xFE0E; | |
|
|
||
| uint32_t FontCollection::sNextId = 0; | ||
|
|
||
| const uint32_t kMinFallbackScore = 0x20000000; | ||
| std::vector<std::shared_ptr<FontFamily>> sFallbackFamilies; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this a member of the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a unclear to me exactly why this is called sFallbackFamilies, maybe consider a more descriptive name?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@GaryQian What's your suggested name? |
||
|
|
||
| // libtxt: return a locale string for a language list ID | ||
| std::string GetFontLocale(uint32_t langListId) { | ||
| const FontLanguages& langs = FontLanguageListCache::getById(langListId); | ||
|
|
@@ -64,6 +67,10 @@ FontCollection::FontCollection( | |
| init(typefaces); | ||
| } | ||
|
|
||
| FontCollection::~FontCollection() { | ||
| sFallbackFamilies.clear(); | ||
| } | ||
|
|
||
| void FontCollection::init( | ||
| const vector<std::shared_ptr<FontFamily>>& typefaces) { | ||
| std::scoped_lock _l(gMinikinLock); | ||
|
|
@@ -299,12 +306,20 @@ const std::shared_ptr<FontFamily>& FontCollection::getFamilyForChar( | |
| uint32_t langListId, | ||
| int variant) const { | ||
| if (ch >= mMaxChar) { | ||
| for (size_t i = 0; i < sFallbackFamilies.size(); i++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (optional) Since this is identical to the snippet below (line 355), consider using helper function to help keep these two sections in sync.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, since it would be helpful to have a short comment explaining why this is necessary. |
||
| const uint32_t score = | ||
| calcFamilyScore(ch, vs, variant, langListId, sFallbackFamilies[i]); | ||
| if (score >= kMinFallbackScore) { | ||
| return sFallbackFamilies[i]; | ||
| } | ||
| } | ||
| // libtxt: check if the fallback font provider can match this character | ||
| if (mFallbackFontProvider) { | ||
| const std::shared_ptr<FontFamily>& fallback = | ||
| mFallbackFontProvider->matchFallbackFont(ch, | ||
| GetFontLocale(langListId)); | ||
| if (fallback) { | ||
| sFallbackFamilies.push_back(fallback); | ||
| return fallback; | ||
| } | ||
| } | ||
|
|
@@ -337,12 +352,20 @@ const std::shared_ptr<FontFamily>& FontCollection::getFamilyForChar( | |
| } | ||
| } | ||
| if (bestFamilyIndex == -1) { | ||
| for (size_t i = 0; i < sFallbackFamilies.size(); i++) { | ||
| const uint32_t score = | ||
| calcFamilyScore(ch, vs, variant, langListId, sFallbackFamilies[i]); | ||
| if (score >= kMinFallbackScore) { | ||
| return sFallbackFamilies[i]; | ||
| } | ||
| } | ||
| // libtxt: check if the fallback font provider can match this character | ||
| if (mFallbackFontProvider) { | ||
| const std::shared_ptr<FontFamily>& fallback = | ||
| mFallbackFontProvider->matchFallbackFont(ch, | ||
| GetFontLocale(langListId)); | ||
| if (fallback) { | ||
| sFallbackFamilies.push_back(fallback); | ||
| return fallback; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the
calcFamilyScore >= kMinFallbackScorechecks with a call tocalcCoverageScore.calcFamilyScoreis a combination ofcalcCoverageScoreand some other scores. IfcalcCoverageScorereturns a nonzero result, then that is equivalent tocalcFamilyScorereturning a score >= 0x20000000.