diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-04-12 12:39:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 10:39:32 +0000 |
commit | efa0d457574f02dfbe2403f501a4626acdcb64db (patch) | |
tree | f114f9a1233a111863170b6eea10f02d11d57b37 /components/gfx/font_cache_thread.rs | |
parent | e9591ce62f210d374463bdf1a6d956e19cca81f0 (diff) | |
download | servo-efa0d457574f02dfbe2403f501a4626acdcb64db.tar.gz servo-efa0d457574f02dfbe2403f501a4626acdcb64db.zip |
Remove `FontContextHandle` (#32038)
The `FontContextHandle` was really only used on FreeType platforms to
store the `FT_Library` handle to use for creating faces. Each
`FontContext` and `FontCacheThread` would create its own
`FontContextHandle`. This change removes this data structure in favor of
a mutex-protected shared `FontContextHandle` for an entire Servo
process. The handle is initialized using a `OnceLock` to ensure that it
only happens once and also that it stays alive for the entire process
lifetime.
In addition to greatly simplifying the code, this will make it possible
for different threads to share platform-specific `FontHandle`s, avoiding
multiple allocations for a single font.
The only downside to all of this is that memory usage of FreeType fonts
isn't measured (though the mechanism is still there). This is because
the `FontCacheThread` currently doesn't do any memory measurement.
Eventually this *will* happen though, during the font system redesign.
In exchange, this should reduce the memory usage since there is only a
single FreeType library loaded into memory now.
This is part of #32033.
Diffstat (limited to 'components/gfx/font_cache_thread.rs')
-rw-r--r-- | components/gfx/font_cache_thread.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/components/gfx/font_cache_thread.rs b/components/gfx/font_cache_thread.rs index 5808295a4a3..a5c6a2b0974 100644 --- a/components/gfx/font_cache_thread.rs +++ b/components/gfx/font_cache_thread.rs @@ -26,7 +26,6 @@ use webrender_api::{FontInstanceKey, FontKey}; use crate::font::{FontFamilyDescriptor, FontFamilyName, FontSearchScope}; use crate::font_context::FontSource; use crate::font_template::{FontTemplate, FontTemplateDescriptor}; -use crate::platform::font_context::FontContextHandle; use crate::platform::font_list::{ for_each_available_family, for_each_variation, system_default_family, LocalFontIdentifier, SANS_SERIF_FONT_FAMILY, @@ -75,13 +74,12 @@ impl FontTemplates { pub fn find_font_for_style( &mut self, desc: &FontTemplateDescriptor, - fctx: &FontContextHandle, ) -> Option<Arc<FontTemplateData>> { // TODO(Issue #189): optimize lookup for // regular/bold/italic/bolditalic with fixed offsets and a // static decision table for fallback between these values. for template in &mut self.templates { - let maybe_template = template.data_for_descriptor(fctx, desc); + let maybe_template = template.data_for_descriptor(desc); if maybe_template.is_some() { return maybe_template; } @@ -91,8 +89,7 @@ impl FontTemplates { // TODO(#190): Do a better job. let (mut best_template_data, mut best_distance) = (None, f32::MAX); for template in &mut self.templates { - if let Some((template_data, distance)) = - template.data_for_approximate_descriptor(fctx, desc) + if let Some((template_data, distance)) = template.data_for_approximate_descriptor(desc) { if distance < best_distance { best_template_data = Some(template_data); @@ -159,7 +156,6 @@ struct FontCache { generic_fonts: HashMap<FontFamilyName, LowercaseString>, local_families: HashMap<LowercaseString, FontTemplates>, web_families: HashMap<LowercaseString, FontTemplates>, - font_context: FontContextHandle, core_resource_thread: CoreResourceThread, webrender_api: Box<dyn WebrenderApi>, webrender_fonts: HashMap<FontIdentifier, FontKey>, @@ -404,7 +400,7 @@ impl FontCache { // TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'. // if such family exists, try to match style to a font - s.find_font_for_style(template_descriptor, &self.font_context) + s.find_font_for_style(template_descriptor) } else { debug!( "FontList: Couldn't find font family with name={}", @@ -423,7 +419,7 @@ impl FontCache { if self.web_families.contains_key(&family_name) { let templates = self.web_families.get_mut(&family_name).unwrap(); - templates.find_font_for_style(template_descriptor, &self.font_context) + templates.find_font_for_style(template_descriptor) } else { None } @@ -498,7 +494,6 @@ impl FontCacheThread { generic_fonts, local_families: HashMap::new(), web_families: HashMap::new(), - font_context: FontContextHandle::default(), core_resource_thread, webrender_api, webrender_fonts: HashMap::new(), |