compositor: Create a single cross-process compositor API (#33619) (#33660)

Instead of exposing many different kinds of messages to the compositor
that are routed through the constellation, expose a single message type
which can be sent across IPC channels. In addition, this IPC channel and
the route to the crossbeam channel with the compositor is created along
with the `CompositorProxy`, simplifying what needs to be passed around
during pipeline initialization.

Previously, some image updates (from video) were sent over IPC with a
special serialization routine and some were sent via crossbeam channels
(canvas). Now all updates go over the IPC channel `IpcSharedMemory` is
used to avoid serialization penalties. This should improve performance
and reduce copies for video, but add a memory copy overhead for canvas.
This will improve in the future when canvas renders directly into a
texture.

All-in-all this is a simplification which opens the path toward having a
standard compositor API and reduces the number of duplicate messages and
proxying that had to happen in libservo.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-10-09 10:30:24 -07:00 committed by GitHub
parent 30cbf01280
commit 9195344b75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 547 additions and 800 deletions

View file

@ -108,8 +108,7 @@ use canvas_traits::canvas::{CanvasId, CanvasMsg};
use canvas_traits::webgl::WebGLThreads;
use canvas_traits::ConstellationCanvasMsg;
use compositing_traits::{
CompositorMsg, CompositorProxy, ConstellationMsg as FromCompositorMsg,
ForwardedToCompositorMsg, SendableFrameTree,
CompositorMsg, CompositorProxy, ConstellationMsg as FromCompositorMsg, SendableFrameTree,
};
use crossbeam_channel::{after, never, select, unbounded, Receiver, Sender};
use devtools_traits::{
@ -157,7 +156,7 @@ use webgpu::swapchain::WGPUImageMap;
use webgpu::{self, WebGPU, WebGPURequest, WebGPUResponse};
use webrender::{RenderApi, RenderApiSender};
use webrender_api::DocumentId;
use webrender_traits::{WebRenderNetApi, WebRenderScriptApi, WebrenderExternalImageRegistry};
use webrender_traits::WebrenderExternalImageRegistry;
use crate::browsingcontext::{
AllBrowsingContextsIterator, BrowsingContext, FullyActiveBrowsingContextsIterator,
@ -392,14 +391,6 @@ pub struct Constellation<STF, SWF> {
/// Webrender related objects required by WebGPU threads
webrender_wgpu: WebrenderWGPU,
/// A channel for content processes to send messages that will
/// be relayed to the WebRender thread.
webrender_api_ipc_sender: WebRenderScriptApi,
/// A channel for content process image caches to send messages
/// that will be relayed to the WebRender thread.
webrender_image_api_sender: WebRenderNetApi,
/// A map of message-port Id to info.
message_ports: HashMap<MessagePortId, MessagePortInfo>,
@ -506,7 +497,7 @@ pub struct InitialConstellationState {
/// A channel through which messages can be sent to the embedder.
pub embedder_proxy: EmbedderProxy,
/// A channel through which messages can be sent to the compositor.
/// A channel through which messages can be sent to the compositor in-process.
pub compositor_proxy: CompositorProxy,
/// A channel to the developer tools, if applicable.
@ -705,35 +696,6 @@ where
// Zero is reserved for the embedder.
PipelineNamespace::install(PipelineNamespaceId(1));
let (webrender_ipc_sender, webrender_ipc_receiver) =
ipc::channel().expect("ipc channel failure");
let (webrender_image_ipc_sender, webrender_image_ipc_receiver) =
ipc::channel().expect("ipc channel failure");
let compositor_proxy = state.compositor_proxy.clone();
ROUTER.add_route(
webrender_ipc_receiver.to_opaque(),
Box::new(move |message| {
compositor_proxy.send(CompositorMsg::Forwarded(
ForwardedToCompositorMsg::Layout(
message.to().expect("conversion failure"),
),
));
}),
);
let compositor_proxy = state.compositor_proxy.clone();
ROUTER.add_route(
webrender_image_ipc_receiver.to_opaque(),
Box::new(move |message| {
compositor_proxy.send(CompositorMsg::Forwarded(
ForwardedToCompositorMsg::Net(
message.to().expect("conversion failure"),
),
));
}),
);
let webrender_wgpu = WebrenderWGPU {
webrender_api: state.webrender_api_sender.create_api(),
webrender_external_images: state.webrender_external_images,
@ -788,8 +750,6 @@ where
scheduler_receiver,
document_states: HashMap::new(),
webrender_document: state.webrender_document,
webrender_api_ipc_sender: WebRenderScriptApi::new(webrender_ipc_sender),
webrender_image_api_sender: WebRenderNetApi::new(webrender_image_ipc_sender),
webrender_wgpu,
shutting_down: false,
handled_warnings: VecDeque::new(),
@ -1053,8 +1013,6 @@ where
event_loop,
load_data,
prev_throttled: throttled,
webrender_api_sender: self.webrender_api_ipc_sender.clone(),
webrender_image_api_sender: self.webrender_image_api_sender.clone(),
webrender_document: self.webrender_document,
webgl_chan: self
.webgl_threads
@ -1751,18 +1709,6 @@ where
response_sender.send(true).unwrap_or_default();
},
FromScriptMsg::GetClientWindow(response_sender) => {
self.compositor_proxy
.send(CompositorMsg::GetClientWindow(response_sender));
},
FromScriptMsg::GetScreenSize(response_sender) => {
self.compositor_proxy
.send(CompositorMsg::GetScreenSize(response_sender));
},
FromScriptMsg::GetScreenAvailSize(response_sender) => {
self.compositor_proxy
.send(CompositorMsg::GetScreenAvailSize(response_sender));
},
FromScriptMsg::LogEntry(thread_name, entry) => {
self.handle_log_entry(Some(source_top_ctx_id), thread_name, entry);
},

View file

@ -43,6 +43,7 @@ use servo_config::prefs;
use servo_config::prefs::PrefValue;
use servo_url::ServoUrl;
use webrender_api::DocumentId;
use webrender_traits::CrossProcessCompositorApi;
use crate::event_loop::EventLoop;
use crate::sandboxing::{spawn_multiprocess, UnprivilegedContent};
@ -183,12 +184,6 @@ pub struct InitialPipelineState {
/// compositor threads after spawning a pipeline.
pub prev_throttled: bool,
/// Webrender api.
pub webrender_image_api_sender: webrender_traits::WebRenderNetApi,
/// Webrender api.
pub webrender_api_sender: webrender_traits::WebRenderScriptApi,
/// The ID of the document processed by this script thread.
pub webrender_document: DocumentId,
@ -293,9 +288,11 @@ impl Pipeline {
opts: (*opts::get()).clone(),
prefs: prefs::pref_map().iter().collect(),
pipeline_namespace_id: state.pipeline_namespace_id,
webrender_api_sender: state.webrender_api_sender,
webrender_image_api_sender: state.webrender_image_api_sender,
webrender_document: state.webrender_document,
cross_process_compositor_api: state
.compositor_proxy
.cross_process_compositor_api
.clone(),
webgl_chan: state.webgl_chan,
webxr_registry: state.webxr_registry,
player_context: state.player_context,
@ -498,8 +495,7 @@ pub struct UnprivilegedPipelineContent {
opts: Opts,
prefs: HashMap<String, PrefValue>,
pipeline_namespace_id: PipelineNamespaceId,
webrender_api_sender: webrender_traits::WebRenderScriptApi,
webrender_image_api_sender: webrender_traits::WebRenderNetApi,
cross_process_compositor_api: CrossProcessCompositorApi,
webrender_document: DocumentId,
webgl_chan: Option<WebGLPipeline>,
webxr_registry: webxr_api::Registry,
@ -518,7 +514,9 @@ impl UnprivilegedPipelineContent {
// Idempotent in single-process mode.
PipelineNamespace::set_installer_sender(self.namespace_request_sender);
let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_image_api_sender.clone()));
let image_cache = Arc::new(ImageCacheImpl::new(
self.cross_process_compositor_api.clone(),
));
let (content_process_shutdown_chan, content_process_shutdown_port) = unbounded();
STF::create(
InitialScriptState {
@ -545,7 +543,7 @@ impl UnprivilegedPipelineContent {
webgl_chan: self.webgl_chan,
webxr_registry: self.webxr_registry,
webrender_document: self.webrender_document,
webrender_api_sender: self.webrender_api_sender.clone(),
compositor_api: self.cross_process_compositor_api.clone(),
player_context: self.player_context.clone(),
inherited_secure_context: self.load_data.inherited_secure_context,
},

View file

@ -181,9 +181,6 @@ mod from_script {
Self::PipelineExited => target!("PipelineExited"),
Self::ForwardDOMMessage(..) => target!("ForwardDOMMessage"),
Self::ScheduleJob(..) => target!("ScheduleJob"),
Self::GetClientWindow(..) => target!("GetClientWindow"),
Self::GetScreenSize(..) => target!("GetScreenSize"),
Self::GetScreenAvailSize(..) => target!("GetScreenAvailSize"),
Self::MediaSessionEvent(..) => target!("MediaSessionEvent"),
Self::RequestAdapter(..) => target!("RequestAdapter"),
Self::GetWebGPUChan(..) => target!("GetWebGPUChan"),