aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_thread_2020
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-05-23 08:49:31 +0200
committerGitHub <noreply@github.com>2024-05-23 06:49:31 +0000
commit14286d913d5a88647fad2255f06bec0763914e55 (patch)
treebb54e1ce8b3b2c4f328d68cfc99bd4a300a64df8 /components/layout_thread_2020
parenta772ecf786bda74cd5202b9ca6fb2d487cc61b94 (diff)
downloadservo-14286d913d5a88647fad2255f06bec0763914e55.tar.gz
servo-14286d913d5a88647fad2255f06bec0763914e55.zip
fonts: Remove web fonts when their stylsheet is removed (#32346)
This is the first part of ensuring that unused fonts do not leak. This change makes it so that when a stylesheet is removed, the corresponding web fonts are removed from the `FontContext`. Note: WebRender assets are still leaked, which was the situation before for all fonts. A followup change will fix this issue. Fixes #15139. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Diffstat (limited to 'components/layout_thread_2020')
-rw-r--r--components/layout_thread_2020/lib.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs
index b9cc25fbc7d..63af1c98349 100644
--- a/components/layout_thread_2020/lib.rs
+++ b/components/layout_thread_2020/lib.rs
@@ -249,7 +249,10 @@ impl Layout for LayoutThread {
fn load_web_fonts_from_stylesheet(&self, stylesheet: ServoArc<Stylesheet>) {
let guard = stylesheet.shared_lock.read();
- self.load_all_web_fonts_from_stylesheet_with_guard(&stylesheet, &guard);
+ self.load_all_web_fonts_from_stylesheet_with_guard(
+ &DocumentStyleSheet(stylesheet.clone()),
+ &guard,
+ );
}
fn add_stylesheet(
@@ -258,25 +261,25 @@ impl Layout for LayoutThread {
before_stylesheet: Option<ServoArc<Stylesheet>>,
) {
let guard = stylesheet.shared_lock.read();
+ let stylesheet = DocumentStyleSheet(stylesheet.clone());
self.load_all_web_fonts_from_stylesheet_with_guard(&stylesheet, &guard);
match before_stylesheet {
Some(insertion_point) => self.stylist.insert_stylesheet_before(
- DocumentStyleSheet(stylesheet.clone()),
+ stylesheet,
DocumentStyleSheet(insertion_point),
&guard,
),
- None => self
- .stylist
- .append_stylesheet(DocumentStyleSheet(stylesheet.clone()), &guard),
+ None => self.stylist.append_stylesheet(stylesheet, &guard),
}
}
fn remove_stylesheet(&mut self, stylesheet: ServoArc<Stylesheet>) {
- // TODO(mrobinson): This should also unload web fonts from the FontCacheThread.
let guard = stylesheet.shared_lock.read();
- self.stylist
- .remove_stylesheet(DocumentStyleSheet(stylesheet.clone()), &guard);
+ let stylesheet = DocumentStyleSheet(stylesheet.clone());
+ self.stylist.remove_stylesheet(stylesheet.clone(), &guard);
+ self.font_context
+ .remove_all_web_fonts_from_stylesheet(&stylesheet);
}
fn query_content_box(&self, node: OpaqueNode) -> Option<UntypedRect<Au>> {
@@ -584,7 +587,7 @@ impl LayoutThread {
fn load_all_web_fonts_from_stylesheet_with_guard(
&self,
- stylesheet: &Stylesheet,
+ stylesheet: &DocumentStyleSheet,
guard: &SharedRwLockReadGuard,
) {
if !stylesheet.is_effective_for_device(self.stylist.device(), guard) {
@@ -651,10 +654,7 @@ impl LayoutThread {
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
self.stylist
.append_stylesheet(stylesheet.clone(), &ua_or_user_guard);
- self.load_all_web_fonts_from_stylesheet_with_guard(
- &stylesheet.0,
- &ua_or_user_guard,
- );
+ self.load_all_web_fonts_from_stylesheet_with_guard(stylesheet, &ua_or_user_guard);
}
if self.stylist.quirks_mode() != QuirksMode::NoQuirks {
@@ -663,7 +663,7 @@ impl LayoutThread {
&ua_or_user_guard,
);
self.load_all_web_fonts_from_stylesheet_with_guard(
- &ua_stylesheets.quirks_mode_stylesheet.0,
+ &ua_stylesheets.quirks_mode_stylesheet,
&ua_or_user_guard,
);
}