script: Unify script-based "update the rendering" and throttle it to 60 FPS (#38431)

Instead of running "update the rendering" at every IPC message, only run
it when a timeout has occured in script. In addition, avoid updating the
rendering if a rendering update isn't necessary. This should greatly
reduce the amount of processing that has to happen in script.

Because we are running many fewer calls to "update the rendering" it is
reasonable now to ensure that these always work the same way. In
particular, we always run rAF and update the animation timeline when
updating the ernder

In addition, pull the following things out of reflow:

 - Code dealing with informing the Constellation that a Pipeline has
   become Idle when waiting for a screenshot.
 - Detecting when it is time to fulfill the `document.fonts.ready`
   promise.

The latter means that reflow can never cause a garbage collection,
making timing of reflows more consistent and simplifying many callsites
that need to do script queries.

Followup changes will seek to simplify the way that ScriptThread-driven
animation timeouts happen even simpler.

Testing: In general, this should not change testable behavior so much,
though it
does seem to fix one test.  The main improvement here should be that
the ScriptThread does less work.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-04 18:27:00 +02:00 committed by GitHub
parent bcc8314dd5
commit 9416251cab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 607 additions and 672 deletions

View file

@ -278,7 +278,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
) -> Fallible<DomRoot<MouseEvent>> {
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
let scroll_offset = window.scroll_offset(can_gc);
let scroll_offset = window.scroll_offset();
let page_point = Point2D::new(
scroll_offset.x as i32 + init.clientX,
scroll_offset.y as i32 + init.clientY,
@ -370,7 +370,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsetx>
fn OffsetX(&self, can_gc: CanGc) -> i32 {
fn OffsetX(&self) -> i32 {
// > The offsetX attribute must follow these steps:
// > 1. If the events dispatch flag is set, return the x-coordinate of the position
// > where the event occurred relative to the origin of the padding edge of the
@ -384,7 +384,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
let Some(node) = target.downcast::<Node>() else {
return 0;
};
return self.ClientX() - node.client_rect(can_gc).origin.x;
return self.ClientX() - node.client_rect().origin.x;
}
// > 2. Return the value of the events pageX attribute.
@ -392,7 +392,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
}
/// <https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsety>
fn OffsetY(&self, can_gc: CanGc) -> i32 {
fn OffsetY(&self) -> i32 {
// > The offsetY attribute must follow these steps:
// > 1. If the events dispatch flag is set, return the y-coordinate of the
// > position where the event occurred relative to the origin of the padding edge of
@ -406,7 +406,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
let Some(node) = target.downcast::<Node>() else {
return 0;
};
return self.ClientY() - node.client_rect(can_gc).origin.y;
return self.ClientY() - node.client_rect().origin.y;
}
// 2. Return the value of the events pageY attribute.
@ -479,7 +479,6 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
meta_key_arg: bool,
button_arg: i16,
related_target_arg: Option<&EventTarget>,
can_gc: CanGc,
) {
if self.upcast::<Event>().dispatching() {
return;
@ -498,7 +497,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
.set(Point2D::new(client_x_arg, client_y_arg));
let global = self.global();
let scroll_offset = global.as_window().scroll_offset(can_gc);
let scroll_offset = global.as_window().scroll_offset();
self.page_point.set(Point2D::new(
scroll_offset.x as i32 + client_x_arg,
scroll_offset.y as i32 + client_y_arg,