From e9d410d0ab7b985ec6c43d453524c88f1ef37379 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 5 Jul 2019 08:46:11 -0500 Subject: [PATCH] Support WebXR devices with main thread affinity --- Cargo.lock | 4 ++-- components/compositing/compositor.rs | 12 +++++++++++- components/compositing/compositor_thread.rs | 1 + components/compositing/windowing.rs | 2 +- components/servo/lib.rs | 9 +++++---- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9779cad90b41..ada44cd808a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5510,7 +5510,7 @@ dependencies = [ [[package]] name = "webxr" version = "0.0.1" -source = "git+https://github.com/servo/webxr#d4e8e1599a34a3c07953cfa2b81187763748daac" +source = "git+https://github.com/servo/webxr#f8bfa261bcd54bfeb47f68f23043e547153d7491" dependencies = [ "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5521,7 +5521,7 @@ dependencies = [ [[package]] name = "webxr-api" version = "0.0.1" -source = "git+https://github.com/servo/webxr#d4e8e1599a34a3c07953cfa2b81187763748daac" +source = "git+https://github.com/servo/webxr#f8bfa261bcd54bfeb47f68f23043e547153d7491" dependencies = [ "euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 221e125957ba..bb8f4d8f2f0b 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -182,6 +182,9 @@ pub struct IOCompositor { /// Some VR displays want to be sent a heartbeat from the main thread. webvr_heartbeats: Vec>, + /// Some XR devices want to run on the main thread. + pub webxr_main_thread: webxr_api::MainThreadRegistry, + /// Map of the pending paint metrics per layout thread. /// The layout thread for each specific pipeline expects the compositor to /// paint frames with specific given IDs (epoch). Once the compositor paints @@ -314,6 +317,7 @@ impl IOCompositor { webrender_document: state.webrender_document, webrender_api: state.webrender_api, webvr_heartbeats: state.webvr_heartbeats, + webxr_main_thread: state.webxr_main_thread, pending_paint_metrics: HashMap::new(), cursor: Cursor::None, output_file, @@ -999,7 +1003,10 @@ impl IOCompositor { pipeline_ids.push(*pipeline_id); } } - let animation_state = if pipeline_ids.is_empty() && !self.webvr_heartbeats_racing() { + let animation_state = if pipeline_ids.is_empty() && + !self.webvr_heartbeats_racing() && + !self.webxr_main_thread.running() + { windowing::AnimationState::Idle } else { windowing::AnimationState::Animating @@ -1456,6 +1463,9 @@ impl IOCompositor { webvr_heartbeat.heartbeat(); } + // Run the WebXR main thread + self.webxr_main_thread.run_one_frame(); + if !self.pending_scroll_zoom_events.is_empty() && !self.waiting_for_results_of_scroll { self.process_pending_scroll_events() } diff --git a/components/compositing/compositor_thread.rs b/components/compositing/compositor_thread.rs index 9e8a4e1f6680..8ef56c813c3d 100644 --- a/components/compositing/compositor_thread.rs +++ b/components/compositing/compositor_thread.rs @@ -155,4 +155,5 @@ pub struct InitialCompositorState { pub webrender_document: webrender_api::DocumentId, pub webrender_api: webrender_api::RenderApi, pub webvr_heartbeats: Vec>, + pub webxr_main_thread: webxr_api::MainThreadRegistry, } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 0cbb51249c6b..91d954a281a9 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -178,7 +178,7 @@ pub trait EmbedderMethods { } /// Register services with a WebXR Registry. - fn register_webxr(&mut self, _: &mut webxr_api::Registry) {} + fn register_webxr(&mut self, _: &mut webxr_api::MainThreadRegistry) {} } #[derive(Clone, Copy, Debug)] diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 0ba8fa478ef1..1d27c75fd094 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -292,10 +292,10 @@ where // For the moment, we enable use both the webxr crate and the rust-webvr crate, // but we are migrating over to just using webxr. - let mut webxr_registry = - webxr_api::Registry::new().expect("Failed to create WebXR device registry"); + let mut webxr_main_thread = + webxr_api::MainThreadRegistry::new().expect("Failed to create WebXR device registry"); if pref!(dom.webvr.enabled) || pref!(dom.webxr.enabled) { - embedder.register_webxr(&mut webxr_registry); + embedder.register_webxr(&mut webxr_main_thread); } let mut webvr_heartbeats = Vec::new(); @@ -332,7 +332,7 @@ where webrender_api_sender, window.gl(), webvr_services, - webxr_registry, + webxr_main_thread.registry(), player_context, ); @@ -359,6 +359,7 @@ where webrender_document, webrender_api, webvr_heartbeats, + webxr_main_thread, }, opts.output_file.clone(), opts.is_running_problem_test,