script: Remove 'pending reflow' concept and some explicit reflows (#34558)

The `pending reflow` concept isn't necessary now that *update the
rendering* is taking care of triggering reflows at the correct time.
`Window::reflow` already avoids reflows if the page is not dirty, so
pending reflows is now just an extraneous check as long as *update the
rendering* runs properly.

This change also removes some explicit reflows, which now wait until the
appropriate moment during *update the rendering*. This should remove
some extra reflows that are not necessary.

Servo needs some way to track that resizing the web view needs to
re-layout due to the initial containing block changing. Move handling
of `Document::needs_paint` to the script thread and use this, expanding
the rustdoc to explain what it is for a bit more clearly.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-12-11 13:58:37 +01:00 committed by GitHub
parent bc741bdc0b
commit 3f85a27097
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 43 additions and 122 deletions

View file

@ -345,8 +345,10 @@ pub struct Document {
/// Information on elements needing restyle to ship over to layout when the
/// time comes.
pending_restyles: DomRefCell<HashMap<Dom<Element>, NoTrace<PendingRestyle>>>,
/// This flag will be true if layout suppressed a reflow attempt that was
/// needed in order for the page to be painted.
/// This flag will be true if the `Document` needs to be painted again
/// during the next full layout attempt due to some external change such as
/// the web view changing size, or because the previous layout was only for
/// layout queries (which do not trigger display).
needs_paint: Cell<bool>,
/// <http://w3c.github.io/touch-events/#dfn-active-touch-point>
active_touch_points: DomRefCell<Vec<Dom<Touch>>>,
@ -823,8 +825,8 @@ impl Document {
}
}
pub fn needs_paint(&self) -> bool {
self.needs_paint.get()
pub(crate) fn set_needs_paint(&self, value: bool) {
self.needs_paint.set(value)
}
pub fn needs_reflow(&self) -> Option<ReflowTriggerCondition> {
@ -844,7 +846,7 @@ impl Document {
return Some(ReflowTriggerCondition::PendingRestyles);
}
if self.needs_paint() {
if self.needs_paint.get() {
return Some(ReflowTriggerCondition::PaintPostponed);
}
@ -3169,8 +3171,6 @@ pub enum DocumentSource {
#[allow(unsafe_code)]
pub trait LayoutDocumentHelpers<'dom> {
fn is_html_document_for_layout(&self) -> bool;
fn needs_paint_from_layout(self);
fn will_paint(self);
fn quirks_mode(self) -> QuirksMode;
fn style_shared_lock(self) -> &'dom StyleSharedRwLock;
fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>>;
@ -3185,16 +3185,6 @@ impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
self.unsafe_get().is_html_document
}
#[inline]
fn needs_paint_from_layout(self) {
(self.unsafe_get()).needs_paint.set(true)
}
#[inline]
fn will_paint(self) {
(self.unsafe_get()).needs_paint.set(false)
}
#[inline]
fn quirks_mode(self) -> QuirksMode {
self.unsafe_get().quirks_mode.get()
@ -4171,14 +4161,9 @@ impl Document {
pub(crate) fn maybe_mark_animating_nodes_as_dirty(&self) {
let current_timeline_value = self.current_animation_timeline_value();
let marked_dirty = self
.animations
self.animations
.borrow()
.mark_animating_nodes_as_dirty(current_timeline_value);
if marked_dirty {
self.window().add_pending_reflow();
}
}
pub(crate) fn current_animation_timeline_value(&self) -> f64 {