Truly independent web browser
LibWeb: Keep the layout arena's update marks and overflow queue plain
Aliaksandr Kalenik7fadba7336b7
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex ca8b9bb3899..d096310a8fe 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1242,7 +1242,7 @@ pub(crate) struct LayoutNodeArena {/// under a key so that it survives the node's identity being retired and re-issued.next_rows_built_for_same_node: Vec<NodeSlotId>,/// What writes since the layout stage last looked did to the boxes its run memos hold entries of.- memo_invalidations: RefCell<super::memo_invalidations::MemoInvalidations>,+ memo_invalidations: super::memo_invalidations::MemoInvalidations,pub(super) layout_trace: super::trace::LayoutTrace,pub(crate) paintable_rows: crate::painting::paintable_rows::PaintableRowStore,paint_state: RefCell<crate::painting::paint_state::PaintState>,@@ -1271,8 +1271,8 @@ pub(crate) struct LayoutNodeArena {/// this escape bit is set. Partial relayout may only run while the bit is clear; a full/// layout pass re-derives every fact boundary qualification depends on, so it clears the bit.pub(crate) pending_updates_escape_partial_relayout: bool,- pub(crate) boxes_needing_scrollable_overflow_recalculation: RefCell<Vec<NodeSlotId>>,- pub(crate) needs_full_scrollable_overflow_recalculation: Cell<bool>,+ pub(crate) boxes_needing_scrollable_overflow_recalculation: Vec<NodeSlotId>,+ pub(crate) needs_full_scrollable_overflow_recalculation: bool,text_nodes_enrolled_for_content_sync: HashSet<NodeSlotId>,/// The scroll containers a running tree build gave a style, which may be where scroll/// snapping happens once the build is over.@@ -1301,7 +1301,7 @@ pub(crate) struct LayoutNodeArena {/// The rows the layout commit in progress gathers for the style engine's container queries.pub(crate) layout_style_snapshot_commit: Vec<super::style_snapshot::CommittedGeometry>,/// What the DOM has asked the next layout tree build to rebuild, by style node identity.- layout_tree_update_marks: RefCell<super::tree_update_marks::LayoutTreeUpdateMarks>,+ layout_tree_update_marks: super::tree_update_marks::LayoutTreeUpdateMarks,/// The counter styles each tree scope registers. The rule cache that settles them is C++'s,/// and the document owns the result because a fallback chain is followed from the scope the/// counter is used in, not from the scope the style was written in.@@ -1357,7 +1357,7 @@ impl LayoutNodeArena {layer_image_paint_facts: Default::default(),svg_paint_resources: crate::painting::svg_paint_resources::SvgPaintResources::default(),next_rows_built_for_same_node: Vec::new(),- memo_invalidations: RefCell::default(),+ memo_invalidations: Default::default(),layout_trace: super::trace::LayoutTrace::default(),paintable_rows: crate::painting::paintable_rows::PaintableRowStore::default(),paint_state: RefCell::new(crate::painting::paint_state::PaintState::default()),@@ -1373,8 +1373,8 @@ impl LayoutNodeArena {inline_boxes_lifted_out_of: HashMap::default(),out_of_flow_positioning_contained: HashMap::default(),pending_updates_escape_partial_relayout: false,- boxes_needing_scrollable_overflow_recalculation: RefCell::new(Vec::new()),- needs_full_scrollable_overflow_recalculation: Cell::new(false),+ boxes_needing_scrollable_overflow_recalculation: Vec::new(),+ needs_full_scrollable_overflow_recalculation: false,text_nodes_enrolled_for_content_sync: HashSet::default(),built_scroll_containers: Default::default(),image_resources_owed_to_host: Default::default(),@@ -1386,7 +1386,7 @@ impl LayoutNodeArena {document_svg_root_natural_size: None,handed_over_document_svg_root_natural_size: (None),layout_style_snapshot_commit: Vec::new(),- layout_tree_update_marks: RefCell::default(),+ layout_tree_update_marks: Default::default(),counter_styles: Default::default(),style_node_tables: StyleNodeTables::default(),}@@ -1436,8 +1436,8 @@ impl LayoutNodeArena {}/// What writes did to the boxes the layout stage's run memos hold entries of since the stage last took it.- pub(crate) fn take_memo_invalidations(&self) -> super::memo_invalidations::MemoInvalidations {- self.memo_invalidations.take()+ pub(crate) fn take_memo_invalidations(&mut self) -> super::memo_invalidations::MemoInvalidations {+ std::mem::take(&mut self.memo_invalidations)}/// Drops the entries of `store` whose slot or epoch no longer matches, marks the entry whose fragments each box@@ -1650,10 +1650,8 @@ impl LayoutNodeArena {self.scrollable_overflow.full_layout_commit.set(false);self.scrollable_overflow.geometry_changed.set(false);self.scrollable_overflow.scrollability_changed.set(false);- self.boxes_needing_scrollable_overflow_recalculation- .borrow_mut()- .clear();- self.needs_full_scrollable_overflow_recalculation.set(false);+ self.boxes_needing_scrollable_overflow_recalculation.clear();+ self.needs_full_scrollable_overflow_recalculation = false;}let mut rows = Vec::new();self.for_each_node_in_layout_subtree_in_pre_order(root, |slot| rows.push(slot));@@ -1745,7 +1743,7 @@ impl LayoutNodeArena {}self.owned_image_natural_sizes.remove(&id);self.owned_image_providers.remove(&id);- self.memo_invalidations.get_mut().note_slot_freed(index);+ self.memo_invalidations.note_slot_freed(index);self.remove_layout_update_flag_node(id);self.math_layout_kinds.remove(&id);if self.replaced_paint_facts.contains_key(&id) {@@ -1878,45 +1876,48 @@ impl LayoutNodeArena {self.dom_node_style_node(id).map(StyleNodeID::raw)}- pub(crate) fn layout_tree_update_marks(&self) -> &RefCell<super::tree_update_marks::LayoutTreeUpdateMarks> {+ pub(crate) fn layout_tree_update_marks(&self) -> &super::tree_update_marks::LayoutTreeUpdateMarks {&self.layout_tree_update_marks}+ pub(crate) fn layout_tree_update_marks_mut(&mut self) -> &mut super::tree_update_marks::LayoutTreeUpdateMarks {+ &mut self.layout_tree_update_marks+ }+/// Retires the layout tree update marks of a node whose stale box was cleared: its own, and its/// host's when the node is a shadow root whose own mark was what marked the host, as clearing a/// mark through the DOM does, and its children's summary.- pub(crate) fn retire_layout_tree_update_marks_of_cleared_node(&self, node: StyleNodeID) {- let mut marks = self.layout_tree_update_marks().borrow_mut();+ pub(crate) fn retire_layout_tree_update_marks_of_cleared_node(&mut self, node: StyleNodeID) {let mut current = node;- while marks.merge(current, false, 0) {+ while self.layout_tree_update_marks.merge(current, false, 0) {let Some(host) = self.with_style_store(|engine| engine.tree().host_of(current)) else {break;};current = host;}- marks.set_child_needs(node, false);+ self.layout_tree_update_marks.set_child_needs(node, false);}/// Retire the layout tree update marks `style_node` holds, own and child alike.- pub(crate) fn clear_layout_tree_update_marks(&self, style_node: Option<StyleNodeID>) {+ pub(crate) fn clear_layout_tree_update_marks(&mut self, style_node: Option<StyleNodeID>) {if let Some(style_node) = style_node {- self.layout_tree_update_marks.borrow_mut().clear(style_node);+ self.layout_tree_update_marks.clear(style_node);}}/// Whether `style_node` itself holds a layout tree update mark.pub(crate) fn needs_layout_tree_update(&self, style_node: StyleNodeID) -> bool {- self.layout_tree_update_marks.borrow().needs(style_node)+ self.layout_tree_update_marks.needs(style_node)}/// Which narrower rebuilds the layout tree update marks `style_node` collected still permit.pub(crate) fn layout_tree_update_reuse_reasons(&self, style_node: StyleNodeID) -> u8 {- self.layout_tree_update_marks.borrow().reuse_reasons(style_node)+ self.layout_tree_update_marks.reuse_reasons(style_node)}/// Whether a flat-tree descendant of `style_node` holds a layout tree update mark.pub(crate) fn child_needs_layout_tree_update(&self, style_node: Option<StyleNodeID>) -> bool {- style_node.is_some_and(|style_node| self.layout_tree_update_marks.borrow().child_needs(style_node))+ style_node.is_some_and(|style_node| self.layout_tree_update_marks.child_needs(style_node))}fn set_node_style_node(&mut self, id: NodeSlotId, style_node: Option<StyleNodeID>) {@@ -4767,15 +4768,16 @@ impl LayoutNodeArena {/// A style change reaches the anonymous boxes below the node without rebuilding them, and/// they take some of their ancestor facts from it.- fn refresh_ancestor_facts_of_anonymous_children(&self, parent: NodeSlotId) {+ fn refresh_ancestor_facts_of_anonymous_children(&mut self, parent: NodeSlotId) {let mut child = self.data(parent).first_child.get();while !child.is_invalid() {- let data = self.data(child);- if super::node_facts::has_flag(data, NodeFlag::Anonymous) && self.derive_ancestor_facts_for_node(child) {+ if super::node_facts::has_flag(self.data(child), NodeFlag::Anonymous)+ && self.derive_ancestor_facts_for_node(child)+ {self.bump_fragment_cache_epoch_of_self_and_ancestors(child);self.refresh_ancestor_facts_of_anonymous_children(child);}- child = data.next_sibling.get();+ child = self.data(child).next_sibling.get();}}@@ -5279,9 +5281,7 @@ impl LayoutNodeArena {pub(crate) fn clear_committed_fragment_link(&mut self, id: NodeSlotId) {// Cached runs may reuse the committed paintable subtree without replaying its fragments.// Once that subtree is cleared, a later layout must rebuild it instead.- self.memo_invalidations- .borrow_mut()- .note_run_cache_entries_dropped(id.slot_index());+ self.memo_invalidations.note_run_cache_entries_dropped(id.slot_index());self.note_subtrees_of_self_and_ancestors_committed_anew(id);drop(self.take_committed_fragment_link(self.data(id)));}@@ -5367,7 +5367,7 @@ impl LayoutNodeArena {}state.content = Some(content);drop(state);- self.memo_invalidations.get_mut().note_text_replaced(id.slot_index());+ self.memo_invalidations.note_text_replaced(id.slot_index());self.searchable_text = None;// Publication can happen through a C++ text read before the enrolled// sync runs. Invalidate here so every publication invalidates layout,@@ -5628,7 +5628,7 @@ impl LayoutNodeArena {// parent pass sizing a child navigable's viewport invalidates the child document), so only// this arena's own pass may not see one. A bump landing between a run's probe and its store// is handled by storing the probe-time validity, which turns it into a fail-safe miss.- fn invalidate_at_and_above(&self, mut node: NodeSlotId, invalidation: AncestorInvalidation) {+ fn invalidate_at_and_above(&mut self, mut node: NodeSlotId, invalidation: AncestorInvalidation) {while !node.is_invalid() {self.invalidate_one(node, invalidation);node = self.data(node).parent.get();@@ -5636,9 +5636,9 @@ impl LayoutNodeArena {}/// The part of `invalidate_at_and_above` that applies to one node, for walks that also do other work on the way up.- pub(super) fn invalidate_one(&self, node: NodeSlotId, invalidation: AncestorInvalidation) {+ pub(super) fn invalidate_one(&mut self, node: NodeSlotId, invalidation: AncestorInvalidation) {if invalidation == AncestorInvalidation::StructuralChange {- self.memo_invalidations.borrow_mut().note_structural_inline_change(node);+ self.memo_invalidations.note_structural_inline_change(node);}self.bump_fragment_cache_epoch(node);if super::node_facts::kind_is_box(self.data(node).kind.get()) {@@ -5646,7 +5646,7 @@ impl LayoutNodeArena {}}- pub(super) fn bump_fragment_cache_epoch(&self, node: NodeSlotId) {+ pub(super) fn bump_fragment_cache_epoch(&mut self, node: NodeSlotId) {let data = self.data(node);let epoch = data.fragment_cache_epoch.get().wrapping_add(1);data.fragment_cache_epoch.set(epoch);@@ -5657,16 +5657,14 @@ impl LayoutNodeArena {!self.layout_pass_is_running(),"a node's committed fragments became stale while a layout pass ran");- self.memo_invalidations- .borrow_mut()- .note_fragment_cache_epoch_bumped(node);+ self.memo_invalidations.note_fragment_cache_epoch_bumped(node);}- pub(crate) fn note_structural_change_at_and_above(&self, node: NodeSlotId) {+ pub(crate) fn note_structural_change_at_and_above(&mut self, node: NodeSlotId) {self.invalidate_at_and_above(node, AncestorInvalidation::StructuralChange);}- pub(crate) fn bump_fragment_cache_epoch_of_self_and_ancestors(&self, node: NodeSlotId) {+ pub(crate) fn bump_fragment_cache_epoch_of_self_and_ancestors(&mut self, node: NodeSlotId) {self.invalidate_at_and_above(node, AncestorInvalidation::ContentChange);}@@ -6293,7 +6291,7 @@ pub extern "C" fn render_state_layout_is_up_to_date(host: &DocumentHost, documenhost.ask(here, |state| {let arena = state.arena_mut();let document_needs_layout_tree_build = document.is_some_and(|document| {- let marks = arena.layout_tree_update_marks().borrow();+ let marks = arena.layout_tree_update_marks();marks.needs(document) || marks.child_needs(document)});arena.layout_is_up_to_date(document_needs_layout_tree_build)diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex 38be754dcb6..6ee54bdf177 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -678,7 +678,7 @@ impl LayoutNodeArena {/// What a box that is not laid out again still owes a child list change that stays inside its/// children: the cached runs that describe the old list, and the paint that depends on it.- fn note_contained_child_list_change(&self, parent: NodeSlotId) {+ fn note_contained_child_list_change(&mut self, parent: NodeSlotId) {use crate::layout::node_data::DomPaintFact;use crate::painting::record::damage::PaintDamage;diff --git a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs b/Libraries/LibWeb/Rust/src/layout/rendered_text.rsindex 99ef6681641..4052d2836cf 100644--- a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs+++ b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs@@ -560,7 +560,7 @@ mod tests {let scratch = crate::layout::run_state::LayoutScratch::default();let node = arena.allocate_for_test().slot;arena.set_text_content(node, content("hello", 0, 5, Vec::new()));- scratch.apply_memo_invalidations(&arena);+ scratch.apply_memo_invalidations(&mut arena);let text_chunks = |arena: &LayoutNodeArena, key: &TextChunkCacheKey, compute: &dyn Fn() -> Vec<TextChunk>| {scratch.text_memos()@@ -619,7 +619,7 @@ mod tests {};let published_hello = published_text(&published);arena.set_text_content(node, content("hello", 0, 5, Vec::new()));- scratch.apply_memo_invalidations(&arena);+ scratch.apply_memo_invalidations(&mut arena);assert_eq!(Arc::strong_count(&replacement), 2);// The same content keeps the rendered text the publication shares.assert!(std::sync::Arc::ptr_eq(@@ -627,7 +627,7 @@ mod tests {&published_text(&arena.publish_paint_facts().text)));arena.set_text_content(node, content("goodbye", 0, 7, Vec::new()));- scratch.apply_memo_invalidations(&arena);+ scratch.apply_memo_invalidations(&mut arena);assert_eq!(Arc::strong_count(&replacement), 1);// A publication keeps the rendered text it was made with.assert_eq!(@@ -643,7 +643,7 @@ mod tests {drop(replacement);assert!(replacement_weak.upgrade().is_none());let _ = arena.free_subtree(node);- scratch.apply_memo_invalidations(&arena);+ scratch.apply_memo_invalidations(&mut arena);assert_eq!(Arc::strong_count(&new_chunks), 1);}diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rsindex 0335a6ba887..80ea0aaba29 100644--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs@@ -130,7 +130,7 @@ impl LayoutScratch {}/// Brings the run memos up to date with what the arena's writes since the last call did to their boxes.- pub(super) fn apply_memo_invalidations(&self, arena: &LayoutNodeArena) {+ pub(super) fn apply_memo_invalidations(&self, arena: &mut LayoutNodeArena) {arena.take_memo_invalidations().apply_to(&self.fc_run_cache_store,&self.in_flow_block_cache_store,@@ -159,7 +159,7 @@ impl LayoutScratch {}/// Lets go of what the pass that just committed into `arena` kept for itself, and sweeps the run cache.- pub(crate) fn end_layout_pass(&self, arena: &LayoutNodeArena) {+ pub(crate) fn end_layout_pass(&self, arena: &mut LayoutNodeArena) {self.apply_memo_invalidations(arena);arena.sweep_stale_fc_run_cache_entries(&self.fc_run_cache_store);self.inline_item_stashes.borrow_mut().clear();diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 00e35c179c5..e28bb2779da 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -1393,7 +1393,7 @@ impl TreeBuildJob {&state.additional_table_fixup_roots,);} else {- host.arena().set_needs_full_scrollable_overflow_recalculation();+ host.arena_mut().set_needs_full_scrollable_overflow_recalculation();fixup_tables(host, document_layout_node);}@@ -1540,7 +1540,7 @@ fn update_layout_tree_for_shadow_root_children(must_create_subtree,FfiInsertionMode::Append,);- host.arena().clear_layout_tree_update_marks(Some(shadow_root));+ host.arena_mut().clear_layout_tree_update_marks(Some(shadow_root));}/// Updates a slot's assigned nodes in flat-tree order.@@ -1892,7 +1892,7 @@ fn update_layout_tree_for_display_contents(assert!(placed.is_none());}- host.arena().clear_layout_tree_update_marks(Some(style_node));+ host.arena_mut().clear_layout_tree_update_marks(Some(style_node));if clear_layout_top_layer_for_descendants {context.layout_top_layer = true;@@ -2305,7 +2305,7 @@ fn update_principal_node_descendants(state.quote_nesting_level = prior_quote_nesting_level;}- host.arena()+ host.arena_mut().clear_layout_tree_update_marks(Some(update.mirror_identity));}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rsindex 3d02116c2e9..7f2d16dc8ab 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs@@ -316,20 +316,19 @@ impl LayoutNodeArena {self.mark_layout_tree_update(Some(owner), mark);}if !self- .layout_tree_update_marks()- .borrow_mut()+ .layout_tree_update_marks_mut().merge(style_node, true, mark.reuse_reason){return;}// The build reaches a top layer member from the document rather than through its ancestors.- let is_in_top_layer = |node: StyleNodeID| {- self.with_style_store(|engine| {+ let is_in_top_layer = |arena: &Self, node: StyleNodeID| {+ arena.with_style_store(|engine| {engine.element_adjustment_facts(node) & element_adjustment_fact::RENDERED_IN_TOP_LAYER != 0})};- let mut is_inside_top_layer_member = node.is_some_and(&is_in_top_layer);+ let mut is_inside_top_layer_member = node.is_some_and(|node| is_in_top_layer(self, node));let mut current = node;while let Some(child) = current {current = self.flat_tree_parent(child);@@ -337,19 +336,13 @@ impl LayoutNodeArena {let Some(parent) = current.or(document) else {break;};- is_inside_top_layer_member |= current.is_some_and(&is_in_top_layer);- if self- .layout_tree_update_marks()- .borrow_mut()- .set_child_needs(parent, true)- {+ is_inside_top_layer_member |= current.is_some_and(|node| is_in_top_layer(self, node));+ if self.layout_tree_update_marks_mut().set_child_needs(parent, true) {break;}}if is_inside_top_layer_member && let Some(document) = document {- self.layout_tree_update_marks()- .borrow_mut()- .set_child_needs(document, true);+ self.layout_tree_update_marks_mut().set_child_needs(document, true);}self.apply_layout_tree_update_mark(node, mark);diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rsindex a82e75932c9..4731cdd8da6 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs@@ -628,7 +628,7 @@ impl SealedRound {return None;}let mut answer = self.job.run_owing(state, work);- answer.prepare_committed_layout_for_rendering(state.arena());+ answer.prepare_committed_layout_for_rendering(state.arena_mut());Some(FlownRound {answer,rebuilds_tree: self.rebuilds_tree,@@ -706,7 +706,7 @@ impl ClockRound {}Ok(arena.document_style_node()- .filter(|&document| arena.layout_tree_update_marks().borrow().child_needs(document))+ .filter(|&document| arena.layout_tree_update_marks().child_needs(document)).map(|document| TreeBuildJob::new(document, None)))}@@ -948,7 +948,7 @@ impl LayoutRoundAnswer {/// Prepares `arena` for rendering where the round committed a layout, as the host's commit of it asks, so that the/// host waits for no preparation of its own after the round.- fn prepare_committed_layout_for_rendering(&mut self, arena: &LayoutNodeArena) {+ fn prepare_committed_layout_for_rendering(&mut self, arena: &mut LayoutNodeArena) {if matches!(self.end,LayoutRoundEnd::Built { .. } | LayoutRoundEnd::NeedsDocumentStyle@@ -1413,10 +1413,10 @@ mod tests {needs_another_build_pass: false,layout: RoundLayout::Full,})- .prepare_committed_layout_for_rendering(&arena);+ .prepare_committed_layout_for_rendering(&mut arena);assert!(rendering_preparation_pending(&arena).is_some());- answer_ending(LayoutRoundEnd::FullLayout).prepare_committed_layout_for_rendering(&arena);+ answer_ending(LayoutRoundEnd::FullLayout).prepare_committed_layout_for_rendering(&mut arena);assert!(rendering_preparation_pending(&arena).is_none());arena.free_subtree(viewport)diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 96d0488d187..cd50dfc15de 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -1524,7 +1524,7 @@ mod tests {arena.paint_state().borrow_mut().visual_context.dirty_boxes.clear();let outcome = crate::painting::paint_passes::prepare_for_rendering(- &arena,+ &mut arena,RootBackgroundSource {root_layout_node: root,..Default::default()diff --git a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs b/Libraries/LibWeb/Rust/src/painting/paint_passes.rsindex 322a5c9ff24..f0176805e46 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs@@ -270,7 +270,7 @@ impl PendingPreparation {/// sticky constraints.pub(crate) fn prepare(self,- arena: &LayoutNodeArena,+ arena: &mut LayoutNodeArena,sticky_inputs: Option<&FfiVisualContextTreeInputs>,) -> RenderingPreparation {prepare_for_rendering(arena, self.root_background_source, sticky_inputs)@@ -305,7 +305,7 @@ pub(crate) fn pending_preparation(read: &BegunRead, host: &DocumentHost) -> Opti/// Prepares `arena` for rendering. The sticky constraints the new overflow moved are refreshed with `sticky_inputs`, the/// inputs of the visual context tree, unless there are none: a visual context update is pending, which refreshes them.pub(crate) fn prepare_for_rendering(- arena: &LayoutNodeArena,+ arena: &mut LayoutNodeArena,root_background_source: RootBackgroundSource,sticky_inputs: Option<&FfiVisualContextTreeInputs>,) -> RenderingPreparation {diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rsindex 8f5c9e7e82b..fa1dbed8862 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs@@ -289,7 +289,7 @@ impl<'a> PaintableCommit<'a> {});if old_content_size != new_content_size {if self.arena().data(node).kind.get() == NodeKind::Viewport {- self.arena().set_needs_full_scrollable_overflow_recalculation();+ self.arena_mut().set_needs_full_scrollable_overflow_recalculation();}assert!(!reuses_committed_subtree || old_content_inline_size == Some(fragment.content_inline_size),@@ -517,15 +517,13 @@ impl<'a> PaintableCommit<'a> {if !self.overflow_invalidated_boxes.insert(node) {break;}- let arena = self.arena();+ let is_full_layout = self.is_full_layout;+ let arena = self.arena_mut();if arena.paintable_row_is_populated(node) {arena.paintable_rows().clear_cached_overflow_data(node);// Commit queues are consumed immediately and are bounded by the committed tree.- if self.is_full_layout && !arena.needs_full_scrollable_overflow_recalculation.get() {- arena- .boxes_needing_scrollable_overflow_recalculation- .borrow_mut()- .push(node);+ if is_full_layout && !arena.needs_full_scrollable_overflow_recalculation {+ arena.boxes_needing_scrollable_overflow_recalculation.push(node);}}node = arena.containing_block_by_walking_ancestors(node);diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rsindex 708f7ce1a96..8e66cc5cd95 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs@@ -705,7 +705,7 @@ impl LayoutNodeArena {PaintableRows { arena: self }}- pub(crate) fn schedule_scrollable_overflow_recalculation(&self, node: NodeSlotId) {+ pub(crate) fn schedule_scrollable_overflow_recalculation(&mut self, node: NodeSlotId) {// SAFETY: The caller supplies a live slot; data() generation-checks every slot the// containing-block walk visits.let node_kind = self.data(node).kind.get();@@ -724,39 +724,40 @@ impl LayoutNodeArena {}}- if self.needs_full_scrollable_overflow_recalculation.get() {+ if self.needs_full_scrollable_overflow_recalculation {return;}// NB: Cap the queue in case it's never consumed (e.g. forced style updates in a document// that never updates layout).const MAX_PENDING_SCROLLABLE_OVERFLOW_RECALCULATIONS: usize = 1024;- let mut boxes = self.boxes_needing_scrollable_overflow_recalculation.borrow_mut();+ let row_is_populated = self.paintable_rows().paintable_row_is_populated(node);+ let boxes = &mut self.boxes_needing_scrollable_overflow_recalculation;if boxes.len() >= MAX_PENDING_SCROLLABLE_OVERFLOW_RECALCULATIONS {boxes.clear();- self.needs_full_scrollable_overflow_recalculation.set(true);+ self.needs_full_scrollable_overflow_recalculation = true;return;}- if self.paintable_rows().paintable_row_is_populated(node) {+ if row_is_populated {boxes.push(node);}}- pub(crate) fn set_needs_full_scrollable_overflow_recalculation(&self) {- self.needs_full_scrollable_overflow_recalculation.set(true);+ pub(crate) fn set_needs_full_scrollable_overflow_recalculation(&mut self) {+ self.needs_full_scrollable_overflow_recalculation = true;}/// Whether a scrollable overflow recalculation is scheduled, which the next rendering preparation settles.pub(crate) fn scrollable_overflow_recalculation_is_scheduled(&self) -> bool {- self.needs_full_scrollable_overflow_recalculation.get()- || !self.boxes_needing_scrollable_overflow_recalculation.borrow().is_empty()+ self.needs_full_scrollable_overflow_recalculation+ || !self.boxes_needing_scrollable_overflow_recalculation.is_empty()}- pub(crate) fn take_scrollable_overflow_recalculation_state(&self) -> (Vec<NodeSlotId>, bool) {+ pub(crate) fn take_scrollable_overflow_recalculation_state(&mut self) -> (Vec<NodeSlotId>, bool) {(- std::mem::take(&mut *self.boxes_needing_scrollable_overflow_recalculation.borrow_mut()),- self.needs_full_scrollable_overflow_recalculation.replace(false),+ std::mem::take(&mut self.boxes_needing_scrollable_overflow_recalculation),+ std::mem::replace(&mut self.needs_full_scrollable_overflow_recalculation, false),)}diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rsindex 0b0da73f8b7..53fd158d34a 100644--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs@@ -831,13 +831,13 @@ fn box_holds_scroll_state(arena: &LayoutNodeArena, slot: NodeSlotId) -> bool {/// Settles the scheduled recalculation, then measures every other row left unmeasured. Answers the scroll offsets the/// new overflow moved out of range, each clamped into it, for the document to store.#[must_use = "the document stores the clamped scroll offsets"]-pub(crate) fn update_scrollable_overflow(arena: &LayoutNodeArena) -> Vec<(NodeSlotId, CssPixelPoint)> {+pub(crate) fn update_scrollable_overflow(arena: &mut LayoutNodeArena) -> Vec<(NodeSlotId, CssPixelPoint)> {let clamped = settle_scheduled_scrollable_overflow(arena);arena.measure_scrollable_overflow();clamped}-fn settle_scheduled_scrollable_overflow(arena: &LayoutNodeArena) -> Vec<(NodeSlotId, CssPixelPoint)> {+fn settle_scheduled_scrollable_overflow(arena: &mut LayoutNodeArena) -> Vec<(NodeSlotId, CssPixelPoint)> {let mut clamped = Vec::new();let Some(viewport) = arena.scrollable_overflow.viewport.get() else {return clamped;diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rsindex 09a3c5bada8..80fc6c92110 100644--- a/Libraries/LibWeb/Rust/src/render_state.rs+++ b/Libraries/LibWeb/Rust/src/render_state.rs@@ -89,9 +89,12 @@ impl RenderState {if let Some(streamed) = self.streamed_marks.take() {marks.fold(streamed);}- *self.arena.arena().layout_tree_update_marks().borrow_mut() = marks;+ *self.arena.arena_mut().layout_tree_update_marks_mut() = marks;let answer = job(self);- (answer, Some(self.arena.arena().layout_tree_update_marks().take()))+ (+ answer,+ Some(std::mem::take(self.arena.arena_mut().layout_tree_update_marks_mut())),+ )}/// Applies `changes`, writes the host streamed to the state beside its task, into marks of their own, which the@@ -99,9 +102,9 @@ impl RenderState {/// its writes wait in its queue.fn apply_streamed(&mut self, changes: Vec<ArenaChange>) {let streamed = self.streamed_marks.take().unwrap_or_default();- *self.arena.arena().layout_tree_update_marks().borrow_mut() = streamed;+ *self.arena.arena_mut().layout_tree_update_marks_mut() = streamed;self.apply(changes);- self.streamed_marks = Some(self.arena.arena().layout_tree_update_marks().take());+ self.streamed_marks = Some(std::mem::take(self.arena.arena_mut().layout_tree_update_marks_mut()));}/// A fork of the state, as it is now: a copy of it that the render clock may write and present from while the host