Truly independent web browser
LibWeb: Keep the children a point may be over between paint phases
Aliaksandr Kalenikbfad48402e5c
diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rsindex f156041c347..c834b061257 100644--- a/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/walk.rs@@ -106,6 +106,8 @@ struct WhatThePointMisses<'walk, 'a, R: PaintRead> {}impl<R: PaintRead> PlanLeavesOut for WhatThePointMisses<'_, '_, R> {+ const LEAVES_OUT_THE_SAME_CHILD_SCOPES_IN_EVERY_PHASE: bool = true;+fn leaves_out_child_scope(&mut self, child: PaintScope, child_inputs: PaintOrderInputs) -> bool {self.walk.point_misses_child_scope(child, child_inputs, self.owner)}@@ -116,6 +118,19 @@ impl<R: PaintRead> PlanLeavesOut for WhatThePointMisses<'_, '_, R> {.walk.point_misses_line(line_root, line_index, self.owner.absolute_content_origin)}++ fn paint_children_kept_by_an_earlier_phase(&mut self, owner: NodeSlotId) -> Option<&[NodeSlotId]> {+ self.walk+ .paint_children_the_point_may_be_over+ .get(&owner)+ .map(|children| children.as_slice())+ }++ fn keep_paint_children_for_later_phases(&mut self, owner: NodeSlotId, children_in_tree_order: &[NodeSlotId]) {+ self.walk+ .paint_children_the_point_may_be_over+ .insert(owner, SmallVec::from_slice(children_in_tree_order));+ }}#[derive(Clone, Copy)]@@ -158,6 +173,7 @@ struct PointWalk<'a, R: PaintRead> {local_points_ignoring_clips: FastMap<SpatialNodeIndex, Option<FloatPoint>>,last_local_point_ignoring_clips: Option<(SpatialNodeIndex, Option<FloatPoint>)>,hits_of_producer_in_paint_order: Vec<PointHit>,+ paint_children_the_point_may_be_over: FastMap<NodeSlotId, SmallVec<[NodeSlotId; 8]>>,/// What lies under the point, topmost first as the walk met it.hits: Vec<PointHit>,/// The 3D rendering context the topmost hit is in, whose planes paint sorted by depth: the walk goes on until@@ -537,6 +553,7 @@ fn walk_for<'a, R: PaintRead>(local_points_ignoring_clips: FastMap::default(),last_local_point_ignoring_clips: None,hits_of_producer_in_paint_order: Vec::new(),+ paint_children_the_point_may_be_over: FastMap::default(),hits: Vec::new(),sorting_group_of_topmost_hit: None,walk_left_the_sorting_group: false,diff --git a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rsindex d89708046db..8007301e88d 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs@@ -385,8 +385,16 @@ impl PaintScopePlan {}pub(crate) trait PlanLeavesOut {+ const LEAVES_OUT_THE_SAME_CHILD_SCOPES_IN_EVERY_PHASE: bool = false;+fn leaves_out_child_scope(&mut self, child: PaintScope, child_inputs: PaintOrderInputs) -> bool;fn leaves_out_line(&mut self, line_root: NodeSlotId, line_index: u32) -> bool;++ fn paint_children_kept_by_an_earlier_phase(&mut self, _owner: NodeSlotId) -> Option<&[NodeSlotId]> {+ None+ }++ fn keep_paint_children_for_later_phases(&mut self, _owner: NodeSlotId, _children_in_tree_order: &[NodeSlotId]) {}}struct LeavesOutNothing;@@ -401,6 +409,8 @@ impl PlanLeavesOut for LeavesOutNothing {}}+const FEWEST_PAINT_CHILDREN_WORTH_KEEPING_FOR_LATER_PHASES: usize = 32;+struct PaintOrderBuilder<'a, R: PaintRead, LeavesOut: PlanLeavesOut> {layout_arena: &'a R,paint_overlay: bool,@@ -758,16 +768,43 @@ impl<R: PaintRead, LeavesOut: PlanLeavesOut> PaintOrderBuilder<'_, R, LeavesOut>matches: impl Fn(&Self, NodeSlotId) -> bool,) {let begin = self.items.len();- let mut next_child = crate::painting::paint_order::first_paint_child(self.layout_arena, paintable);- while let Some(child) = next_child {- next_child = crate::painting::paint_order::next_paint_sibling_of_paint_child(self.layout_arena, child);- if !matches(self, child) || self.descendant_phase_is_empty(child, phase) {- continue;+ let scope_of = |child| PaintScope {+ owner: child,+ kind: PaintScopeKind::Descendants(phase),+ };+ let children_kept_by_an_earlier_phase = self+ .leaves_out+ .paint_children_kept_by_an_earlier_phase(paintable)+ .map(SmallVec::<[NodeSlotId; 8]>::from_slice);+ if let Some(children) = children_kept_by_an_earlier_phase {+ for child in children {+ if matches(self, child) && !self.descendant_phase_is_empty(child, phase) {+ self.append_child_scope(scope_of(child));+ }+ }+ } else {+ let mut children_with_no_scope_left_out = SmallVec::<[NodeSlotId; 8]>::new();+ let mut child_count = 0;+ let mut next_child = crate::painting::paint_order::first_paint_child(self.layout_arena, paintable);+ while let Some(child) = next_child {+ next_child = crate::painting::paint_order::next_paint_sibling_of_paint_child(self.layout_arena, child);+ child_count += 1;+ let has_a_scope_in_this_phase = matches(self, child) && !self.descendant_phase_is_empty(child, phase);+ let item_count_before = self.items.len();+ if has_a_scope_in_this_phase {+ self.append_child_scope(scope_of(child));+ }+ let scope_was_left_out = has_a_scope_in_this_phase && self.items.len() == item_count_before;+ if LeavesOut::LEAVES_OUT_THE_SAME_CHILD_SCOPES_IN_EVERY_PHASE && !scope_was_left_out {+ children_with_no_scope_left_out.push(child);+ }+ }+ if LeavesOut::LEAVES_OUT_THE_SAME_CHILD_SCOPES_IN_EVERY_PHASE+ && child_count >= FEWEST_PAINT_CHILDREN_WORTH_KEEPING_FOR_LATER_PHASES+ {+ self.leaves_out+ .keep_paint_children_for_later_phases(paintable, &children_with_no_scope_left_out);}- self.append_child_scope(PaintScope {- owner: child,- kind: PaintScopeKind::Descendants(phase),- });}let display = style_queries::display(self.layout_arena, paintable);if display.is_flex_inside() || display.is_grid_inside() {