From e65f65a943e4bd0bd02e6e7e2166e84ad51f9659 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Mon, 17 Jul 2023 11:33:24 +0200 Subject: [PATCH] Stop using webrender_api::get_scroll_node_state (#30000) This API has been removed in the latest version of WebRender and we can simply get this information from the compositor-side scroll tree. In addition, this change limits the amount of data sent to the pipeline that actually changed and gives the function in the compositor a better name. Signed-off-by: Martin Robinson --- components/compositing/compositor.rs | 50 +++++++++++++--------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index ce6b2bdd4d7..e7ec426d263 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -487,7 +487,7 @@ impl IOCompositor { (Msg::SetFrameTree(frame_tree), ShutdownState::NotShuttingDown) => { self.set_frame_tree(&frame_tree); - self.send_viewport_rects(); + self.send_scroll_positions_to_layout_for_pipeline(&frame_tree.pipeline.id); }, (Msg::Recomposite(reason), ShutdownState::NotShuttingDown) => { @@ -1208,8 +1208,6 @@ impl IOCompositor { } fn process_pending_scroll_events(&mut self) { - let had_events = self.pending_scroll_zoom_events.len() > 0; - // Batch up all scroll events into one, or else we'll do way too much painting. let mut last_combined_event: Option = None; for scroll_event in self.pending_scroll_zoom_events.drain(..) { @@ -1290,6 +1288,7 @@ impl IOCompositor { None => {}, } } + self.send_scroll_positions_to_layout_for_pipeline(&result.pipeline_id); if combined_event.magnification != 1.0 { let old_zoom = self.pinch_zoom_level(); @@ -1301,10 +1300,6 @@ impl IOCompositor { .send_transaction(self.webrender_document, txn); self.waiting_for_results_of_scroll = true } - - if had_events { - self.send_viewport_rects(); - } } /// If there are any animations running, dispatches appropriate messages to the constellation. @@ -1404,28 +1399,29 @@ impl IOCompositor { }); } - fn send_viewport_rects(&self) { - let mut scroll_states_per_pipeline = HashMap::new(); - for scroll_layer_state in self - .webrender_api - .get_scroll_node_state(self.webrender_document) - { - let scroll_state = ScrollState { - scroll_id: scroll_layer_state.id, - scroll_offset: scroll_layer_state.scroll_offset, - }; + fn send_scroll_positions_to_layout_for_pipeline(&self, pipeline_id: &PipelineId) { + let details = match self.pipeline_details.get(&pipeline_id) { + Some(details) => details, + None => return, + }; - scroll_states_per_pipeline - .entry(scroll_layer_state.id.pipeline_id()) - .or_insert(vec![]) - .push(scroll_state); - } - - for (pipeline_id, scroll_states) in scroll_states_per_pipeline { - if let Some(pipeline) = self.pipeline(pipeline_id.from_webrender()) { - let msg = LayoutControlMsg::SetScrollStates(scroll_states); - let _ = pipeline.layout_chan.send(msg); + let mut scroll_states = Vec::new(); + details.scroll_tree.nodes.iter().for_each(|node| { + match (node.external_id(), node.offset()) { + (Some(scroll_id), Some(scroll_offset)) => { + scroll_states.push(ScrollState { + scroll_id, + scroll_offset, + }); + }, + _ => {}, } + }); + + if let Some(pipeline) = details.pipeline.as_ref() { + let _ = pipeline + .layout_chan + .send(LayoutControlMsg::SetScrollStates(scroll_states)); } }