layout: Skip box tree construction when possible (#37957)

When a style change does not chang the structure of the box tree, it is
possible to skip box tree rebuilding for an element. This change adds
support for reusing old box trees when no element has that type of
damage. In order to make this happen, there needs to be a type of
"empty" `LayoutDamage` that just indicates that a fragment tree layout
is necessary.

This is the first step toward incremental fragment tree layout.

Testing: This should not change observable behavior and thus is covered
by
existing WPT tests. Performance numbers to follow.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-07-09 19:33:09 +02:00 committed by GitHub
parent d5d131c172
commit 436c9072c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 181 additions and 78 deletions

View file

@ -25,7 +25,29 @@ impl LayoutDamage {
RestyleDamage::RELAYOUT
}
pub fn rebuild_box_tree() -> RestyleDamage {
RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits()) | RestyleDamage::RELAYOUT
}
pub fn has_box_damage(&self) -> bool {
self.intersects(Self::REBUILD_BOX)
}
}
impl From<RestyleDamage> for LayoutDamage {
fn from(restyle_damage: RestyleDamage) -> Self {
LayoutDamage::from_bits_retain(restyle_damage.bits())
}
}
impl std::fmt::Debug for LayoutDamage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.contains(Self::REBUILD_BOX) {
f.write_str("REBUILD_BOX")
} else if self.contains(Self::RECOLLECT_BOX_TREE_CHILDREN) {
f.write_str("RECOLLECT_BOX_TREE_CHILDREN")
} else {
f.write_str("EMPTY")
}
}
}