Skip to content

Truly independent web browser

LibWeb: Build the layout tree where the arena's own marks ask for it

Aliaksandr Kalenik7da41e71a575
diff --git a/Libraries/LibWeb/Layout/UpdateLayout.cpp b/Libraries/LibWeb/Layout/UpdateLayout.cpp
index e2bfb3a62c8..da4edb80e42 100644
--- a/Libraries/LibWeb/Layout/UpdateLayout.cpp
+++ b/Libraries/LibWeb/Layout/UpdateLayout.cpp
@@ -59,7 +59,6 @@ Layout::RustFFI::FfiLayoutUpdateHostCallbacks Document::layout_update_host_callb
.prepare_for_rendering = [](void* context, Layout::BegunRead const* read) { static_cast<Document*>(context)->prepare_for_rendering(*read); },
.prepare_layout_tree_build = [](void* context, Layout::BegunRead const* read, bool may_create_viewport) -> u64 {
auto& document = *static_cast<Document*>(context);
- document.m_needs_throttled_animation_style_update_check = true;
// The viewport's style is the document's, which the style computer makes rather than publishes, so a build
// that may build the viewport is handed it before it starts.
CSS::StyleRecordID document_style_record;
@@ -74,6 +73,7 @@ Layout::RustFFI::FfiLayoutUpdateHostCallbacks Document::layout_update_host_callb
// tree that was replaced and give the new one a paint state.
.finish_layout_tree_build = [](void* context, Layout::BegunRead const* read, Compositing::RustFFI::NodeSlotId replaced_root, Compositing::RustFFI::NodeSlotId viewport) {
auto& document = *static_cast<Document*>(context);
+ document.m_needs_throttled_animation_style_update_check = true;
auto& arena = document.layout_node_arena();
VERIFY(is<Layout::Viewport>(arena.node_if_live(*read, viewport)));
if (replaced_root.index == viewport.index)
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index b62f0bc05c0..e7c5f457911 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -3094,10 +3094,18 @@ impl LayoutNodeArena {
}
!self.node_needs_layout_update(layout_root)
&& !document_needs_layout_tree_build
+ && !self.layout_tree_update_marks_need_build()
&& !self.needs_full_layout_tree_update()
&& !self.has_partial_relayout_boundary_roots()
}
+ pub(crate) fn layout_tree_update_marks_need_build(&self) -> bool {
+ self.document_style_node.is_some_and(|document| {
+ let marks = self.layout_tree_update_marks();
+ marks.needs(document) || marks.child_needs(document)
+ })
+ }
+
pub(crate) fn set_pending_rebuilt_subtree_roots(
&mut self,
roots: Vec<NodeSlotId>,
diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
index 2652a6997e3..ab2c72628d0 100644
--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
@@ -605,10 +605,8 @@ impl SealedRound {
}
let mut answer = self.job.run(state);
answer.prepare_committed_layout_for_rendering(state.arena_mut());
- Some(FlownRound {
- answer,
- rebuilds_tree: self.rebuilds_tree,
- })
+ let rebuilds_tree = self.rebuilds_tree || answer.build.is_some();
+ Some(FlownRound { answer, rebuilds_tree })
}
}
@@ -777,6 +775,12 @@ impl LayoutRoundJob {
fn run_with(mut self, state: &mut ArenaHandle, work: &OwedHostWork) -> LayoutRoundAnswer {
let facts = self.facts;
+ if self.build.is_none()
+ && state.arena().layout_tree_update_marks_need_build()
+ && let Some(document) = state.arena().document_style_node()
+ {
+ self.build = Some(TreeBuildJob::new(document, None));
+ }
let mut answer = LayoutRoundAnswer {
build: None,
work: HostWorkDue::default(),
@@ -992,7 +996,9 @@ fn next_round(
) -> SealedRound {
let rebuilds_tree = facts.document_needs_layout_tree_build
|| read_arena(document_host, read, (), |arena, ()| {
- arena.layout_root().is_invalid() || arena.needs_full_layout_tree_update()
+ arena.layout_root().is_invalid()
+ || arena.needs_full_layout_tree_update()
+ || arena.layout_tree_update_marks_need_build()
});
let build = rebuilds_tree.then(|| {
let document_style_node = StyleNodeID::from_raw(facts.document_style_node)
@@ -1120,7 +1126,7 @@ fn update_layout(
// A round that flew in the frame the update took in is the update's first, which the host pays before
// anything else of the update reads the layout.
document_host.take_frame_in_with(read);
- let (rebuilds_tree, mut next) = match document_host.take_flown_round() {
+ let (mut rebuilds_tree, mut next) = match document_host.take_flown_round() {
Some(FlownRound { answer, rebuilds_tree }) => {
trace.flown_rounds += 1;
(rebuilds_tree, NextRound::Flown(answer))
@@ -1153,6 +1159,7 @@ fn update_layout(
NextRound::Job(job) => run_layout_round_job(document_host, read, job),
};
trace.note_build_reports(&answer);
+ rebuilds_tree |= answer.build.is_some();
answer.pay(main_thread, document_host, read);
if matches!(answer.end, LayoutRoundEnd::NeedsDocumentStyle) {
let facts = host.document_facts(main_thread, read);