aboutsummaryrefslogtreecommitdiffstats
path: root/components/fonts/font.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-10-01 17:31:26 +0200
committerGitHub <noreply@github.com>2024-10-01 15:31:26 +0000
commitabad89a49c1fbad584627deaa7440f50a5cc9912 (patch)
tree52d1d8ba2f57d884e547b15b0df8451233c0ccc9 /components/fonts/font.rs
parent05ecb8eddb3989ffcee51df5c2c86887fee8b7e8 (diff)
downloadservo-abad89a49c1fbad584627deaa7440f50a5cc9912.tar.gz
servo-abad89a49c1fbad584627deaa7440f50a5cc9912.zip
fonts: Make `FontKey` and `FontInstanceKey` generation asynchronous (#33600)
Instead of a blocking a layout thread on the generation of WebRender `FontKey`s and `FontInstanceKey`s, generate the keys ahead of time and send the font data to WebRender asynchronously. This has the benefit of allowing use of the font much more quickly in layout, though blocking display list sending itself on the font data upload. In order to make this work for web fonts, `FontContext` now asks the `SystemFontService` for a `FontKey`s and `FontInstanceKey`s for new web fonts. This should happen much more quickly as the `SystemFontService` is only blocking in order to load system fonts into memory now. In practice this still drops layout thread blocking to fractions of a millisecond instead of multiple milliseconds as before. In addition, ensure that we don't send font data or generate keys for fonts that are used in layout but never added to display lists. This should help to reduce memory usage and increase performance. Performance of this change was verified by putting a microbenchmark around `FontContext::create_font` which is what triggered font key generation. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/fonts/font.rs')
-rw-r--r--components/fonts/font.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/components/fonts/font.rs b/components/fonts/font.rs
index 47de63bad2c..dce89c78746 100644
--- a/components/fonts/font.rs
+++ b/components/fonts/font.rs
@@ -224,7 +224,7 @@ pub struct Font {
pub descriptor: FontDescriptor,
shaper: OnceLock<Shaper>,
cached_shape_data: RwLock<CachedShapeData>,
- pub font_key: FontInstanceKey,
+ pub font_instance_key: OnceLock<FontInstanceKey>,
/// If this is a synthesized small caps font, then this font reference is for
/// the version of the font used to replace lowercase ASCII letters. It's up
@@ -252,7 +252,9 @@ impl malloc_size_of::MallocSizeOf for Font {
self.metrics.size_of(ops) +
self.descriptor.size_of(ops) +
self.cached_shape_data.read().size_of(ops) +
- self.font_key.size_of(ops)
+ self.font_instance_key
+ .get()
+ .map_or(0, |key| key.size_of(ops))
}
}
@@ -278,7 +280,7 @@ impl Font {
descriptor,
metrics,
cached_shape_data: Default::default(),
- font_key: FontInstanceKey::default(),
+ font_instance_key: Default::default(),
synthesized_small_caps,
has_color_bitmap_or_colr_table: OnceLock::new(),
can_do_fast_shaping: OnceLock::new(),
@@ -301,6 +303,12 @@ impl Font {
self.table_for_tag(COLR).is_some()
})
}
+
+ pub fn key(&self, font_context: &FontContext) -> FontInstanceKey {
+ *self
+ .font_instance_key
+ .get_or_init(|| font_context.create_font_instance_key(self))
+ }
}
bitflags! {