Truly independent web browser
LibWeb: Stale paint preparation when set-aside writes are queued again
Aliaksandr Kalenik17b8e3e45f89
diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rsindex 1a3a2186738..3f789549370 100644--- a/Libraries/LibWeb/Rust/src/render_state.rs+++ b/Libraries/LibWeb/Rust/src/render_state.rs@@ -351,6 +351,12 @@ pub(crate) enum ArenaChange {}impl ArenaChange {+ /// Whether the change writes what the paint and hit testing properties are prepared from: all but a style write that+ /// only keeps the engine from reclaiming records do.+ pub(crate) fn stales_paint_preparation(&self) -> bool {+ !matches!(self, Self::Style(change) if change.only_keeps_records_alive())+ }+/// Whether the change leaves the render state showing what the frame sampled last showed: it takes in the recording/// of that frame, which a lane's fork takes in too, or only keeps the engine from reclaiming records.pub(crate) fn keeps_the_presented_frame(&self) -> bool {@@ -717,12 +723,15 @@ impl ChangeQueue {*self.set_aside.borrow_mut() = self.queued.take();}- /// Queues the writes set aside behind the writes queued meanwhile.- fn queue_set_aside(&self) {+ /// Queues the writes set aside behind the writes queued meanwhile, and answers whether any of them stales the paint+ /// and hit testing properties.+ fn queue_set_aside(&self) -> bool {self.sets_writes_aside.set(false);let mut set_aside = self.set_aside.take();set_aside.iter().for_each(|change| self.note(change));+ let stales_paint_preparation = set_aside.iter().any(ArenaChange::stales_paint_preparation);self.queued.borrow_mut().append(&mut set_aside);+ stales_paint_preparation}/// Keeps `buffer`, emptied by the render side, as the spare.@@ -1128,6 +1137,27 @@ mod tests {assert!(document_host_paint_preparation_is_current(host));}+ #[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(+ host,+ crate::layout::used_values::FfiCssPixelPoint {+ x: crate::css::css_pixels::CssPixels::from_raw(0),+ y: crate::css::css_pixels::CssPixels::from_raw(640),+ },+ );+ 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.queue_writes_set_aside();+ assert!(!document_host_paint_preparation_is_current(host));+ }+#[test]fn a_style_write_leaves_what_the_rows_are_to_read_from_the_rows_the_host_has() {use crate::layout::node_data::{NodeFlag, NodeKind, StylePayloadsRef};diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex 60e98d15fdd..28ac7ae6ef7 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -250,13 +250,13 @@ impl DocumentHost {/// Writes `change` to the document's render state, before anything that reads what it changes: the render owner/// applies it ahead of the host's next job. A write never reaches the render state as the host makes it.pub(crate) fn queue_change(&self, change: ArenaChange) {- match &change {- ArenaChange::Style(change) if change.only_keeps_records_alive() => {}- ArenaChange::Style(change) => {- self.note_render_state_write();- self.engine_memo.follow(change);- }- _ => self.note_render_state_write(),+ if change.stales_paint_preparation() {+ self.note_render_state_write();+ }+ if let ArenaChange::Style(change) = &change+ && !change.only_keeps_records_alive()+ {+ self.engine_memo.follow(change);}self.changes.push(change, |queued| self.engine_memo.follow_queued(queued));@@ -899,7 +899,11 @@ impl DocumentHost {/// Queues the writes the host set aside behind those it queued meanwhile.pub(crate) fn queue_writes_set_aside(&self) {- self.changes.queue_set_aside();+ // The paint and hit testing properties prepared while they were set aside read the render state as it was+ // before them.+ if self.changes.queue_set_aside() {+ self.note_render_state_write();+ }}/// Ends the drain of the style transaction that flew: the writes the host queued beside it are queued again, behind