From 9232b0f55070c9a52efd16f8db557486a18bec64 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 27 Jun 2025 17:01:30 +0200 Subject: [PATCH] layout: Only create a `LayoutContext` if restyling (#37726) The creation of `LayoutContext` does more work than necessary if layout just needs to do something like make a display list and not restyle and relayout. This change makes it so that these kind of non-restyle layouts do not need to create a display list. In addition, the creation of `LayoutContext` is better encapsulate Testing: This should not change observable behavior and is thus covered by existing WPT tests. Signed-off-by: Martin Robinson Co-authored-by: Oriol Brufau --- components/layout/context.rs | 95 ++++---- components/layout/display_list/mod.rs | 44 ++-- components/layout/dom_traversal.rs | 14 +- components/layout/flow/root.rs | 15 +- components/layout/formatting_contexts.rs | 4 +- .../layout/fragment_tree/fragment_tree.rs | 1 + components/layout/layout_impl.rs | 216 +++++++++--------- components/layout/replaced.rs | 11 +- components/layout/traversal.rs | 4 +- 9 files changed, 208 insertions(+), 196 deletions(-) diff --git a/components/layout/context.rs b/components/layout/context.rs index 39b24f92025..9efe148ba41 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -4,7 +4,6 @@ use std::sync::Arc; -use base::id::PipelineId; use euclid::Size2D; use fnv::FnvHashMap; use fonts::FontContext; @@ -26,10 +25,8 @@ use webrender_api::units::{DeviceIntSize, DeviceSize}; pub(crate) type CachedImageOrError = Result; -pub struct LayoutContext<'a> { - pub id: PipelineId, +pub(crate) struct LayoutContext<'a> { pub use_rayon: bool, - pub origin: ImmutableOrigin, /// Bits shared by the layout and style system. pub style_context: SharedStyleContext<'a>, @@ -37,31 +34,12 @@ pub struct LayoutContext<'a> { /// A FontContext to be used during layout. pub font_context: Arc, - /// Reference to the script thread image cache. - pub image_cache: Arc, - - /// A list of in-progress image loads to be shared with the script thread. - pub pending_images: Mutex>, - - /// A list of fully loaded vector images that need to be rasterized to a specific - /// size determined by layout. This will be shared with the script thread. - pub pending_rasterization_images: Mutex>, - /// A collection of `