Truly independent web browser
LibWeb: Keep the unpublished facts of layout nodes plain
Aliaksandr Kalenikfa522a321843
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rsindex ae3dec4a900..5d59c40b78d 100644--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs@@ -765,7 +765,7 @@ pub(super) fn run_root_validity(callbacks: &LayoutPass<'_>, box_: Node) -> FcRunlet data = NodeFacts::new(callbacks, box_).data();FcRunCacheValidity {slot_generation: data.slot_generation.get(),- fragment_cache_epoch: data.fragment_cache_epoch.get(),+ fragment_cache_epoch: data.fragment_cache_epoch,}}diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 814c5e8528b..0a2b786ce22 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1429,14 +1429,14 @@ impl LayoutNodeArena {IntrinsicSizeCacheStamp {index: id.slot_index(),generation: id.generation(),- epoch: self.data(id).intrinsic_cache_epoch.get(),+ epoch: self.data(id).intrinsic_cache_epoch,}}pub(crate) fn reset_cached_intrinsic_sizes(&mut self, node: NodeSlotId) {- let data = self.data(node);- let bumped_epoch = data.intrinsic_cache_epoch.get().wrapping_add(1);- data.intrinsic_cache_epoch.set(bumped_epoch);+ let epoch = self.unpublished_facts_mut(node).intrinsic_cache_epoch;+ *epoch = epoch.wrapping_add(1);+ let bumped_epoch = *epoch;if bumped_epoch == 0 {self.drop_intrinsic_size_cache(node);}@@ -1461,7 +1461,7 @@ impl LayoutNodeArena {return false;}let id = NodeSlotId::new(slot, metadata.generation);- self.data(id).fragment_cache_epoch.get() == validity.fragment_cache_epoch+ self.data(id).fragment_cache_epoch == validity.fragment_cache_epoch},|box_, entry| {entry@@ -1839,6 +1839,13 @@ impl LayoutNodeArena {)}+ /// The facts of `id` that no publication carries, to write: writing them marks nothing for the paint side.+ pub(crate) fn unpublished_facts_mut(&mut self, id: NodeSlotId) -> super::node_data::UnpublishedNodeFactsMut<'_> {+ self.data(id);+ let index = id.slot_index() as usize;+ self.chunks[index / SLOTS_PER_CHUNK].unpublished_facts_mut(index % SLOTS_PER_CHUNK)+ }+/// The shape of the node whose data `data` is, for writing.fn write_shape_of(&self, data: &NodeData) -> ShapeWriter<'_> {let (index, metadata) = self.slot_for_data(data);@@ -4722,7 +4729,7 @@ impl LayoutNodeArena {}/// Returns whether the node's ancestor facts changed.- fn derive_ancestor_facts_for_node(&self, node: NodeSlotId) -> bool {+ fn derive_ancestor_facts_for_node(&mut self, node: NodeSlotId) -> bool {let data = self.data(node);let parent = data.parent.get();let mut facts = 0;@@ -4762,7 +4769,7 @@ impl LayoutNodeArena {}}}- data.ancestor_facts.replace(facts) != facts+ std::mem::replace(self.unpublished_facts_mut(node).ancestor_facts, facts) != facts}/// A style change reaches the anonymous boxes below the node without rebuilding them, and@@ -5243,7 +5250,7 @@ impl LayoutNodeArena {self.paintable_rows.holds_current_committed_fragment_link(id.slot_index(),id.generation(),- self.data(id).fragment_cache_epoch.get(),+ self.data(id).fragment_cache_epoch,link,)}@@ -5256,7 +5263,7 @@ impl LayoutNodeArena {self.paintable_rows.with_current_committed_fragment(node.slot_index(),node.generation(),- self.data(node).fragment_cache_epoch.get(),+ self.data(node).fragment_cache_epoch,read,)}@@ -5436,7 +5443,7 @@ impl LayoutNodeArena {/// Gives the row the spans its element published again, after one of the element's span/// attributes changed, and answers whether they moved.- pub(crate) fn restamp_table_spans(&self, id: NodeSlotId) -> bool {+ pub(crate) fn restamp_table_spans(&mut self, id: NodeSlotId) -> bool {let element = self.node_style_node(id).expect("a row whose spans are restamped is built for an element");@@ -5446,11 +5453,11 @@ impl LayoutNodeArena {/// Gives the row the spans its table cell or table column element has, and answers whether/// they changed.- pub(crate) fn set_table_spans(&self, id: NodeSlotId, spans: TableSpans) -> bool {- let data = self.data(id);- let changed = data.table_column_span.get() != spans.column_span || data.table_row_span.get() != spans.row_span;- data.table_column_span.set(spans.column_span);- data.table_row_span.set(spans.row_span);+ pub(crate) fn set_table_spans(&mut self, id: NodeSlotId, spans: TableSpans) -> bool {+ let facts = self.unpublished_facts_mut(id);+ let changed = *facts.table_column_span != spans.column_span || *facts.table_row_span != spans.row_span;+ *facts.table_column_span = spans.column_span;+ *facts.table_row_span = spans.row_span;changed}@@ -5646,9 +5653,9 @@ impl LayoutNodeArena {}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);+ let epoch = self.unpublished_facts_mut(node).fragment_cache_epoch;+ *epoch = epoch.wrapping_add(1);+ let epoch = *epoch;if epoch == 0 {self.paintable_rows.invalidate_committed_geometry(node.slot_index());}@@ -6858,14 +6865,14 @@ mod tests {let cell = arena.allocate_unbound();arena.stamp_dom_row(cell, NodeKind::BlockContainer, Some(element));- assert_eq!(arena.data(cell).table_column_span.get(), 2);- assert_eq!(arena.data(cell).table_row_span.get(), 3);+ assert_eq!(arena.data(cell).table_column_span, 2);+ assert_eq!(arena.data(cell).table_row_span, 3);engine.set_element_table_spans(element, TableSpans::default());arena.reset_layout_update_flags_in_subtree(cell);crate::layout::layout_changes::LayoutChange::RestampTableSpans { node: cell }.apply(&mut arena);- assert_eq!(arena.data(cell).table_column_span.get(), 1);- assert_eq!(arena.data(cell).table_row_span.get(), 1);+ assert_eq!(arena.data(cell).table_column_span, 1);+ assert_eq!(arena.data(cell).table_row_span, 1);assert!(arena.node_needs_layout_update(cell));arena.free_subtree(cell)@@ -7046,7 +7053,7 @@ mod tests {arena.set_committed_fragment_link(node,fragment_tree::FragmentLink::for_test(node),- Some(arena.data(node).fragment_cache_epoch.get()),+ Some(arena.data(node).fragment_cache_epoch),);};commit_from_layout(&arena);@@ -7066,11 +7073,11 @@ mod tests {assert!(arena.leave_active_layout_pass());assert_eq!(current(&arena), Some(node));- arena.data(node).fragment_cache_epoch.set(0);+ *arena.unpublished_facts_mut(node).fragment_cache_epoch = 0;commit_from_layout(&arena);- arena.data(node).fragment_cache_epoch.set(u32::MAX);+ *arena.unpublished_facts_mut(node).fragment_cache_epoch = u32::MAX;arena.bump_fragment_cache_epoch_of_self_and_ancestors(node);- assert_eq!(arena.data(node).fragment_cache_epoch.get(), 0);+ assert_eq!(arena.data(node).fragment_cache_epoch, 0);assert_eq!(current(&arena), None);}@@ -7095,8 +7102,8 @@ mod tests {}assert_eq!(first_data_address, std::ptr::from_ref(arena.data(first.slot)) as usize);- arena.data(first.slot).table_column_span.set(42);- assert_eq!(arena.data(first.slot).table_column_span.get(), 42);+ *arena.unpublished_facts_mut(first.slot).table_column_span = 42;+ assert_eq!(arena.data(first.slot).table_column_span, 42);arena.free_subtree(first.slot).destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());@@ -7483,7 +7490,6 @@ mod tests {};let dependency_computations = Cell::new(0);- let first_data = arena.data(first.slot);caches.intrinsic_block_size_cache_put(arena.intrinsic_size_cache_stamp(first.slot),IntrinsicSizeCacheKind::MaxContentBlock,@@ -7519,9 +7525,7 @@ mod tests {);assert_eq!(dependency_computations.get(), 1);- first_data- .intrinsic_cache_epoch- .set(first_data.intrinsic_cache_epoch.get() + 1);+ *arena.unpublished_facts_mut(first.slot).intrinsic_cache_epoch += 1;assert_eq!(caches.intrinsic_block_size_cache_get(arena.intrinsic_size_cache_stamp(first.slot),diff --git a/Libraries/LibWeb/Rust/src/layout/node_data.rs b/Libraries/LibWeb/Rust/src/layout/node_data.rsindex ed8eb303a27..b5302758c8e 100644--- a/Libraries/LibWeb/Rust/src/layout/node_data.rs+++ b/Libraries/LibWeb/Rust/src/layout/node_data.rs@@ -6,7 +6,6 @@use super::tree_shape::ShapeCell;use crate::layout::CssPixels;-use std::cell::Cell;use std::ffi::c_void;pub const GENERATED_FOR_AFTER: u8 = 1;@@ -277,7 +276,7 @@ pub(crate) struct NodeData {pub next_sibling: ShapeCell<NodeSlotId>,pub kind: ShapeCell<NodeKind>,pub generated_for: ShapeCell<u8>,- pub intrinsic_cache_epoch: Cell<u16>,+ pub intrinsic_cache_epoch: u16,pub flags: ShapeCell<u32>,/// Advanced on every layout invalidation that reaches this node or its/// subtree, with no propagation boundary: unlike the intrinsic epoch,@@ -285,13 +284,13 @@ pub(crate) struct NodeData {/// every ancestor, because their fragments live in ancestor run trees./// Wide enough that wrapping between a cache store and the next probe/// is unreachable.- pub fragment_cache_epoch: Cell<u32>,+ pub fragment_cache_epoch: u32,pub slot_generation: ShapeCell<u8>,pub compositor_animation_frame_kinds: ShapeCell<u8>,- pub table_column_span: Cell<u16>,- pub table_row_span: Cell<u16>,+ pub table_column_span: u16,+ pub table_row_span: u16,pub dom_paint_facts: ShapeCell<u8>,- pub ancestor_facts: Cell<u8>,+ pub ancestor_facts: u8,pub style: ShapeCell<StylePayloadsRef>,}@@ -305,20 +304,42 @@ impl Default for NodeData {next_sibling: ShapeCell::new(NodeSlotId::INVALID),kind: ShapeCell::new(NodeKind::Unset),generated_for: ShapeCell::new(0),- intrinsic_cache_epoch: Cell::new(0),+ intrinsic_cache_epoch: 0,flags: ShapeCell::new(0),slot_generation: ShapeCell::new(0),compositor_animation_frame_kinds: ShapeCell::new(0),- table_column_span: Cell::new(1),- table_row_span: Cell::new(1),+ table_column_span: 1,+ table_row_span: 1,dom_paint_facts: ShapeCell::new(0),- ancestor_facts: Cell::new(0),- fragment_cache_epoch: Cell::new(0),+ ancestor_facts: 0,+ fragment_cache_epoch: 0,style: ShapeCell::new(StylePayloadsRef::null()),}}}+/// The facts of a node that no publication carries, for writing: writing them marks nothing for the paint side,+/// unlike a write to the node's shape.+pub(crate) struct UnpublishedNodeFactsMut<'a> {+ pub(crate) intrinsic_cache_epoch: &'a mut u16,+ pub(crate) fragment_cache_epoch: &'a mut u32,+ pub(crate) table_column_span: &'a mut u16,+ pub(crate) table_row_span: &'a mut u16,+ pub(crate) ancestor_facts: &'a mut u8,+}++impl NodeData {+ pub(super) fn unpublished_facts_mut(&mut self) -> UnpublishedNodeFactsMut<'_> {+ UnpublishedNodeFactsMut {+ intrinsic_cache_epoch: &mut self.intrinsic_cache_epoch,+ fragment_cache_epoch: &mut self.fragment_cache_epoch,+ table_column_span: &mut self.table_column_span,+ table_row_span: &mut self.table_row_span,+ ancestor_facts: &mut self.ancestor_facts,+ }+ }+}+/// The part of a node the paint side reads, as a row of the arena's published column.#[derive(Clone, PartialEq)]pub(crate) struct PaintNode {diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rsindex 4aab6671aa3..46965c53c0a 100644--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs@@ -600,7 +600,7 @@ pub(crate) fn node_applies_text_overflow_ellipsis(style: Option<ComputedValuesVi}pub(crate) fn has_ancestor_fact(data: &NodeData, fact: AncestorFact) -> bool {- data.ancestor_facts.get() & fact as u8 != 0+ data.ancestor_facts & fact as u8 != 0}/// The construction facts a test row is built with, as the word the style mirror publishes them in.diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex 6ee54bdf177..9f8f968e538 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -906,7 +906,7 @@ mod tests {}fn intrinsic_cache_epoch(arena: &LayoutNodeArena, allocation: &NodeAllocation) -> u16 {- arena.data(allocation.slot).intrinsic_cache_epoch.get()+ arena.data(allocation.slot).intrinsic_cache_epoch}#[test]diff --git a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs b/Libraries/LibWeb/Rust/src/layout/rendered_text.rsindex 4052d2836cf..69086a5d226 100644--- a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs+++ b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs@@ -709,13 +709,13 @@ mod tests {arena.write_shape(node).set_parent(parent);let sharp_s_first = || content("SSS", 0, 2, vec![edit(0, 1, 0, 2)]);arena.set_text_content(node, sharp_s_first());- let epoch = arena.data(parent).fragment_cache_epoch.get();+ let epoch = arena.data(parent).fragment_cache_epoch;assert_eq!(arena.rendered_text_offset_for_dom_offset(node, 1, Start), 2);arena.set_text_content(node, sharp_s_first());- assert_eq!(arena.data(parent).fragment_cache_epoch.get(), epoch);+ assert_eq!(arena.data(parent).fragment_cache_epoch, epoch);arena.set_text_content(node, content("SSS", 0, 2, vec![edit(1, 1, 1, 2)]));- assert_ne!(arena.data(parent).fragment_cache_epoch.get(), epoch);+ assert_ne!(arena.data(parent).fragment_cache_epoch, epoch);assert_eq!(arena.rendered_text_offset_for_dom_offset(node, 1, Start), 1);assert_eq!(arena.dom_offset_for_rendered_text_offset(node, 2, End), 2);}@@ -740,7 +740,7 @@ mod tests {original.rendering_key = Some(key.clone());arena.set_text_content(node, original);let storage = arena.text_content(node).unwrap().text.as_ptr();- let epoch = arena.data(node).fragment_cache_epoch.get();+ let epoch = arena.data(node).fragment_cache_epoch;arena.invalidate_text_content(node);assert!(arena.text_content(node).unwrap().rendering_key.is_none());@@ -753,7 +753,7 @@ mod tests {assert_eq!(arena.text_content(node).unwrap().rendering_key.as_ref(), Some(&new_key));assert_eq!(arena.text_content(node).unwrap().text.as_ptr(), storage);- assert_eq!(arena.data(node).fragment_cache_epoch.get(), epoch);+ assert_eq!(arena.data(node).fragment_cache_epoch, epoch);assert!(arena.pending_text_nodes_for_content_sync().is_empty());}diff --git a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rsindex 7552eb94090..a19b1f25335 100644--- a/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/table_formatting_context.rs@@ -1014,11 +1014,11 @@ pub(crate) trait TableTree {fn display(&self, node: Node) -> FfiDisplay;fn table_column_span(&self, node: Node) -> usize {- self.node_data(node).table_column_span.get() as usize+ self.node_data(node).table_column_span as usize}fn table_row_span(&self, node: Node) -> usize {- self.node_data(node).table_row_span.get() as usize+ self.node_data(node).table_row_span as usize}fn row_is_collapsed(&self, _row: Node, _row_group: Option<Node>) -> bool {diff --git a/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs b/Libraries/LibWeb/Rust/src/layout/tree_mutation.rsindex db9ded22340..347087ef27a 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_mutation.rs@@ -330,7 +330,7 @@ mod tests {}fn fragment_cache_epoch(arena: &LayoutNodeArena, node: NodeSlotId) -> u32 {- arena.data(node).fragment_cache_epoch.get()+ arena.data(node).fragment_cache_epoch}fn owned(slot: NodeSlotId) -> UnplacedLayoutNode {diff --git a/Libraries/LibWeb/Rust/src/layout/tree_shape.rs b/Libraries/LibWeb/Rust/src/layout/tree_shape.rsindex 9896f935031..01b8c3c3511 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_shape.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_shape.rs@@ -267,6 +267,12 @@ impl Chunk {&self.slots[offset]}+ /// The facts of the node at `offset` that no publication carries, to write without marking the node.+ #[inline]+ pub(crate) fn unpublished_facts_mut(&mut self, offset: usize) -> super::node_data::UnpublishedNodeFactsMut<'_> {+ self.slots[offset].unpublished_facts_mut()+ }+/// The node at `offset` of this chunk, the arena's chunk at `chunk_index`, marked for the next publication.#[inline]pub(crate) fn slot_mut(&mut self, chunk_index: usize, offset: usize, writes: &ShapeWrites) -> &mut NodeData {diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rsindex fa1dbed8862..ea9995813f4 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs@@ -375,7 +375,7 @@ impl<'a> PaintableCommit<'a> {node,link.clone(),// A layout pass bumps no epoch, so its geometry is laid out against the epoch the node has now.- Some(self.arena().data(node).fragment_cache_epoch.get()),+ Some(self.arena().data(node).fragment_cache_epoch),);ReplacedCommittedFragmentLink {content_size_change,