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_template.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_template.rs')
-rw-r--r-- | components/gfx/font_template.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/components/gfx/font_template.rs b/components/gfx/font_template.rs index 00d95159632..66db059db13 100644 --- a/components/gfx/font_template.rs +++ b/components/gfx/font_template.rs @@ -15,7 +15,6 @@ use style::values::computed::font::FontWeight; use crate::font::FontHandleMethods; use crate::font_cache_thread::FontIdentifier; use crate::platform::font::FontHandle; -use crate::platform::font_context::FontContextHandle; use crate::platform::font_template::FontTemplateData; /// Describes how to select a font from a given family. This is very basic at the moment and needs @@ -130,10 +129,7 @@ impl FontTemplate { } /// Get the descriptor. Returns `None` when instantiating the data fails. - pub fn descriptor( - &mut self, - font_context: &FontContextHandle, - ) -> Option<FontTemplateDescriptor> { + pub fn descriptor(&mut self) -> Option<FontTemplateDescriptor> { // The font template data can be unloaded when nothing is referencing // it (via the Weak reference to the Arc above). However, if we have // already loaded a font, store the style information about it separately, @@ -141,7 +137,7 @@ impl FontTemplate { // without having to reload the font (unless it is an actual match). self.descriptor.or_else(|| { - if self.instantiate(font_context).is_err() { + if self.instantiate().is_err() { return None; }; @@ -155,10 +151,9 @@ impl FontTemplate { /// Get the data for creating a font if it matches a given descriptor. pub fn data_for_descriptor( &mut self, - fctx: &FontContextHandle, requested_desc: &FontTemplateDescriptor, ) -> Option<Arc<FontTemplateData>> { - self.descriptor(fctx).and_then(|descriptor| { + self.descriptor().and_then(|descriptor| { if *requested_desc == descriptor { self.data().ok() } else { @@ -171,23 +166,22 @@ impl FontTemplate { /// descriptor, if the font can be loaded. pub fn data_for_approximate_descriptor( &mut self, - font_context: &FontContextHandle, requested_descriptor: &FontTemplateDescriptor, ) -> Option<(Arc<FontTemplateData>, f32)> { - self.descriptor(font_context).and_then(|descriptor| { + self.descriptor().and_then(|descriptor| { self.data() .ok() .map(|data| (data, descriptor.distance_from(requested_descriptor))) }) } - fn instantiate(&mut self, font_context: &FontContextHandle) -> Result<(), &'static str> { + fn instantiate(&mut self) -> Result<(), &'static str> { if !self.is_valid { return Err("Invalid font template"); } let data = self.data().map_err(|_| "Could not get FontTemplate data")?; - let handle = FontHandleMethods::new_from_template(font_context, data, None); + let handle = FontHandleMethods::new_from_template(data, None); self.is_valid = handle.is_ok(); let handle: FontHandle = handle?; self.descriptor = Some(FontTemplateDescriptor::new( |