Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

libtxt: fix reference counting of SkFontStyleSets held by font asset providers #9561

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/ui/text/asset_manager_font_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ SkFontStyleSet* AssetManagerFontProvider::MatchFamily(
if (found == registered_families_.end()) {
return nullptr;
}
return SkRef(&found->second);
sk_sp<SkFontStyleSet> font_style_set = found->second;
return font_style_set.release();
}

void AssetManagerFontProvider::RegisterAsset(std::string family_name,
Expand All @@ -54,14 +55,12 @@ void AssetManagerFontProvider::RegisterAsset(std::string family_name,

if (family_it == registered_families_.end()) {
family_names_.push_back(family_name);
family_it = registered_families_
.emplace(std::piecewise_construct,
std::forward_as_tuple(canonical_name),
std::forward_as_tuple(asset_manager_))
.first;
auto value = std::make_pair(
canonical_name, sk_make_sp<AssetManagerFontStyleSet>(asset_manager_));
family_it = registered_families_.emplace(value).first;
}

family_it->second.registerAsset(asset);
family_it->second->registerAsset(asset);
}

AssetManagerFontStyleSet::AssetManagerFontStyleSet(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/text/asset_manager_font_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AssetManagerFontProvider : public txt::FontAssetProvider {

private:
std::shared_ptr<AssetManager> asset_manager_;
std::unordered_map<std::string, AssetManagerFontStyleSet>
std::unordered_map<std::string, sk_sp<AssetManagerFontStyleSet>>
registered_families_;
std::vector<std::string> family_names_;

Expand Down
13 changes: 6 additions & 7 deletions third_party/txt/src/txt/typeface_font_asset_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ SkFontStyleSet* TypefaceFontAssetProvider::MatchFamily(
if (found == registered_families_.end()) {
return nullptr;
}
return SkRef(&found->second);
sk_sp<TypefaceFontStyleSet> font_style_set = found->second;
return font_style_set.release();
}

void TypefaceFontAssetProvider::RegisterTypeface(sk_sp<SkTypeface> typeface) {
Expand All @@ -69,13 +70,11 @@ void TypefaceFontAssetProvider::RegisterTypeface(
auto family_it = registered_families_.find(canonical_name);
if (family_it == registered_families_.end()) {
family_names_.push_back(family_name_alias);
family_it = registered_families_
.emplace(std::piecewise_construct,
std::forward_as_tuple(canonical_name),
std::forward_as_tuple())
.first;
auto value =
std::make_pair(canonical_name, sk_make_sp<TypefaceFontStyleSet>());
family_it = registered_families_.emplace(value).first;
}
family_it->second.registerTypeface(std::move(typeface));
family_it->second->registerTypeface(std::move(typeface));
}

TypefaceFontStyleSet::TypefaceFontStyleSet() = default;
Expand Down
3 changes: 2 additions & 1 deletion third_party/txt/src/txt/typeface_font_asset_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class TypefaceFontAssetProvider : public FontAssetProvider {
SkFontStyleSet* MatchFamily(const std::string& family_name) override;

private:
std::unordered_map<std::string, TypefaceFontStyleSet> registered_families_;
std::unordered_map<std::string, sk_sp<TypefaceFontStyleSet>>
registered_families_;
std::vector<std::string> family_names_;

FML_DISALLOW_COPY_AND_ASSIGN(TypefaceFontAssetProvider);
Expand Down