aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/webrender/lib.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/shared/webrender/lib.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/shared/webrender/lib.rs')
-rw-r--r--components/shared/webrender/lib.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/components/shared/webrender/lib.rs b/components/shared/webrender/lib.rs
index accb73df316..58580175e7d 100644
--- a/components/shared/webrender/lib.rs
+++ b/components/shared/webrender/lib.rs
@@ -186,12 +186,18 @@ impl ExternalImageHandler for WebrenderExternalImageHandlers {
pub trait WebRenderFontApi {
fn add_font_instance(
&self,
+ font_instance_key: FontInstanceKey,
font_key: FontKey,
size: f32,
flags: FontInstanceFlags,
- ) -> FontInstanceKey;
- fn add_font(&self, data: Arc<IpcSharedMemory>, index: u32) -> FontKey;
- fn add_system_font(&self, handle: NativeFontHandle) -> FontKey;
+ );
+ fn add_font(&self, font_key: FontKey, data: Arc<IpcSharedMemory>, index: u32);
+ fn add_system_font(&self, font_key: FontKey, handle: NativeFontHandle);
+ fn fetch_font_keys(
+ &self,
+ number_of_font_keys: usize,
+ number_of_font_instance_keys: usize,
+ ) -> (Vec<FontKey>, Vec<FontInstanceKey>);
}
pub enum CanvasToCompositorMsg {
@@ -200,9 +206,10 @@ pub enum CanvasToCompositorMsg {
}
pub enum FontToCompositorMsg {
- AddFontInstance(FontKey, f32, FontInstanceFlags, Sender<FontInstanceKey>),
- AddFont(Sender<FontKey>, u32, Arc<IpcSharedMemory>),
- AddSystemFont(Sender<FontKey>, NativeFontHandle),
+ GenerateKeys(usize, usize, Sender<(Vec<FontKey>, Vec<FontInstanceKey>)>),
+ AddFontInstance(FontInstanceKey, FontKey, f32, FontInstanceFlags),
+ AddFont(FontKey, u32, Arc<IpcSharedMemory>),
+ AddSystemFont(FontKey, NativeFontHandle),
}
#[derive(Deserialize, Serialize)]
@@ -242,8 +249,8 @@ pub enum ScriptToCompositorMsg {
UpdateImages(Vec<SerializedImageUpdate>),
/// Remove the given font resources from our WebRender instance.
RemoveFonts(Vec<FontKey>, Vec<FontInstanceKey>),
- AddFontInstance(FontKey, f32, FontInstanceFlags, IpcSender<FontInstanceKey>),
- AddFont(Arc<IpcSharedMemory>, u32, IpcSender<FontKey>),
+ AddFontInstance(FontInstanceKey, FontKey, f32, FontInstanceFlags),
+ AddFont(FontKey, Arc<IpcSharedMemory>, u32),
}
/// A mechanism to send messages from networking to the WebRender instance.