From 8882507ad06b598fb43d8542c67ad76daeda739c Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Fri, 22 Mar 2024 14:06:28 +0800 Subject: =?UTF-8?q?Rework=20=E2=80=9Cvisible=E2=80=9D=20to=20=E2=80=9Cthro?= =?UTF-8?q?ttled=E2=80=9D=20in=20constellation=20+=20script=20+=20composit?= =?UTF-8?q?or=20(#31816)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/script/dom/document.rs | 2 +- components/script/dom/htmliframeelement.rs | 10 +++++----- components/script/dom/window.rs | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'components/script/dom') diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index d03a31aa3a6..62ead49cb77 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1966,7 +1966,7 @@ impl Document { // If we are running 'fake' animation frames, we unconditionally // set up a one-shot timer for script to execute the rAF callbacks. - if self.is_faking_animation_frames() && self.window().visible() { + if self.is_faking_animation_frames() && !self.window().throttled() { warn!("Scheduling fake animation frame. Animation frames tick too fast."); let callback = FakeRequestAnimationFrameCallback { document: Trusted::new(self), diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index c108bed11c6..23613c9f1ba 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -87,7 +87,7 @@ pub struct HTMLIFrameElement { sandbox: MutNullableDom, sandbox_allowance: Cell>, load_blocker: DomRefCell>, - visibility: Cell, + throttled: Cell, } impl HTMLIFrameElement { @@ -438,7 +438,7 @@ impl HTMLIFrameElement { sandbox: Default::default(), sandbox_allowance: Cell::new(None), load_blocker: DomRefCell::new(None), - visibility: Cell::new(true), + throttled: Cell::new(false), } } @@ -473,9 +473,9 @@ impl HTMLIFrameElement { self.top_level_browsing_context_id.get() } - pub fn change_visibility_status(&self, visibility: bool) { - if self.visibility.get() != visibility { - self.visibility.set(visibility); + pub fn set_throttled(&self, throttled: bool) { + if self.throttled.get() != throttled { + self.throttled.set(throttled); } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index c58700b1a37..9a92955a007 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -349,7 +349,7 @@ pub struct Window { #[no_trace] player_context: WindowGLContext, - visible: Cell, + throttled: Cell, /// A shared marker for the validity of any cached layout values. A value of true /// indicates that any such values remain valid; any new layout that invalidates @@ -2454,18 +2454,18 @@ impl Window { self.Document().react_to_environment_changes(); } - /// Slow down/speed up timers based on visibility. - pub fn alter_resource_utilization(&self, visible: bool) { - self.visible.set(visible); - if visible { - self.upcast::().speed_up_timers(); - } else { + /// Set whether to use less resources by running timers at a heavily limited rate. + pub fn set_throttled(&self, throttled: bool) { + self.throttled.set(throttled); + if throttled { self.upcast::().slow_down_timers(); + } else { + self.upcast::().speed_up_timers(); } } - pub fn visible(&self) -> bool { - self.visible.get() + pub fn throttled(&self) -> bool { + self.throttled.get() } pub fn unminified_js_dir(&self) -> Option { @@ -2621,7 +2621,7 @@ impl Window { userscripts_path, replace_surrogates, player_context, - visible: Cell::new(true), + throttled: Cell::new(false), layout_marker: DomRefCell::new(Rc::new(Cell::new(true))), current_event: DomRefCell::new(None), }); -- cgit v1.2.3