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",
"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",

View file

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

View file

@ -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 }

View file

@ -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<dyn EventLoopWaker>;
fn wake(&self);
}
#[cfg(not(feature = "webxr"))]
impl Clone for Box<dyn EventLoopWaker> {
fn clone(&self) -> Self {
EventLoopWaker::clone_box(self.as_ref())
self.clone_box()
}
}
/// Sends messages to the embedder.
pub struct EmbedderProxy {
pub sender: Sender<EmbedderMsg>,

View file

@ -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 }

View file

@ -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,

View file

@ -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<GL> {
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)]
#[cfg_attr(feature = "ipc", derive(Serialize, Deserialize))]
struct MainThreadWakerImpl {
#[cfg(feature = "ipc")]
sender: WebXrSender<()>,
#[cfg(not(feature = "ipc"))]
waker: Box<dyn MainThreadWaker>,
waker: Box<dyn EventLoopWaker>,
}
#[cfg(feature = "ipc")]
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))?;
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<dyn MainThreadWaker>) -> Result<MainThreadWakerImpl, Error> {
fn new(waker: Box<dyn EventLoopWaker>) -> Result<MainThreadWakerImpl, Error> {
Ok(MainThreadWakerImpl { waker })
}
@ -110,7 +100,7 @@ impl Registry {
impl<GL: 'static + GLTypes> MainThreadRegistry<GL> {
pub fn new(
waker: Box<dyn MainThreadWaker>,
waker: Box<dyn EventLoopWaker>,
grand_manager: LayerGrandManager<GL>,
) -> Result<Self, Error> {
let (sender, receiver) = crate::webxr_channel().or(Err(Error::CommunicationError))?;