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 <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-09 16:19:33 +02:00 committed by GitHub
parent f8db2d2e86
commit 3b41a16fcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 9 additions and 28 deletions

2
Cargo.lock generated
View file

@ -1949,7 +1949,6 @@ dependencies = [
"url", "url",
"webdriver", "webdriver",
"webrender_api", "webrender_api",
"webxr-api",
] ]
[[package]] [[package]]
@ -8699,6 +8698,7 @@ dependencies = [
name = "webxr-api" name = "webxr-api"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"embedder_traits",
"euclid", "euclid",
"ipc-channel", "ipc-channel",
"log", "log",

View file

@ -46,7 +46,6 @@ webxr = [
"dep:webxr", "dep:webxr",
"dep:webxr-api", "dep:webxr-api",
"compositing/webxr", "compositing/webxr",
"embedder_traits/webxr",
"canvas/webxr", "canvas/webxr",
"script/webxr", "script/webxr",
] ]

View file

@ -11,9 +11,6 @@ rust-version.workspace = true
name = "embedder_traits" name = "embedder_traits"
path = "lib.rs" path = "lib.rs"
[features]
webxr = ["dep:webxr-api"]
[dependencies] [dependencies]
base = { workspace = true } base = { workspace = true }
cfg-if = { workspace = true } cfg-if = { workspace = true }
@ -37,4 +34,3 @@ stylo_traits = { workspace = true }
url = { workspace = true } url = { workspace = true }
webdriver = { workspace = true } webdriver = { workspace = true }
webrender_api = { workspace = true } webrender_api = { workspace = true }
webxr-api = { workspace = true, features = ["ipc"], optional = true }

View file

@ -90,21 +90,16 @@ pub enum Cursor {
ZoomOut, ZoomOut,
} }
#[cfg(feature = "webxr")]
pub use webxr_api::MainThreadWaker as EventLoopWaker;
#[cfg(not(feature = "webxr"))]
pub trait EventLoopWaker: 'static + Send { pub trait EventLoopWaker: 'static + Send {
fn clone_box(&self) -> Box<dyn EventLoopWaker>; fn clone_box(&self) -> Box<dyn EventLoopWaker>;
fn wake(&self); fn wake(&self);
} }
#[cfg(not(feature = "webxr"))]
impl Clone for Box<dyn EventLoopWaker> { impl Clone for Box<dyn EventLoopWaker> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
EventLoopWaker::clone_box(self.as_ref()) self.clone_box()
} }
} }
/// Sends messages to the embedder. /// Sends messages to the embedder.
pub struct EmbedderProxy { pub struct EmbedderProxy {
pub sender: Sender<EmbedderMsg>, pub sender: Sender<EmbedderMsg>,

View file

@ -19,6 +19,7 @@ path = "lib.rs"
ipc = ["serde", "ipc-channel", "euclid/serde"] ipc = ["serde", "ipc-channel", "euclid/serde"]
[dependencies] [dependencies]
embedder_traits = { workspace = true }
euclid = { workspace = true } euclid = { workspace = true }
ipc-channel = { workspace = true, optional = true } ipc-channel = { workspace = true, optional = true }
log = { workspace = true } log = { workspace = true }

View file

@ -50,7 +50,7 @@ pub use mock::{
MockButton, MockButtonType, MockDeviceInit, MockDeviceMsg, MockDiscoveryAPI, MockInputInit, MockButton, MockButtonType, MockDeviceInit, MockDeviceMsg, MockDiscoveryAPI, MockInputInit,
MockInputMsg, MockRegion, MockViewInit, MockViewsInit, MockWorld, MockInputMsg, MockRegion, MockViewInit, MockViewsInit, MockWorld,
}; };
pub use registry::{MainThreadRegistry, MainThreadWaker, Registry}; pub use registry::{MainThreadRegistry, Registry};
pub use session::{ pub use session::{
EnvironmentBlendMode, MainThreadSession, Quitter, Session, SessionBuilder, SessionId, EnvironmentBlendMode, MainThreadSession, Quitter, Session, SessionBuilder, SessionId,
SessionInit, SessionMode, SessionThread, SessionInit, SessionMode, SessionThread,

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use embedder_traits::EventLoopWaker;
use log::warn; use log::warn;
#[cfg(feature = "ipc")] #[cfg(feature = "ipc")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -30,29 +31,18 @@ pub struct MainThreadRegistry<GL> {
next_session_id: u32, next_session_id: u32,
} }
pub trait MainThreadWaker: 'static + Send {
fn clone_box(&self) -> Box<dyn MainThreadWaker>;
fn wake(&self);
}
impl Clone for Box<dyn MainThreadWaker> {
fn clone(&self) -> Self {
self.clone_box()
}
}
#[derive(Clone)] #[derive(Clone)]
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))] #[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
struct MainThreadWakerImpl { struct MainThreadWakerImpl {
#[cfg(feature = "ipc")] #[cfg(feature = "ipc")]
sender: WebXrSender<()>, sender: WebXrSender<()>,
#[cfg(not(feature = "ipc"))] #[cfg(not(feature = "ipc"))]
waker: Box<dyn MainThreadWaker>, waker: Box<dyn EventLoopWaker>,
} }
#[cfg(feature = "ipc")] #[cfg(feature = "ipc")]
impl MainThreadWakerImpl { impl MainThreadWakerImpl {
fn new(waker: Box<dyn MainThreadWaker>) -> Result<MainThreadWakerImpl, Error> { fn new(waker: Box<dyn EventLoopWaker>) -> Result<MainThreadWakerImpl, Error> {
let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?; let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?;
ipc_channel::router::ROUTER.add_typed_route(receiver, Box::new(move |_| waker.wake())); ipc_channel::router::ROUTER.add_typed_route(receiver, Box::new(move |_| waker.wake()));
Ok(MainThreadWakerImpl { sender }) Ok(MainThreadWakerImpl { sender })
@ -65,7 +55,7 @@ impl MainThreadWakerImpl {
#[cfg(not(feature = "ipc"))] #[cfg(not(feature = "ipc"))]
impl MainThreadWakerImpl { impl MainThreadWakerImpl {
fn new(waker: Box<dyn MainThreadWaker>) -> Result<MainThreadWakerImpl, Error> { fn new(waker: Box<dyn EventLoopWaker>) -> Result<MainThreadWakerImpl, Error> {
Ok(MainThreadWakerImpl { waker }) Ok(MainThreadWakerImpl { waker })
} }
@ -110,7 +100,7 @@ impl Registry {
impl<GL: 'static + GLTypes> MainThreadRegistry<GL> { impl<GL: 'static + GLTypes> MainThreadRegistry<GL> {
pub fn new( pub fn new(
waker: Box<dyn MainThreadWaker>, waker: Box<dyn EventLoopWaker>,
grand_manager: LayerGrandManager<GL>, grand_manager: LayerGrandManager<GL>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?; let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?;