Skip to content

Truly independent web browser

LibWeb: Push paint damage through a mutable layout arena

Aliaksandr Kalenike6739be42ba9
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index 85dff34bd20..d2e7106bdce 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -267,7 +267,7 @@ fn commit_subtree(
if reuses_committed_subtree {
return;
}
- paintables.arena().refresh_paint_order_inputs(node);
+ paintables.arena_mut().refresh_paint_order_inputs(node);
let mut child = paintables.arena().data(node).first_child.get();
while !child.is_invalid() {
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
index cf0592e3d1b..2d7242383d6 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
@@ -2560,7 +2560,7 @@ fn construct_principal_layout_node(
// and inline-box-piece lists held by the containing block of a node that participated in inline
// layout carry over to it; a subtree relayout that skips the containing block never rebuilds them.
fn transfer_fragments_to_replacement_box(
- arena: &LayoutNodeArena,
+ arena: &mut LayoutNodeArena,
old_layout_node: LayoutNode,
new_layout_node: LayoutNode,
) {
diff --git a/Libraries/LibWeb/Rust/src/painting/fragment_ownership.rs b/Libraries/LibWeb/Rust/src/painting/fragment_ownership.rs
index 71e0eeaed49..ec8e5c2ac46 100644
--- a/Libraries/LibWeb/Rust/src/painting/fragment_ownership.rs
+++ b/Libraries/LibWeb/Rust/src/painting/fragment_ownership.rs
@@ -8,7 +8,7 @@ use crate::layout::LayoutNodeArena;
use crate::layout::node_data::NodeSlotId;
use crate::painting::node_painting;
use crate::painting::paint_read::PaintRead;
-use crate::painting::paintable_rows::PaintableRowsRead;
+use crate::painting::paintable_rows::PaintableRowsWrite;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FragmentRange {
@@ -103,18 +103,18 @@ pub(crate) fn nearest_self_painting_inline_box(layout_arena: &impl PaintRead, no
None
}
-pub(crate) fn assign_fragment_ownership(layout_arena: &impl PaintableRowsRead, viewport: NodeSlotId) {
+pub(crate) fn assign_fragment_ownership(layout_arena: &mut impl PaintableRowsWrite, viewport: NodeSlotId) {
let mut stack = vec![viewport];
while let Some(current) = stack.pop() {
- if let Some(next) = crate::painting::paint_order::next_paint_sibling(layout_arena, current)
+ if let Some(next) = crate::painting::paint_order::next_paint_sibling(&*layout_arena, current)
&& current != viewport
{
stack.push(next);
}
- if let Some(first_child) = crate::painting::paint_order::first_paint_child(layout_arena, current) {
+ if let Some(first_child) = crate::painting::paint_order::first_paint_child(&*layout_arena, current) {
stack.push(first_child);
}
- if node_painting::has_lines(layout_arena, current)
+ if node_painting::has_lines(&*layout_arena, current)
&& !layout_arena.committed_side_data(current).inline_box_pieces().is_empty()
{
assign_for_block(layout_arena, current);
@@ -122,20 +122,20 @@ pub(crate) fn assign_fragment_ownership(layout_arena: &impl PaintableRowsRead, v
}
}
-pub(crate) fn assign_fragment_ownership_for_pending_line_roots(layout_arena: &LayoutNodeArena) {
+pub(crate) fn assign_fragment_ownership_for_pending_line_roots(layout_arena: &mut LayoutNodeArena) {
let mut line_roots = layout_arena.take_line_roots_needing_fragment_ownership();
line_roots.sort_unstable_by_key(|slot| (slot.index, slot.generation()));
line_roots.dedup();
- let paintable_rows = layout_arena.paintable_rows();
+ let mut paintable_rows = layout_arena.paintable_rows_mut();
for line_root in line_roots {
if paintable_rows.paintable_row_is_populated(line_root)
&& node_painting::has_lines(&paintable_rows, line_root)
- && !layout_arena
+ && !paintable_rows
.committed_side_data(line_root)
.inline_box_pieces()
.is_empty()
{
- assign_for_block(&paintable_rows, line_root);
+ assign_for_block(&mut paintable_rows, line_root);
}
}
}
@@ -202,33 +202,38 @@ pub(crate) fn compute_fragment_ownership_for_block(
owners_with_filters
}
-fn assign_for_block(layout_arena: &impl PaintableRowsRead, block: NodeSlotId) {
+/// Takes the fragment ownership filter `paintable` was assigned, or the one it held before its recommit.
+fn take_previous_fragment_ownership(
+ layout_arena: &mut impl PaintableRowsWrite,
+ paintable: NodeSlotId,
+) -> Option<std::sync::Arc<FragmentOwnershipFilter>> {
+ let assigned = layout_arena
+ .committed_side_data_mut(paintable)
+ .fragment_ownership
+ .take();
+ assigned.or_else(|| {
+ layout_arena
+ .paintable_side_data_mut(paintable)
+ .fragment_ownership_before_recommit
+ .take()
+ })
+}
+
+fn assign_for_block(layout_arena: &mut impl PaintableRowsWrite, block: NodeSlotId) {
use crate::painting::record::damage::PaintDamage;
- let owners_with_filters = compute_fragment_ownership_for_block(layout_arena, block);
+ let owners_with_filters = compute_fragment_ownership_for_block(&*layout_arena, block);
// Start every piece's box from a clean slate. A box whose filter changes paints a
// different selection of the block's fragments.
let pieces = layout_arena.committed_side_data(block).inline_box_pieces().to_vec();
- let previous_filter_of = |paintable: NodeSlotId| {
- let assigned = layout_arena
- .committed_side_data_mut(paintable)
- .fragment_ownership
- .take();
- assigned.or_else(|| {
- layout_arena
- .paintable_side_data_mut(paintable)
- .fragment_ownership_before_recommit
- .take()
- })
- };
let mut boxes_with_previous_filters = Vec::new();
for piece in &pieces {
- if let Some(paintable) = piece_paintable_of(layout_arena, piece.node)
- && let Some(previous) = previous_filter_of(paintable)
+ if let Some(paintable) = piece_paintable_of(&*layout_arena, piece.node)
+ && let Some(previous) = take_previous_fragment_ownership(layout_arena, paintable)
{
boxes_with_previous_filters.push((paintable, previous));
}
}
- if let Some(previous) = previous_filter_of(block) {
+ if let Some(previous) = take_previous_fragment_ownership(layout_arena, block) {
boxes_with_previous_filters.push((block, previous));
}
for (owner, filter) in owners_with_filters {
diff --git a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs
index 8b6bc09f7cd..a7de0a8b952 100644
--- a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs
@@ -309,10 +309,7 @@ pub(crate) fn prepare_for_rendering(
root_background_source: RootBackgroundSource,
sticky_inputs: Option<&FfiVisualContextTreeInputs>,
) -> RenderingPreparation {
- let background_source_changed = arena
- .paint_state()
- .borrow_mut()
- .update_root_background_source(arena, root_background_source);
+ let background_source_changed = arena.update_root_background_source(root_background_source);
// This measures all overflow left unmeasured, including the root's: the root background covers
// the viewport united with it, so a flip in its scrollability is seen here rather than while
// recording holds the paint state.
@@ -345,7 +342,7 @@ pub(crate) fn prepare_for_rendering(
}
pub(crate) fn refresh_scroll_state(
- arena: &LayoutNodeArena,
+ arena: &mut LayoutNodeArena,
device_pixels_per_css_pixel: f64,
) -> Option<Vec<FloatPoint>> {
arena.measure_scrollable_overflow();
@@ -426,7 +423,7 @@ pub(crate) fn update_accumulated_visual_contexts(
}
while scope != VisualContextUpdateScope::FreshTree {
- let result = update_visual_context_tree(&arena.paintable_rows(), viewport, inputs, scope, &mut state);
+ let result = update_visual_context_tree(&mut arena.paintable_rows_mut(), viewport, inputs, scope, &mut state);
match result {
IncrementalUpdateResult::Applied(mut outcome) => {
super::ffi::apply_walk_assignments(arena, &mut outcome);
@@ -484,7 +481,7 @@ fn fresh_visual_context_tree_build(
state.tree = Some(std::sync::Arc::new(fresh_tree.tree));
state.dirty_boxes.clear();
let mut outcome = match update_visual_context_tree(
- &arena.paintable_rows(),
+ &mut arena.paintable_rows_mut(),
viewport,
inputs,
VisualContextUpdateScope::FreshTree,
@@ -500,7 +497,7 @@ fn fresh_visual_context_tree_build(
super::ffi::apply_walk_assignments(arena, &mut outcome);
arena.rebuild_all_stacking_context_entries_from_records(viewport);
arena.take_line_roots_needing_fragment_ownership();
- crate::painting::fragment_ownership::assign_fragment_ownership(&arena.paintable_rows(), viewport);
+ crate::painting::fragment_ownership::assign_fragment_ownership(&mut arena.paintable_rows_mut(), viewport);
state.quarantined_slots_are_releasable = false;
debug_assert_every_live_node_is_owned(
&arena.paintable_rows(),
diff --git a/Libraries/LibWeb/Rust/src/painting/paint_state.rs b/Libraries/LibWeb/Rust/src/painting/paint_state.rs
index fe9aea2a844..5d0668ccefa 100644
--- a/Libraries/LibWeb/Rust/src/painting/paint_state.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paint_state.rs
@@ -66,12 +66,25 @@ impl PaintState {
}
}
+ pub(crate) fn reset_visual_context_state(&mut self) {
+ self.visual_context = crate::painting::visual_context::VisualContextState {
+ needs_to_refresh_scroll_state: true,
+ ..Default::default()
+ };
+ self.visual_context
+ .dirty_boxes
+ .request_full_rebuild(crate::painting::visual_context::dirty::VisualContextUpdateScope::FreshTree);
+ }
+}
+
+impl crate::layout::LayoutNodeArena {
+ /// Makes `source` the root background source, and pushes the damage of the boxes the move changes which paints
+ /// the root's background. Answers whether the source moved.
pub(crate) fn update_root_background_source(
&mut self,
- arena: &crate::layout::LayoutNodeArena,
source: crate::painting::host::RootBackgroundSource,
) -> bool {
- let Some(previous) = self.root_background_source.replace(source) else {
+ let Some(previous) = self.paint_state().borrow_mut().root_background_source.replace(source) else {
return false;
};
if previous == source {
@@ -82,23 +95,13 @@ impl PaintState {
// and new owners, including inline pieces painted by their containing block.
for source in [previous, source] {
for slot in [source.root_layout_node, source.body_layout_node] {
- arena.push_paint_damage_for_repaint(slot, PaintDamage::DRAW_BACKGROUND);
+ self.push_paint_damage_for_repaint(slot, PaintDamage::DRAW_BACKGROUND);
}
// The viewport's scrollbars take their colors from the propagated background.
- if let Some(viewport) = arena.node_parent_if_live(source.root_layout_node) {
- arena.push_paint_damage(viewport, PaintDamage::DRAW_OVERLAY | PaintDamage::SCROLL_METADATA);
+ if let Some(viewport) = self.node_parent_if_live(source.root_layout_node) {
+ self.push_paint_damage(viewport, PaintDamage::DRAW_OVERLAY | PaintDamage::SCROLL_METADATA);
}
}
true
}
-
- pub(crate) fn reset_visual_context_state(&mut self) {
- self.visual_context = crate::painting::visual_context::VisualContextState {
- needs_to_refresh_scroll_state: true,
- ..Default::default()
- };
- self.visual_context
- .dirty_boxes
- .request_full_rebuild(crate::painting::visual_context::dirty::VisualContextUpdateScope::FreshTree);
- }
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index fbfb97785b7..6f7f56b72ec 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -171,7 +171,7 @@ impl<'a> PaintableCommit<'a> {
let inline_paint_changed = enclosing_line_root_changes.inline_content_changed
|| (enclosing_line_root_changes.fragment_changed && has_descendant_dependent_paint(self.arena(), node));
if row_existed_before_this_commit && inline_paint_changed {
- self.arena().push_paint_damage(node, PaintDamage::ALL_PRODUCERS);
+ self.arena_mut().push_paint_damage(node, PaintDamage::ALL_PRODUCERS);
}
if row_existed_before_this_commit && enclosing_line_root_changes.fragment_changed {
self.arena()
@@ -301,7 +301,7 @@ impl<'a> PaintableCommit<'a> {
// Inserted, removed or reordered children change which scopes this row's plans list,
// independently of where the children were placed.
if !child_sequence_unchanged {
- self.arena().push_paint_damage(node, PaintDamage::ORDER);
+ self.arena_mut().push_paint_damage(node, PaintDamage::ORDER);
}
let painted_geometry_lives_in_enclosing_line_root = {
let data = self.arena().data(node);
@@ -346,7 +346,7 @@ impl<'a> PaintableCommit<'a> {
if !paint_offset_unchanged {
damage |= PaintDamage::MOVED;
}
- self.arena().push_paint_damage(node, damage);
+ self.arena_mut().push_paint_damage(node, damage);
if !offset_unchanged {
self.arena()
.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::MovedWithDescendants);
@@ -456,7 +456,7 @@ impl<'a> PaintableCommit<'a> {
if geometry_unchanged {
return;
}
- self.arena()
+ self.arena_mut()
.push_paint_damage(slot, PaintDamage::ALL_PRODUCERS | PaintDamage::MOVED);
self.arena().note_visual_context_box_dirty(
slot,
@@ -470,7 +470,7 @@ impl<'a> PaintableCommit<'a> {
}
pub(crate) fn set_line_data(
- &self,
+ &mut self,
slot: NodeSlotId,
line_data: &std::sync::Arc<crate::layout::inline_content::InlineContent>,
previous_fragmented_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,
@@ -496,7 +496,7 @@ impl<'a> PaintableCommit<'a> {
});
self.arena().committed_side_data_mut(slot).inline_content = Some(line_data.clone());
if item_order_changed {
- self.arena().push_paint_damage(slot, PaintDamage::ORDER);
+ self.arena_mut().push_paint_damage(slot, PaintDamage::ORDER);
}
if has_pieces {
self.arena().note_line_root_needs_fragment_ownership(slot);
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
index 8e66cc5cd95..aeadfd6186b 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
@@ -197,17 +197,19 @@ mod tests {
}
arena.paintable_side_data(node).overflow_measured_this_commit.set(true);
- let rows = arena.paintable_rows();
- let geometry = rows.paintable_data(node);
- let previous_geometry = *geometry;
- rows.clear_cached_overflow_data(node);
+ let previous_geometry = *arena.paintable_rows().paintable_data(node);
+ arena.paintable_rows().clear_cached_overflow_data(node);
// Reading overflow never measures it.
- assert_eq!(paintable_geometry::scrollable_overflow_rect(&rows, node), None);
+ assert_eq!(
+ paintable_geometry::scrollable_overflow_rect(&arena.paintable_rows(), node),
+ None
+ );
assert!(!arena.scrollable_overflow.geometry_changed.get());
arena.measure_scrollable_overflow();
+ let rows = arena.paintable_rows();
assert_eq!(paintable_geometry::scrollable_overflow_rect(&rows, node), Some(rect));
assert!(!paintable_geometry::has_scrollable_overflow(&rows, node));
- assert_eq!(*geometry, previous_geometry);
+ assert_eq!(*rows.paintable_data(node), previous_geometry);
assert!(arena.scrollable_overflow.geometry_changed.get());
assert!(arena.scrollable_overflow.scrollability_changed.get());
}
@@ -318,7 +320,7 @@ pub(crate) struct PaintableRowStore {
rows: CowColumn<PaintableData, PAINTABLE_SLOTS_PER_CHUNK>,
side_data: RefCell<Vec<PaintableSideData>>,
committed_side_data: RefCell<CowColumn<CommittedSideData, PAINTABLE_SLOTS_PER_CHUNK>>,
- pub(crate) row_paint_states: RefCell<Vec<RowPaintState>>,
+ pub(crate) row_paint_states: Vec<RowPaintState>,
pub(crate) damage: DamageSet,
// NB: Boxed, as most rows have no record, and a row holds no more than a pointer for one.
visual_context_records: RefCell<CowColumn<Option<Box<PaintableVisualContextRecord>>, PAINTABLE_SLOTS_PER_CHUNK>>,
@@ -384,7 +386,8 @@ pub(crate) type CommittedSideDataMut<'a> = RowMut<
PAINTABLE_SLOTS_PER_CHUNK,
>;
-pub(crate) trait PaintableRowsWrite: PaintableRowsRead {
+/// A view of the live rows that writes them, and the rest of the arena.
+pub(crate) trait PaintableRowsWrite: PaintableRowsRead + DerefMut<Target = LayoutNodeArena> {
fn paintable_data_mut(&mut self, id: NodeSlotId) -> PaintableDataMut<'_>;
}
@@ -461,50 +464,50 @@ where
}
}
+ pub(crate) fn prepare_paintable_row_recommit_notification(&self, id: NodeSlotId) -> PaintableRowReset {
+ assert!(self.paintable_row_is_populated(id));
+ // The host hears which row is the viewport's here: a layout pass is under way, so it cannot read the rows.
+ let kind = if id == self.arena.bound_viewport_row() {
+ PaintableRowResetKind::ViewportRecommitted
+ } else {
+ PaintableRowResetKind::Recommitted
+ };
+ self.arena.prepare_paintable_row_reset(id, kind)
+ }
+}
+
+impl<Arena> PaintableRows<Arena>
+where
+ Arena: DerefMut<Target = LayoutNodeArena>,
+{
/// A text-decoration change on a box repaints the text of every line root and inline
/// below it that inherits the decoration.
- pub(crate) fn push_propagated_text_decoration_damage(&self, root: NodeSlotId) {
+ pub(crate) fn push_propagated_text_decoration_damage(&mut self, root: NodeSlotId) {
if !self.paintable_row_is_populated(root) {
return;
}
let mut stack = Vec::new();
- if let Some(first_child) = crate::painting::paint_order::first_paint_child(self, root) {
+ if let Some(first_child) = crate::painting::paint_order::first_paint_child(&*self, root) {
stack.push(first_child);
}
while let Some(current) = stack.pop() {
- if let Some(next_sibling) = crate::painting::paint_order::next_paint_sibling(self, current) {
+ if let Some(next_sibling) = crate::painting::paint_order::next_paint_sibling(&*self, current) {
stack.push(next_sibling);
}
if crate::painting::style_queries::is_text_decoration_propagation_boundary(self.arena.deref(), current) {
continue;
}
- if node_painting::has_lines(self, current) || node_painting::is_fragmented_inline(self, current) {
+ if node_painting::has_lines(&*self, current) || node_painting::is_fragmented_inline(&*self, current) {
self.arena.push_paint_damage(current, PaintDamage::DRAW_FOREGROUND);
}
- if let Some(first_child) = crate::painting::paint_order::first_paint_child(self, current) {
+ if let Some(first_child) = crate::painting::paint_order::first_paint_child(&*self, current) {
stack.push(first_child);
}
}
}
- pub(crate) fn prepare_paintable_row_recommit_notification(&self, id: NodeSlotId) -> PaintableRowReset {
- assert!(self.paintable_row_is_populated(id));
- // The host hears which row is the viewport's here: a layout pass is under way, so it cannot read the rows.
- let kind = if id == self.arena.bound_viewport_row() {
- PaintableRowResetKind::ViewportRecommitted
- } else {
- PaintableRowResetKind::Recommitted
- };
- self.arena.prepare_paintable_row_reset(id, kind)
- }
-}
-
-impl<Arena> PaintableRows<Arena>
-where
- Arena: DerefMut<Target = LayoutNodeArena>,
-{
pub(crate) fn paintable_data_mut(&mut self, id: NodeSlotId) -> PaintableDataMut<'_> {
assert!(!id.is_invalid(), "invalid paintable arena slot ID");
let data = self
@@ -678,7 +681,7 @@ impl PaintableRowStore {
}
impl LayoutNodeArena {
- pub(crate) fn refresh_paint_order_inputs(&self, row: NodeSlotId) {
+ pub(crate) fn refresh_paint_order_inputs(&mut self, row: NodeSlotId) {
if !self.paintable_row_is_populated(row) {
return;
}
@@ -690,14 +693,14 @@ impl LayoutNodeArena {
// A row whose ordering decisions changed is placed differently by its ancestors' plans and
// may plan its own descendants differently.
- pub(crate) fn note_paint_order_changed(&self, row: NodeSlotId) {
+ pub(crate) fn note_paint_order_changed(&mut self, row: NodeSlotId) {
self.push_paint_damage(row, PaintDamage::ORDER);
self.push_enclosing_paint_order_damage(row);
}
// The entry tables decide how a stacking context composes its hoisted content, so a table
// change reorders the context's own painting even when no row changed its own decisions.
- pub(crate) fn note_stacking_context_composition_changed(&self, context_root: NodeSlotId) {
+ pub(crate) fn note_stacking_context_composition_changed(&mut self, context_root: NodeSlotId) {
self.push_paint_damage(context_root, PaintDamage::CONTEXT_ORDER);
}
@@ -851,7 +854,6 @@ impl LayoutNodeArena {
let store = &mut self.paintable_rows;
let index = layout_node.slot_index() as usize;
let mut side_data = store.side_data.borrow_mut();
- let mut row_paint_states = store.row_paint_states.borrow_mut();
let mut absolute_rect_memo = store.absolute_rect_memo.borrow_mut();
let mut visual_context_records = store.visual_context_records.borrow_mut();
store.rows.grow_to(index + 1);
@@ -861,7 +863,7 @@ impl LayoutNodeArena {
store.stacking_context_entries.get_mut().grow_to(index + 1);
while side_data.len() <= index {
side_data.push(PaintableSideData::default());
- row_paint_states.push(RowPaintState::default());
+ store.row_paint_states.push(RowPaintState::default());
absolute_rect_memo.push(None);
}
@@ -881,13 +883,13 @@ impl LayoutNodeArena {
.committed_side_data
.get_mut()
.set(index, CommittedSideData::default());
- row_paint_states[index].clear();
+ store.row_paint_states[index].clear();
absolute_rect_memo[index] = None;
visual_context_records.set(index, None);
set_visual_context_node_handles(store.visual_context_node_handles.get_mut(), index, None);
drop_table(store.stacking_context_entries.get_mut(), index);
self.scrollable_overflow.rows_to_measure.get_mut().push(layout_node);
- drop((side_data, row_paint_states, absolute_rect_memo, visual_context_records));
+ drop((side_data, absolute_rect_memo, visual_context_records));
self.notify_committed_box_changed(layout_node);
}
@@ -928,7 +930,7 @@ impl LayoutNodeArena {
.committed_side_data
.get_mut()
.set(index, CommittedSideData::default());
- store.row_paint_states.borrow()[index].clear();
+ store.row_paint_states[index].clear();
store.visual_context_records.borrow_mut().set(index, None);
set_visual_context_node_handles(store.visual_context_node_handles.get_mut(), index, None);
drop_table(store.stacking_context_entries.get_mut(), index);
@@ -988,7 +990,7 @@ impl LayoutNodeArena {
}
pub(crate) fn set_paintable_visual_context_record(
- &self,
+ &mut self,
id: NodeSlotId,
record: PaintableVisualContextRecord,
node_handles: BoxVisualContextNodeHandles,
@@ -1218,7 +1220,7 @@ impl LayoutNodeArena {
}
pub(crate) fn transfer_fragments_to_replacement_node(
- &self,
+ &mut self,
containing_block: NodeSlotId,
old_node: NodeSlotId,
new_node: NodeSlotId,
@@ -1246,8 +1248,8 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn push_propagated_text_decoration_damage(&self, root: NodeSlotId) {
- self.paintable_rows().push_propagated_text_decoration_damage(root);
+ pub(crate) fn push_propagated_text_decoration_damage(&mut self, root: NodeSlotId) {
+ self.paintable_rows_mut().push_propagated_text_decoration_damage(root);
}
/// Stores the paint-order inputs gathered for a row, answering whether they changed.
diff --git a/Libraries/LibWeb/Rust/src/painting/record/damage.rs b/Libraries/LibWeb/Rust/src/painting/record/damage.rs
index 0918e1cd587..c26748cbf47 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/damage.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/damage.rs
@@ -12,7 +12,6 @@ use crate::layout::node_data::NodeSlotId;
use crate::painting::node_painting;
use crate::painting::paint_order;
use crate::painting::paint_read::GeometryRead;
-use std::cell::{Cell, Ref, RefCell};
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
pub(crate) struct PaintDamage(u32);
@@ -121,26 +120,26 @@ impl std::fmt::Debug for PaintDamage {
/// The per-row state of the retained paint output, kept next to the other parallel row vectors.
#[derive(Clone, Default)]
pub(crate) struct RowPaintState {
- damage: Cell<PaintDamage>,
+ damage: PaintDamage,
// The recording sequence number the row was last pushed in; publication clears rows pushed
// before the recording it publishes started and keeps rows pushed after.
- damage_stamp: Cell<u32>,
+ damage_stamp: u32,
}
impl RowPaintState {
pub(crate) fn damage(&self) -> PaintDamage {
- self.damage.get()
+ self.damage
}
- pub(crate) fn clear(&self) {
- self.damage.set(PaintDamage::NONE);
- self.damage_stamp.set(0);
+ pub(crate) fn clear(&mut self) {
+ self.damage = PaintDamage::NONE;
+ self.damage_stamp = 0;
}
- fn add(&self, damage: PaintDamage, stamp: u32) -> bool {
- let before = self.damage.get();
- self.damage.set(before | damage);
- self.damage_stamp.set(stamp);
+ fn add(&mut self, damage: PaintDamage, stamp: u32) -> bool {
+ let before = self.damage;
+ self.damage = before | damage;
+ self.damage_stamp = stamp;
before.is_empty()
}
}
@@ -149,16 +148,16 @@ impl RowPaintState {
pub(crate) struct DamageSet {
// Every row whose damage is non-empty, listed once when its first bit is pushed. Entries of
// rows reset since are skipped by their slot generation.
- rows: RefCell<Vec<NodeSlotId>>,
+ rows: Vec<NodeSlotId>,
// Zero, or the stamp the whole-document damage was pushed at.
- all: Cell<u32>,
- scroll_metadata_everywhere: Cell<u32>,
- started_publishing_recordings: Cell<u32>,
+ all: u32,
+ scroll_metadata_everywhere: u32,
+ started_publishing_recordings: u32,
}
impl DamageSet {
fn stamp_for_push(&self) -> u32 {
- self.started_publishing_recordings.get() + 1
+ self.started_publishing_recordings + 1
}
}
@@ -220,7 +219,6 @@ impl LayoutNodeArena {
.paintable_rows
.damage
.rows
- .borrow()
.iter()
.filter(|row| self.paintable_row_is_populated(**row))
.filter_map(|&row| {
@@ -237,10 +235,8 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn row_paint_state(&self, row: NodeSlotId) -> Ref<'_, RowPaintState> {
- Ref::map(self.paintable_rows.row_paint_states.borrow(), |states| {
- &states[row.slot_index() as usize]
- })
+ pub(crate) fn row_paint_state(&self, row: NodeSlotId) -> &RowPaintState {
+ &self.paintable_rows.row_paint_states[row.slot_index() as usize]
}
#[cfg(test)]
@@ -251,38 +247,35 @@ impl LayoutNodeArena {
self.row_paint_state(row).damage()
}
- pub(crate) fn push_paint_damage(&self, row: NodeSlotId, damage: PaintDamage) {
+ pub(crate) fn push_paint_damage(&mut self, row: NodeSlotId, damage: PaintDamage) {
if damage.is_empty() || !self.paintable_row_is_populated(row) {
return;
}
- let set = &self.paintable_rows.damage;
- let stamp = set.stamp_for_push();
+ let stamp = self.paintable_rows.damage.stamp_for_push();
// Whole-document damage pushed for the same recording already covers every row.
- if set.all.get() == stamp {
+ if self.paintable_rows.damage.all == stamp {
return;
}
- let states = self.paintable_rows.row_paint_states.borrow();
// A listed row already hinted its ancestors: every push hints up to the root or to an
// ancestor whose own push did, and publication hints again for the rows it keeps.
- if states[row.slot_index() as usize].add(damage, stamp) {
- set.rows.borrow_mut().push(row);
- self.hint_descendant_readers_above(row, stamp, &states);
+ if self.paintable_rows.row_paint_states[row.slot_index() as usize].add(damage, stamp) {
+ self.paintable_rows.damage.rows.push(row);
+ self.hint_descendant_readers_above(row, stamp);
}
}
// Producers that read descendants, such as an SVG root or a snap container's scroll
// metadata, learn about damage below them from this hint. The walk stops at the first
// ancestor already hinted.
- fn hint_descendant_readers_above(&self, row: NodeSlotId, stamp: u32, states: &[RowPaintState]) {
- let set = &self.paintable_rows.damage;
+ fn hint_descendant_readers_above(&mut self, row: NodeSlotId, stamp: u32) {
let mut current = row;
while let Some(ancestor) = self.paint_ancestor_for_damage_hints(current) {
- let state = &states[ancestor.slot_index() as usize];
+ let state = &mut self.paintable_rows.row_paint_states[ancestor.slot_index() as usize];
if state.damage().contains(PaintDamage::DESCENDANT_READERS) {
break;
}
if state.add(PaintDamage::DESCENDANT_READERS, stamp) {
- set.rows.borrow_mut().push(ancestor);
+ self.paintable_rows.damage.rows.push(ancestor);
}
current = ancestor;
}
@@ -312,33 +305,42 @@ impl LayoutNodeArena {
None
}
- pub(crate) fn push_paint_damage_to_paint_subtree(&self, root: NodeSlotId, damage: PaintDamage) {
- let rows = self.paintable_rows();
- paint_order::for_each_in_paint_subtree(&rows, root, |row| self.push_paint_damage(row, damage));
+ pub(crate) fn push_paint_damage_to_paint_subtree(&mut self, root: NodeSlotId, damage: PaintDamage) {
+ let mut subtree = Vec::new();
+ paint_order::for_each_in_paint_subtree(&self.paintable_rows(), root, |row| subtree.push(row));
+ for row in subtree {
+ self.push_paint_damage(row, damage);
+ }
}
/// The fan-out of a style repaint: the row, the anonymous boxes it generated, and for an
/// inline the ancestors up to the line root that paints its pieces.
- pub(crate) fn push_paint_damage_for_repaint(&self, row: NodeSlotId, damage: PaintDamage) {
+ pub(crate) fn push_paint_damage_for_repaint(&mut self, row: NodeSlotId, damage: PaintDamage) {
+ let mut repainted_rows = smallvec::SmallVec::<[NodeSlotId; 4]>::new();
self.paintable_rows()
- .for_each_row_repainted_with(row, |repainted| self.push_paint_damage(repainted, damage));
+ .for_each_row_repainted_with(row, |repainted| repainted_rows.push(repainted));
+ for repainted in repainted_rows {
+ self.push_paint_damage(repainted, damage);
+ }
}
/// The row's producers and scopes are listed by the plans of its nearest paint ancestor;
/// resolved now, while the links are intact, for rows about to appear, disappear or move.
/// The ancestor's content changed below it as well.
- pub(crate) fn push_enclosing_paint_order_damage(&self, node: NodeSlotId) {
+ pub(crate) fn push_enclosing_paint_order_damage(&mut self, node: NodeSlotId) {
if let Some(owner) = self.enclosing_paint_order_owner(node) {
- self.push_paint_damage(owner, PaintDamage::ORDER | PaintDamage::DESCENDANT_READERS);
// A line's plan also places content nested inside ordinary inline boxes.
// Changes there must reach the block or self-painting inline that owns it.
let rows = self.paintable_rows();
- if node_painting::is_fragmented_inline(&rows, owner) {
- let line_owner = crate::painting::fragment_ownership::nearest_self_painting_inline_box(&rows, node)
- .unwrap_or(rows.paintable_data(owner).containing_block);
- if !line_owner.is_invalid() {
- self.push_paint_damage(line_owner, PaintDamage::ORDER);
- }
+ let line_owner = node_painting::is_fragmented_inline(&rows, owner)
+ .then(|| {
+ crate::painting::fragment_ownership::nearest_self_painting_inline_box(&rows, node)
+ .unwrap_or(rows.paintable_data(owner).containing_block)
+ })
+ .filter(|line_owner| !line_owner.is_invalid());
+ self.push_paint_damage(owner, PaintDamage::ORDER | PaintDamage::DESCENDANT_READERS);
+ if let Some(line_owner) = line_owner {
+ self.push_paint_damage(line_owner, PaintDamage::ORDER);
}
}
}
@@ -358,22 +360,22 @@ impl LayoutNodeArena {
None
}
- pub(crate) fn push_all_paint_damage(&self) {
- let set = &self.paintable_rows.damage;
- set.all.set(set.stamp_for_push());
+ pub(crate) fn push_all_paint_damage(&mut self) {
+ let set = &mut self.paintable_rows.damage;
+ set.all = set.stamp_for_push();
}
- pub(crate) fn push_scroll_metadata_damage_everywhere(&self) {
- let set = &self.paintable_rows.damage;
- set.scroll_metadata_everywhere.set(set.stamp_for_push());
+ pub(crate) fn push_scroll_metadata_damage_everywhere(&mut self) {
+ let set = &mut self.paintable_rows.damage;
+ set.scroll_metadata_everywhere = set.stamp_for_push();
}
pub(crate) fn paint_damage_covers_everything(&self) -> bool {
- self.paintable_rows.damage.all.get() != 0
+ self.paintable_rows.damage.all != 0
}
pub(crate) fn scroll_metadata_damaged_everywhere(&self) -> bool {
- self.paintable_rows.damage.scroll_metadata_everywhere.get() != 0
+ self.paintable_rows.damage.scroll_metadata_everywhere != 0
}
#[cfg(test)]
@@ -382,7 +384,6 @@ impl LayoutNodeArena {
.paintable_rows
.damage
.rows
- .borrow()
.iter()
.copied()
.filter(|row| self.paintable_row_is_populated(*row) && !self.row_paint_state(*row).damage().is_empty())
@@ -392,38 +393,31 @@ impl LayoutNodeArena {
rows
}
- pub(crate) fn note_publishing_paint_recording_started(&self) {
- let counter = &self.paintable_rows.damage.started_publishing_recordings;
- counter.set(
- counter
- .get()
- .checked_add(1)
- .expect("paint recording sequence overflowed"),
- );
+ pub(crate) fn note_publishing_paint_recording_started(&mut self) {
+ let counter = &mut self.paintable_rows.damage.started_publishing_recordings;
+ *counter = counter.checked_add(1).expect("paint recording sequence overflowed");
}
/// The published recording consumed everything pushed before it started. Rows pushed since
/// stay listed, and their hints are renewed because the ancestors they hinted were cleared.
- pub(crate) fn clear_paint_damage_consumed_by_published_recording(&self) {
- let set = &self.paintable_rows.damage;
- let consumed_through = set.started_publishing_recordings.get();
- if set.all.get() != 0 && set.all.get() <= consumed_through {
- set.all.set(0);
+ pub(crate) fn clear_paint_damage_consumed_by_published_recording(&mut self) {
+ let set = &mut self.paintable_rows.damage;
+ let consumed_through = set.started_publishing_recordings;
+ if set.all != 0 && set.all <= consumed_through {
+ set.all = 0;
}
- if set.scroll_metadata_everywhere.get() != 0 && set.scroll_metadata_everywhere.get() <= consumed_through {
- set.scroll_metadata_everywhere.set(0);
+ if set.scroll_metadata_everywhere != 0 && set.scroll_metadata_everywhere <= consumed_through {
+ set.scroll_metadata_everywhere = 0;
}
- let listed = std::mem::take(&mut *set.rows.borrow_mut());
- let states = self.paintable_rows.row_paint_states.borrow();
+ let listed = std::mem::take(&mut set.rows);
let mut kept = Vec::new();
for row in listed {
if !self.paintable_row_is_populated(row) {
continue;
}
- let state = &states[row.slot_index() as usize];
- if state.damage_stamp.get() <= consumed_through {
- state.damage.set(PaintDamage::NONE);
- state.damage_stamp.set(0);
+ let state = &mut self.paintable_rows.row_paint_states[row.slot_index() as usize];
+ if state.damage_stamp <= consumed_through {
+ state.clear();
} else {
kept.push(row);
}
@@ -431,10 +425,10 @@ impl LayoutNodeArena {
// A row populated again after its push is listed again by its next push.
kept.sort_unstable_by_key(|row| (row.slot_index(), row.generation()));
kept.dedup();
- *set.rows.borrow_mut() = kept.clone();
+ self.paintable_rows.damage.rows.clone_from(&kept);
for row in kept {
- let stamp = states[row.slot_index() as usize].damage_stamp.get();
- self.hint_descendant_readers_above(row, stamp, &states);
+ let stamp = self.paintable_rows.row_paint_states[row.slot_index() as usize].damage_stamp;
+ self.hint_descendant_readers_above(row, stamp);
}
}
}
@@ -455,7 +449,7 @@ mod tests {
}
// Building the tree pushes attachment damage; a published recording consumes it.
- fn settle(arena: &LayoutNodeArena) {
+ fn settle(arena: &mut LayoutNodeArena) {
arena.note_publishing_paint_recording_started();
arena.clear_paint_damage_consumed_by_published_recording();
assert_eq!(arena.damaged_paint_rows(), Vec::new());
@@ -466,7 +460,7 @@ mod tests {
let mut arena = LayoutNodeArena::new();
let first = populated_child(&mut arena, NodeSlotId::INVALID);
let second = populated_child(&mut arena, NodeSlotId::INVALID);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage(first, PaintDamage::DRAW_FOREGROUND);
let frame = arena.paint_damage_for_frame();
arena.push_paint_damage(second, PaintDamage::DRAW_BACKGROUND);
@@ -485,7 +479,7 @@ mod tests {
let middle = populated_child(&mut arena, root);
let leaf = populated_child(&mut arena, middle);
let unrelated = populated_child(&mut arena, root);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage(leaf, PaintDamage::DRAW_BACKGROUND);
arena.push_paint_damage(leaf, PaintDamage::HIT_FOREGROUND);
@@ -514,7 +508,7 @@ mod tests {
arena.write_shape(unpopulated).set_kind(NodeKind::InlineNode);
arena.insert_child(owner, unpopulated, NodeSlotId::INVALID);
let child = populated_child(&mut arena, unpopulated);
- settle(&arena);
+ settle(&mut arena);
arena.note_paint_order_changed(child);
@@ -536,7 +530,7 @@ mod tests {
let new_owner = populated_child(&mut arena, root);
let moved = populated_child(&mut arena, old_owner);
let leaf = populated_child(&mut arena, moved);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage(leaf, PaintDamage::DRAW_FOREGROUND);
arena.remove_child(old_owner, moved);
@@ -566,7 +560,7 @@ mod tests {
let mask = populated_child(&mut arena, svg_root);
arena.write_shape(mask).set_kind(NodeKind::SVGMaskBox);
let mask_content = populated_child(&mut arena, mask);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage(mask_content, PaintDamage::SVG);
@@ -580,7 +574,7 @@ mod tests {
let mut arena = LayoutNodeArena::new();
let root = populated_child(&mut arena, NodeSlotId::INVALID);
let child = populated_child(&mut arena, root);
- settle(&arena);
+ settle(&mut arena);
arena.push_all_paint_damage();
arena.push_paint_damage(child, PaintDamage::ALL_PRODUCERS);
@@ -603,7 +597,7 @@ mod tests {
let root = populated_child(&mut arena, NodeSlotId::INVALID);
let early = populated_child(&mut arena, root);
let late = populated_child(&mut arena, root);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage(early, PaintDamage::DRAW_FOREGROUND);
arena.push_scroll_metadata_damage_everywhere();
@@ -631,7 +625,7 @@ mod tests {
let mut arena = LayoutNodeArena::new();
let root = populated_child(&mut arena, NodeSlotId::INVALID);
let rows: Vec<NodeSlotId> = (0..3).map(|_| populated_child(&mut arena, root)).collect();
- settle(&arena);
+ settle(&mut arena);
arena.note_publishing_paint_recording_started();
for &row in &rows {
@@ -643,7 +637,7 @@ mod tests {
let mut expected = vec![root, rows[0], rows[1], rows[2]];
expected.sort_unstable_by_key(|row| (row.slot_index(), row.generation()));
- assert_eq!(*arena.paintable_rows.damage.rows.borrow(), expected);
+ assert_eq!(arena.paintable_rows.damage.rows, expected);
}
#[test]
@@ -652,7 +646,7 @@ mod tests {
let root = populated_child(&mut arena, NodeSlotId::INVALID);
let owner = populated_child(&mut arena, root);
let cleared = populated_child(&mut arena, owner);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage(cleared, PaintDamage::DRAW_BACKGROUND);
let reset = arena.prepare_paintable_row_cleared_reset(cleared).unwrap();
@@ -673,7 +667,7 @@ mod tests {
let anonymous = populated_child(&mut arena, inline);
arena.write_shape(anonymous).set_kind(NodeKind::BlockContainer);
arena.set_node_flag(anonymous, crate::layout::node_data::NodeFlag::Anonymous, true);
- settle(&arena);
+ settle(&mut arena);
arena.push_paint_damage_for_repaint(inline, PaintDamage::ALL_DRAW);
diff --git a/Libraries/LibWeb/Rust/src/painting/record/publish.rs b/Libraries/LibWeb/Rust/src/painting/record/publish.rs
index 81520c71923..88a08f01444 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/publish.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/publish.rs
@@ -377,18 +377,20 @@ pub(crate) fn take_in_presented_output(
/// the hit-test list generation moves on where the list changed, and a recording that publishes consumes the damage it
/// painted. Answers the hit-test list generation.
pub(crate) fn take_in_recording(
- arena: &LayoutNodeArena,
+ arena: &mut LayoutNodeArena,
output: std::sync::Arc<RecordingOutput>,
hit_test_list_changed: bool,
publishes_recording: bool,
) -> u64 {
+ // Read-only recordings publish nothing and must not consume the damage.
+ if publishes_recording {
+ arena.clear_paint_damage_consumed_by_published_recording();
+ }
let mut paint_state = arena.paint_state().borrow_mut();
if hit_test_list_changed {
paint_state.hit_test_list_generation += 1;
}
if publishes_recording {
- // Read-only recordings publish nothing and must not consume the damage.
- arena.clear_paint_damage_consumed_by_published_recording();
paint_state.visual_context.quarantined_slots_are_releasable = true;
}
paint_state.last_recording = Some(output);
@@ -428,7 +430,7 @@ mod tests {
output,
read_write,
|output, changed| {
- generation = take_in_recording(&arena, output, changed, read_write);
+ generation = take_in_recording(&mut arena, output, changed, read_write);
},
);
assert_eq!(generation, hit_test_generation);
diff --git a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs
index 53fd158d34a..88c6d0ee9f3 100644
--- a/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/painting/scrollable_overflow.rs
@@ -13,7 +13,7 @@ use crate::layout::node_data::{NodeFlag, NodeKind, NodeSlotId};
use crate::layout::node_facts::{self, NodeShape};
use crate::painting::paint_read::{GeometryRead, PaintRead, PaintRow};
use crate::painting::paintable_data::FfiOverflowData;
-use crate::painting::paintable_rows::PaintableRowsRead;
+use crate::painting::paintable_rows::{PaintableRowsRead, PaintableRowsWrite};
use crate::painting::visual_context::dirty::VisualContextBoxDirtyKind;
use crate::painting::visual_context::node_values;
use crate::painting::{paintable_geometry, style_queries, text_fragment};
@@ -156,7 +156,7 @@ pub(crate) struct OverflowAssignment {
}
impl OverflowAssignment {
- pub(crate) fn apply(self, layout_arena: &impl PaintableRowsRead) {
+ pub(crate) fn apply(self, layout_arena: &mut impl PaintableRowsWrite) {
let previously_measured = layout_arena
.paintable_side_data(self.box_paintable)
.overflow_measured_this_commit
@@ -189,10 +189,11 @@ impl OverflowAssignment {
PaintDamage::SCROLL_METADATA | PaintDamage::DRAW_OVERLAY | PaintDamage::HIT_OVERLAY,
);
// The root background covers the viewport united with the root's overflow.
- if layout_arena.node_kind_if_live(self.box_paintable) == Some(NodeKind::Viewport)
- && let Some(source) = layout_arena.paint_state().borrow().root_background_source
- {
- layout_arena.push_paint_damage(source.root_layout_node, PaintDamage::DRAW_BACKGROUND);
+ if layout_arena.node_kind_if_live(self.box_paintable) == Some(NodeKind::Viewport) {
+ let root_background_source = layout_arena.paint_state().borrow().root_background_source;
+ if let Some(source) = root_background_source {
+ layout_arena.push_paint_damage(source.root_layout_node, PaintDamage::DRAW_BACKGROUND);
+ }
}
}
// A flip changes what rendering preparation answers even where it is the box's first measurement since it
@@ -773,7 +774,7 @@ impl LayoutNodeArena {
/// Measures every row whose overflow a read could find unmeasured, so that reading overflow
/// never measures it. Rendering preparation, hit testing, the recording and every query that
/// reads overflow run this first; it never clamps a stored scroll offset.
- pub(crate) fn measure_scrollable_overflow(&self) {
+ pub(crate) fn measure_scrollable_overflow(&mut self) {
if self.scrollable_overflow_is_measured() {
return;
}
@@ -789,7 +790,7 @@ impl LayoutNodeArena {
self.scrollable_overflow.rows_to_measure.borrow_mut().push(slot);
}
- fn ensure_scrollable_overflow(&self, slot: NodeSlotId) {
+ fn ensure_scrollable_overflow(&mut self, slot: NodeSlotId) {
if !self.paintable_row_is_populated(slot)
|| !self
.scrollable_overflow
@@ -809,11 +810,14 @@ impl LayoutNodeArena {
return;
}
self.ensure_overflow_contained_boxes();
- let rows = self.paintable_rows();
- let assignments =
- measure_box_scrollable_overflow(&rows, &self.scrollable_overflow.non_child_boxes.borrow(), slot);
+ let assignments = measure_box_scrollable_overflow(
+ &self.paintable_rows(),
+ &self.scrollable_overflow.non_child_boxes.borrow(),
+ slot,
+ );
+ let mut rows = self.paintable_rows_mut();
for assignment in assignments {
- assignment.apply(&rows);
+ assignment.apply(&mut rows);
}
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/selection.rs b/Libraries/LibWeb/Rust/src/painting/selection.rs
index 10648e3aa74..94661843c1d 100644
--- a/Libraries/LibWeb/Rust/src/painting/selection.rs
+++ b/Libraries/LibWeb/Rust/src/painting/selection.rs
@@ -68,7 +68,7 @@ pub(crate) struct SelectionRange {
pub boxes_with_selection_state: Vec<NodeSlotId>,
}
-fn invalidate_text_node(layout_arena: &PaintableRowsMut<'_>, node: NodeSlotId) {
+fn invalidate_text_node(layout_arena: &mut PaintableRowsMut<'_>, node: NodeSlotId) {
if let Some(containing_block) = text_fragment::containing_block_paintable_of_node(layout_arena, node) {
layout_arena.push_paint_damage(containing_block, PaintDamage::ALL_DRAW);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs b/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs
index 3f3b5d86e01..61fb21a5a69 100644
--- a/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs
+++ b/Libraries/LibWeb/Rust/src/painting/stacking_context/entries.rs
@@ -113,7 +113,7 @@ impl LayoutNodeArena {
);
}
- pub(crate) fn register_stacking_context_contribution(&self, slot: NodeSlotId, facts: &StackingContextFacts) {
+ pub(crate) fn register_stacking_context_contribution(&mut self, slot: NodeSlotId, facts: &StackingContextFacts) {
let enclosing = facts.enclosing_stacking_context;
if !self.paintable_row_is_populated(enclosing) {
return;
@@ -155,7 +155,7 @@ impl LayoutNodeArena {
}
}
- pub(crate) fn withdraw_stacking_context_contribution(&self, slot: NodeSlotId, facts: &StackingContextFacts) {
+ pub(crate) fn withdraw_stacking_context_contribution(&mut self, slot: NodeSlotId, facts: &StackingContextFacts) {
let enclosing = facts.enclosing_stacking_context;
if !self.paintable_row_is_populated(enclosing) {
return;
@@ -195,7 +195,7 @@ impl LayoutNodeArena {
}
}
- fn flag_stacking_context_entries_for_resort(&self, root: NodeSlotId) {
+ fn flag_stacking_context_entries_for_resort(&mut self, root: NodeSlotId) {
if !self.paintable_row_is_populated(root) {
return;
}
@@ -215,7 +215,7 @@ impl LayoutNodeArena {
}
pub(crate) fn apply_stacking_context_facts_delta(
- &self,
+ &mut self,
slot: NodeSlotId,
previous: Option<&StackingContextFacts>,
next: &mut StackingContextFacts,
@@ -333,7 +333,7 @@ impl LayoutNodeArena {
}
pub(crate) fn withdraw_stacking_context_state_of_reset_row(
- &self,
+ &mut self,
slot: NodeSlotId,
facts: Option<StackingContextFacts>,
) {
@@ -345,19 +345,21 @@ impl LayoutNodeArena {
self.drop_stacking_context_entries_of_root(slot);
}
- pub(crate) fn note_layout_subtree_attached(&self, subtree_root: NodeSlotId) {
+ pub(crate) fn note_layout_subtree_attached(&mut self, subtree_root: NodeSlotId) {
if self.paintable_row_count() == 0 {
return;
}
// The new parent lists the subtree from now on, and every row inside plans its own
// descendants under the new ancestry.
self.push_enclosing_paint_order_damage(subtree_root);
- self.for_each_node_in_layout_subtree_in_pre_order(subtree_root, |node| {
+ let mut cursor = Some(subtree_root);
+ while let Some(node) = cursor {
if self.paintable_row_is_populated(node) {
self.note_overflow_contained_box_added(node);
self.note_visual_context_box_dirty(node, VisualContextBoxDirtyKind::ReattachedInLayoutTree);
self.push_paint_damage(node, crate::painting::record::damage::PaintDamage::ORDER);
}
- });
+ cursor = self.next_node_in_layout_subtree_in_pre_order(subtree_root, node);
+ }
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs
index 7d01d992b7c..5e20cff5cec 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/box_build.rs
@@ -35,6 +35,9 @@ pub(crate) struct PaintableVisualContextAssignment {
pub has_non_invertible_css_transform: bool,
pub record: PaintableVisualContextRecord,
pub node_handles: BoxVisualContextNodeHandles,
+ /// The bounds of the SVG filter the box references, as the build gathered them, which the row takes as the
+ /// assignment applies. None for an assignment no build gathered.
+ pub gathered_svg_filter_bounds: Option<Option<crate::layout::used_values::FfiCssPixelRect>>,
}
impl PaintableVisualContextAssignment {
@@ -50,11 +53,15 @@ impl PaintableVisualContextAssignment {
has_non_invertible_css_transform: data.has_flag(PaintableFlag::HasNonInvertibleCssTransform),
record,
node_handles: BoxVisualContextNodeHandles::default(),
+ gathered_svg_filter_bounds: None,
}
}
pub(crate) fn apply(self, layout_arena: &mut impl PaintableRowsWrite) {
use crate::painting::record::damage::PaintDamage;
+ if let Some(svg_filter_bounds) = self.gathered_svg_filter_bounds {
+ super::node_values::set_svg_filter_bounds(layout_arena, self.slot, svg_filter_bounds);
+ }
// Commands and hit-test items name the row's own nodes; the scroll metadata of every
// descendant names the nearest scroll node above it.
let (scroll_nodes_changed, non_invertible_transform_flipped) = match layout_arena
@@ -238,7 +245,7 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(
anchor_scroll_shift_resolver: &dyn AnchorScrollShiftResolver,
) -> PaintableVisualContextAssignment {
let layout_arena = env.layout_arena;
- let facts = super::build::BoxFacts::gather(layout_arena, slot, env.pixel_ratio, true);
+ let (facts, svg_filter_bounds) = super::build::BoxFacts::gather(layout_arena, slot, env.pixel_ratio, true);
let position = crate::painting::style_queries::position(layout_arena, slot);
let is_fixed = position == crate::css::css_enums::positioning::FIXED;
let is_absolute = position == crate::css::css_enums::positioning::ABSOLUTE;
@@ -263,6 +270,7 @@ pub(crate) fn build_box_visual_context_nodes<Arena: PaintableRowsRead>(
assignment.enclosing_scroll_node_index = VISUAL_VIEWPORT_NODE_INDEX;
assignment.own_scroll_node_index = VISUAL_VIEWPORT_NODE_INDEX;
assignment.node_identity = 0;
+ assignment.gathered_svg_filter_bounds = Some(svg_filter_bounds);
let mut nearest_scroll_nodes_for_descendants = if is_fixed {
NearestScrollNodeIndices {
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
index 490655bd957..30053a765d8 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
@@ -92,26 +92,32 @@ impl BoxFacts {
.is_some_and(|effects| effects.backdrop_filter.is_some())
}
- /// Gathers a box's facts for the visual context update, which keeps the bounds of the SVG
- /// filter the box references on its row.
+ /// Gathers a box's facts for the visual context update, with the bounds of the SVG filter the box references,
+ /// which the update keeps on its row.
pub(crate) fn gather(
layout_arena: &impl PaintableRowsRead,
slot: NodeSlotId,
pixel_ratio: f64,
consults_default_scroll_shift_anchors: bool,
- ) -> Self {
+ ) -> (Self, Option<crate::layout::used_values::FfiCssPixelRect>) {
let default_scroll_shift_anchor = if consults_default_scroll_shift_anchors {
layout_arena.default_scroll_shift_anchor(slot)
} else {
NodeSlotId::INVALID
};
- Self::gather_with_effects(
+ let mut svg_filter_bounds = None;
+ let facts = Self::gather_with_effects(
layout_arena,
slot,
pixel_ratio,
default_scroll_shift_anchor,
- |layout_arena| super::node_values::compute_effects_data(layout_arena, slot, pixel_ratio),
- )
+ |layout_arena| {
+ let resolved = super::node_values::resolve_effects_data(layout_arena, slot, pixel_ratio)?;
+ svg_filter_bounds = resolved.svg_filter_bounds;
+ resolved.effects
+ },
+ );
+ (facts, svg_filter_bounds)
}
/// Gathers the facts of a box painted inside an SVG resource, which the visual context update
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs
index 701846b8395..0fb9684e394 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/incremental.rs
@@ -17,7 +17,7 @@ use crate::fast_hash::{FastMap as HashMap, FastSet as HashSet};
use crate::layout::node_data::{NodeKind, NodeSlotId};
use crate::painting::host::FfiVisualContextTreeInputs;
use crate::painting::paint_order;
-use crate::painting::paintable_rows::PaintableRowsRead;
+use crate::painting::paintable_rows::{PaintableRowsRead, PaintableRowsWrite};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
struct ChildCascade {
@@ -317,9 +317,10 @@ pub(crate) fn box_owns_geometry_dependent_nodes(
layout_arena: &impl PaintableRowsRead,
tree: &VisualContextTree,
slot: NodeSlotId,
+ has_svg_filter_bounds: bool,
handles: &BoxVisualContextNodeHandles,
) -> bool {
- if layout_arena.committed_side_data(slot).svg_filter_bounds.is_some() {
+ if has_svg_filter_bounds {
return true;
}
let spatial_is_geometry_dependent = handles.spatial.iter().any(|index| {
@@ -422,8 +423,8 @@ fn take_next_deferred_anchor_positioned(
Some(entry.pending)
}
-pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
- layout_arena: &Arena,
+pub(crate) fn update_visual_context_tree<Arena: PaintableRowsWrite>(
+ layout_arena: &mut Arena,
viewport: NodeSlotId,
tree_inputs: FfiVisualContextTreeInputs,
scope: VisualContextUpdateScope,
@@ -432,7 +433,7 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
let plan = if scope.rebuilds_every_box() {
WorkPlan::default()
} else {
- match expand_dirty_entries(layout_arena, &state.dirty_boxes, &state.offset_path_boxes) {
+ match expand_dirty_entries(&*layout_arena, &state.dirty_boxes, &state.offset_path_boxes) {
Ok(plan) => plan,
Err(reason) => return IncrementalUpdateResult::NeedsFullBuild(reason),
}
@@ -450,10 +451,6 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
state.offset_path_boxes.clear();
}
- let environment = BoxBuildEnvironment {
- layout_arena,
- pixel_ratio: tree_inputs.device_pixels_per_css_pixel,
- };
let viewport_output = layout_arena
.paintable_visual_context_record(viewport)
.map(|record| record.output_for_descendants);
@@ -473,7 +470,8 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
let mut assignment_index_by_slot: HashMap<NodeSlotId, usize> =
HashMap::with_capacity_and_hasher(every_box_capacity, Default::default());
let mut stack: Vec<PendingBox> = Vec::new();
- let push_children = |stack: &mut Vec<PendingBox>,
+ let push_children = |layout_arena: &Arena,
+ stack: &mut Vec<PendingBox>,
parent: NodeSlotId,
input_for_children: DescendantVisualContexts,
cascade: ChildCascade,
@@ -491,6 +489,7 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
stack[pushed_children_begin..].reverse();
};
push_children(
+ &*layout_arena,
&mut stack,
viewport,
viewport_output,
@@ -507,7 +506,7 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
let (pending, may_defer_this_box) = match stack.pop() {
Some(pending) => (pending, defers_anchor_positioned),
None => match take_next_deferred_anchor_positioned(
- layout_arena,
+ &*layout_arena,
&mut deferred_anchor_positioned,
&mut deferred_awaiting_build,
) {
@@ -543,25 +542,34 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
}
}
let (child_cascade, output_for_children) = if rebuild {
- let existing_record = layout_arena.paintable_visual_context_record(slot);
- let record_existed = existing_record.is_some();
- let previous_output = existing_record.as_ref().map(|record| record.output_for_descendants);
- let previous_stacking_context_facts = existing_record.as_ref().map(|record| record.stacking_context);
+ let (record_existed, previous_output, previous_stacking_context_facts) = {
+ let existing_record = layout_arena.paintable_visual_context_record(slot);
+ (
+ existing_record.is_some(),
+ existing_record.as_ref().map(|record| record.output_for_descendants),
+ existing_record.as_ref().map(|record| record.stacking_context),
+ )
+ };
let tree = std::sync::Arc::make_mut(state.tree.as_mut().expect("the tree exists throughout the pass"));
let existing_handles = layout_arena.paintable_visual_context_node_handles(slot);
let mut writer = BoxNodeWriter::new(tree, existing_handles.as_deref(), &mut delta);
+ let environment = BoxBuildEnvironment {
+ layout_arena: &*layout_arena,
+ pixel_ratio: tree_inputs.device_pixels_per_css_pixel,
+ };
let mut assignment = build_box_visual_context_nodes(
&environment,
&mut writer,
slot,
input,
&WalkAnchorScrollShiftResolver {
- layout_arena,
+ layout_arena: &*layout_arena,
assignments: &assignments,
assignment_index_by_slot: &assignment_index_by_slot,
},
);
let (handles, reconcile) = writer.finish();
+ drop(existing_handles);
if layout_arena
.node_style_if_live(slot)
.is_some_and(|style| style.transform().has_offset_path)
@@ -572,8 +580,13 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
}
let new_output = assignment.record.output_for_descendants;
assignment.node_handles = handles;
- assignment.record.owns_geometry_dependent_nodes =
- box_owns_geometry_dependent_nodes(layout_arena, tree, slot, &assignment.node_handles);
+ assignment.record.owns_geometry_dependent_nodes = box_owns_geometry_dependent_nodes(
+ &*layout_arena,
+ tree,
+ slot,
+ assignment.gathered_svg_filter_bounds.flatten().is_some(),
+ &assignment.node_handles,
+ );
assignment.record.subtree_may_own_geometry_dependent_nodes =
assignment.record.owns_geometry_dependent_nodes || subtree_may_own_geometry_dependent_nodes;
if scope != VisualContextUpdateScope::FreshTree {
@@ -605,9 +618,8 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
if reconcile.shape_changed || !record_existed || contexts_changed {
layout_arena.push_paint_damage(slot, crate::painting::record::damage::PaintDamage::ALL_PRODUCERS);
}
- drop(existing_record);
if assignment.record.owns_geometry_dependent_nodes && !subtree_may_own_geometry_dependent_nodes {
- let mut ancestor = paint_order::paint_parent(layout_arena, slot);
+ let mut ancestor = paint_order::paint_parent(&*layout_arena, slot);
while let Some(current) = ancestor {
let ancestor_was_flagged = if let Some(&index) = assignment_index_by_slot.get(&current) {
let flagged = assignments[index].record.subtree_may_own_geometry_dependent_nodes;
@@ -621,7 +633,7 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
if ancestor_was_flagged {
break;
}
- ancestor = paint_order::paint_parent(layout_arena, current);
+ ancestor = paint_order::paint_parent(&*layout_arena, current);
}
}
assignment_index_by_slot.insert(slot, assignments.len());
@@ -647,7 +659,14 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
.expect("a box that was not rebuilt keeps its record")
.output_for_descendants
});
- push_children(&mut stack, slot, output_for_children, child_cascade, visit_every_child);
+ push_children(
+ &*layout_arena,
+ &mut stack,
+ slot,
+ output_for_children,
+ child_cascade,
+ visit_every_child,
+ );
}
}
@@ -656,7 +675,7 @@ pub(crate) fn update_visual_context_tree<Arena: PaintableRowsRead>(
return IncrementalUpdateResult::NeedsFullBuild(VisualContextUpdateScope::FreshTree);
}
debug_assert!(tree.node_references_are_consistent());
- let scroll_state = rebuild_scroll_state_from_tree(layout_arena, tree, &tree_inputs);
+ let scroll_state = rebuild_scroll_state_from_tree(&*layout_arena, tree, &tree_inputs);
tree.debug_assert_slot_accounting();
if delta.structural_epoch_changed {
tree.structural_epoch = allocate_structural_epoch();
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
index fa22fdacd3d..cf63eeb88ca 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
@@ -19,7 +19,7 @@ use crate::painting::host::FfiVisualContextTreeInputs;
use crate::painting::node_painting;
use crate::painting::paint_read::{PaintRead, PaintRow};
use crate::painting::paintable_geometry;
-use crate::painting::paintable_rows::PaintableRowsRead;
+use crate::painting::paintable_rows::PaintableRowsWrite;
use crate::painting::style_queries;
use libgfx_rust::{
AffineTransform, CompositingAndBlendingOperator, CornerRadii, FloatPoint, affine_to_matrix, perspective_matrix,
@@ -571,8 +571,8 @@ pub(crate) fn mix_blend_mode_to_compositing_and_blending_operator(
/// box, or the whole enclosing viewport rect for an element without geometry of its own.
// The bounds size the transparent fill that triggers a content-generating SVG filter, which
// the stacking-context preamble records.
-fn set_svg_filter_bounds(
- layout_arena: &impl PaintableRowsRead,
+pub(crate) fn set_svg_filter_bounds(
+ layout_arena: &mut impl PaintableRowsWrite,
slot: NodeSlotId,
bounds: Option<crate::layout::used_values::FfiCssPixelRect>,
) {
@@ -643,16 +643,6 @@ fn published_svg_filter(
}
}
-pub(crate) fn compute_effects_data(
- layout_arena: &impl PaintableRowsRead,
- slot: NodeSlotId,
- device_pixels_per_css_pixel: f64,
-) -> Option<EffectsData> {
- let resolved = resolve_effects_data(layout_arena, slot, device_pixels_per_css_pixel)?;
- set_svg_filter_bounds(layout_arena, slot, resolved.svg_filter_bounds);
- resolved.effects
-}
-
/// A box's effects, and the bounds of the SVG filter it references.
pub(crate) struct ResolvedEffects {
pub(crate) effects: Option<EffectsData>,