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_2020/flow/inline.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_2020/flow/inline.rs')
-rw-r--r-- | components/layout_2020/flow/inline.rs | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs index cadf5840e32..047cfc7087d 100644 --- a/components/layout_2020/flow/inline.rs +++ b/components/layout_2020/flow/inline.rs @@ -1638,10 +1638,9 @@ impl InlineFormattingContext { // It's unfortunate that it isn't possible to get this during IFC text processing, but in // that situation the style of the containing block is unknown. - let default_font_metrics = layout_context.with_font_context(|font_context| { - get_font_for_first_font_for_style(style, font_context) - .map(|font| font.borrow().metrics.clone()) - }); + let default_font_metrics = + get_font_for_first_font_for_style(style, &layout_context.font_context) + .map(|font| font.metrics.clone()); let style_text = containing_block.style.get_inherited_text(); let mut ifc = InlineFormattingContextState { @@ -1768,34 +1767,30 @@ impl InlineFormattingContext { // For the purposes of `text-transform: capitalize` the start of the IFC is a word boundary. let mut on_word_boundary = true; - layout_context.with_font_context(|font_context| { - let mut linebreaker = None; - self.foreach(|iter_item| match iter_item { - InlineFormattingContextIterItem::Item(InlineLevelBox::TextRun( - ref mut text_run, - )) => { - text_run.break_and_shape( - font_context, - &mut linebreaker, - &mut ifc_fonts, - &mut last_inline_box_ended_with_white_space, - &mut on_word_boundary, - ); - }, - InlineFormattingContextIterItem::Item(InlineLevelBox::InlineBox(inline_box)) => { - if let Some(font) = - get_font_for_first_font_for_style(&inline_box.style, font_context) - { - inline_box.default_font_index = - Some(add_or_get_font(&font, &mut ifc_fonts)); - } - }, - InlineFormattingContextIterItem::Item(InlineLevelBox::Atomic(_)) => { - last_inline_box_ended_with_white_space = false; - on_word_boundary = true; - }, - _ => {}, - }); + let mut linebreaker = None; + self.foreach(|iter_item| match iter_item { + InlineFormattingContextIterItem::Item(InlineLevelBox::TextRun(ref mut text_run)) => { + text_run.break_and_shape( + &layout_context.font_context, + &mut linebreaker, + &mut ifc_fonts, + &mut last_inline_box_ended_with_white_space, + &mut on_word_boundary, + ); + }, + InlineFormattingContextIterItem::Item(InlineLevelBox::InlineBox(inline_box)) => { + if let Some(font) = get_font_for_first_font_for_style( + &inline_box.style, + &layout_context.font_context, + ) { + inline_box.default_font_index = Some(add_or_get_font(&font, &mut ifc_fonts)); + } + }, + InlineFormattingContextIterItem::Item(InlineLevelBox::Atomic(_)) => { + last_inline_box_ended_with_white_space = false; + on_word_boundary = true; + }, + _ => {}, }); self.font_metrics = ifc_fonts; |