diff options
author | Delan Azabani <dazabani@igalia.com> | 2024-03-22 14:06:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 06:06:28 +0000 |
commit | 8882507ad06b598fb43d8542c67ad76daeda739c (patch) | |
tree | 5d78c92d40aab37a71f87c6f5a1df0c5218e81c5 /components/script | |
parent | 9b26dca141159ddc75266de9ef5a54f537450921 (diff) | |
download | servo-8882507ad06b598fb43d8542c67ad76daeda739c.tar.gz servo-8882507ad06b598fb43d8542c67ad76daeda739c.zip |
Rework “visible” to “throttled” in constellation + script + compositor (#31816)
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/document.rs | 2 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 10 | ||||
-rw-r--r-- | components/script/dom/window.rs | 20 | ||||
-rw-r--r-- | components/script/script_thread.rs | 43 |
4 files changed, 37 insertions, 38 deletions
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<DOMTokenList>, sandbox_allowance: Cell<Option<SandboxAllowance>>, load_blocker: DomRefCell<Option<LoadBlocker>>, - visibility: Cell<bool>, + throttled: Cell<bool>, } 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<bool>, + throttled: Cell<bool>, /// 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::<GlobalScope>().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::<GlobalScope>().slow_down_timers(); + } else { + self.upcast::<GlobalScope>().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<String> { @@ -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), }); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 79c63ac101c..2f5600cd932 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -206,8 +206,8 @@ struct InProgressLoad { /// The activity level of the document (inactive, active or fully active). #[no_trace] activity: DocumentActivity, - /// Window is visible. - is_visible: bool, + /// Window is throttled, running timers at a heavily limited rate. + throttled: bool, /// The requested URL of the load. #[no_trace] url: ServoUrl, @@ -250,7 +250,7 @@ impl InProgressLoad { opener, window_size, activity: DocumentActivity::FullyActive, - is_visible: true, + throttled: false, url, origin, navigation_start: navigation_start as u64, @@ -1832,8 +1832,8 @@ impl ScriptThread { SetScrollState(id, ..) => Some(id), GetTitle(id) => Some(id), SetDocumentActivity(id, ..) => Some(id), - ChangeFrameVisibilityStatus(id, ..) => Some(id), - NotifyVisibilityChange(id, ..) => Some(id), + SetThrottled(id, ..) => Some(id), + SetThrottledInContainingIframe(id, ..) => Some(id), NavigateIframe(id, ..) => Some(id), PostMessage { target: id, .. } => Some(id), UpdatePipelineId(_, _, _, id, _) => Some(id), @@ -1991,17 +1991,17 @@ impl ScriptThread { ConstellationControlMsg::SetDocumentActivity(pipeline_id, activity) => { self.handle_set_document_activity_msg(pipeline_id, activity) }, - ConstellationControlMsg::ChangeFrameVisibilityStatus(pipeline_id, visible) => { - self.handle_visibility_change_msg(pipeline_id, visible) + ConstellationControlMsg::SetThrottled(pipeline_id, throttled) => { + self.handle_set_throttled_msg(pipeline_id, throttled) }, - ConstellationControlMsg::NotifyVisibilityChange( + ConstellationControlMsg::SetThrottledInContainingIframe( parent_pipeline_id, browsing_context_id, - visible, - ) => self.handle_visibility_change_complete_msg( + throttled, + ) => self.handle_set_throttled_in_containing_iframe_msg( parent_pipeline_id, browsing_context_id, - visible, + throttled, ), ConstellationControlMsg::PostMessage { target: target_pipeline_id, @@ -2556,45 +2556,44 @@ impl ScriptThread { } /// Updates iframe element after a change in visibility - fn handle_visibility_change_complete_msg( + fn handle_set_throttled_in_containing_iframe_msg( &self, parent_pipeline_id: PipelineId, browsing_context_id: BrowsingContextId, - visible: bool, + throttled: bool, ) { let iframe = self .documents .borrow() .find_iframe(parent_pipeline_id, browsing_context_id); if let Some(iframe) = iframe { - iframe.change_visibility_status(visible); + iframe.set_throttled(throttled); } } - /// Handle visibility change message - fn handle_visibility_change_msg(&self, id: PipelineId, visible: bool) { + fn handle_set_throttled_msg(&self, id: PipelineId, throttled: bool) { // Separate message sent since parent script thread could be different (Iframe of different // domain) self.script_sender - .send((id, ScriptMsg::VisibilityChangeComplete(visible))) + .send((id, ScriptMsg::SetThrottledComplete(throttled))) .unwrap(); let window = self.documents.borrow().find_window(id); match window { Some(window) => { - window.alter_resource_utilization(visible); + window.set_throttled(throttled); return; }, None => { let mut loads = self.incomplete_loads.borrow_mut(); if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) { - load.is_visible = visible; + load.throttled = throttled; return; } }, } - warn!("change visibility message sent to nonexistent pipeline"); + warn!("SetThrottled sent to nonexistent pipeline"); } /// Handles activity change message @@ -3435,8 +3434,8 @@ impl ScriptThread { window.suspend(); } - if !incomplete.is_visible { - window.alter_resource_utilization(false); + if incomplete.throttled { + window.set_throttled(true); } document.get_current_parser().unwrap() |