Truly independent web browser
LibWeb: Note scroll offset changes where frames present them
Aliaksandr Kalenikad02f28441d8
diff --git a/Libraries/LibWeb/Compositor/NavigablePresenter.cpp b/Libraries/LibWeb/Compositor/NavigablePresenter.cppindex 0ecba782823..5fd482634cd 100644--- a/Libraries/LibWeb/Compositor/NavigablePresenter.cpp+++ b/Libraries/LibWeb/Compositor/NavigablePresenter.cpp@@ -19,8 +19,11 @@ struct PresenterFFI {return sealed.presented_by == PresentedBy::Clock && sealed.generation < presenter.m_last_committed_generation;}- static void note_presented(NavigablePresenter& presenter, SealedPresentation& sealed)+ static void note_presented(NavigablePresenter& presenter, SealedPresentation& sealed, ReadonlyBytes encoded_scroll_state){+ sealed.presented_other_scroll_offsets = presenter.m_last_presented_encoded_scroll_state.bytes() != encoded_scroll_state;+ if (sealed.presented_other_scroll_offsets)+ presenter.m_last_presented_encoded_scroll_state = MUST(ByteBuffer::copy(encoded_scroll_state));if (sealed.presented_by == PresentedBy::Commit) {presenter.m_last_committed_generation = max(presenter.m_last_committed_generation, sealed.generation);presenter.m_committed_command_resources = presenter.m_compositor_display_list_command_resources;@@ -36,7 +39,7 @@ struct PresenterFFI {return;auto frame = presenter.build_frame_beside_event_loop(sealed, move(display_list), encoded_scroll_state);frame.scroll_requests = move(sealed.scroll_requests);- note_presented(presenter, sealed);+ note_presented(presenter, sealed, encoded_scroll_state);if (sink)sink->submit(move(frame));}@@ -48,7 +51,7 @@ struct PresenterFFI {return;auto frame = presenter.build_frame(sealed, {}, encoded_scroll_state);frame.scroll_requests = move(sealed.scroll_requests);- note_presented(presenter, sealed);+ note_presented(presenter, sealed, encoded_scroll_state);if (sink)sink->submit(move(frame));}diff --git a/Libraries/LibWeb/Compositor/NavigablePresenter.h b/Libraries/LibWeb/Compositor/NavigablePresenter.hindex dd47d13b94d..a6832750936 100644--- a/Libraries/LibWeb/Compositor/NavigablePresenter.h+++ b/Libraries/LibWeb/Compositor/NavigablePresenter.h@@ -7,6 +7,7 @@#pragma once#include <AK/AtomicRefCounted.h>+#include <AK/ByteBuffer.h>#include <AK/Mutex.h>#include <AK/Noncopyable.h>#include <AK/NonnullOwnPtr.h>@@ -59,8 +60,9 @@ struct SealedPresentation {Optional<Compositing::AccumulatedVisualContextTree> visual_context_tree;// Whether the document's tree changed since the compositor took one.bool sends_visual_context_tree { false };- // Whether the document's scroll offsets changed since the frame before.- bool scroll_state_changed { false };+ // Whether presenting the frame sent the compositor other scroll offsets than the frame presented before it, which the+ // presenter notes as it presents.+ bool presented_other_scroll_offsets { false };// The scrolls the navigable asked for since the frame before, which the compositor applies once it has the frame's// boxes. Only the frame a rendering update commits carries them.Vector<Compositing::ScrollRequest> scroll_requests;@@ -173,6 +175,8 @@ private:Optional<Compositing::AccumulatedVisualContextTree> m_compositor_visual_context_tree;// The generation of the last frame a rendering update committed that the presenter presented.u64 m_last_committed_generation { 0 };+ // The scroll offsets the last frame the presenter presented sent the compositor.+ ByteBuffer m_last_presented_encoded_scroll_state;// What the display list of the last frame a rendering update committed references, which the frames of a clock lane// keep beside their own.Compositing::DisplayListResourceSet m_committed_command_resources;diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 0d484d248a1..2fff2962fa4 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -7118,7 +7118,6 @@ Compositor::SealedPresentation LocalNavigable::seal_presentation(Layout::BegunRe.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(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(),@@ -7137,8 +7136,6 @@ void LocalNavigable::unseal_presentation(DOM::Document& document, Compositor::Se{if (sealed.sends_visual_context_tree && document.has_paint_state())document.paint_state().did_update_visual_context_values();- if (sealed.scroll_state_changed && document.has_paint_state())- document.paint_state().did_change_scroll_state();give_back_unsent_scroll_requests(move(sealed.scroll_requests));}@@ -7200,7 +7197,7 @@ void LocalNavigable::finish_recording_in_flight(RecordingInFlight& in_flight, Lahit_test_list_adoption = document->adopt_published_recording(Painting::hit_test_list_read(read, hit_test_list_stands), *in_flight.recording, sealed->published->display_list, [&] { return sealed->published->referenced_resources; });}// A frame that kept its hit-test items, and sent no visual context tree, placed them as the frame before it did,- // unless it scrolled them. The hover waits for a scroll of the user's to stop instead (see+ // unless it sent other scroll offsets. The hover waits for a scroll of the user's to stop instead (see// schedule_hover_update_after_async_scroll).auto const frame_placement = [&] {if (hit_test_list_adoption == Painting::HitTestListAdoption::TookNew)@@ -7209,7 +7206,7 @@ void LocalNavigable::finish_recording_in_flight(RecordingInFlight& in_flight, Lareturn Web::EventHandler::FramePlacement::Unchanged;if (sealed->sends_visual_context_tree)return Web::EventHandler::FramePlacement::Changed;- if (sealed->scroll_state_changed && !has_user_scroll_gesture())+ if (sealed->presented_other_scroll_offsets && !has_user_scroll_gesture())return Web::EventHandler::FramePlacement::Changed;return Web::EventHandler::FramePlacement::Unchanged;}();diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.cpp b/Libraries/LibWeb/Painting/DocumentPaintState.cppindex f3caac4a68d..822ac150605 100644--- a/Libraries/LibWeb/Painting/DocumentPaintState.cpp+++ b/Libraries/LibWeb/Painting/DocumentPaintState.cpp@@ -56,16 +56,6 @@ 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());diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.h b/Libraries/LibWeb/Painting/DocumentPaintState.hindex 6b2e55fb0ca..54874d15210 100644--- a/Libraries/LibWeb/Painting/DocumentPaintState.h+++ b/Libraries/LibWeb/Painting/DocumentPaintState.h@@ -53,9 +53,6 @@ public:// 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;u64 accumulated_visual_context_tree_incremental_update_count() const;diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 961bf81cc42..ba9c0d34dc4 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -189,12 +189,6 @@ pub extern "C" fn document_host_note_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 {diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 2930801be9f..6f2b06c2822 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -349,22 +349,6 @@ pub unsafe extern "C" fn render_state_take_visual_context_tree_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 unsafe extern "C" fn render_state_take_scroll_state_change(- host: &crate::render_state::DocumentHost,- read: &crate::render_state::BegunRead,-) -> bool {- // SAFETY: Guaranteed by the caller.- unsafe { prepare_paint_properties(host, read) };- host.paint_preparation().scroll_state_changed.replace(false)-}-#[unsafe(no_mangle)]pub extern "C" fn render_state_update_visual_viewport_transform(host: &crate::render_state::DocumentHost,diff --git a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs b/Libraries/LibWeb/Rust/src/painting/paint_passes.rsindex bf2ee920101..951538f5cb0 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs@@ -346,8 +346,6 @@ pub(crate) struct PaintPreparationNotes {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>,}@@ -356,7 +354,6 @@ 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);}@@ -403,8 +400,8 @@ pub(crate) fn prepare_paint_properties(main_thread: &MainThread, host: &Documentlet 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 let Some(device_offsets) = device_offsets {+ host.refresh_scroll_state(device_offsets);}if outcome.table_changed {notes.visual_context_tree_needs_compositor_update.set(true);diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex f08516421a2..a46d9d2b82f 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -1527,13 +1527,10 @@ impl DocumentHost {self.scroll_state.borrow().clone()}- /// Takes `device_offsets`, the offsets the render state refreshed, as the document's scroll state. Answers whether- /// they differ from the ones the host had.- pub(crate) fn refresh_scroll_state(&self, device_offsets: Vec<FloatPoint>) -> bool {- let changed = self.scroll_state.borrow().device_offsets() != device_offsets.as_slice();+ /// Takes `device_offsets`, the offsets the render state refreshed, as the document's scroll state.+ pub(crate) fn refresh_scroll_state(&self, device_offsets: Vec<FloatPoint>) {self.scroll_state.replace(Rc::new(ScrollStateSnapshot::from_device_offsets(device_offsets)));- changed}/// Forgets where the document's boxes were scrolled to: nothing is scrolled until the next refresh.