feat: webxr feature flag (#34241)

* Add webxr feature flag

Add webxr feature flag to embedder_traits

Add webxr flag to constellation

Add webxr flag to compositor

Add webxr flag to canvas

Turn registry into optional

Add webxr flag to servo lib

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>
Co-authored-by: august kline <me@augustkline.com>

* Cargo fmt

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Add missing license

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

* Cargo clippy

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>

---------

Signed-off-by: Wu Yu Wei <yuweiwu@pm.me>
Co-authored-by: august kline <me@augustkline.com>
This commit is contained in:
Ngo Iok Ui (Wu Yu Wei) 2024-11-14 02:16:58 +09:00 committed by GitHub
parent 91f96cc9dd
commit 47a243614f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 456 additions and 374 deletions

View file

@ -15,6 +15,7 @@ path = "lib.rs"
default = []
multiview = []
tracing = ["dep:tracing"]
webxr = ["dep:webxr"]
[dependencies]
base = { workspace = true }
@ -46,7 +47,7 @@ tracing = { workspace = true, optional = true }
webrender = { workspace = true }
webrender_api = { workspace = true }
webrender_traits = { workspace = true }
webxr = { workspace = true }
webxr = { workspace = true, optional = true }
[dev-dependencies]
surfman = { workspace = true }

View file

@ -169,6 +169,7 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// The GL bindings for webrender
webrender_gl: Rc<dyn gleam::gl::Gl>,
#[cfg(feature = "webxr")]
/// Some XR devices want to run on the main thread.
pub webxr_main_thread: webxr::MainThreadRegistry,
@ -409,6 +410,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
webrender_api: state.webrender_api,
rendering_context: state.rendering_context,
webrender_gl: state.webrender_gl,
#[cfg(feature = "webxr")]
webxr_main_thread: state.webxr_main_thread,
pending_paint_metrics: HashMap::new(),
cursor: Cursor::None,
@ -1803,7 +1805,11 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
pipeline_ids.push(*pipeline_id);
}
}
let animation_state = if pipeline_ids.is_empty() && !self.webxr_main_thread.running() {
#[cfg(feature = "webxr")]
let webxr_running = self.webxr_main_thread.running();
#[cfg(not(feature = "webxr"))]
let webxr_running = false;
let animation_state = if pipeline_ids.is_empty() && webxr_running {
windowing::AnimationState::Idle
} else {
windowing::AnimationState::Animating
@ -2395,6 +2401,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
CompositionRequest::CompositeNow(_) => self.composite(),
}
#[cfg(feature = "webxr")]
// Run the WebXR main thread
self.webxr_main_thread.run_one_frame();

View file

@ -42,5 +42,6 @@ pub struct InitialCompositorState {
pub webrender_api: RenderApi,
pub rendering_context: RenderingContext,
pub webrender_gl: Rc<dyn gleam::gl::Gl>,
#[cfg(feature = "webxr")]
pub webxr_main_thread: webxr::MainThreadRegistry,
}

View file

@ -8,7 +8,7 @@ use std::fmt::{Debug, Error, Formatter};
use std::time::Duration;
use base::id::{PipelineId, TopLevelBrowsingContextId};
use embedder_traits::{EmbedderProxy, EventLoopWaker};
use embedder_traits::EventLoopWaker;
use euclid::Scale;
use keyboard_types::KeyboardEvent;
use libc::c_void;
@ -219,8 +219,14 @@ pub trait EmbedderMethods {
/// Returns a thread-safe object to wake up the window's event loop.
fn create_event_loop_waker(&mut self) -> Box<dyn EventLoopWaker>;
#[cfg(feature = "webxr")]
/// Register services with a WebXR Registry.
fn register_webxr(&mut self, _: &mut webxr::MainThreadRegistry, _: EmbedderProxy) {}
fn register_webxr(
&mut self,
_: &mut webxr::MainThreadRegistry,
_: embedder_traits::EmbedderProxy,
) {
}
/// Returns the user agent string to report in network requests.
fn get_user_agent_string(&self) -> Option<String> {