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/fragment.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/fragment.rs')
-rw-r--r-- | components/layout/fragment.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 8e50d1c499e..45843627493 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -57,7 +57,7 @@ use style::values::generics::transform; use webrender_api::units::LayoutTransform; use webrender_api::{self, ImageKey}; -use crate::context::{with_thread_local_font_context, LayoutContext}; +use crate::context::LayoutContext; use crate::display_list::items::{ClipScrollNodeIndex, OpaqueNode, BLUR_INFLATION_FACTOR}; use crate::display_list::ToLayout; use crate::floats::ClearType; @@ -852,9 +852,8 @@ impl Fragment { ))), ); unscanned_ellipsis_fragments.push_back(ellipsis_fragment); - let ellipsis_fragments = with_thread_local_font_context(layout_context, |font_context| { - TextRunScanner::new().scan_for_runs(font_context, unscanned_ellipsis_fragments) - }); + let ellipsis_fragments = TextRunScanner::new() + .scan_for_runs(&layout_context.font_context, unscanned_ellipsis_fragments); debug_assert_eq!(ellipsis_fragments.len(), 1); ellipsis_fragment = ellipsis_fragments.fragments.into_iter().next().unwrap(); ellipsis_fragment.flags |= FragmentFlags::IS_ELLIPSIS; @@ -2346,9 +2345,10 @@ impl Fragment { return InlineMetrics::new(Au(0), Au(0), Au(0)); } // See CSS 2.1 § 10.8.1. - let font_metrics = with_thread_local_font_context(layout_context, |font_context| { - text::font_metrics_for_style(font_context, self_.style.clone_font()) - }); + let font_metrics = text::font_metrics_for_style( + &layout_context.font_context, + self_.style.clone_font(), + ); let line_height = text::line_height_from_style(&self_.style, &font_metrics); InlineMetrics::from_font_metrics(&info.run.font_metrics, line_height) } @@ -2426,10 +2426,10 @@ impl Fragment { VerticalAlign::Keyword(kw) => match kw { VerticalAlignKeyword::Baseline => {}, VerticalAlignKeyword::Middle => { - let font_metrics = - with_thread_local_font_context(layout_context, |font_context| { - text::font_metrics_for_style(font_context, self.style.clone_font()) - }); + let font_metrics = text::font_metrics_for_style( + &layout_context.font_context, + self.style.clone_font(), + ); offset += (content_inline_metrics.ascent - content_inline_metrics.space_below_baseline - font_metrics.x_height) |