From 3b41a16fcf018f6a13fbc0cfa3b165b8d331c914 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Wed, 9 Apr 2025 16:19:33 +0200 Subject: [PATCH] libservo: Move `EventLooperWaker` from `webxr_traits` to `embedder_traits` (#36420) Now that `webxr` is integrated into the Servo directory, `webxr` can depend on `embedder_traits` instead of having it re-export this type conditionally (and sometimes duplicating it). Testing: This just moves a data type, so no tests are necessary. Signed-off-by: Martin Robinson Signed-off-by: Martin Robinson --- Cargo.lock | 2 +- components/servo/Cargo.toml | 1 - components/shared/embedder/Cargo.toml | 4 ---- components/shared/embedder/lib.rs | 7 +------ components/shared/webxr/Cargo.toml | 1 + components/shared/webxr/lib.rs | 2 +- components/shared/webxr/registry.rs | 20 +++++--------------- 7 files changed, 9 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index deb8ae4a8bb..30d3be0bf8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1949,7 +1949,6 @@ dependencies = [ "url", "webdriver", "webrender_api", - "webxr-api", ] [[package]] @@ -8699,6 +8698,7 @@ dependencies = [ name = "webxr-api" version = "0.0.1" dependencies = [ + "embedder_traits", "euclid", "ipc-channel", "log", diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 37468593ef0..a91ad813ecd 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -46,7 +46,6 @@ webxr = [ "dep:webxr", "dep:webxr-api", "compositing/webxr", - "embedder_traits/webxr", "canvas/webxr", "script/webxr", ] diff --git a/components/shared/embedder/Cargo.toml b/components/shared/embedder/Cargo.toml index 66c8d179a46..1dfe363a93b 100644 --- a/components/shared/embedder/Cargo.toml +++ b/components/shared/embedder/Cargo.toml @@ -11,9 +11,6 @@ rust-version.workspace = true name = "embedder_traits" path = "lib.rs" -[features] -webxr = ["dep:webxr-api"] - [dependencies] base = { workspace = true } cfg-if = { workspace = true } @@ -37,4 +34,3 @@ stylo_traits = { workspace = true } url = { workspace = true } webdriver = { workspace = true } webrender_api = { workspace = true } -webxr-api = { workspace = true, features = ["ipc"], optional = true } diff --git a/components/shared/embedder/lib.rs b/components/shared/embedder/lib.rs index 529ae465567..11952f60cb6 100644 --- a/components/shared/embedder/lib.rs +++ b/components/shared/embedder/lib.rs @@ -90,21 +90,16 @@ pub enum Cursor { ZoomOut, } -#[cfg(feature = "webxr")] -pub use webxr_api::MainThreadWaker as EventLoopWaker; -#[cfg(not(feature = "webxr"))] pub trait EventLoopWaker: 'static + Send { fn clone_box(&self) -> Box; fn wake(&self); } -#[cfg(not(feature = "webxr"))] impl Clone for Box { fn clone(&self) -> Self { - EventLoopWaker::clone_box(self.as_ref()) + self.clone_box() } } - /// Sends messages to the embedder. pub struct EmbedderProxy { pub sender: Sender, diff --git a/components/shared/webxr/Cargo.toml b/components/shared/webxr/Cargo.toml index d9a80f84a25..3ba1d112f96 100644 --- a/components/shared/webxr/Cargo.toml +++ b/components/shared/webxr/Cargo.toml @@ -19,6 +19,7 @@ path = "lib.rs" ipc = ["serde", "ipc-channel", "euclid/serde"] [dependencies] +embedder_traits = { workspace = true } euclid = { workspace = true } ipc-channel = { workspace = true, optional = true } log = { workspace = true } diff --git a/components/shared/webxr/lib.rs b/components/shared/webxr/lib.rs index a539fd55457..ff10fc33656 100644 --- a/components/shared/webxr/lib.rs +++ b/components/shared/webxr/lib.rs @@ -50,7 +50,7 @@ pub use mock::{ MockButton, MockButtonType, MockDeviceInit, MockDeviceMsg, MockDiscoveryAPI, MockInputInit, MockInputMsg, MockRegion, MockViewInit, MockViewsInit, MockWorld, }; -pub use registry::{MainThreadRegistry, MainThreadWaker, Registry}; +pub use registry::{MainThreadRegistry, Registry}; pub use session::{ EnvironmentBlendMode, MainThreadSession, Quitter, Session, SessionBuilder, SessionId, SessionInit, SessionMode, SessionThread, diff --git a/components/shared/webxr/registry.rs b/components/shared/webxr/registry.rs index fc894b62fd6..89ab6c1e2e6 100644 --- a/components/shared/webxr/registry.rs +++ b/components/shared/webxr/registry.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use embedder_traits::EventLoopWaker; use log::warn; #[cfg(feature = "ipc")] use serde::{Deserialize, Serialize}; @@ -30,29 +31,18 @@ pub struct MainThreadRegistry { next_session_id: u32, } -pub trait MainThreadWaker: 'static + Send { - fn clone_box(&self) -> Box; - fn wake(&self); -} - -impl Clone for Box { - fn clone(&self) -> Self { - self.clone_box() - } -} - #[derive(Clone)] #[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))] struct MainThreadWakerImpl { #[cfg(feature = "ipc")] sender: WebXrSender<()>, #[cfg(not(feature = "ipc"))] - waker: Box, + waker: Box, } #[cfg(feature = "ipc")] impl MainThreadWakerImpl { - fn new(waker: Box) -> Result { + fn new(waker: Box) -> Result { let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?; ipc_channel::router::ROUTER.add_typed_route(receiver, Box::new(move |_| waker.wake())); Ok(MainThreadWakerImpl { sender }) @@ -65,7 +55,7 @@ impl MainThreadWakerImpl { #[cfg(not(feature = "ipc"))] impl MainThreadWakerImpl { - fn new(waker: Box) -> Result { + fn new(waker: Box) -> Result { Ok(MainThreadWakerImpl { waker }) } @@ -110,7 +100,7 @@ impl Registry { impl MainThreadRegistry { pub fn new( - waker: Box, + waker: Box, grand_manager: LayerGrandManager, ) -> Result { let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?;