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

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-03 16:42:04 +02:00 committed by GitHub
parent 986c3a38a3
commit f2f5614ad6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 547 additions and 801 deletions

View file

@ -16,8 +16,7 @@ use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use log::warn;
use net_traits::ResourceThreads;
use webrender_api::ImageKey;
use webrender_traits::{ImageUpdate, WebRenderScriptApi};
use webrender_traits::CrossProcessCompositorApi;
use crate::canvas_data::*;
@ -26,36 +25,26 @@ pub enum AntialiasMode {
None,
}
pub trait WebrenderApi {
/// Attempt to generate an [`ImageKey`], returning `None` in case of failure.
fn generate_key(&self) -> Option<ImageKey>;
fn update_images(&self, updates: Vec<ImageUpdate>);
fn clone(&self) -> Box<dyn WebrenderApi>;
}
pub struct CanvasPaintThread<'a> {
canvases: HashMap<CanvasId, CanvasData<'a>>,
next_canvas_id: CanvasId,
webrender_api: Box<dyn WebrenderApi>,
compositor_api: CrossProcessCompositorApi,
font_context: Arc<FontContext>,
}
impl<'a> CanvasPaintThread<'a> {
fn new(
webrender_api: Box<dyn WebrenderApi>,
compositor_api: CrossProcessCompositorApi,
system_font_service: Arc<SystemFontServiceProxy>,
resource_threads: ResourceThreads,
) -> CanvasPaintThread<'a> {
// This is only used for web fonts and currently canvas never uses web fonts.
let webrender_script_api = WebRenderScriptApi::dummy();
CanvasPaintThread {
canvases: HashMap::new(),
next_canvas_id: CanvasId(0),
webrender_api,
compositor_api: compositor_api.clone(),
font_context: Arc::new(FontContext::new(
system_font_service,
webrender_script_api,
compositor_api,
resource_threads,
)),
}
@ -64,7 +53,7 @@ impl<'a> CanvasPaintThread<'a> {
/// Creates a new `CanvasPaintThread` and returns an `IpcSender` to
/// communicate with it.
pub fn start(
webrender_api: Box<dyn WebrenderApi + Send>,
compositor_api: CrossProcessCompositorApi,
system_font_service: Arc<SystemFontServiceProxy>,
resource_threads: ResourceThreads,
) -> (Sender<ConstellationCanvasMsg>, IpcSender<CanvasMsg>) {
@ -75,7 +64,7 @@ impl<'a> CanvasPaintThread<'a> {
.name("Canvas".to_owned())
.spawn(move || {
let mut canvas_paint_thread = CanvasPaintThread::new(
webrender_api, system_font_service, resource_threads);
compositor_api, system_font_service, resource_threads);
loop {
select! {
recv(msg_receiver) -> msg => {
@ -141,7 +130,7 @@ impl<'a> CanvasPaintThread<'a> {
let canvas_data = CanvasData::new(
size,
self.webrender_api.clone(),
self.compositor_api.clone(),
antialias,
self.font_context.clone(),
);