diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-05-02 12:34:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 10:34:10 +0000 |
commit | 556bfb7dff48f64e9e02872dba29fbdabc8c6ad0 (patch) | |
tree | 0c9e1e80582fee2a64aa5904df3230e8a3d2befd /components/layout/construct.rs | |
parent | 8ec5344f70dd1d556cacd72d778924048b0b1154 (diff) | |
download | servo-556bfb7dff48f64e9e02872dba29fbdabc8c6ad0.tar.gz servo-556bfb7dff48f64e9e02872dba29fbdabc8c6ad0.zip |
fonts: Make `FontContext` thread-safe and share it per-Layout (#32205)
This allows sharing font templates, fonts, and platform fonts across
layout threads. It's the first step toward storing web fonts in the
layout versus the shared `FontCacheThread`. Now fonts and font groups
have some locking (especially on FreeType), which will probably affect
performance. On the other hand, we measured memory usage and this saves
roughly 40 megabytes of memory when loading servo.org based on data from
the memory profiler.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Diffstat (limited to 'components/layout/construct.rs')
-rw-r--r-- | components/layout/construct.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 522635543fd..1c4eff55898 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -42,7 +42,7 @@ use style::values::generics::counters::ContentItem; use style::LocalName; use crate::block::BlockFlow; -use crate::context::{with_thread_local_font_context, LayoutContext}; +use crate::context::LayoutContext; use crate::data::{InnerLayoutData, LayoutDataFlags}; use crate::display_list::items::OpaqueNode; use crate::flex::FlexFlow; @@ -517,11 +517,10 @@ where // We must scan for runs before computing minimum ascent and descent because scanning // for runs might collapse so much whitespace away that only hypothetical fragments // remain. In that case the inline flow will compute its ascent and descent to be zero. - let scanned_fragments = - with_thread_local_font_context(self.layout_context, |font_context| { - TextRunScanner::new() - .scan_for_runs(font_context, mem::take(&mut fragments.fragments)) - }); + let scanned_fragments = TextRunScanner::new().scan_for_runs( + &self.layout_context.font_context, + mem::take(&mut fragments.fragments), + ); let mut inline_flow_ref = FlowRef::new(Arc::new(InlineFlow::from_fragments( scanned_fragments, node.style(self.style_context()).writing_mode, @@ -550,11 +549,10 @@ where { // FIXME(#6503): Use Arc::get_mut().unwrap() here. let inline_flow = FlowRef::deref_mut(&mut inline_flow_ref).as_mut_inline(); - inline_flow.minimum_line_metrics = - with_thread_local_font_context(self.layout_context, |font_context| { - inline_flow - .minimum_line_metrics(font_context, &node.style(self.style_context())) - }); + inline_flow.minimum_line_metrics = inline_flow.minimum_line_metrics( + &self.layout_context.font_context, + &node.style(self.style_context()), + ); } inline_flow_ref.finish(); @@ -1545,11 +1543,10 @@ where )), self.layout_context, )); - let marker_fragments = - with_thread_local_font_context(self.layout_context, |font_context| { - TextRunScanner::new() - .scan_for_runs(font_context, unscanned_marker_fragments) - }); + let marker_fragments = TextRunScanner::new().scan_for_runs( + &self.layout_context.font_context, + unscanned_marker_fragments, + ); marker_fragments.fragments }, ListStyleTypeContent::GeneratedContent(info) => vec![Fragment::new( |