Skip to content

Truly independent web browser

LibWeb: Let the render state prepare paint properties as they are read

Aliaksandr Kalenik335fb6224877
diff --git a/Libraries/LibWeb/CSS/ScrollStateContainerQuery.cpp b/Libraries/LibWeb/CSS/ScrollStateContainerQuery.cpp
index ac67371105b..d28bd1dc995 100644
--- a/Libraries/LibWeb/CSS/ScrollStateContainerQuery.cpp
+++ b/Libraries/LibWeb/CSS/ScrollStateContainerQuery.cpp
@@ -168,9 +168,6 @@ bool ScrollStateQueryContainers::snapshot_post_layout_state(Layout::BegunRead co
if (which == Snapshot::NewContainersOnly && all_of(m_containers, [](auto const& it) { return it.value.has_been_snapshotted; }))
return false;
- // Sticky offsets are resolved with the scroll state of the settled visual context tree.
- document.update_paint_and_hit_testing_properties_if_needed();
-
GC::RootVector<GC::Ref<DOM::Element>> containers_to_forget;
bool any_state_changed = false;
for (auto& [element, container] : m_containers) {
diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cpp
index 5027d4dce2e..519f476265f 100644
--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp
+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp
@@ -416,7 +416,7 @@ void StyleEngineFFI::web_css_install_styles(StyleReactionApplication* applicatio
// The render side noted the boxes whose visual contexts the moves change, which the document updates ahead of
// its next paint.
if (invalidation.accumulated_visual_contexts() != AccumulatedVisualContextInvalidation::None || invalidation.needs_stacking_context_tree_rebuild())
- document.set_needs_accumulated_visual_contexts_update(true);
+ document.set_needs_accumulated_visual_contexts_update();
if (invalidation.needs_repaint())
Painting::request_document_repaint(document, invalidation.invalidates_hit_test_display_list() ? InvalidateDisplayList::PaintCommandsAndHitTestList : InvalidateDisplayList::PaintCommands);
application->invalidation |= invalidation;
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 08c34f341df..eca22628768 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -252,6 +252,7 @@
#include <LibWeb/Painting/PaintFacts.h>
#include <LibWeb/Painting/PaintableTypes.h>
#include <LibWeb/Painting/PaintingRustBridge.h>
+#include <LibWeb/Painting/SvgPaintResources.h>
#include <LibWeb/PictureInPicture/PictureInPictureController.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/ResizeObserver/ResizeObserver.h>
@@ -899,6 +900,7 @@ Layout::NodeArena& Document::layout_node_arena()
m_layout_node_arena->set_document({}, this);
Layout::register_layout_host(*m_layout_node_arena, *this);
Layout::RustFFI::document_host_set_layout_update_host_callbacks(m_layout_node_arena->host(), layout_update_host_callbacks());
+ Layout::RustFFI::document_host_set_paint_preparation_host(m_layout_node_arena->host(), paint_preparation_host_callbacks());
Layout::RustFFI::FfiStyleRecordHostCallbacks style_record_host_callbacks {
.context = this,
.shell_style_changed = [](void*, void* shell, u64 record, void const* payloads, bool derived, bool attach_resources) { as<Layout::NodeWithStyle>(*static_cast<Layout::Node*>(shell)).refresh_style_from_arena(CSS::StyleRecordID { record }, payloads, derived, attach_resources); },
@@ -2514,7 +2516,7 @@ void Document::after_layout_commit(Layout::BegunRead const& read, LayoutTreeChan
set_needs_to_record_display_list();
// The round that committed the layout prepared it for rendering, but for the visual contexts, which update next.
- set_needs_accumulated_visual_contexts_update(true);
+ set_needs_accumulated_visual_contexts_update();
// A tree update can replace layout nodes referenced by selection state.
if (auto range = get_selection()->range())
@@ -3145,54 +3147,30 @@ void Document::finish_animated_style_update()
effect->request_observation_sample();
}
-void Document::prepare_for_rendering(Layout::BegunRead const& read)
+// What preparing the paint and hit testing properties, which the render state does as they are read, asks of the
+// document and tells it.
+Layout::RustFFI::FfiPaintPreparationHostCallbacks Document::paint_preparation_host_callbacks()
{
- if (!m_layout_node_arena)
- return;
-
- auto outcome = Painting::rust_prepare_for_rendering(read, *this, m_needs_accumulated_visual_contexts_update);
- if (outcome.requires_visual_context_update)
- set_needs_accumulated_visual_contexts_update(true);
- if (outcome.visual_context_values_changed)
- paint_state().did_update_visual_context_values();
- if (outcome.requires_display_list_recording) {
- set_needs_to_record_display_list();
- m_document->set_needs_repaint();
- }
-}
-
-void Document::update_paint_and_hit_testing_properties_if_needed()
-{
- Layout::ForcedReadScope read { *this };
-
- // Nothing was written to the render state since the properties were prepared from it: every pass below would find
- // nothing to do, so none is sent to the render owner.
- auto* host = m_layout_node_arena ? m_layout_node_arena->host() : nullptr;
- if (host && Layout::RustFFI::document_host_paint_preparation_is_current(host) && !m_needs_accumulated_visual_contexts_update)
- return;
-
- // What the passes prepare stays current until something is written to the render state, from here on as well.
- if (host)
- Layout::RustFFI::document_host_note_paint_preparation_is_current(host);
-
- prepare_for_rendering(read);
- if (m_needs_accumulated_visual_contexts_update) {
- m_needs_accumulated_visual_contexts_update = false;
- if (has_committed_viewport_box())
- paint_state().update_accumulated_visual_contexts(read, *this);
- }
-
- // Scroll nodes are (re)created by the visual context tree build above, so scroll offsets and
- // the snapshot must be derived only after structure work is done.
- if (has_committed_viewport_box() && paint_state().refresh_scroll_state(read, *this) == Painting::RequiresDisplayListRecording::Yes) {
- set_needs_to_record_display_list();
- m_document->set_needs_repaint();
- }
+ return {
+ .context = this,
+ .viewport = [](void* context, Layout::RustFFI::FfiPaintPreparationViewport* viewport) {
+ auto& document = *static_cast<Document*>(context);
+ viewport->visual_context_tree_inputs = Painting::visual_context_tree_inputs(document);
+ viewport->device_viewport_size = document.page().css_to_device_rect(document.viewport_rect()).size().to_type<int>(); },
+ .resolve_svg_filter = [](void* context, Layout::BegunRead const* read, Compositing::RustFFI::NodeSlotId slot, void const* url_value, void* sink) { return Painting::push_svg_filter_reference(*read, *static_cast<Document*>(context), slot, url_value, sink); },
+ .resolve_svg_paint_server = [](void* context, Layout::BegunRead const* read, Compositing::RustFFI::NodeSlotId slot, bool is_stroke, void* sink) { Painting::push_svg_paint_server_description(*read, *static_cast<Document*>(context), slot, is_stroke, sink); },
+ .require_display_list_recording = [](void* context, bool request_frame) {
+ auto& document = *static_cast<Document*>(context);
+ if (request_frame)
+ document.set_needs_repaint();
+ else
+ document.set_needs_to_record_display_list(); },
+ };
}
bool Document::can_compute_client_rects_without_accumulated_visual_contexts_update(Layout::Node const& layout_node) const
{
- if (!m_needs_accumulated_visual_contexts_update || !has_layout_root())
+ if (!has_layout_root() || !Layout::RustFFI::document_host_visual_contexts_need_update(layout_node.document_host()))
return false;
auto navigable = this->navigable();
@@ -8071,8 +8049,6 @@ void Document::run_the_update_intersection_observations_steps(HighResolutionTime
for (auto& observer : m_intersection_observers)
intersection_observers.append(observer);
- update_paint_and_hit_testing_properties_if_needed();
-
GC::RootHashMap<Document*, Compositing::AccumulatedVisualContextTree> observation_visual_context_trees;
auto sample_time_ns = MonotonicTime::now().nanoseconds();
auto sampled_visual_context_tree = [&](Document& document) -> Optional<Compositing::AccumulatedVisualContextTree> {
@@ -9317,7 +9293,7 @@ void Document::update_compositor_animations(Layout::BegunRead const& read)
};
Optional<Compositing::AccumulatedVisualContextTree> visual_context_tree = paint_state().visual_context_tree(*this);
- paint_state().begin_compositor_animation_update(*this);
+ paint_state().begin_compositor_animation_update();
GC::RootHashMap<GC::Ref<Layout::Node>, bool> previous_content_retention;
GC::RootHashTable<GC::Ref<Layout::Node>> retained_this_pass;
GC::RootHashTable<GC::Ref<Animations::KeyframeEffect>> previously_compositor_driven_effects;
@@ -10018,7 +9994,7 @@ void Document::update_compositor_animations(Layout::BegunRead const& read)
// A descriptor must target the tree it is published with. The selection pass above can force
// or release animation-only visual context nodes, so redo it after applying those updates.
- if (m_needs_accumulated_visual_contexts_update) {
+ if (Layout::RustFFI::document_host_visual_contexts_need_update(layout_node_arena().host())) {
paint_state().publish_compositor_animations(read, *this, Painting::DocumentPaintState::PublishPendingCompositorAnimations::No);
update_compositor_animations(read);
return;
@@ -12024,11 +12000,11 @@ void Document::request_frame_for_pending_repaint()
container->document().request_frame_for_pending_repaint();
}
-void Document::set_needs_accumulated_visual_contexts_update(bool value)
+void Document::set_needs_accumulated_visual_contexts_update()
{
- m_needs_accumulated_visual_contexts_update = value;
- if (value)
- set_needs_repaint(InvalidateDisplayList::No);
+ if (m_layout_node_arena)
+ Layout::RustFFI::document_host_note_visual_contexts_need_update(m_layout_node_arena->host());
+ set_needs_repaint(InvalidateDisplayList::No);
}
// A pattern connecting or disconnecting needs no republication of its own here: one that can be named has an id, and
@@ -12069,14 +12045,14 @@ void Document::note_svg_paint_resources_changed()
if (!m_layout_node_arena)
return;
if (Layout::RustFFI::render_state_note_svg_paint_resources_changed(m_layout_node_arena->host()))
- set_needs_accumulated_visual_contexts_update(true);
+ set_needs_accumulated_visual_contexts_update();
}
void Document::schedule_full_accumulated_visual_context_rebuild(Layout::RustFFI::VisualContextUpdateScope scope)
{
if (m_layout_node_arena)
Layout::RustFFI::render_state_visual_context_request_full_rebuild(m_layout_node_arena->host(), scope);
- set_needs_accumulated_visual_contexts_update(true);
+ set_needs_accumulated_visual_contexts_update();
}
void Document::schedule_accumulated_visual_context_update(Layout::Node const& layout_node, AccumulatedVisualContextUpdateScope scope)
@@ -12096,7 +12072,7 @@ void Document::schedule_accumulated_visual_context_update(Layout::Node const& la
&& Painting::display(layout_node).is_table_inside() && Painting::has_committed_box(*wrapper))
note_style_change(*wrapper);
- set_needs_accumulated_visual_contexts_update(true);
+ set_needs_accumulated_visual_contexts_update();
}
void Document::schedule_accumulated_visual_context_update(Layout::BegunRead const& read, Element& element, AccumulatedVisualContextUpdateScope scope)
@@ -12211,7 +12187,6 @@ Optional<Painting::DisplayListRecording> Document::start_recording(Layout::Begun
{
update_highlight_states_if_needed(read);
Painting::publish_image_map_area_facts_if_needed(read, *this);
- update_paint_and_hit_testing_properties_if_needed();
VERIFY(has_committed_viewport_box());
bool const line_box_border_overlays_replace_cacheable_content = config.should_show_line_box_borders;
@@ -12282,10 +12257,11 @@ Painting::HitTestListAdoption Document::adopt_published_recording(Optional<Layou
bool Document::hit_test_display_list_is_current(Layout::BegunRead const& read)
{
Painting::publish_image_map_area_facts_if_needed(read, *this);
- update_paint_and_hit_testing_properties_if_needed();
if (!has_committed_viewport_box())
return false;
- return m_hit_test_display_list && m_hit_test_display_list->is_current() && m_hit_test_display_list->visual_context_tree_structural_epoch() == paint_state().visual_context_tree_structural_epoch_without_update(read);
+ // Reading the epoch prepares the paint properties, which can drop the hit-test list.
+ auto structural_epoch = paint_state().visual_context_tree_structural_epoch(read);
+ return m_hit_test_display_list && m_hit_test_display_list->is_current() && m_hit_test_display_list->visual_context_tree_structural_epoch() == structural_epoch;
}
void Document::set_caret_hit_test_debug_rect(Optional<CSSPixelRect> rect)
@@ -12301,8 +12277,6 @@ void Document::set_caret_hit_test_debug_rect(Optional<CSSPixelRect> rect)
Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunRead const& read, Optional<i64> visual_animation_sample_time_nanoseconds)
{
- update_paint_and_hit_testing_properties_if_needed();
-
if (!has_committed_viewport_box())
return {};
@@ -12790,8 +12764,6 @@ Utf16String Document::dump_stacking_context_tree()
if (!has_committed_viewport_box())
return "No paintable"_utf16;
- update_paint_and_hit_testing_properties_if_needed();
-
StringBuilder builder;
Painting::dump_stacking_context_tree(read, builder, *this);
if (builder.is_empty())
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 6cc7f8b9688..d83c8b0146e 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -646,8 +646,6 @@ public:
[[nodiscard]] bool layout_is_up_to_date() const;
[[nodiscard]] bool layout_is_known_stale() const;
void clear_devtools_layout_inspection_data();
- void prepare_for_rendering(Layout::BegunRead const& read);
- void update_paint_and_hit_testing_properties_if_needed();
void sample_animation_effects_needing_style_update();
void update_style_computer_viewport_rect();
bool needs_animated_style_update() const { return m_needs_animated_style_update; }
@@ -1526,7 +1524,7 @@ public:
Values,
Structure,
};
- void set_needs_accumulated_visual_contexts_update(bool);
+ void set_needs_accumulated_visual_contexts_update();
void set_image_map_areas_need_publication() { m_image_map_areas_need_publication = true; }
[[nodiscard]] bool take_image_map_areas_need_publication() { return exchange(m_image_map_areas_need_publication, false); }
void note_svg_paint_resources_changed();
@@ -1949,6 +1947,7 @@ private:
void collect_boxes_with_auto_content_visibility(Layout::BegunRead const& read);
bool needs_style_update_after_layout(Layout::BegunRead const& read);
Layout::RustFFI::FfiLayoutUpdateHostCallbacks layout_update_host_callbacks();
+ Layout::RustFFI::FfiPaintPreparationHostCallbacks paint_preparation_host_callbacks();
void process_pending_list_item_renumbers();
bool reconcile_stale_list_item_counters_after_tree_build(ReadonlySpan<Layout::RustFFI::FfiNodeIdentity> rebuilt_roots);
@@ -2482,7 +2481,6 @@ private:
bool m_design_mode_enabled { false };
- bool m_needs_accumulated_visual_contexts_update { false };
bool m_image_map_areas_need_publication { false };
HashMap<Web::AsyncScrollNodeStableID, Compositing::SnappedAreas> m_scroll_container_snapped_areas;
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index da3ea684378..875567c8463 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -1483,7 +1483,7 @@ void Node::update_layout_tree_for_removal(Layout::BegunRead const& read, Node& p
static_cast<SVG::SVGElement&>(*node).mark_resource_box_referencing_elements_for_content_change();
// A contained absolutely positioned box leaves without a layout following: do what one would have done for it.
if (element && element->computed_style() && element->computed_style()->position() == CSS::Positioning::Absolute) {
- document().set_needs_accumulated_visual_contexts_update(true);
+ document().set_needs_accumulated_visual_contexts_update();
document().schedule_scroll_container_resnap();
document().set_needs_repaint(Badge<Node> {}, InvalidateDisplayList::PaintCommandsAndHitTestList);
}
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 75d86fd8935..0d484d248a1 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -6976,7 +6976,8 @@ bool LocalNavigable::commit_frame(PaintConfig paint_config)
adopt_pending_async_scroll_offsets();
document->update_highlight_states_if_needed(read);
Painting::publish_image_map_area_facts_if_needed(read, *document);
- document->update_paint_and_hit_testing_properties_if_needed();
+ // Updating the compositor animations reads the visual context tree, which prepares the paint properties: a
+ // preparation can ask for the recording decided below.
document->update_compositor_animations(read);
// Hit testing can publish a display list before the next frame. Give both paths the same canvas fill so that
@@ -6994,7 +6995,7 @@ bool LocalNavigable::commit_frame(PaintConfig paint_config)
auto should_record_display_list = m_needs_to_record_display_list
|| !compositor_display_list_paint_config.has_value()
|| !(compositor_display_list_paint_config.value() == paint_config);
- auto sealed = seal_presentation(*document, paint_config, should_record_display_list);
+ auto sealed = seal_presentation(read, *document, paint_config, should_record_display_list);
set_rendering_pending(*document, RenderingPendingReason::NeedsRenderingUpdate, 0);
if (!should_record_display_list) {
commit_unrecorded_frame(read, *document, move(sealed));
@@ -7041,7 +7042,7 @@ void LocalNavigable::commit_mismatched_visual_context_tree_for_testing()
if (!paint_config.has_value())
return;
Layout::ForcedReadScope read { *document };
- auto sealed = seal_presentation(*document, *paint_config, false);
+ auto sealed = seal_presentation(read, *document, *paint_config, false);
sealed.sends_visual_context_tree = true;
sealed.visual_context_tree_mismatches_for_testing = true;
commit_unrecorded_frame(read, *document, move(sealed));
@@ -7100,19 +7101,15 @@ void LocalNavigable::arm_clock_lane(TickNow tick_now)
// Seals what a frame of `document` reads of the document and this navigable where the frame begins: the frame is built
// from nothing else (see SealedPresentation).
-Compositor::SealedPresentation LocalNavigable::seal_presentation(DOM::Document& document, PaintConfig const& paint_config, bool records_display_list)
+Compositor::SealedPresentation LocalNavigable::seal_presentation(Layout::BegunRead const& read, DOM::Document& document, PaintConfig const& paint_config, bool records_display_list)
{
VERIFY(document.has_committed_viewport_box());
- // The paint properties are brought up to date before the frame asks whether its tree is to be sent: an update of the
- // tree they make asks for it.
- document.update_paint_and_hit_testing_properties_if_needed();
auto& paint_state = document.paint_state();
- bool const sends_visual_context_tree = paint_state.visual_context_tree_needs_compositor_update();
+ bool const sends_visual_context_tree = paint_state.take_visual_context_tree_compositor_update(read);
// A frame that records nothing takes the render state's tree as it is sampled.
Optional<Compositing::AccumulatedVisualContextTree> visual_context_tree;
if (records_display_list)
visual_context_tree = paint_state.visual_context_tree(document);
- paint_state.did_update_visual_context_tree_in_compositor();
// A keyboard scroll reads the layout, which one the host knows is stale leaves to the next frame that lays it out.
Optional<Compositing::KeyboardScrollState> keyboard_scroll_state;
if (is_top_level_traversable() && !document.layout_is_known_stale())
@@ -7121,7 +7118,7 @@ Compositor::SealedPresentation LocalNavigable::seal_presentation(DOM::Document&
.paint_config = paint_config,
.visual_context_tree = move(visual_context_tree),
.sends_visual_context_tree = sends_visual_context_tree,
- .scroll_state_changed = paint_state.take_scroll_state_change(),
+ .scroll_state_changed = paint_state.take_scroll_state_change(read),
.scroll_requests = take_unsent_scroll_requests(),
.keyboard_scroll_state = move(keyboard_scroll_state),
.paint_command_cache_source = paint_state.display_list_used_as_paint_command_cache_source(),
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index f394365ef01..4440efc1b4d 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -465,7 +465,7 @@ private:
Compositor::FlightPresentation take_presentation(Compositor::SealedPresentation);
void commit_unrecorded_frame(Layout::BegunRead const&, DOM::Document&, Compositor::SealedPresentation);
- Compositor::SealedPresentation seal_presentation(DOM::Document&, PaintConfig const&, bool records_display_list);
+ Compositor::SealedPresentation seal_presentation(Layout::BegunRead const&, DOM::Document&, PaintConfig const&, bool records_display_list);
void unseal_presentation(DOM::Document&, Compositor::SealedPresentation&);
void finish_recording_in_flight(RecordingInFlight&, Layout::RustFFI::FfiRecordingLanding, Layout::RustFFI::FfiPresentation);
Gfx::IntRect present_viewport_rect() const;
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 1e6f7166cff..710070f7354 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -290,7 +290,6 @@ GC::Ref<JS::Object> Internals::visual_context_node_indices(DOM::Element& element
auto& document = window().associated_document();
Layout::ForcedReadScope read { document };
document.update_layout(DOM::UpdateLayoutReason::Debugging);
- document.update_paint_and_hit_testing_properties_if_needed();
auto const* layout_node = element.layout_node(read);
auto owned_indices_as_array = [&](Layout::RustFFI::FfiVisualContextBoxNodeList list) -> GC::Ref<JS::Array> {
Vector<u32> indices;
@@ -356,7 +355,6 @@ void Internals::send_mismatched_visual_context_tree_update_to_compositor()
// Force a fresh, incompatible rebuild — so the tree is minted with a new structural epoch that the Compositor's installed
// display list was never recorded against.
document.schedule_full_accumulated_visual_context_rebuild(Layout::RustFFI::VisualContextUpdateScope::FreshTree);
- document.update_paint_and_hit_testing_properties_if_needed();
// Send a visual-context-tree update carrying that new structural epoch *without* re-recording the display list —
// deliberately reproducing the peer inconsistency behind issue #10368.
@@ -2195,10 +2193,9 @@ Utf16String Internals::stacking_context_structure_verification_report()
document.update_layout(DOM::UpdateLayoutReason::DumpDisplayList);
if (!document.has_committed_viewport_box())
return {};
- document.update_paint_and_hit_testing_properties_if_needed();
StringBuilder builder;
Layout::RustFFI::render_state_stacking_context_structure_verification_report(
- document.layout_node_arena().host(), Painting::viewport_row_slot(read, document), &builder,
+ document.layout_node_arena().host(), read, Painting::viewport_row_slot(read, document), &builder,
[](void* context, u8 const* bytes, size_t byte_count) {
static_cast<StringBuilder*>(context)->append(StringView { bytes, byte_count });
});
diff --git a/Libraries/LibWeb/Layout/UpdateLayout.cpp b/Libraries/LibWeb/Layout/UpdateLayout.cpp
index da4edb80e42..253e915c8a8 100644
--- a/Libraries/LibWeb/Layout/UpdateLayout.cpp
+++ b/Libraries/LibWeb/Layout/UpdateLayout.cpp
@@ -56,7 +56,6 @@ Layout::RustFFI::FfiLayoutUpdateHostCallbacks Document::layout_update_host_callb
}; },
.container_query_evaluation_is_pending = [](void* context, Layout::BegunRead const* read) -> bool { return static_cast<Document*>(context)->has_size_containers_needing_evaluation_after_layout(*read); },
.needs_style_update_after_layout = [](void* context, Layout::BegunRead const* read) -> bool { return static_cast<Document*>(context)->needs_style_update_after_layout(*read); },
- .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);
// The viewport's style is the document's, which the style computer makes rather than publishes, so a build
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index 3759481d065..5d5a8574f02 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -1052,8 +1052,7 @@ EventResult EventHandler::handle_mousewheel(CSSPixelPoint visual_viewport_positi
if (!display_list || !root_document || !root_document->has_paint_state())
return false;
Layout::ForcedReadScope root_read { *root_document };
- root_document->update_paint_and_hit_testing_properties_if_needed();
- return display_list->compatible_visual_context_tree_structural_epoch() != root_document->paint_state().visual_context_tree_structural_epoch_without_update(root_read);
+ return display_list->compatible_visual_context_tree_structural_epoch() != root_document->paint_state().visual_context_tree_structural_epoch(root_read);
};
// An event that no compositor has seen, such as one a test makes, goes there first, as the UI's events do. The
diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.cpp b/Libraries/LibWeb/Painting/DocumentPaintState.cpp
index 599766cf8e2..f3caac4a68d 100644
--- a/Libraries/LibWeb/Painting/DocumentPaintState.cpp
+++ b/Libraries/LibWeb/Painting/DocumentPaintState.cpp
@@ -19,20 +19,15 @@
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/DocumentPaintState.h>
#include <LibWeb/Painting/PaintingRustBridge.h>
-#include <LibWeb/Painting/SvgPaintResources.h>
namespace Web::Painting {
DocumentPaintState::DocumentPaintState(Layout::NodeArena& layout_node_arena)
: m_layout_node_arena(layout_node_arena)
{
- // The render state keeps the scroll state, and outlives the layout tree this paint state is for.
- Layout::RustFFI::render_state_forget_scroll_state(m_layout_node_arena->host());
-}
-
-void DocumentPaintState::ensure_visual_context_tree(DOM::Document const& document) const
-{
- const_cast<DOM::Document&>(document).update_paint_and_hit_testing_properties_if_needed();
+ // The render state keeps the scroll state and what paint preparation left for frames, and outlives the layout tree
+ // this paint state is for.
+ Layout::RustFFI::document_host_paint_state_was_created(m_layout_node_arena->host());
}
bool DocumentPaintState::has_visual_context_tree(Layout::BegunRead const& read) const
@@ -40,21 +35,45 @@ bool DocumentPaintState::has_visual_context_tree(Layout::BegunRead const& read)
return Layout::RustFFI::render_state_has_visual_context_tree(m_layout_node_arena->host(), &read);
}
-Compositing::AccumulatedVisualContextTree DocumentPaintState::visual_context_tree_without_update(Layout::BegunRead const& read, DOM::Document const& document) const
+Compositing::AccumulatedVisualContextTree DocumentPaintState::visual_context_tree(DOM::Document const& document) const
{
+ Layout::ForcedReadScope read { document };
return Compositing::AccumulatedVisualContextTree::adopt_rust_handle(retain_rust_main_visual_context_tree(read, document));
}
-Compositing::AccumulatedVisualContextTree DocumentPaintState::visual_context_tree(DOM::Document const& document) const
+u64 DocumentPaintState::visual_context_tree_structural_epoch(Layout::BegunRead const& read) const
{
- ensure_visual_context_tree(document);
- Layout::ForcedReadScope read { document };
- return visual_context_tree_without_update(read, document);
+ return Layout::RustFFI::render_state_visual_context_tree_structural_epoch(m_layout_node_arena->host(), &read);
}
-u64 DocumentPaintState::visual_context_tree_structural_epoch_without_update(Layout::BegunRead const& read) const
+bool DocumentPaintState::take_visual_context_tree_compositor_update(Layout::BegunRead const& read)
{
- return Layout::RustFFI::render_state_visual_context_tree_structural_epoch(m_layout_node_arena->host(), &read);
+ return Layout::RustFFI::render_state_take_visual_context_tree_compositor_update(m_layout_node_arena->host(), &read);
+}
+
+void DocumentPaintState::did_update_visual_context_values()
+{
+ Layout::RustFFI::document_host_note_visual_context_tree_needs_compositor_update(m_layout_node_arena->host());
+}
+
+bool DocumentPaintState::take_scroll_state_change(Layout::BegunRead const& read)
+{
+ return Layout::RustFFI::render_state_take_scroll_state_change(m_layout_node_arena->host(), &read);
+}
+
+void DocumentPaintState::did_change_scroll_state()
+{
+ Layout::RustFFI::document_host_note_scroll_state_changed(m_layout_node_arena->host());
+}
+
+u64 DocumentPaintState::accumulated_visual_context_tree_build_count() const
+{
+ return Layout::RustFFI::document_host_visual_context_tree_build_count(m_layout_node_arena->host());
+}
+
+u64 DocumentPaintState::accumulated_visual_context_tree_incremental_update_count() const
+{
+ return Layout::RustFFI::document_host_visual_context_tree_incremental_update_count(m_layout_node_arena->host());
}
BlockingWheelEventRegionState DocumentPaintState::collect_root_blocking_wheel_event_regions(DOM::Document& document)
@@ -78,48 +97,25 @@ BlockingWheelEventRegionState DocumentPaintState::collect_root_blocking_wheel_ev
void DocumentPaintState::viewport_row_was_reset()
{
- Layout::RustFFI::render_state_forget_scroll_state(m_layout_node_arena->host());
+ Layout::RustFFI::document_host_viewport_row_was_reset(m_layout_node_arena->host());
m_boxes_with_auto_content_visibility.clear();
- m_visual_context_tree_needs_compositor_update = false;
-}
-
-void DocumentPaintState::update_accumulated_visual_contexts(Layout::BegunRead const& read, DOM::Document& document)
-{
- bool svg_paint_resources_changed = sync_svg_paint_resources(read, document);
- auto result = rust_update_accumulated_visual_contexts(read, document);
- if (result.performed_full_build)
- ++m_accumulated_visual_context_tree_build_count;
- else
- ++m_accumulated_visual_context_tree_incremental_update_count;
- if (result.requires_display_list_recording || svg_paint_resources_changed)
- document.set_needs_to_record_display_list();
- if (result.values_may_have_changed)
- m_visual_context_tree_needs_compositor_update = true;
}
void DocumentPaintState::update_visual_viewport_accumulated_visual_context(Layout::BegunRead const& read, DOM::Document& document)
{
- if (!has_visual_context_tree(read)) {
- update_accumulated_visual_contexts(read, document);
- return;
- }
rust_update_visual_viewport_transform(read, document);
- m_visual_context_tree_needs_compositor_update = true;
}
-void DocumentPaintState::begin_compositor_animation_update(DOM::Document& document)
+void DocumentPaintState::begin_compositor_animation_update()
{
- ensure_visual_context_tree(document);
Layout::RustFFI::render_state_begin_compositor_animation_update(m_layout_node_arena->host());
}
void DocumentPaintState::publish_compositor_animations(Layout::BegunRead const& read, DOM::Document& document, PublishPendingCompositorAnimations publish_pending)
{
- ensure_visual_context_tree(document);
auto outcome = Layout::RustFFI::render_state_publish_compositor_animations(m_layout_node_arena->host(), &read, publish_pending == PublishPendingCompositorAnimations::Yes);
if (!outcome.published)
return;
- m_visual_context_tree_needs_compositor_update = true;
if (outcome.parameters_changed)
++document.style_invalidation_counters().compositor_visual_animation_updates;
if (outcome.timing_anchors_changed)
@@ -130,7 +126,7 @@ void DocumentPaintState::republish_visual_animations(Layout::BegunRead const& re
{
if (!Layout::RustFFI::render_state_visual_context_tree_has_visual_animations(m_layout_node_arena->host(), &read))
return;
- m_visual_context_tree_needs_compositor_update = true;
+ did_update_visual_context_values();
++document.style_invalidation_counters().compositor_visual_animation_updates;
}
@@ -139,18 +135,6 @@ void DocumentPaintState::append_paint_command_cache_source_resources(Compositing
retained_resources.include(m_paint_command_cache_source_referenced_resources);
}
-RequiresDisplayListRecording DocumentPaintState::refresh_scroll_state(Layout::BegunRead const& read, DOM::Document& document)
-{
- auto outcome = Layout::RustFFI::render_state_refresh_scroll_state(
- m_layout_node_arena->host(), &read, document.page().client().device_pixels_per_css_pixel(),
- document.page().css_to_device_rect(document.viewport_rect()).size().to_type<int>());
- if (outcome.scroll_state_changed)
- m_scroll_state_changed = true;
- if (outcome.table_changed)
- did_update_visual_context_values();
- return outcome.requires_display_list_recording ? RequiresDisplayListRecording::Yes : RequiresDisplayListRecording::No;
-}
-
Layout::RustFFI::FfiViewportMapping DocumentPaintState::viewport_mapping(Compositing::AccumulatedVisualContextTree const& visual_context_tree, double device_pixels_per_css_pixel) const
{
Layout::RustFFI::FfiViewportMapping mapping {};
diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.h b/Libraries/LibWeb/Painting/DocumentPaintState.h
index 3ddbfefc040..6b2e55fb0ca 100644
--- a/Libraries/LibWeb/Painting/DocumentPaintState.h
+++ b/Libraries/LibWeb/Painting/DocumentPaintState.h
@@ -25,11 +25,6 @@ struct BlockingWheelEventRegionState {
bool has_blocking_wheel_event_region_covering_viewport { false };
};
-enum class RequiresDisplayListRecording {
- No,
- Yes,
-};
-
class WEB_API DocumentPaintState {
public:
AK_ALLOC_WITH_KMALLOC;
@@ -40,33 +35,30 @@ public:
BlockingWheelEventRegionState collect_root_blocking_wheel_event_regions(DOM::Document&);
- // Called from Document::update_paint_and_hit_testing_properties_if_needed() once the visual
- // context tree is settled; every other consumer reaches the scroll state through that update.
- RequiresDisplayListRecording refresh_scroll_state(Layout::BegunRead const& read, DOM::Document&);
// The mapping reads the tree and the scroll state where it is used, so the tree has to outlive it.
Layout::RustFFI::FfiViewportMapping viewport_mapping(Compositing::AccumulatedVisualContextTree const&, double device_pixels_per_css_pixel) const;
// Only the scroll logic of the compositor, which is Rust, decodes it.
ByteBuffer encoded_scroll_state() const;
- void did_update_visual_context_values() { m_visual_context_tree_needs_compositor_update = true; }
+ void did_update_visual_context_values();
- void update_accumulated_visual_contexts(Layout::BegunRead const& read, DOM::Document&);
void update_visual_viewport_accumulated_visual_context(Layout::BegunRead const& read, DOM::Document&);
// An update pass publishes each effect's compositor animations into a list the tree takes at the end.
- void begin_compositor_animation_update(DOM::Document&);
+ void begin_compositor_animation_update();
enum class PublishPendingCompositorAnimations {
No,
Yes,
};
void publish_compositor_animations(Layout::BegunRead const& read, DOM::Document&, PublishPendingCompositorAnimations);
void republish_visual_animations(Layout::BegunRead const& read, DOM::Document&);
- bool visual_context_tree_needs_compositor_update() const { return m_visual_context_tree_needs_compositor_update; }
- void did_update_visual_context_tree_in_compositor() { m_visual_context_tree_needs_compositor_update = false; }
- // Whether the scroll offsets changed since a frame last took the change.
- bool take_scroll_state_change() { return exchange(m_scroll_state_changed, false); }
- void did_change_scroll_state() { m_scroll_state_changed = true; }
+ // Whether the visual context tree changed since a frame last took it to the compositor, which the caller's frame now
+ // does.
+ bool take_visual_context_tree_compositor_update(Layout::BegunRead const& read);
+ // Whether the scroll offsets changed since a frame last took the change, which the caller's frame now does.
+ bool take_scroll_state_change(Layout::BegunRead const& read);
+ void did_change_scroll_state();
bool has_visual_context_tree(Layout::BegunRead const& read) const;
- u64 accumulated_visual_context_tree_build_count() const { return m_accumulated_visual_context_tree_build_count; }
- u64 accumulated_visual_context_tree_incremental_update_count() const { return m_accumulated_visual_context_tree_incremental_update_count; }
+ u64 accumulated_visual_context_tree_build_count() const;
+ u64 accumulated_visual_context_tree_incremental_update_count() const;
void append_recording_trace(String trace) { m_recording_traces.append(move(trace)); }
Vector<String> take_recording_traces() { return exchange(m_recording_traces, {}); }
@@ -83,9 +75,7 @@ public:
Vector<Compositing::RustFFI::NodeSlotId> const& boxes_with_auto_content_visibility() const { return m_boxes_with_auto_content_visibility; }
Compositing::AccumulatedVisualContextTree visual_context_tree(DOM::Document const&) const;
- // Passive access for consumers of an already settled recording.
- Compositing::AccumulatedVisualContextTree visual_context_tree_without_update(Layout::BegunRead const& read, DOM::Document const&) const;
- u64 visual_context_tree_structural_epoch_without_update(Layout::BegunRead const& read) const;
+ u64 visual_context_tree_structural_epoch(Layout::BegunRead const& read) const;
void set_display_list_used_as_paint_command_cache_source(RefPtr<Compositing::DisplayList> display_list, Compositing::DisplayListResourceSet referenced_resources, Compositing::AccumulatedVisualContextTree visual_context_tree)
{
@@ -102,7 +92,6 @@ public:
private:
Vector<String> m_recording_traces;
- void ensure_visual_context_tree(DOM::Document const&) const;
NonnullRefPtr<Layout::NodeArena> m_layout_node_arena;
@@ -111,11 +100,6 @@ private:
RefPtr<Compositing::DisplayList> m_display_list_used_as_paint_command_cache_source;
Optional<Compositing::AccumulatedVisualContextTree> m_paint_command_cache_source_visual_context_tree;
Compositing::DisplayListResourceSet m_paint_command_cache_source_referenced_resources;
-
- u64 m_accumulated_visual_context_tree_build_count { 0 };
- u64 m_accumulated_visual_context_tree_incremental_update_count { 0 };
- bool m_visual_context_tree_needs_compositor_update { false };
- bool m_scroll_state_changed { false };
};
}
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index e4557246ee6..7eb04731bd5 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -183,8 +183,9 @@ static Layout::NodeWithStyle::ImageObserver const* layer_image_observer(Layout::
VERIFY_NOT_REACHED();
}
-// The render side draws into a viewport it never asks about: every pass that reads it is handed this.
-static Compositing::RustFFI::FfiVisualContextTreeInputs visual_context_tree_inputs(DOM::Document& document)
+}
+
+Compositing::RustFFI::FfiVisualContextTreeInputs visual_context_tree_inputs(DOM::Document& document)
{
Compositing::RustFFI::FfiVisualContextTreeInputs inputs {};
inputs.device_pixels_per_css_pixel = document.page().client().device_pixels_per_css_pixel();
@@ -196,22 +197,11 @@ static Compositing::RustFFI::FfiVisualContextTreeInputs visual_context_tree_inpu
return inputs;
}
-}
-
static Layout::RustFFI::DocumentHost* document_host(DOM::Document const& document)
{
return const_cast<DOM::Document&>(document).layout_node_arena().host();
}
-Layout::RustFFI::FfiVisualContextUpdateOutcome rust_update_accumulated_visual_contexts(Layout::BegunRead const& read, DOM::Document& document)
-{
- auto update_timer = Core::ElapsedTimer::start_new(Core::TimerType::Precise);
- auto outcome = Layout::RustFFI::render_state_update_accumulated_visual_contexts(document.layout_node_arena().host(), &read, viewport_row_slot(read, document), visual_context_tree_inputs(document));
- if (rust_painting_timing_enabled())
- dbgln("AVC_UPDATE rust={} µs {}", update_timer.elapsed_time().to_microseconds(), outcome.performed_full_build ? "full"sv : "incremental"sv);
- return outcome;
-}
-
Vector<u32> rust_owned_visual_context_node_indices(Layout::Node const& layout_node, Layout::RustFFI::FfiVisualContextBoxNodeList list)
{
Vector<u32> indices;
@@ -259,12 +249,6 @@ void register_geometry_host(Layout::NodeArena& arena)
Layout::RustFFI::document_host_set_geometry_host(arena.host(), callbacks);
}
-Layout::RustFFI::FfiRenderingPreparationOutcome rust_prepare_for_rendering(Layout::BegunRead const& read, DOM::Document& document, bool visual_context_update_pending)
-{
- return Layout::RustFFI::render_state_prepare_for_rendering(document.layout_node_arena().host(), &read, visual_context_update_pending, &document,
- [](void* document) { return visual_context_tree_inputs(*static_cast<DOM::Document*>(document)); });
-}
-
void rust_update_visual_viewport_transform(Layout::BegunRead const& read, DOM::Document& document)
{
Layout::RustFFI::render_state_update_visual_viewport_transform(document.layout_node_arena().host(), &read, visual_context_tree_inputs(document));
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.h b/Libraries/LibWeb/Painting/PaintingRustBridge.h
index de104924ca5..b5e657e2c5e 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.h
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.h
@@ -35,13 +35,12 @@ struct ImagePaintRequest;
WEB_API void dump_stacking_context_tree(Layout::BegunRead const&, StringBuilder&, DOM::Document const&);
WEB_API void dump_layout_tree(StringBuilder&, Layout::Node const&, bool interactive);
-WEB_API Layout::RustFFI::FfiVisualContextUpdateOutcome rust_update_accumulated_visual_contexts(Layout::BegunRead const&, DOM::Document&);
+WEB_API Compositing::RustFFI::FfiVisualContextTreeInputs visual_context_tree_inputs(DOM::Document&);
WEB_API Vector<u32> rust_owned_visual_context_node_indices(Layout::Node const&, Layout::RustFFI::FfiVisualContextBoxNodeList);
WEB_API bool rust_background_color_can_be_compositor_animated(Layout::Node const&);
WEB_API void const* retain_rust_main_visual_context_tree(Layout::BegunRead const&, DOM::Document const&);
WEB_API Layout::RustFFI::FfiPhysicalOverflowDirections rust_physical_overflow_directions(Layout::Node const&);
WEB_API void register_geometry_host(Layout::NodeArena&);
-WEB_API Layout::RustFFI::FfiRenderingPreparationOutcome rust_prepare_for_rendering(Layout::BegunRead const&, DOM::Document&, bool visual_context_update_pending);
WEB_API void rust_update_visual_viewport_transform(Layout::BegunRead const&, DOM::Document&);
struct InspectorOverlayInputs {
Layout::Node const* highlighted_layout_node { nullptr };
diff --git a/Libraries/LibWeb/Painting/SvgPaintResources.cpp b/Libraries/LibWeb/Painting/SvgPaintResources.cpp
index b9c64e3b188..7a241badf5c 100644
--- a/Libraries/LibWeb/Painting/SvgPaintResources.cpp
+++ b/Libraries/LibWeb/Painting/SvgPaintResources.cpp
@@ -16,8 +16,9 @@
namespace Web::Painting {
-static bool push_svg_filter_reference(void const* url_value, Layout::NodeWithStyle const& layout_node, void* sink)
+bool push_svg_filter_reference(Layout::BegunRead const& read, DOM::Document& document, Compositing::RustFFI::NodeSlotId slot, void const* url_value, void* sink)
{
+ auto const& layout_node = as<Layout::NodeWithStyle>(*document.layout_node_arena().node_if_live(read, slot));
auto filter_element = resolve_svg_filter_reference({ .pointer = url_value }, layout_node);
if (!filter_element)
return false;
@@ -26,8 +27,9 @@ static bool push_svg_filter_reference(void const* url_value, Layout::NodeWithSty
return true;
}
-static void push_svg_paint_server_description(Layout::NodeWithStyle const& layout_node, bool is_stroke, void* sink)
+void push_svg_paint_server_description(Layout::BegunRead const& read, DOM::Document& document, Compositing::RustFFI::NodeSlotId slot, bool is_stroke, void* sink)
{
+ auto const& layout_node = as<Layout::NodeWithStyle>(*document.layout_node_arena().node_if_live(read, slot));
auto const* graphics_element = as_if<SVG::SVGGraphicsElement>(layout_node.dom_node());
if (!graphics_element)
return;
@@ -41,26 +43,4 @@ static void push_svg_paint_server_description(Layout::NodeWithStyle const& layou
pattern->push_paint_server_description(sink, layout_node);
}
-bool sync_svg_paint_resources(Layout::BegunRead const& read, DOM::Document& document)
-{
- // The boxes the resources are drawn from are found in the read the sync is made in.
- struct Context {
- Layout::NodeArena& arena;
- Layout::BegunRead const& read;
- } context { document.layout_node_arena(), read };
- return Layout::RustFFI::render_state_sync_svg_paint_resources(
- context.arena.host(),
- &read, &context,
- [](void* context_pointer, Compositing::RustFFI::NodeSlotId slot, void const* url_value, void* sink) -> bool {
- auto& context = *static_cast<Context*>(context_pointer);
- auto const& layout_node = as<Layout::NodeWithStyle>(*context.arena.node_if_live(context.read, slot));
- return push_svg_filter_reference(url_value, layout_node, sink);
- },
- [](void* context_pointer, Compositing::RustFFI::NodeSlotId slot, bool is_stroke, void* sink) {
- auto& context = *static_cast<Context*>(context_pointer);
- auto const& layout_node = as<Layout::NodeWithStyle>(*context.arena.node_if_live(context.read, slot));
- push_svg_paint_server_description(layout_node, is_stroke, sink);
- });
-}
-
}
diff --git a/Libraries/LibWeb/Painting/SvgPaintResources.h b/Libraries/LibWeb/Painting/SvgPaintResources.h
index 7197dced7c6..132f136eeae 100644
--- a/Libraries/LibWeb/Painting/SvgPaintResources.h
+++ b/Libraries/LibWeb/Painting/SvgPaintResources.h
@@ -8,9 +8,11 @@
#include <LibWeb/Export.h>
#include <LibWeb/Forward.h>
+#include <LibWeb/Layout/LayoutRustFFI.h>
namespace Web::Painting {
-WEB_API bool sync_svg_paint_resources(Layout::BegunRead const&, DOM::Document&);
+bool push_svg_filter_reference(Layout::BegunRead const&, DOM::Document&, Compositing::RustFFI::NodeSlotId, void const* url_value, void* sink);
+void push_svg_paint_server_description(Layout::BegunRead const&, DOM::Document&, Compositing::RustFFI::NodeSlotId, bool is_stroke, void* sink);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/host_tables.rs b/Libraries/LibWeb/Rust/src/layout/host_tables.rs
index 13e67ed926d..d6f2a9e65b7 100644
--- a/Libraries/LibWeb/Rust/src/layout/host_tables.rs
+++ b/Libraries/LibWeb/Rust/src/layout/host_tables.rs
@@ -16,7 +16,7 @@ use super::node_data::{NodeKind, NodeSlotId};
use super::trace::DescribeNode;
use super::update_layout::FfiLayoutUpdateHostCallbacks;
use crate::css::style::fast_hash::{FastMap as HashMap, FastSet as HashSet};
-use crate::painting::host::FfiGeometryHostCallbacks;
+use crate::painting::host::{FfiGeometryHostCallbacks, FfiPaintPreparationHostCallbacks};
use crate::painting::paintable_rows::ChromeStateCallback;
use std::cell::Cell;
use std::cell::RefCell;
@@ -40,6 +40,8 @@ pub(crate) struct HostTables {
pub(crate) chrome_state_callback: Cell<Option<ChromeStateCallback>>,
/// What the overflow pass tells the document once it has settled a box's scroll offset.
pub(crate) geometry_host: Cell<Option<FfiGeometryHostCallbacks>>,
+ /// What preparing the paint and hit testing properties asks of the document, and tells it.
+ pub(crate) paint_preparation_host: Cell<Option<FfiPaintPreparationHostCallbacks>>,
/// How the host names a node a layout trace mentions, set when tracing begins.
pub(super) layout_trace_describe_node: Cell<Option<DescribeNode>>,
/// The image provider each row whose image comes from its style owns, made for the row and
@@ -75,6 +77,7 @@ impl HostTables {
self.style_record_host.set(None);
self.chrome_state_callback.set(None);
self.geometry_host.set(None);
+ self.paint_preparation_host.set(None);
}
/// The layout node of the row `facts` describes, made by the shell factory the first time
diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
index e68850d79a1..7b2ab8a4918 100644
--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
@@ -76,7 +76,6 @@ pub struct FfiLayoutUpdateHostCallbacks {
/// that may take the partial relayout path asks.
container_query_evaluation_is_pending: extern "C" fn(*mut c_void, &BegunRead) -> bool,
needs_style_update_after_layout: extern "C" fn(*mut c_void, &BegunRead) -> bool,
- prepare_for_rendering: extern "C" fn(*mut c_void, &BegunRead),
/// Readies the document for a layout tree build, and answers the document's style, interned as a
/// record, where the flag says the build may build the viewport, and 0 otherwise.
prepare_layout_tree_build: extern "C" fn(*mut c_void, &BegunRead, bool) -> u64,
@@ -200,10 +199,6 @@ impl FfiLayoutUpdateHostCallbacks {
(self.needs_style_update_after_layout)(self.context, read)
}
- fn prepare_for_rendering(&self, _: &MainThread, read: &BegunRead) {
- (self.prepare_for_rendering)(self.context, read);
- }
-
fn prepare_layout_tree_build(&self, _: &MainThread, read: &BegunRead, may_create_viewport: bool) -> Option<u64> {
let record = (self.prepare_layout_tree_build)(self.context, read, may_create_viewport);
(record != 0).then_some(record)
@@ -1151,7 +1146,7 @@ fn update_layout(
inspection_round_pending && facts.should_collect_devtools_layout_data;
inspection_round_pending = false;
if host_layout_is_up_to_date(document_host, read, &facts) && !force_devtools_layout_data_collection {
- host.prepare_for_rendering(main_thread, read);
+ crate::painting::paint_passes::prepare_for_rendering_if_pending(main_thread, document_host, read);
return;
}
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rs
index eff6abadd60..961bf81cc42 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs
@@ -154,6 +154,79 @@ pub unsafe extern "C" fn document_host_set_geometry_host(
host.host_tables().geometry_host.set(Some(callbacks));
}
+/// Has the document of `host` tell paint preparation what it asks of the document through `callbacks`.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread. The callbacks must remain valid until the document
+/// clears them, and answer synchronously.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn document_host_set_paint_preparation_host(
+ host: &DocumentHost,
+ callbacks: crate::painting::host::FfiPaintPreparationHostCallbacks,
+) {
+ host.host_tables().paint_preparation_host.set(Some(callbacks));
+}
+
+/// Has the next preparation of the paint and hit testing properties of `host`'s document update its visual contexts.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_note_visual_contexts_need_update(host: &DocumentHost) {
+ host.paint_preparation().visual_contexts_need_update.set(true);
+}
+
+/// Whether the next preparation of the paint and hit testing properties of `host`'s document updates its visual
+/// contexts.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_visual_contexts_need_update(host: &DocumentHost) -> bool {
+ host.paint_preparation().visual_contexts_need_update.get()
+}
+
+/// Notes that the visual context tree of `host`'s document changed in a way the compositor has not been sent.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_note_visual_context_tree_needs_compositor_update(host: &DocumentHost) {
+ host.paint_preparation()
+ .visual_context_tree_needs_compositor_update
+ .set(true);
+}
+
+/// Notes that the scroll offsets of `host`'s document changed in a way no frame took.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_note_scroll_state_changed(host: &DocumentHost) {
+ host.paint_preparation().scroll_state_changed.set(true);
+}
+
+/// How many times the visual context tree of `host`'s document was built anew since its paint state started.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_visual_context_tree_build_count(host: &DocumentHost) -> u64 {
+ host.paint_preparation().visual_context_tree_build_count.get()
+}
+
+/// How many times the visual context tree of `host`'s document was updated in place since its paint state started.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_visual_context_tree_incremental_update_count(host: &DocumentHost) -> u64 {
+ host.paint_preparation()
+ .visual_context_tree_incremental_update_count
+ .get()
+}
+
+/// Has `host` forget its document's scroll state and what paint preparation left for frames, as the document's paint
+/// state starts over.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_paint_state_was_created(host: &DocumentHost) {
+ host.forget_scroll_state();
+ host.paint_preparation().reset();
+}
+
+/// Has `host` forget its document's scroll state and the visual context tree changes left for the compositor, as the
+/// viewport's row starts over.
+#[unsafe(no_mangle)]
+pub extern "C" fn document_host_viewport_row_was_reset(host: &DocumentHost) {
+ host.forget_scroll_state();
+ host.paint_preparation()
+ .visual_context_tree_needs_compositor_update
+ .set(false);
+}
+
#[unsafe(no_mangle)]
pub extern "C" fn render_state_paintable_scrollable_overflow(
host: &DocumentHost,
@@ -329,44 +402,6 @@ pub extern "C" fn render_state_background_color_can_be_compositor_animated(
})
}
-#[unsafe(no_mangle)]
-pub extern "C" fn render_state_paintable_visual_context_node_count(
- host: &DocumentHost,
- slot: NodeSlotId,
- list: crate::painting::host::FfiVisualContextBoxNodeList,
-) -> usize {
- read_arena(host, node_read(), (slot, list), |arena, (slot, list)| {
- use crate::painting::host::FfiVisualContextBoxNodeList;
- arena.with_paintable_visual_context_node_handles(slot, |handles| match list {
- FfiVisualContextBoxNodeList::SpatialNodes => handles.spatial.len(),
- FfiVisualContextBoxNodeList::ClipNodes => handles.clip_handles().count(),
- FfiVisualContextBoxNodeList::EffectNodes => handles.effects.len(),
- })
- })
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn render_state_paintable_visual_context_copy_node_indices(
- host: &DocumentHost,
- slot: NodeSlotId,
- list: crate::painting::host::FfiVisualContextBoxNodeList,
- out: ak::SpanMut<'_, u32>,
-) {
- let indices = {
- read_arena(host, node_read(), (slot, list), |arena, (slot, list)| {
- use crate::painting::host::FfiVisualContextBoxNodeList;
- arena.with_paintable_visual_context_node_handles(slot, |handles| -> Vec<u32> {
- match list {
- FfiVisualContextBoxNodeList::SpatialNodes => handles.spatial.iter().map(|index| index.0).collect(),
- FfiVisualContextBoxNodeList::ClipNodes => handles.clip_handles().map(|index| index.0).collect(),
- FfiVisualContextBoxNodeList::EffectNodes => handles.effects.iter().map(|index| index.0).collect(),
- }
- })
- })
- };
- out.into_slice()[..indices.len()].copy_from_slice(&indices);
-}
-
pub(super) fn apply_walk_assignments(
arena: &mut crate::layout::LayoutNodeArena,
outcome: &mut crate::painting::visual_context::incremental::IncrementalUpdateOutcome,
@@ -377,32 +412,6 @@ pub(super) fn apply_walk_assignments(
}
}
-/// How far sticky positioning moved `paintable` from its normal position, in device pixels, as the scroll state of
-/// `host`'s document resolved it. Answers false when the accumulated visual context tree holds no sticky node for
-/// `paintable`.
-#[unsafe(no_mangle)]
-pub extern "C" fn render_state_sticky_device_offset(
- host: &DocumentHost,
- paintable: NodeSlotId,
- out: &mut libgfx_rust::FloatPoint,
-) -> bool {
- let sticky_node_index = read_arena(host, node_read(), paintable, |arena, paintable| {
- let paint_state = arena.paint_state();
- paint_state
- .visual_context
- .scroll_state
- .states()
- .iter()
- .find(|state| state.is_sticky && state.paintable == paintable)
- .map(|state| state.node_index)
- });
- let Some(sticky_node_index) = sticky_node_index else {
- return false;
- };
- *out = host.scroll_state().device_offset_for_index(sticky_node_index);
- true
-}
-
/// Marks the entry the event loop calls between two tasks to take a finished recording in.
pub(crate) struct TakesFinishedRecordingIn {
_private: (),
@@ -1448,24 +1457,6 @@ pub extern "C" fn render_state_paintable_used_grid_tracks(
)
}
-#[unsafe(no_mangle)]
-pub extern "C" fn render_state_main_visual_context_tree_retain(
- host: &DocumentHost,
- read: &crate::render_state::BegunRead,
-) -> *const c_void {
- fn retain(tree: Option<&std::sync::Arc<crate::painting::visual_context::VisualContextTree>>) -> *const c_void {
- tree.map_or(std::ptr::null(), |tree| {
- std::sync::Arc::into_raw(std::sync::Arc::clone(tree)).cast()
- })
- }
- if let Some(tree) = host.read_known_rows(|rows, _| retain(rows.visual_context_tree.as_ref())) {
- return tree;
- }
- read_arena(host, read, (), |arena, ()| {
- retain(arena.paint_state().visual_context.tree.as_ref())
- })
-}
-
#[unsafe(no_mangle)]
pub extern "C" fn render_state_has_visual_context_tree(
host: &DocumentHost,
@@ -1477,24 +1468,6 @@ pub extern "C" fn render_state_has_visual_context_tree(
})
}
-#[unsafe(no_mangle)]
-pub extern "C" fn render_state_visual_context_tree_structural_epoch(
- host: &DocumentHost,
- read: &crate::render_state::BegunRead,
-) -> u64 {
- let known = host.read_known_rows(|rows, _| {
- rows.visual_context_tree
- .as_ref()
- .map_or(0, |tree| tree.structural_epoch)
- });
- known.unwrap_or_else(|| {
- read_arena(host, read, (), |arena, ()| {
- let paint_state = arena.paint_state();
- paint_state.visual_context.structural_epoch()
- })
- })
-}
-
#[unsafe(no_mangle)]
pub extern "C" fn render_state_visual_context_tree_has_visual_animations(
host: &DocumentHost,
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
index 3577e8bc971..2930801be9f 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs
@@ -11,7 +11,7 @@
use super::*;
use crate::painting::host::FfiCaretAt;
use crate::painting::host::FfiVisualContextTreeInputs;
-use crate::painting::paint_passes::{PassEffect, pending_preparation, run as run_paint_pass};
+use crate::painting::paint_passes::{PassEffect, run as run_paint_pass};
crate::stage::main_thread_ffi_entries!();
@@ -319,51 +319,50 @@ pub extern "C" fn render_state_first_wheel_scrollable_box_in_containing_block_ch
})
}
-/// Prepares the document of `host` for rendering, and stores the scroll offsets the new overflow moved out of range.
-/// The viewport the preparation reads is asked of `inputs_of` only when there is something to prepare.
+/// Brings the paint and hit testing properties of `host`'s document up to date, for an entry of this module that hands
+/// the host what they are prepared into.
///
/// # Safety
///
-/// `host` must be a live document host, on its document's thread. Host callbacks must remain valid for this call, and
-/// `inputs_of` must answer synchronously from `document`.
+/// `host` must be a live document host, on its document's thread, as the calling entry's contract requires.
+unsafe fn prepare_paint_properties(host: &crate::render_state::DocumentHost, read: &crate::render_state::BegunRead) {
+ // SAFETY: Guaranteed by the caller.
+ let main_thread = unsafe { main_thread(host) };
+ crate::painting::paint_passes::prepare_paint_properties(&main_thread, host, read);
+}
+
+/// Whether the visual context tree of `host`'s document, prepared up to date, changed since a frame last took it to the
+/// compositor, which the caller's frame now does.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_prepare_for_rendering(
+pub unsafe extern "C" fn render_state_take_visual_context_tree_compositor_update(
host: &crate::render_state::DocumentHost,
read: &crate::render_state::BegunRead,
- visual_context_update_pending: bool,
- document: *mut c_void,
- inputs_of: unsafe extern "C" fn(*mut c_void) -> FfiVisualContextTreeInputs,
-) -> crate::painting::paint_passes::FfiRenderingPreparationOutcome {
- let Some(pending) = pending_preparation(read, host) else {
- return Default::default();
- };
+) -> bool {
// SAFETY: Guaranteed by the caller.
- let inputs = unsafe { inputs_of(document) };
- let prepared = run_paint_pass(read, host, PassEffect::RewritesRows, move |arena| {
- pending.prepare(arena, (!visual_context_update_pending).then_some(&inputs))
- });
- if !prepared.clamped_scroll_offsets.is_empty() {
- // SAFETY: Guaranteed by the caller.
- let main_thread = unsafe { main_thread(host) };
- if let Some(geometry_host) = host.host_tables().geometry_host.get() {
- for (slot, offset) in prepared.clamped_scroll_offsets {
- geometry_host.set_scroll_offset(&main_thread, read, slot, offset.into());
- }
- }
- }
- prepared.outcome
+ unsafe { prepare_paint_properties(host, read) };
+ host.paint_preparation()
+ .visual_context_tree_needs_compositor_update
+ .replace(false)
}
+/// Whether the scroll offsets of `host`'s document, prepared up to date, changed since a frame last took them, which the
+/// caller's frame now does.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
#[unsafe(no_mangle)]
-pub extern "C" fn render_state_update_accumulated_visual_contexts(
+pub unsafe extern "C" fn render_state_take_scroll_state_change(
host: &crate::render_state::DocumentHost,
read: &crate::render_state::BegunRead,
- viewport: NodeSlotId,
- inputs: FfiVisualContextTreeInputs,
-) -> crate::painting::host::FfiVisualContextUpdateOutcome {
- run_paint_pass(read, host, PassEffect::RewritesRows, |arena| {
- crate::painting::paint_passes::update_accumulated_visual_contexts(arena, viewport, inputs)
- })
+) -> bool {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, read) };
+ host.paint_preparation().scroll_state_changed.replace(false)
}
#[unsafe(no_mangle)]
@@ -375,6 +374,9 @@ pub extern "C" fn render_state_update_visual_viewport_transform(
run_paint_pass(read, host, PassEffect::StalesPaintPreparation, |arena| {
crate::painting::paint_passes::update_visual_viewport_transform(arena, &inputs);
});
+ host.paint_preparation()
+ .visual_context_tree_needs_compositor_update
+ .set(true);
}
/// Starts an update pass of the compositor animations of `host`'s document, with none published.
@@ -396,114 +398,191 @@ pub extern "C" fn compositor_animation_effect_publish_pending(
host.publish_compositor_animations(animations);
}
-/// Ends the current update pass of the compositor animations of `host`'s document, and gives the visual context tree
-/// what its effects published where `publish_pending`, or none.
+/// Ends the current update pass of the compositor animations of `host`'s document, and gives the visual context tree,
+/// prepared up to date, what its effects published where `publish_pending`, or none.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
#[unsafe(no_mangle)]
-pub extern "C" fn render_state_publish_compositor_animations(
+pub unsafe extern "C" fn render_state_publish_compositor_animations(
host: &crate::render_state::DocumentHost,
read: &crate::render_state::BegunRead,
publish_pending: bool,
) -> crate::painting::host::FfiCompositorAnimationPublishOutcome {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, read) };
let mut animations = host.take_compositor_animations();
if !publish_pending {
animations.clear();
}
- run_paint_pass(read, host, PassEffect::KeepsPaintPreparation, |arena| {
+ let outcome = run_paint_pass(read, host, PassEffect::KeepsPaintPreparation, |arena| {
crate::painting::visual_context::publish_compositor_animations(
&mut arena.paint_state_mut().visual_context,
animations,
)
+ });
+ if outcome.published {
+ host.paint_preparation()
+ .visual_context_tree_needs_compositor_update
+ .set(true);
+ }
+ outcome
+}
+
+/// The visual context tree of `host`'s document, prepared up to date, retained for the caller.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn render_state_main_visual_context_tree_retain(
+ host: &crate::render_state::DocumentHost,
+ read: &crate::render_state::BegunRead,
+) -> *const c_void {
+ fn retain(tree: Option<&std::sync::Arc<crate::painting::visual_context::VisualContextTree>>) -> *const c_void {
+ tree.map_or(std::ptr::null(), |tree| {
+ std::sync::Arc::into_raw(std::sync::Arc::clone(tree)).cast()
+ })
+ }
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, read) };
+ if let Some(tree) = host.read_known_rows(|rows, _| retain(rows.visual_context_tree.as_ref())) {
+ return tree;
+ }
+ read_arena(host, read, (), |arena, ()| {
+ retain(arena.paint_state().visual_context.tree.as_ref())
})
}
-/// Resolves the SVG paint resources the enrolled rows of `host`'s document name: the render state answers what to
-/// resolve, the host resolves it from the DOM, and the render state publishes what it resolved. Answers whether a
-/// published resource changed.
+/// The structural epoch of the visual context tree of `host`'s document, prepared up to date.
///
/// # Safety
///
-/// `host` must be a live document host, on its document's thread, and both resolvers must answer synchronously for the
-/// row they are handed and only push into the sink whose pointer they receive.
+/// `host` must be a live document host, on its document's thread.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_sync_svg_paint_resources(
+pub unsafe extern "C" fn render_state_visual_context_tree_structural_epoch(
host: &crate::render_state::DocumentHost,
read: &crate::render_state::BegunRead,
- context: *mut c_void,
- resolve_filter: unsafe extern "C" fn(*mut c_void, NodeSlotId, *const c_void, *mut c_void) -> bool,
- resolve_paint_server: unsafe extern "C" fn(*mut c_void, NodeSlotId, bool, *mut c_void),
+) -> u64 {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, read) };
+ let known = host.read_known_rows(|rows, _| {
+ rows.visual_context_tree
+ .as_ref()
+ .map_or(0, |tree| tree.structural_epoch)
+ });
+ known.unwrap_or_else(|| {
+ read_arena(host, read, (), |arena, ()| {
+ let paint_state = arena.paint_state();
+ paint_state.visual_context.structural_epoch()
+ })
+ })
+}
+
+/// How far sticky positioning moved `paintable` from its normal position, in device pixels, as the scroll state of
+/// `host`'s document, prepared up to date, resolved it. Answers false when the accumulated visual context tree holds no
+/// sticky node for `paintable`.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn render_state_sticky_device_offset(
+ host: &crate::render_state::DocumentHost,
+ paintable: NodeSlotId,
+ out: &mut libgfx_rust::FloatPoint,
) -> bool {
- use crate::painting::paint_passes::{ResolvedSvgPaintResource, SvgPaintResourceRequest};
- use crate::painting::svg_paint_resources::{PublishedSvgFilter, PublishedSvgPaintServer, SvgPaintResourceKind};
- let requests = run_paint_pass(read, host, PassEffect::KeepsPaintPreparation, |arena| {
- crate::painting::paint_passes::svg_paint_resource_requests(arena)
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, host.begun_read_of_held_node(super::node_read())) };
+ let sticky_node_index = read_arena(host, super::node_read(), paintable, |arena, paintable| {
+ let paint_state = arena.paint_state();
+ paint_state
+ .visual_context
+ .scroll_state
+ .states()
+ .iter()
+ .find(|state| state.is_sticky && state.paintable == paintable)
+ .map(|state| state.node_index)
});
- let Some(requests) = requests else {
+ let Some(sticky_node_index) = sticky_node_index else {
return false;
};
- let resolved = requests
- .into_iter()
- .map(|request| match request {
- SvgPaintResourceRequest::PaintServer { slot, kind } => {
- let mut published = PublishedSvgPaintServer::None;
- // SAFETY: The host resolves synchronously for the row, and only pushes into the sink it is handed.
- unsafe {
- resolve_paint_server(
- context,
- slot,
- kind == SvgPaintResourceKind::Stroke,
- (&raw mut published).cast(),
- );
- }
- ResolvedSvgPaintResource::PaintServer { slot, kind, published }
- }
- SvgPaintResourceRequest::Filter { slot, kind, urls } => {
- let mut published = PublishedSvgFilter::default();
- for url in &urls {
- let mut primitives: Vec<SvgFilterPrimitive> = Vec::new();
- // SAFETY: The host resolves synchronously for the row, and only pushes into the primitive list it
- // is handed as its sink.
- let found =
- unsafe { resolve_filter(context, slot, url.pointer().cast(), (&raw mut primitives).cast()) };
- published = PublishedSvgFilter {
- failed: !found,
- primitives: if found { primitives } else { Vec::new() },
- };
- if published.failed {
- break;
- }
- }
- ResolvedSvgPaintResource::Filter { slot, kind, published }
+ *out = host.scroll_state().device_offset_for_index(sticky_node_index);
+ true
+}
+
+/// The visual context nodes of `list` that the box in `slot` of `host`'s document owns, as the prepared tree has them.
+fn paintable_visual_context_node_indices(
+ host: &crate::render_state::DocumentHost,
+ slot: NodeSlotId,
+ list: crate::painting::host::FfiVisualContextBoxNodeList,
+) -> Vec<u32> {
+ read_arena(host, super::node_read(), (slot, list), |arena, (slot, list)| {
+ use crate::painting::host::FfiVisualContextBoxNodeList;
+ arena.with_paintable_visual_context_node_handles(slot, |handles| -> Vec<u32> {
+ match list {
+ FfiVisualContextBoxNodeList::SpatialNodes => handles.spatial.iter().map(|index| index.0).collect(),
+ FfiVisualContextBoxNodeList::ClipNodes => handles.clip_handles().map(|index| index.0).collect(),
+ FfiVisualContextBoxNodeList::EffectNodes => handles.effects.iter().map(|index| index.0).collect(),
}
})
- .collect();
- run_paint_pass(read, host, PassEffect::StalesPaintPreparation, |arena| {
- crate::painting::paint_passes::publish_resolved_svg_paint_resources(arena, resolved)
})
}
-/// Re-reads the scroll containers' offsets when something invalidated them since the last refresh, resolves the
-/// sticky nodes' offsets on top of them, and has `host` keep them as its document's scroll state; otherwise the host
-/// keeps the one it has. Refreshes the compositor scroll table of the tree as well. Answers whether the offsets
-/// changed, and what refreshing the table changed.
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
#[unsafe(no_mangle)]
-pub extern "C" fn render_state_refresh_scroll_state(
+pub unsafe extern "C" fn render_state_paintable_visual_context_node_count(
host: &crate::render_state::DocumentHost,
- read: &crate::render_state::BegunRead,
- device_pixels_per_css_pixel: f64,
- device_viewport_size: libgfx_rust::IntSize,
-) -> crate::painting::paint_passes::FfiCompositorScrollRefreshOutcome {
- let (device_offsets, mut outcome) = run_paint_pass(read, host, PassEffect::RewritesRows, |arena| {
- crate::painting::paint_passes::refresh_scroll_state(arena, device_pixels_per_css_pixel, device_viewport_size)
- });
- outcome.scroll_state_changed =
- device_offsets.is_some_and(|device_offsets| host.refresh_scroll_state(device_offsets));
- outcome
+ slot: NodeSlotId,
+ list: crate::painting::host::FfiVisualContextBoxNodeList,
+) -> usize {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, host.begun_read_of_held_node(super::node_read())) };
+ paintable_visual_context_node_indices(host, slot, list).len()
+}
+
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn render_state_paintable_visual_context_copy_node_indices(
+ host: &crate::render_state::DocumentHost,
+ slot: NodeSlotId,
+ list: crate::painting::host::FfiVisualContextBoxNodeList,
+ out: ak::SpanMut<'_, u32>,
+) {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, host.begun_read_of_held_node(super::node_read())) };
+ let indices = paintable_visual_context_node_indices(host, slot, list);
+ out.into_slice()[..indices.len()].copy_from_slice(&indices);
}
-/// Has `host` forget its document's scroll state, as the viewport's row or the document's paint state starts over.
+/// Where the stacking context structure below the viewport of `host`'s document differs from what paint preparation
+/// recorded, handed to `consume` unless it does not.
+///
+/// # Safety
+///
+/// `host` must be a live document host, on its document's thread, and `consume` must copy the bytes synchronously.
#[unsafe(no_mangle)]
-pub extern "C" fn render_state_forget_scroll_state(host: &crate::render_state::DocumentHost) {
- host.forget_scroll_state();
+pub unsafe extern "C" fn render_state_stacking_context_structure_verification_report(
+ host: &crate::render_state::DocumentHost,
+ read: &crate::render_state::BegunRead,
+ viewport: NodeSlotId,
+ context: *mut c_void,
+ consume: unsafe extern "C" fn(*mut c_void, *const u8, usize),
+) {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { prepare_paint_properties(host, read) };
+ let report = read_arena(host, read, viewport, |arena, viewport| {
+ crate::painting::stacking_context::verify::verification_report(arena, viewport)
+ });
+ if !report.is_empty() {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { consume(context, report.as_ptr(), report.len()) };
+ }
}
/// Hands `append` the scroll state of `host`'s document as the scroll logic of the compositor reads it.
diff --git a/Libraries/LibWeb/Rust/src/painting/host/mod.rs b/Libraries/LibWeb/Rust/src/painting/host/mod.rs
index 3fc18cf3878..340997558b2 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/mod.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/mod.rs
@@ -59,3 +59,84 @@ impl FfiGeometryHostCallbacks {
(self.set_scroll_offset)(self.context, read, slot, offset);
}
}
+
+/// The viewport a document's paint and hit testing properties are prepared for, which only the document knows.
+#[derive(Clone, Copy)]
+#[repr(C)]
+pub struct FfiPaintPreparationViewport {
+ pub visual_context_tree_inputs: FfiVisualContextTreeInputs,
+ pub device_viewport_size: libgfx_rust::IntSize,
+}
+
+/// What preparing the paint and hit testing properties of a document asks of the document, and tells it. The fields
+/// are private, so the callbacks are reached only through the methods below, which take the main thread token.
+///
+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export
+/// whose safety contract keeps them callable, and the private fields let nothing else call them.
+#[derive(Clone, Copy)]
+#[repr(C)]
+pub struct FfiPaintPreparationHostCallbacks {
+ context: *mut std::ffi::c_void,
+ viewport: extern "C" fn(*mut std::ffi::c_void, &mut FfiPaintPreparationViewport),
+ resolve_svg_filter: extern "C" fn(
+ *mut std::ffi::c_void,
+ &crate::render_state::BegunRead,
+ crate::layout::node_data::NodeSlotId,
+ *const std::ffi::c_void,
+ *mut std::ffi::c_void,
+ ) -> bool,
+ resolve_svg_paint_server: extern "C" fn(
+ *mut std::ffi::c_void,
+ &crate::render_state::BegunRead,
+ crate::layout::node_data::NodeSlotId,
+ bool,
+ *mut std::ffi::c_void,
+ ),
+ require_display_list_recording: extern "C" fn(*mut std::ffi::c_void, bool),
+}
+
+impl FfiPaintPreparationHostCallbacks {
+ pub(crate) fn viewport(&self, _: &crate::stage::MainThread) -> FfiPaintPreparationViewport {
+ let mut viewport = FfiPaintPreparationViewport {
+ visual_context_tree_inputs: FfiVisualContextTreeInputs {
+ device_pixels_per_css_pixel: 1.0,
+ visual_viewport_offset_x: 0.0,
+ visual_viewport_offset_y: 0.0,
+ visual_viewport_scale: 1.0,
+ },
+ device_viewport_size: libgfx_rust::IntSize::default(),
+ };
+ (self.viewport)(self.context, &mut viewport);
+ viewport
+ }
+
+ /// Pushes the primitives of the SVG filter that the `url()` value `url` of the row in `slot` names into `primitives`,
+ /// and answers whether it names one.
+ pub(crate) fn resolve_svg_filter(
+ &self,
+ _: &crate::stage::MainThread,
+ read: &crate::render_state::BegunRead,
+ slot: crate::layout::node_data::NodeSlotId,
+ url: *const std::ffi::c_void,
+ primitives: &mut Vec<crate::painting::svg_filter::SvgFilterPrimitive>,
+ ) -> bool {
+ (self.resolve_svg_filter)(self.context, read, slot, url, (&raw mut *primitives).cast())
+ }
+
+ /// Writes the paint server that the fill, or with `is_stroke` the stroke, of the row in `slot` names to `published`.
+ pub(crate) fn resolve_svg_paint_server(
+ &self,
+ _: &crate::stage::MainThread,
+ read: &crate::render_state::BegunRead,
+ slot: crate::layout::node_data::NodeSlotId,
+ is_stroke: bool,
+ published: &mut crate::painting::svg_paint_resources::PublishedSvgPaintServer,
+ ) {
+ (self.resolve_svg_paint_server)(self.context, read, slot, is_stroke, (&raw mut *published).cast());
+ }
+
+ /// Has the document record its display list again, and with `request_frame` render a frame for it.
+ pub(crate) fn require_display_list_recording(&self, _: &crate::stage::MainThread, request_frame: bool) {
+ (self.require_display_list_recording)(self.context, request_frame);
+ }
+}
diff --git a/Libraries/LibWeb/Rust/src/painting/host/visual_context.rs b/Libraries/LibWeb/Rust/src/painting/host/visual_context.rs
index 065e30505be..330b9cc00af 100644
--- a/Libraries/LibWeb/Rust/src/painting/host/visual_context.rs
+++ b/Libraries/LibWeb/Rust/src/painting/host/visual_context.rs
@@ -40,17 +40,6 @@ pub enum FfiVisualContextBoxNodeList {
EffectNodes,
}
-#[derive(Clone, Copy, Debug, Default)]
-#[repr(C)]
-pub struct FfiVisualContextUpdateOutcome {
- pub performed_full_build: bool,
- pub structural_epoch_changed: bool,
- pub requires_display_list_recording: bool,
- /// Whether the update may have given a node of the tree other values: it visited a dirty box, or every box.
- pub values_may_have_changed: bool,
- pub structural_epoch: u64,
-}
-
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
#[expect(dead_code, reason = "C++ constructs the variants")]
diff --git a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs
index 597fc3f364c..bf2ee920101 100644
--- a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs
@@ -10,7 +10,7 @@
use crate::css::css_pixels::CssPixelPoint;
use crate::layout::LayoutNodeArena;
use crate::layout::node_data::NodeSlotId;
-use crate::painting::host::{FfiVisualContextTreeInputs, FfiVisualContextUpdateOutcome, RootBackgroundSource};
+use crate::painting::host::{FfiPaintPreparationHostCallbacks, FfiVisualContextTreeInputs, RootBackgroundSource};
use crate::painting::paint_read::PaintRead;
use crate::painting::svg_paint_resources::{PublishedSvgFilter, PublishedSvgPaintServer, SvgPaintResourceKind};
use crate::painting::visual_context::compositor_scroll_table::{
@@ -22,7 +22,9 @@ use crate::painting::visual_context::incremental::{
};
use crate::painting::visual_context::{VisualContextState, VisualContextTree};
use crate::render_state::{BegunRead, DocumentHost};
+use crate::stage::MainThread;
use libgfx_rust::{FloatPoint, IntSize};
+use std::cell::Cell;
use std::sync::Arc;
/// What a paint pass writes, which decides what the host lets go of before it sends the pass, and whether the paint and
@@ -44,26 +46,31 @@ impl PassEffect {
}
}
-#[derive(Default)]
-#[repr(C)]
-pub struct FfiRenderingPreparationOutcome {
- pub requires_display_list_recording: bool,
- pub requires_visual_context_update: bool,
- pub visual_context_values_changed: bool,
+pub(crate) struct RenderingPreparationOutcome {
+ pub(crate) requires_display_list_recording: bool,
+ pub(crate) requires_visual_context_update: bool,
+ pub(crate) visual_context_values_changed: bool,
}
#[derive(Default)]
-#[repr(C)]
-pub struct FfiCompositorScrollRefreshOutcome {
- pub scroll_state_changed: bool,
- pub table_changed: bool,
- pub requires_display_list_recording: bool,
+pub(crate) struct CompositorScrollRefreshOutcome {
+ pub(crate) table_changed: bool,
+ pub(crate) requires_display_list_recording: bool,
+}
+
+#[derive(Clone, Copy, Debug, Default)]
+pub(crate) struct VisualContextUpdateOutcome {
+ pub(crate) performed_full_build: bool,
+ pub(crate) structural_epoch_changed: bool,
+ pub(crate) requires_display_list_recording: bool,
+ /// Whether the update may have given a node of the tree other values: it visited a dirty box, or every box.
+ pub(crate) values_may_have_changed: bool,
}
/// What preparing for rendering answers: its outcome, and the scroll offsets the new overflow moved out of range,
/// each clamped into it, for the host to store.
pub(crate) struct RenderingPreparation {
- pub(crate) outcome: FfiRenderingPreparationOutcome,
+ pub(crate) outcome: RenderingPreparationOutcome,
pub(crate) clamped_scroll_offsets: Vec<(NodeSlotId, CssPixelPoint)>,
}
@@ -331,6 +338,227 @@ pub(crate) fn pending_preparation(read: &BegunRead, host: &DocumentHost) -> Opti
host.ask(read, |state| rendering_preparation_pending(state.arena_mut()))
}
+/// What the next preparation of a document's paint and hit testing properties owes, and what the ones before left for
+/// the document's frames, which the document's host keeps.
+#[derive(Default)]
+pub(crate) struct PaintPreparationNotes {
+ /// Whether the next preparation updates the visual contexts.
+ pub(crate) visual_contexts_need_update: Cell<bool>,
+ /// Whether the visual context tree changed since a frame last took it to the compositor.
+ pub(crate) visual_context_tree_needs_compositor_update: Cell<bool>,
+ /// Whether the scroll offsets changed since a frame last took them.
+ pub(crate) scroll_state_changed: Cell<bool>,
+ pub(crate) visual_context_tree_build_count: Cell<u64>,
+ pub(crate) visual_context_tree_incremental_update_count: Cell<u64>,
+}
+
+impl PaintPreparationNotes {
+ /// Forgets what the preparations left for frames, as the document's paint state starts over.
+ pub(crate) fn reset(&self) {
+ self.visual_context_tree_needs_compositor_update.set(false);
+ self.scroll_state_changed.set(false);
+ self.visual_context_tree_build_count.set(0);
+ self.visual_context_tree_incremental_update_count.set(0);
+ }
+}
+
+/// The document's viewport row, where its box is committed.
+fn committed_viewport(arena: &LayoutNodeArena) -> Option<NodeSlotId> {
+ let viewport = arena.bound_viewport_row();
+ arena.paintable_row_is_populated(viewport).then_some(viewport)
+}
+
+/// Brings the paint and hit testing properties of `host`'s document up to date with its render state in `read`: the
+/// scrollable overflow and root background, the visual contexts and the scroll state. Every entry that hands the host
+/// what they are prepared into calls this first, and it returns at once where nothing was written to the render state
+/// since they were prepared last.
+pub(crate) fn prepare_paint_properties(main_thread: &MainThread, host: &DocumentHost, read: &BegunRead) {
+ let notes = host.paint_preparation();
+ if host.paint_preparation_is_current() && !notes.visual_contexts_need_update.get() {
+ return;
+ }
+ let Some(callbacks) = host.host_tables().paint_preparation_host.get() else {
+ return;
+ };
+ // What the passes prepare stays current until something is written to the render state, from here on as well.
+ host.note_paint_preparation_is_current();
+
+ settle_scrollable_overflow_and_root_background(main_thread, host, read, &callbacks);
+
+ if notes.visual_contexts_need_update.replace(false) {
+ update_visual_contexts(main_thread, host, read, &callbacks);
+ }
+
+ // Scroll nodes are (re)created by the visual context tree build above, so scroll offsets and the snapshot must be
+ // derived only after structure work is done.
+ let viewport = callbacks.viewport(main_thread);
+ let refreshed = run(read, host, PassEffect::RewritesRows, |arena| {
+ committed_viewport(arena)?;
+ Some(refresh_scroll_state(
+ arena,
+ viewport.visual_context_tree_inputs.device_pixels_per_css_pixel,
+ viewport.device_viewport_size,
+ ))
+ });
+ let Some((device_offsets, outcome)) = refreshed else {
+ return;
+ };
+ if device_offsets.is_some_and(|device_offsets| host.refresh_scroll_state(device_offsets)) {
+ notes.scroll_state_changed.set(true);
+ }
+ if outcome.table_changed {
+ notes.visual_context_tree_needs_compositor_update.set(true);
+ }
+ if outcome.requires_display_list_recording {
+ callbacks.require_display_list_recording(main_thread, true);
+ }
+}
+
+/// Settles the scrollable overflow and root background of `host`'s document where they are left to settle, and stores
+/// the scroll offsets the new overflow moved out of range: the first step of preparing the paint and hit testing
+/// properties, which a layout update that finds the layout up to date takes as well.
+pub(crate) fn prepare_for_rendering_if_pending(main_thread: &MainThread, host: &DocumentHost, read: &BegunRead) {
+ if let Some(callbacks) = host.host_tables().paint_preparation_host.get() {
+ settle_scrollable_overflow_and_root_background(main_thread, host, read, &callbacks);
+ }
+}
+
+fn settle_scrollable_overflow_and_root_background(
+ main_thread: &MainThread,
+ host: &DocumentHost,
+ read: &BegunRead,
+ callbacks: &FfiPaintPreparationHostCallbacks,
+) {
+ let Some(pending) = pending_preparation(read, host) else {
+ return;
+ };
+ let notes = host.paint_preparation();
+ let inputs = callbacks.viewport(main_thread).visual_context_tree_inputs;
+ let visual_contexts_need_update = notes.visual_contexts_need_update.get();
+ let prepared = run(read, host, PassEffect::RewritesRows, move |arena| {
+ pending.prepare(arena, (!visual_contexts_need_update).then_some(&inputs))
+ });
+ if let Some(geometry_host) = host.host_tables().geometry_host.get() {
+ for (slot, offset) in prepared.clamped_scroll_offsets {
+ geometry_host.set_scroll_offset(main_thread, read, slot, offset.into());
+ }
+ }
+ if prepared.outcome.requires_visual_context_update {
+ notes.visual_contexts_need_update.set(true);
+ }
+ if prepared.outcome.visual_context_values_changed {
+ notes.visual_context_tree_needs_compositor_update.set(true);
+ }
+ if prepared.outcome.requires_display_list_recording {
+ callbacks.require_display_list_recording(main_thread, true);
+ }
+}
+
+/// Brings the visual context tree of `host`'s document up to date, with the SVG paint resources it is built from, where
+/// the document's viewport box is committed.
+fn update_visual_contexts(
+ main_thread: &MainThread,
+ host: &DocumentHost,
+ read: &BegunRead,
+ callbacks: &FfiPaintPreparationHostCallbacks,
+) {
+ let Some(svg_paint_resources_changed) = sync_svg_paint_resources(main_thread, host, read, callbacks) else {
+ return;
+ };
+ let inputs = callbacks.viewport(main_thread).visual_context_tree_inputs;
+ let started = painting_timing_enabled().then(std::time::Instant::now);
+ let outcome = run(read, host, PassEffect::RewritesRows, |arena| {
+ committed_viewport(arena).map(|viewport| update_accumulated_visual_contexts(arena, viewport, inputs))
+ });
+ let Some(outcome) = outcome else {
+ return;
+ };
+ if let Some(started) = started {
+ eprintln!(
+ "AVC_UPDATE rust={} µs {}",
+ started.elapsed().as_micros(),
+ if outcome.performed_full_build {
+ "full"
+ } else {
+ "incremental"
+ }
+ );
+ }
+ let notes = host.paint_preparation();
+ let count = if outcome.performed_full_build {
+ &notes.visual_context_tree_build_count
+ } else {
+ &notes.visual_context_tree_incremental_update_count
+ };
+ count.set(count.get() + 1);
+ if outcome.requires_display_list_recording || svg_paint_resources_changed {
+ callbacks.require_display_list_recording(main_thread, false);
+ }
+ if outcome.values_may_have_changed {
+ notes.visual_context_tree_needs_compositor_update.set(true);
+ }
+}
+
+fn painting_timing_enabled() -> bool {
+ static PAINTING_TIMING_ENABLED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+ *PAINTING_TIMING_ENABLED.get_or_init(|| {
+ std::env::var("LADYBIRD_RUST_PAINTING_TIMING").is_ok_and(|value| !value.is_empty() && value != "0")
+ })
+}
+
+/// Resolves the SVG paint resources the enrolled rows of `host`'s document name: the render state answers what to
+/// resolve, the document resolves it from the DOM, and the render state publishes what it resolved. Answers whether a
+/// published resource changed, or nothing where the document's viewport box is not committed.
+fn sync_svg_paint_resources(
+ main_thread: &MainThread,
+ host: &DocumentHost,
+ read: &BegunRead,
+ callbacks: &FfiPaintPreparationHostCallbacks,
+) -> Option<bool> {
+ let requests = run(read, host, PassEffect::KeepsPaintPreparation, |arena| {
+ committed_viewport(arena)?;
+ Some(svg_paint_resource_requests(arena))
+ })?;
+ let Some(requests) = requests else {
+ return Some(false);
+ };
+ let resolved = requests
+ .into_iter()
+ .map(|request| match request {
+ SvgPaintResourceRequest::PaintServer { slot, kind } => {
+ let mut published = PublishedSvgPaintServer::None;
+ callbacks.resolve_svg_paint_server(
+ main_thread,
+ read,
+ slot,
+ kind == SvgPaintResourceKind::Stroke,
+ &mut published,
+ );
+ ResolvedSvgPaintResource::PaintServer { slot, kind, published }
+ }
+ SvgPaintResourceRequest::Filter { slot, kind, urls } => {
+ let mut published = PublishedSvgFilter::default();
+ for url in &urls {
+ let mut primitives = Vec::new();
+ let found =
+ callbacks.resolve_svg_filter(main_thread, read, slot, url.pointer().cast(), &mut primitives);
+ published = PublishedSvgFilter {
+ failed: !found,
+ primitives: if found { primitives } else { Vec::new() },
+ };
+ if published.failed {
+ break;
+ }
+ }
+ ResolvedSvgPaintResource::Filter { slot, kind, published }
+ }
+ })
+ .collect();
+ Some(run(read, host, PassEffect::StalesPaintPreparation, |arena| {
+ publish_resolved_svg_paint_resources(arena, resolved)
+ }))
+}
+
/// Prepares `arena` for rendering. The sticky constraints the new overflow moved are refreshed with `sticky_inputs`, the
/// inputs of the visual context tree, unless there are none: a visual context update is pending, which refreshes them.
pub(crate) fn prepare_for_rendering(
@@ -362,7 +590,7 @@ pub(crate) fn prepare_for_rendering(
});
}
RenderingPreparation {
- outcome: FfiRenderingPreparationOutcome {
+ outcome: RenderingPreparationOutcome {
requires_display_list_recording: changed || background_source_changed,
requires_visual_context_update: flipped,
visual_context_values_changed,
@@ -375,7 +603,7 @@ pub(crate) fn refresh_scroll_state(
arena: &mut LayoutNodeArena,
device_pixels_per_css_pixel: f64,
device_viewport_size: IntSize,
-) -> (Option<Vec<FloatPoint>>, FfiCompositorScrollRefreshOutcome) {
+) -> (Option<Vec<FloatPoint>>, CompositorScrollRefreshOutcome) {
arena.settle_scrollable_overflow();
arena.with_visual_context_state_lent(|arena, state| {
let outcome = refresh_compositor_scroll_table(
@@ -425,10 +653,10 @@ pub(crate) fn update_accumulated_visual_contexts(
arena: &mut LayoutNodeArena,
viewport: NodeSlotId,
inputs: FfiVisualContextTreeInputs,
-) -> FfiVisualContextUpdateOutcome {
+) -> VisualContextUpdateOutcome {
arena.settle_scrollable_overflow();
if !arena.paintable_row_is_populated(viewport) {
- return FfiVisualContextUpdateOutcome::default();
+ return VisualContextUpdateOutcome::default();
}
let mut state = std::mem::take(&mut arena.paint_state_mut().visual_context);
state.release_quarantined_slots_while_no_handle_is_retained();
@@ -475,12 +703,11 @@ pub(crate) fn update_accumulated_visual_contexts(
}
state.dirty_boxes.clear();
state.last_tree_inputs = Some(inputs);
- let outcome = FfiVisualContextUpdateOutcome {
+ let outcome = VisualContextUpdateOutcome {
performed_full_build,
structural_epoch_changed: outcome.delta.structural_epoch_changed,
requires_display_list_recording: outcome.delta.requires_display_list_recording,
values_may_have_changed,
- structural_epoch: state.structural_epoch(),
};
arena.paint_state_mut().visual_context = state;
return outcome;
@@ -503,7 +730,7 @@ fn fresh_visual_context_tree_build(
viewport: NodeSlotId,
inputs: crate::painting::host::FfiVisualContextTreeInputs,
state: &mut VisualContextState,
-) -> FfiVisualContextUpdateOutcome {
+) -> VisualContextUpdateOutcome {
let mut fresh_tree = crate::painting::visual_context::build::create_fresh_tree_with_viewport_nodes(
&arena.paintable_rows(),
viewport,
@@ -541,12 +768,11 @@ fn fresh_visual_context_tree_build(
state.tree.as_deref().expect("a fresh tree walk keeps the tree"),
viewport,
);
- FfiVisualContextUpdateOutcome {
+ VisualContextUpdateOutcome {
performed_full_build: true,
structural_epoch_changed: true,
requires_display_list_recording: true,
values_may_have_changed: true,
- structural_epoch: state.structural_epoch(),
}
}
diff --git a/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs b/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs
index 6b63b585ab3..79ed850d258 100644
--- a/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs
+++ b/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs
@@ -59,6 +59,7 @@ pub unsafe extern "C" fn render_state_dump_stacking_context_tree(
) {
// SAFETY: Guaranteed by the caller.
let main_thread = unsafe { main_thread(host) };
+ crate::painting::paint_passes::prepare_paint_properties(&main_thread, host, read);
let lines = {
crate::painting::ffi::read_arena(host, read, viewport, |arena, viewport| {
let mut lines = Vec::new();
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/compositor_scroll_table.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/compositor_scroll_table.rs
index 9cd78860cdc..701f2682905 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/compositor_scroll_table.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/compositor_scroll_table.rs
@@ -9,7 +9,7 @@ use crate::layout::node_data::{DomPaintFact, NodeKind, NodeSlotId};
use crate::painting::chrome_geometry::{PhysicalAxes, maximum_scroll_offset, minimum_scroll_offset};
use crate::painting::display_list::commands::UniqueNodeId;
use crate::painting::display_list::device_pixels::DevicePixelConverter;
-use crate::painting::paint_passes::FfiCompositorScrollRefreshOutcome;
+use crate::painting::paint_passes::CompositorScrollRefreshOutcome;
use crate::painting::paint_read::PaintRead;
use crate::painting::{paintable_geometry, scroll_snap, style_queries};
use libcompositing_rust::visual_context::{
@@ -165,13 +165,13 @@ pub(crate) fn refresh_compositor_scroll_table(
arena: &mut crate::layout::LayoutNodeArena,
state: &mut super::VisualContextState,
inputs: CompositorScrollInputs,
-) -> FfiCompositorScrollRefreshOutcome {
+) -> CompositorScrollRefreshOutcome {
use crate::painting::record::damage::PaintDamage;
use libcompositing_rust::visual_context::CompositorScrollTable;
use std::sync::Arc;
let Some(tree) = state.tree.as_mut() else {
- return FfiCompositorScrollRefreshOutcome::default();
+ return CompositorScrollRefreshOutcome::default();
};
let previous = tree.compositor_scroll_table();
let inputs_changed = state.last_compositor_scroll_inputs != Some(inputs);
@@ -274,9 +274,8 @@ pub(crate) fn refresh_compositor_scroll_table(
}
state.last_compositor_scroll_inputs = Some(inputs);
state.compositor_snap_damage_revision = Some(arena.paint_damage_push_revision());
- FfiCompositorScrollRefreshOutcome {
+ CompositorScrollRefreshOutcome {
table_changed,
requires_display_list_recording,
- ..Default::default()
}
}
diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rs
index e50cb60625d..f30adec7d2d 100644
--- a/Libraries/LibWeb/Rust/src/render_state.rs
+++ b/Libraries/LibWeb/Rust/src/render_state.rs
@@ -1274,9 +1274,6 @@ mod tests {
#[test]
fn a_read_that_first_settles_a_scrollability_flip_leaves_the_paint_preparation_stale() {
use crate::layout::node_data::NodeKind;
- use document_host::{
- document_host_note_paint_preparation_is_current, document_host_paint_preparation_is_current,
- };
let test_host = TestHost::new();
let host = test_host.host();
let viewport = host.with_arena_for_test(|arena| {
@@ -1299,15 +1296,15 @@ mod tests {
});
};
- document_host_note_paint_preparation_is_current(host);
+ host.note_paint_preparation_is_current();
measure();
- assert!(!document_host_paint_preparation_is_current(host));
+ assert!(!host.paint_preparation_is_current());
assert!(host.with_arena_for_test(|arena| arena.scrollable_overflow.scrollability_changed));
// A read that settles nothing leaves the preparation as it is.
- document_host_note_paint_preparation_is_current(host);
+ host.note_paint_preparation_is_current();
measure();
- assert!(document_host_paint_preparation_is_current(host));
+ assert!(host.paint_preparation_is_current());
host.with_arena_for_test(|arena| {
arena
@@ -1319,21 +1316,15 @@ mod tests {
#[test]
fn a_mark_that_asks_nothing_of_the_box_leaves_the_paint_preparation_current() {
use crate::layout::tree_update_marks::{FfiBoxMarks, render_state_mark_node_box};
- use document_host::{
- document_host_note_paint_preparation_is_current, document_host_paint_preparation_is_current,
- };
let test_host = TestHost::new();
let host = test_host.host();
- document_host_note_paint_preparation_is_current(host);
+ host.note_paint_preparation_is_current();
render_state_mark_node_box(host, 1, FfiBoxMarks::default());
- assert!(document_host_paint_preparation_is_current(host));
+ assert!(host.paint_preparation_is_current());
}
#[test]
fn a_write_set_aside_leaves_the_paint_preparation_stale_once_queued_again() {
- use document_host::{
- document_host_note_paint_preparation_is_current, document_host_paint_preparation_is_current,
- };
let test_host = TestHost::new();
let host = test_host.host();
crate::painting::paint_changes::render_state_set_viewport_scroll_offset(
@@ -1345,9 +1336,9 @@ mod tests {
);
host.set_writes_aside();
// The properties prepared meanwhile read the render state as it was before the write.
- document_host_note_paint_preparation_is_current(host);
+ host.note_paint_preparation_is_current();
host.queue_writes_set_aside();
- assert!(!document_host_paint_preparation_is_current(host));
+ assert!(!host.paint_preparation_is_current());
}
#[test]
diff --git a/Libraries/LibWeb/Rust/src/render_state/devtools.rs b/Libraries/LibWeb/Rust/src/render_state/devtools.rs
index 11b7edc26bf..61e4632b314 100644
--- a/Libraries/LibWeb/Rust/src/render_state/devtools.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/devtools.rs
@@ -9,7 +9,6 @@
use super::{DocumentHost, ScriptForcedRead};
use crate::layout::LayoutNodeArena;
use crate::layout::node_data::NodeSlotId;
-use std::ffi::c_void;
/// How many layout passes and tree builds a document's layout has run, and how many rows it holds.
#[repr(C)]
@@ -96,28 +95,6 @@ pub extern "C" fn render_state_scrollable_overflow_recalculation_count(host: &Do
})
}
-/// Where the stacking context structure below `viewport` differs from what paint preparation recorded, handed to
-/// `consume` unless it does not.
-///
-/// # Safety
-///
-/// `host` must be a live document host, on its document's thread, and `consume` must copy the bytes synchronously.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_stacking_context_structure_verification_report(
- host: &DocumentHost,
- viewport: NodeSlotId,
- context: *mut c_void,
- consume: unsafe extern "C" fn(*mut c_void, *const u8, usize),
-) {
- let report = read_arena(host, |arena| {
- crate::painting::stacking_context::verify::verification_report(arena, viewport)
- });
- if !report.is_empty() {
- // SAFETY: Guaranteed by the caller.
- unsafe { consume(context, report.as_ptr(), report.len()) };
- }
-}
-
/// How many layout nodes the host made for the rows of its document.
#[unsafe(no_mangle)]
pub extern "C" fn render_state_shell_count(host: &DocumentHost) -> u32 {
diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rs
index 4c43a3885d3..f08516421a2 100644
--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs
@@ -94,6 +94,9 @@ pub struct DocumentHost {
/// is: nothing was written to it since, queued, in place or by a job. Preparing them again would find nothing
/// to do.
paint_preparation_is_current: Cell<bool>,
+ /// What the next preparation of the paint and hit testing properties owes, and what the ones before left for the
+ /// document's frames.
+ paint_preparation: crate::painting::paint_passes::PaintPreparationNotes,
/// The layout round that flew with the frame, from its landing until the host's next layout update pays it.
flown_round: RefCell<Option<FlownRound>>,
/// Whether a job of the host runs, whose host callbacks see rows it freed and the host has not heard of yet.
@@ -209,6 +212,7 @@ impl DocumentHost {
changes: ChangeQueue::default(),
flown_style: RefCell::default(),
paint_preparation_is_current: Cell::new(false),
+ paint_preparation: Default::default(),
flown_round: RefCell::default(),
in_job: Cell::new(false),
streamed: Cell::new(false),
@@ -1536,6 +1540,25 @@ impl DocumentHost {
pub(crate) fn forget_scroll_state(&self) {
self.scroll_state.take();
}
+
+ /// Whether the paint and hit testing properties of the document were prepared from its render state as it is, so
+ /// that preparing them again would find nothing to do: they were noted current as their preparation began, and
+ /// nothing was written to the render state since, queued, in place or by a job.
+ pub(crate) fn paint_preparation_is_current(&self) -> bool {
+ self.paint_preparation_is_current.get()
+ }
+
+ /// Notes that the paint and hit testing properties of the document are current, as their preparation begins: they
+ /// stay current until something writes to the render state.
+ pub(crate) fn note_paint_preparation_is_current(&self) {
+ self.paint_preparation_is_current.set(true);
+ }
+
+ /// What the next preparation of the paint and hit testing properties owes, and what the ones before left for the
+ /// document's frames.
+ pub(crate) fn paint_preparation(&self) -> &crate::painting::paint_passes::PaintPreparationNotes {
+ &self.paint_preparation
+ }
}
/// Creates the host of a new document.
@@ -1593,21 +1616,6 @@ impl Drop for TestHost {
}
}
-/// Whether the paint and hit testing properties of `host`'s document were prepared from its render state as it is, so
-/// that preparing them again would find nothing to do: the host noted them current as it began to prepare them, and
-/// wrote nothing to the render state since, queued, in place or by a job.
-#[unsafe(no_mangle)]
-pub extern "C" fn document_host_paint_preparation_is_current(host: &DocumentHost) -> bool {
- host.paint_preparation_is_current.get()
-}
-
-/// Notes that the paint and hit testing properties of `host`'s document are current, as the host begins to prepare them:
-/// they stay current until the host writes to the render state.
-#[unsafe(no_mangle)]
-pub extern "C" fn document_host_note_paint_preparation_is_current(host: &DocumentHost) {
- host.paint_preparation_is_current.set(true);
-}
-
/// What a scope of a read of a document's render state reads of the document's host: whether the host waits for the
/// frame, which it keeps up to date, and the read the scope lends.
#[repr(C)]
diff --git a/Meta/Linters/check_rust_process_wide_state.py b/Meta/Linters/check_rust_process_wide_state.py
index d011f8aa9f4..a6f74b120ef 100755
--- a/Meta/Linters/check_rust_process_wide_state.py
+++ b/Meta/Linters/check_rust_process_wide_state.py
@@ -102,6 +102,7 @@ RENDER_STATE_ALLOWED = {
"layout/parallel_layout.rs:SUBTREE_LEASES_ARE_VERIFIED",
"layout/run_repeatability.rs:ENABLED",
"layout/run_repeatability.rs:VERIFICATION",
+ "painting/paint_passes.rs:PAINTING_TIMING_ENABLED",
"render_state/clock/hover.rs:LOGS",
],
),
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 6f97034c84f..12f10782064 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -1176,7 +1176,6 @@ void ConnectionFromClient::debug_request(Web::PageId page_id, ByteString request
Web::Layout::ForcedReadScope read { *doc };
if (doc->layout_node(read)) {
VERIFY(doc->has_committed_viewport_box());
- doc->update_paint_and_hit_testing_properties_if_needed();
StringBuilder builder;
Web::Painting::dump_stacking_context_tree(read, builder, *doc);
dbgln("{}", builder.string_view());
@@ -2741,7 +2740,6 @@ static void append_stacking_context_tree(Web::Page& page, StringBuilder& builder
return;
}
- document->update_paint_and_hit_testing_properties_if_needed();
Web::Painting::dump_stacking_context_tree(read, builder, *document);
}
diff --git a/Tests/LibWeb/BenchmarkDisplayListRecording.cpp b/Tests/LibWeb/BenchmarkDisplayListRecording.cpp
index a7b7d11f0ff..686a6919e59 100644
--- a/Tests/LibWeb/BenchmarkDisplayListRecording.cpp
+++ b/Tests/LibWeb/BenchmarkDisplayListRecording.cpp
@@ -355,7 +355,7 @@ void time_document_recordings(DocumentShape shape, StringView label, Optional<Mu
// The fresh visual context tree is built before the timer starts, so only the recording is timed.
if (cache_state == CacheState::Cold) {
document.schedule_full_accumulated_visual_context_rebuild(Web::Layout::RustFFI::VisualContextUpdateScope::FreshTree);
- document.update_paint_and_hit_testing_properties_if_needed();
+ (void)document.visual_context_tree();
}
Web::Layout::ForcedReadScope read { document };
auto timer = Core::ElapsedTimer::start_new(Core::TimerType::Precise);
@@ -379,7 +379,6 @@ void time_rust_recordings(DocumentShape shape, StringView label)
for (size_t i = 0; i < timed_iterations; ++i) {
apply_mutation(loaded_page, Mutation::OneCardBackground);
document.update_layout(Web::DOM::UpdateLayoutReason::Debugging);
- document.update_paint_and_hit_testing_properties_if_needed();
auto visual_context_tree = document.paint_state().visual_context_tree(document);
Web::Painting::InspectorOverlayInputs overlay_inputs;
Web::Layout::ForcedReadScope read { document };