From 33e934421e69aa8108c5f6f9872395378ab80486 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Wed, 27 Aug 2025 11:42:01 +0200 Subject: [PATCH] compositor: Hide IpcSender as implementation detail (#38963) The `CrossProcessCompositorApi` already provides methods for most messages. Remove the `sender()` method, and hide the IpcSender as an implementation detail. This is a preparation for abstracting over the internal IpcSender. Testing: No functional changes --------- Signed-off-by: Jonathan Schwender --- components/script/dom/htmlmetaelement.rs | 8 +----- components/script/script_thread.rs | 10 ++------ components/servo/lib.rs | 2 +- components/shared/compositing/lib.rs | 31 +++++++++++++++++++----- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 4ec6db7212c..e5b32c353e2 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -4,7 +4,6 @@ use std::str::FromStr; -use compositing_traits::CompositorMsg; use compositing_traits::viewport_description::ViewportDescription; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix, local_name, ns}; @@ -136,12 +135,7 @@ impl HTMLMetaElement { if let Ok(viewport) = ViewportDescription::from_str(&content.value()) { self.owner_window() .compositor_api() - .sender() - .send(CompositorMsg::Viewport( - self.owner_window().webview_id(), - viewport, - )) - .unwrap(); + .viewport(self.owner_window().webview_id(), viewport); } } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 89c2f35b1c9..7d80f8d4df4 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -36,7 +36,7 @@ use base::cross_process_instant::CrossProcessInstant; use base::id::{BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, WebViewId}; use canvas_traits::webgl::WebGLPipeline; use chrono::{DateTime, Local}; -use compositing_traits::{CompositorMsg, CrossProcessCompositorApi, PipelineExitSource}; +use compositing_traits::{CrossProcessCompositorApi, PipelineExitSource}; use constellation_traits::{ JsEvalResult, LoadData, LoadOrigin, NavigationHistoryBehavior, ScriptToConstellationChan, ScriptToConstellationMessage, StructuredSerializedData, WindowSizeType, @@ -2956,13 +2956,7 @@ impl ScriptThread { .ok(); self.compositor_api - .sender() - .send(CompositorMsg::PipelineExited( - webview_id, - id, - PipelineExitSource::Script, - )) - .ok(); + .pipeline_exited(webview_id, id, PipelineExitSource::Script); debug!("{id}: Finished pipeline exit"); } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 075493d79b0..f4dc9522600 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -1101,7 +1101,7 @@ fn create_compositor_channel( let (compositor_ipc_sender, compositor_ipc_receiver) = ipc::channel().expect("ipc channel failure"); - let cross_process_compositor_api = CrossProcessCompositorApi(compositor_ipc_sender); + let cross_process_compositor_api = CrossProcessCompositorApi::new(compositor_ipc_sender); let compositor_proxy = CompositorProxy { sender, cross_process_compositor_api, diff --git a/components/shared/compositing/lib.rs b/components/shared/compositing/lib.rs index 9435c9d0581..402d36c0885 100644 --- a/components/shared/compositing/lib.rs +++ b/components/shared/compositing/lib.rs @@ -174,9 +174,14 @@ pub struct CompositionPipeline { /// A mechanism to send messages from ScriptThread to the parent process' WebRender instance. #[derive(Clone, Deserialize, MallocSizeOf, Serialize)] -pub struct CrossProcessCompositorApi(pub IpcSender); +pub struct CrossProcessCompositorApi(IpcSender); impl CrossProcessCompositorApi { + /// Create a new [`CrossProcessCompositorApi`] struct. + pub fn new(sender: IpcSender) -> Self { + CrossProcessCompositorApi(sender) + } + /// Create a new [`CrossProcessCompositorApi`] struct that does not have a listener on the other /// end to use for unit testing. pub fn dummy() -> Self { @@ -184,11 +189,6 @@ impl CrossProcessCompositorApi { Self(sender) } - /// Get the sender for this proxy. - pub fn sender(&self) -> &IpcSender { - &self.0 - } - /// Inform WebRender of the existence of this pipeline. pub fn send_initial_transaction(&self, pipeline: WebRenderPipelineId) { if let Err(e) = self.0.send(CompositorMsg::SendInitialTransaction(pipeline)) { @@ -352,6 +352,25 @@ impl CrossProcessCompositorApi { )); receiver.recv().unwrap() } + + pub fn viewport(&self, webview_id: WebViewId, description: ViewportDescription) { + let _ = self + .0 + .send(CompositorMsg::Viewport(webview_id, description)); + } + + pub fn pipeline_exited( + &self, + webview_id: WebViewId, + pipeline_id: PipelineId, + source: PipelineExitSource, + ) { + let _ = self.0.send(CompositorMsg::PipelineExited( + webview_id, + pipeline_id, + source, + )); + } } /// This trait is used as a bridge between the different GL clients