Skip to content

Commit 1662cc9

Browse files
jason-simmonsNoamDev
authored andcommitted
[SkParagraph] Cache the font collection created for use by the Skia text shaper library (flutter#15317)
1 parent a2bd950 commit 1662cc9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

third_party/txt/src/txt/font_collection.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,20 @@ void FontCollection::ClearFontFamilyCache() {
315315

316316
sk_sp<skia::textlayout::FontCollection>
317317
FontCollection::CreateSktFontCollection() {
318-
sk_sp<skia::textlayout::FontCollection> skt_collection =
319-
sk_make_sp<skia::textlayout::FontCollection>();
320-
321-
skt_collection->setDefaultFontManager(default_font_manager_,
322-
GetDefaultFontFamily().c_str());
323-
skt_collection->setAssetFontManager(asset_font_manager_);
324-
skt_collection->setDynamicFontManager(dynamic_font_manager_);
325-
skt_collection->setTestFontManager(test_font_manager_);
326-
if (!enable_font_fallback_) {
327-
skt_collection->disableFontFallback();
318+
if (!skt_collection_) {
319+
skt_collection_ = sk_make_sp<skia::textlayout::FontCollection>();
320+
321+
skt_collection_->setDefaultFontManager(default_font_manager_,
322+
GetDefaultFontFamily().c_str());
323+
skt_collection_->setAssetFontManager(asset_font_manager_);
324+
skt_collection_->setDynamicFontManager(dynamic_font_manager_);
325+
skt_collection_->setTestFontManager(test_font_manager_);
326+
if (!enable_font_fallback_) {
327+
skt_collection_->disableFontFallback();
328+
}
328329
}
329330

330-
return skt_collection;
331+
return skt_collection_;
331332
}
332333

333334
#endif // FLUTTER_ENABLE_SKSHAPER

third_party/txt/src/txt/font_collection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {
107107
fallback_fonts_for_locale_;
108108
bool enable_font_fallback_;
109109

110+
#if FLUTTER_ENABLE_SKSHAPER
111+
// An equivalent font collection usable by the Skia text shaper library.
112+
sk_sp<skia::textlayout::FontCollection> skt_collection_;
113+
#endif
114+
110115
// Performs the actual work of MatchFallbackFont. The result is cached in
111116
// fallback_match_cache_.
112117
const std::shared_ptr<minikin::FontFamily>& DoMatchFallbackFont(

0 commit comments

Comments
 (0)