Skip to content

Commit

Permalink
Support WebXR devices with main thread affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Jul 5, 2019
1 parent 683bd0d commit e9d410d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion components/compositing/compositor.rs
Expand Up @@ -182,6 +182,9 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// Some VR displays want to be sent a heartbeat from the main thread.
webvr_heartbeats: Vec<Box<dyn WebVRMainThreadHeartbeat>>,

/// 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
Expand Down Expand Up @@ -314,6 +317,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
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,
Expand Down Expand Up @@ -999,7 +1003,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
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
Expand Down Expand Up @@ -1456,6 +1463,9 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
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()
}
Expand Down
1 change: 1 addition & 0 deletions components/compositing/compositor_thread.rs
Expand Up @@ -155,4 +155,5 @@ pub struct InitialCompositorState {
pub webrender_document: webrender_api::DocumentId,
pub webrender_api: webrender_api::RenderApi,
pub webvr_heartbeats: Vec<Box<dyn WebVRMainThreadHeartbeat>>,
pub webxr_main_thread: webxr_api::MainThreadRegistry,
}
2 changes: 1 addition & 1 deletion components/compositing/windowing.rs
Expand Up @@ -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)]
Expand Down
9 changes: 5 additions & 4 deletions components/servo/lib.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -332,7 +332,7 @@ where
webrender_api_sender,
window.gl(),
webvr_services,
webxr_registry,
webxr_main_thread.registry(),
player_context,
);

Expand All @@ -359,6 +359,7 @@ where
webrender_document,
webrender_api,
webvr_heartbeats,
webxr_main_thread,
},
opts.output_file.clone(),
opts.is_running_problem_test,
Expand Down

0 comments on commit e9d410d

Please sign in to comment.