Skip to content

Commit

Permalink
Update scroll tree offsets in SetScrollStates
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson committed Mar 6, 2024
1 parent 8f0e41f commit 6e5dbc7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 19 deletions.
34 changes: 25 additions & 9 deletions components/compositing/compositor.rs
Expand Up @@ -698,27 +698,46 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
) => {
let mut txn = Transaction::new();
txn.set_display_list(WebRenderEpoch(0), (pipeline, Default::default()));
debug!("INITIAL");
self.generate_frame(&mut txn, RenderReasons::APZ);
self.generate_frame(&mut txn, RenderReasons::SCENE);
self.webrender_api
.send_transaction(self.webrender_document, txn);
self.webrender_api.flush_scene_builder();
},

ForwardedToCompositorMsg::Layout(
script_traits::ScriptToCompositorMsg::SendScrollNode(point, scroll_id),
script_traits::ScriptToCompositorMsg::SendScrollNode(
pipeline_id,
point,
external_scroll_id,
),
) => {
let pipeline_id = PipelineId::from_webrender(pipeline_id);
let pipeline_details = match self.pipeline_details.get_mut(&pipeline_id) {
Some(details) => details,
None => return,
};

let offset = LayoutVector2D::new(point.x, point.y);
if !pipeline_details
.scroll_tree
.set_scroll_offsets_for_node_with_external_scroll_id(
external_scroll_id,
-offset,
)
{
warn!("Could not scroll not with id: {external_scroll_id:?}");
return;
}

let mut txn = Transaction::new();
let offset = point.to_vector();
self.webrender_api.flush_scene_builder();
txn.set_scroll_offsets(
scroll_id,
external_scroll_id,
vec![SampledScrollOffset {
offset,
generation: 0,
}],
);
debug!("OFFSETS");
self.generate_frame(&mut txn, RenderReasons::APZ);
self.webrender_api
.send_transaction(self.webrender_document, txn);
Expand Down Expand Up @@ -787,7 +806,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
);
}
}
debug!("DISPLAY LIST");
self.generate_frame(&mut transaction, RenderReasons::SCENE);
self.webrender_api
.send_transaction(self.webrender_document, transaction);
Expand Down Expand Up @@ -1477,7 +1495,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.send_scroll_positions_to_layout_for_pipeline(&pipeline_id);
}

debug!("SCROLL ZOOM");
self.generate_frame(&mut transaction, RenderReasons::APZ);
self.webrender_api
.send_transaction(self.webrender_document, transaction);
Expand Down Expand Up @@ -2155,7 +2172,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.webrender.set_debug_flags(flags);

let mut txn = Transaction::new();
debug!("TESTING");
self.generate_frame(&mut txn, RenderReasons::TESTING);
self.webrender_api
.send_transaction(self.webrender_document, txn);
Expand Down
7 changes: 5 additions & 2 deletions components/layout_thread/lib.rs
Expand Up @@ -1317,8 +1317,11 @@ impl LayoutThread {
.insert(state.scroll_id, state.scroll_offset);

let point = Point2D::new(-state.scroll_offset.x, -state.scroll_offset.y);
self.webrender_api
.send_scroll_node(units::LayoutPoint::from_untyped(point), state.scroll_id);
self.webrender_api.send_scroll_node(
self.id.to_webrender(),
units::LayoutPoint::from_untyped(point),
state.scroll_id,
);
}

fn set_scroll_states<'a, 'b>(
Expand Down
7 changes: 5 additions & 2 deletions components/layout_thread_2020/lib.rs
Expand Up @@ -984,8 +984,11 @@ impl LayoutThread {
.insert(state.scroll_id, state.scroll_offset);

let point = Point2D::new(-state.scroll_offset.x, -state.scroll_offset.y);
self.webrender_api
.send_scroll_node(units::LayoutPoint::from_untyped(point), state.scroll_id);
self.webrender_api.send_scroll_node(
self.id.to_webrender(),
units::LayoutPoint::from_untyped(point),
state.scroll_id,
);
}

fn set_scroll_states<'a, 'b>(
Expand Down
19 changes: 19 additions & 0 deletions components/shared/script/compositor.rs
Expand Up @@ -216,6 +216,25 @@ impl ScrollTree {

parent.and_then(|parent| self.scroll_node_or_ancestor(&parent, scroll_location))
}

/// Given an [`ExternalScrollId`] and an offset, update the scroll offset of the scroll node
/// with the given id.
pub fn set_scroll_offsets_for_node_with_external_scroll_id(
&mut self,
external_scroll_id: ExternalScrollId,
offset: LayoutVector2D,
) -> bool {
for node in self.nodes.iter_mut() {
match node.scroll_info {
Some(ref mut scroll_info) if scroll_info.external_id == external_scroll_id => {
scroll_info.offset = offset;
return true;
},
_ => {},
}
}
false
}
}

/// A data structure which stores compositor-side information about
Expand Down
18 changes: 12 additions & 6 deletions components/shared/script/lib.rs
Expand Up @@ -1121,7 +1121,7 @@ pub enum ScriptToCompositorMsg {
/// Inform WebRender of the existence of this pipeline.
SendInitialTransaction(WebRenderPipelineId),
/// Perform a scroll operation.
SendScrollNode(LayoutPoint, ExternalScrollId),
SendScrollNode(WebRenderPipelineId, LayoutPoint, ExternalScrollId),
/// Inform WebRender of a new display list for the given pipeline.
SendDisplayList {
/// The [CompositorDisplayListInfo] that describes the display list being sent.
Expand Down Expand Up @@ -1167,11 +1167,17 @@ impl WebrenderIpcSender {
}

/// Perform a scroll operation.
pub fn send_scroll_node(&self, point: LayoutPoint, scroll_id: ExternalScrollId) {
if let Err(e) = self
.0
.send(ScriptToCompositorMsg::SendScrollNode(point, scroll_id))
{
pub fn send_scroll_node(
&self,
pipeline_id: WebRenderPipelineId,
point: LayoutPoint,
scroll_id: ExternalScrollId,
) {
if let Err(e) = self.0.send(ScriptToCompositorMsg::SendScrollNode(
pipeline_id,
point,
scroll_id,
)) {
warn!("Error sending scroll node: {}", e);
}
}
Expand Down

0 comments on commit 6e5dbc7

Please sign in to comment.