aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/webrender/lib.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-06-18 16:02:27 +0200
committerGitHub <noreply@github.com>2024-06-18 14:02:27 +0000
commitfef1337da0f5bfed27225972e33d8c94d38bfbb3 (patch)
treecd9f7db68402ea92da91294968b13fd1193d5a23 /components/shared/webrender/lib.rs
parentbd15a4fbd803d2a7d73f440efd741d98f7cc72a6 (diff)
downloadservo-fef1337da0f5bfed27225972e33d8c94d38bfbb3.tar.gz
servo-fef1337da0f5bfed27225972e33d8c94d38bfbb3.zip
fonts: Clean up WebRender web fonts when they are no longer used (#32545)
This is the first part of cleaning up unused WebRender resources. Currently this only cleans up web font resources, but a more full-featured implementation in the future could also clean up unused system fonts. Fixes #32345. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Diffstat (limited to 'components/shared/webrender/lib.rs')
-rw-r--r--components/shared/webrender/lib.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/components/shared/webrender/lib.rs b/components/shared/webrender/lib.rs
index e5a794fccf0..718d53e44a1 100644
--- a/components/shared/webrender/lib.rs
+++ b/components/shared/webrender/lib.rs
@@ -191,16 +191,18 @@ pub trait WebRenderFontApi {
flags: FontInstanceFlags,
) -> FontInstanceKey;
fn add_font(&self, data: Arc<Vec<u8>>, index: u32) -> FontKey;
- /// Forward an already prepared `AddFont` message, sending it on to the compositor. This is used
- /// to get WebRender [`FontKey`]s for web fonts in the per-layout `FontContext`.
+ fn add_system_font(&self, handle: NativeFontHandle) -> FontKey;
+
+ /// Forward a `AddFont` message, sending it on to the compositor. This is used to get WebRender
+ /// [`FontKey`]s for web fonts in the per-layout `FontContext`.
fn forward_add_font_message(
&self,
bytes_receiver: IpcBytesReceiver,
font_index: u32,
result_sender: IpcSender<FontKey>,
);
- /// Forward an already prepared `AddFontInstance` message, sending it on to the compositor. This
- /// is used to get WebRender [`FontInstanceKey`]s for web fonts in the per-layout `FontContext`.
+ /// Forward a `AddFontInstance` message, sending it on to the compositor. This is used to get
+ /// WebRender [`FontInstanceKey`]s for web fonts in the per-layout `FontContext`.
fn forward_add_font_instance_message(
&self,
font_key: FontKey,
@@ -208,7 +210,6 @@ pub trait WebRenderFontApi {
flags: FontInstanceFlags,
result_receiver: IpcSender<FontInstanceKey>,
);
- fn add_system_font(&self, handle: NativeFontHandle) -> FontKey;
}
pub enum CanvasToCompositorMsg {
@@ -257,6 +258,8 @@ pub enum ScriptToCompositorMsg {
GenerateImageKey(IpcSender<ImageKey>),
/// Perform a resource update operation.
UpdateImages(Vec<SerializedImageUpdate>),
+ /// Remove the given font resources from our WebRender instance.
+ RemoveFonts(Vec<FontKey>, Vec<FontInstanceKey>),
}
/// A mechanism to send messages from networking to the WebRender instance.
@@ -420,6 +423,19 @@ impl WebRenderScriptApi {
}
});
}
+
+ pub fn remove_unused_font_resources(
+ &self,
+ keys: Vec<FontKey>,
+ instance_keys: Vec<FontInstanceKey>,
+ ) {
+ if keys.is_empty() && instance_keys.is_empty() {
+ return;
+ }
+ let _ = self
+ .0
+ .send(ScriptToCompositorMsg::RemoveFonts(keys, instance_keys));
+ }
}
#[derive(Deserialize, Serialize)]