diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 677bdbc9cc4..2d1852ab837 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -13,7 +13,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use base::Epoch; use base::cross_process_instant::CrossProcessInstant; -use base::generic_channel::GenericSender; +use base::generic_channel::{GenericSender, RoutedReceiver}; use base::id::{PipelineId, WebViewId}; use bitflags::bitflags; use compositing_traits::display_list::{CompositorDisplayListInfo, ScrollTree, ScrollType}; @@ -23,7 +23,7 @@ use compositing_traits::{ WebViewTrait, }; use constellation_traits::{EmbedderToConstellationMessage, PaintMetricEvent}; -use crossbeam_channel::{Receiver, Sender}; +use crossbeam_channel::Sender; use dpi::PhysicalSize; use embedder_traits::{CompositorHitTestResult, InputEvent, ShutdownState, ViewportDetails}; use euclid::{Point2D, Rect, Scale, Size2D, Transform3D}; @@ -93,7 +93,7 @@ pub struct ServoRenderer { shutdown_state: Rc>, /// The port on which we receive messages. - compositor_receiver: Receiver, + compositor_receiver: RoutedReceiver, /// The channel on which messages can be sent to the constellation. pub(crate) constellation_sender: Sender, @@ -1394,7 +1394,7 @@ impl IOCompositor { } /// Get the message receiver for this [`IOCompositor`]. - pub fn receiver(&self) -> Ref<'_, Receiver> { + pub fn receiver(&self) -> Ref<'_, RoutedReceiver> { Ref::map(self.global.borrow(), |global| &global.compositor_receiver) } diff --git a/components/compositing/lib.rs b/components/compositing/lib.rs index 4faeadf5ba6..bc4468425e8 100644 --- a/components/compositing/lib.rs +++ b/components/compositing/lib.rs @@ -7,10 +7,11 @@ use std::cell::Cell; use std::rc::Rc; +use base::generic_channel::RoutedReceiver; use compositing_traits::rendering_context::RenderingContext; use compositing_traits::{CompositorMsg, CompositorProxy}; use constellation_traits::EmbedderToConstellationMessage; -use crossbeam_channel::{Receiver, Sender}; +use crossbeam_channel::Sender; use embedder_traits::{EventLoopWaker, ShutdownState}; use profile_traits::{mem, time}; use webrender::RenderApi; @@ -32,7 +33,7 @@ pub struct InitialCompositorState { /// A channel to the compositor. pub sender: CompositorProxy, /// A port on which messages inbound to the compositor can be received. - pub receiver: Receiver, + pub receiver: RoutedReceiver, /// A channel to the constellation. pub constellation_chan: Sender, /// A channel to the time profiler thread. diff --git a/components/servo/lib.rs b/components/servo/lib.rs index f4dc9522600..60564068063 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -33,6 +33,7 @@ use std::rc::{Rc, Weak}; use std::sync::{Arc, Mutex}; use std::thread; +use base::generic_channel::RoutedReceiver; pub use base::id::WebViewId; use base::id::{PipelineNamespace, PipelineNamespaceId}; #[cfg(feature = "bluetooth")] @@ -544,7 +545,12 @@ impl Servo { let mut compositor = self.compositor.borrow_mut(); let mut messages = Vec::new(); while let Ok(message) = compositor.receiver().try_recv() { - messages.push(message); + match message { + Ok(message) => messages.push(message), + Err(error) => { + warn!("Router deserialization error: {error}. Ignoring this CompositorMsg.") + }, + } } compositor.handle_messages(messages); } @@ -1095,7 +1101,7 @@ fn create_embedder_channel( fn create_compositor_channel( event_loop_waker: Box, -) -> (CompositorProxy, Receiver) { +) -> (CompositorProxy, RoutedReceiver) { let (sender, receiver) = unbounded(); let (compositor_ipc_sender, compositor_ipc_receiver) = @@ -1112,7 +1118,7 @@ fn create_compositor_channel( ROUTER.add_typed_route( compositor_ipc_receiver, Box::new(move |message| { - compositor_proxy_clone.send(message.expect("Could not convert Compositor message")); + compositor_proxy_clone.route_msg(message); }), ); diff --git a/components/shared/compositing/lib.rs b/components/shared/compositing/lib.rs index 402d36c0885..f5fdb97b25c 100644 --- a/components/shared/compositing/lib.rs +++ b/components/shared/compositing/lib.rs @@ -45,7 +45,7 @@ use crate::viewport_description::ViewportDescription; /// Sends messages to the compositor. #[derive(Clone)] pub struct CompositorProxy { - pub sender: Sender, + pub sender: Sender>, /// Access to [`Self::sender`] that is possible to send across an IPC /// channel. These messages are routed via the router thread to /// [`Self::sender`]. @@ -61,6 +61,14 @@ impl OpaqueSender for CompositorProxy { impl CompositorProxy { pub fn send(&self, msg: CompositorMsg) { + self.route_msg(Ok(msg)) + } + + /// Helper method to route a deserialized IPC message to the receiver. + /// + /// This method is a temporary solution, and will be removed when migrating + /// to `GenericChannel`. + pub fn route_msg(&self, msg: Result) { if let Err(err) = self.sender.send(msg) { warn!("Failed to send response ({:?}).", err); }