compositor: Make PipelineDetails and pending paint metrics per-WebView (#35701)

This is one of the first big steps toward making the compositor work
per-WebView. It moves the collection of pipelines into the per-WebView
data structure in the compositor as well as the pending paint metrics.

This means that more messages need to carry information about the
WebView they apply to. Note that there are still a few places that we
need to map from `PipelineId` to `WebViewId`, so this also includes a
shared mapping which tracks this. The mapping can be removed once event
handling is fully per-WebView.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
Martin Robinson 2025-03-04 03:31:23 +01:00 committed by GitHub
parent 0d0bcdeb4d
commit f3e6e4f04e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 537 additions and 373 deletions

View file

@ -9,7 +9,7 @@ mod constellation_msg;
use std::fmt::{Debug, Error, Formatter};
use base::Epoch;
use base::id::{PipelineId, TopLevelBrowsingContextId};
use base::id::{PipelineId, TopLevelBrowsingContextId, WebViewId};
pub use constellation_msg::ConstellationMsg;
use crossbeam_channel::{Receiver, Sender};
use embedder_traits::{EventLoopWaker, MouseButton, MouseButtonAction};
@ -59,7 +59,7 @@ impl CompositorReceiver {
/// Messages from (or via) the constellation thread to the compositor.
pub enum CompositorMsg {
/// Alerts the compositor that the given pipeline has changed whether it is running animations.
ChangeRunningAnimationsState(PipelineId, AnimationState),
ChangeRunningAnimationsState(WebViewId, PipelineId, AnimationState),
/// Create or update a webview, given its frame tree.
CreateOrUpdateWebView(SendableFrameTree),
/// Remove a webview.
@ -71,7 +71,7 @@ pub enum CompositorMsg {
/// A reply to the compositor asking if the output image is stable.
IsReadyToSaveImageReply(bool),
/// Set whether to use less resources by stopping animations.
SetThrottled(PipelineId, bool),
SetThrottled(WebViewId, PipelineId, bool),
/// WebRender has produced a new frame. This message informs the compositor that
/// the frame is ready. It contains a bool to indicate if it needs to composite and the
/// `DocumentId` of the new frame.
@ -81,11 +81,11 @@ pub enum CompositorMsg {
// when it shuts down a pipeline, to the compositor; when the compositor
// sends a reply on the IpcSender, the constellation knows it's safe to
// tear down the other threads associated with this pipeline.
PipelineExited(PipelineId, IpcSender<()>),
PipelineExited(WebViewId, PipelineId, IpcSender<()>),
/// Indicates to the compositor that it needs to record the time when the frame with
/// the given ID (epoch) is painted and report it to the layout of the given
/// pipeline ID.
PendingPaintMetric(PipelineId, Epoch),
/// WebViewId and PipelienId.
PendingPaintMetric(WebViewId, PipelineId, Epoch),
/// The load of a page has completed
LoadComplete(TopLevelBrowsingContextId),
/// WebDriver mouse button event
@ -114,7 +114,7 @@ pub struct CompositionPipeline {
impl Debug for CompositorMsg {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match *self {
CompositorMsg::ChangeRunningAnimationsState(_, state) => {
CompositorMsg::ChangeRunningAnimationsState(_, _, state) => {
write!(f, "ChangeRunningAnimationsState({:?})", state)
},
CompositorMsg::CreateOrUpdateWebView(..) => write!(f, "CreateOrUpdateWebView"),

View file

@ -9,7 +9,7 @@ use base::Epoch;
use base::id::{
BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId,
MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId,
TopLevelBrowsingContextId,
TopLevelBrowsingContextId, WebViewId,
};
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
@ -49,7 +49,7 @@ pub struct IFrameSizeMsg {
pub enum LayoutMsg {
/// Requests that the constellation inform the compositor that it needs to record
/// the time when the frame with the given ID (epoch) is painted.
PendingPaintMetric(PipelineId, Epoch),
PendingPaintMetric(WebViewId, PipelineId, Epoch),
}
impl fmt::Debug for LayoutMsg {

View file

@ -11,7 +11,7 @@ use core::fmt;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use base::id::PipelineId;
use base::id::{PipelineId, WebViewId};
use display_list::{CompositorDisplayListInfo, ScrollTreeNodeId};
use embedder_traits::Cursor;
use euclid::default::Size2D as UntypedSize2D;
@ -33,9 +33,16 @@ pub enum CrossProcessCompositorMessage {
/// Inform WebRender of the existence of this pipeline.
SendInitialTransaction(WebRenderPipelineId),
/// Perform a scroll operation.
SendScrollNode(WebRenderPipelineId, LayoutPoint, ExternalScrollId),
SendScrollNode(
WebViewId,
WebRenderPipelineId,
LayoutPoint,
ExternalScrollId,
),
/// Inform WebRender of a new display list for the given pipeline.
SendDisplayList {
/// The [`WebViewId`] that this display list belongs to.
webview_id: WebViewId,
/// The [CompositorDisplayListInfo] that describes the display list being sent.
display_list_info: Box<CompositorDisplayListInfo>,
/// A descriptor of this display list used to construct this display list from raw data.
@ -138,11 +145,13 @@ impl CrossProcessCompositorApi {
/// Perform a scroll operation.
pub fn send_scroll_node(
&self,
webview_id: WebViewId,
pipeline_id: WebRenderPipelineId,
point: LayoutPoint,
scroll_id: ExternalScrollId,
) {
if let Err(e) = self.0.send(CrossProcessCompositorMessage::SendScrollNode(
webview_id,
pipeline_id,
point,
scroll_id,
@ -154,12 +163,14 @@ impl CrossProcessCompositorApi {
/// Inform WebRender of a new display list for the given pipeline.
pub fn send_display_list(
&self,
webview_id: WebViewId,
display_list_info: CompositorDisplayListInfo,
list: BuiltDisplayList,
) {
let (display_list_data, display_list_descriptor) = list.into_data();
let (display_list_sender, display_list_receiver) = ipc::bytes_channel().unwrap();
if let Err(e) = self.0.send(CrossProcessCompositorMessage::SendDisplayList {
webview_id,
display_list_info: Box::new(display_list_info),
display_list_descriptor,
display_list_receiver,