mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:57:34 +00:00
LibWeb: Reduce paintable tree traversals during hit-testing
By storing a list of positioned and floating descendants within the stacking context tree node, we can eliminate the need for costly paintable tree traversals during hit-testing. This optimization results in hit-testing being 2 to 2.5 times faster on https://ziglang.org/documentation/master/
This commit is contained in:
parent
9c6c3fe0d8
commit
2764966ccc
5 changed files with 95 additions and 77 deletions
|
@ -38,11 +38,16 @@ void ViewportPaintable::build_stacking_context_tree()
|
|||
size_t index_in_tree_order = 1;
|
||||
for_each_in_subtree([&](Paintable const& paintable) {
|
||||
const_cast<Paintable&>(paintable).invalidate_stacking_context();
|
||||
if (!paintable.layout_node().establishes_stacking_context()) {
|
||||
auto* parent_context = const_cast<Paintable&>(paintable).enclosing_stacking_context();
|
||||
auto establishes_stacking_context = paintable.layout_node().establishes_stacking_context();
|
||||
if ((paintable.is_positioned() || establishes_stacking_context) && paintable.computed_values().z_index().value_or(0) == 0)
|
||||
parent_context->m_positioned_descendants_with_stack_level_0_and_stacking_contexts.append(paintable);
|
||||
if (!paintable.is_positioned() && paintable.is_floating())
|
||||
parent_context->m_non_positioned_floating_descendants.append(paintable);
|
||||
if (!establishes_stacking_context) {
|
||||
VERIFY(!paintable.stacking_context());
|
||||
return TraversalDecision::Continue;
|
||||
}
|
||||
auto* parent_context = const_cast<Paintable&>(paintable).enclosing_stacking_context();
|
||||
VERIFY(parent_context);
|
||||
const_cast<Paintable&>(paintable).set_stacking_context(make<Painting::StackingContext>(const_cast<Paintable&>(paintable), parent_context, index_in_tree_order++));
|
||||
return TraversalDecision::Continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue