Skip to content

Commit

Permalink
Use webxr IPC to get a WebXR device registry to each script thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Jul 3, 2019
1 parent fee1418 commit 9eb75d4
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 35 deletions.
151 changes: 117 additions & 34 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/canvas_traits/Cargo.toml
Expand Up @@ -25,6 +25,7 @@ pixels = {path = "../pixels"}
serde = "1.0"
serde_bytes = "0.10"
servo_config = {path = "../config"}
typetag = "0.1"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}
webxr-api = {git = "https://github.com/servo/webxr"}
1 change: 1 addition & 0 deletions components/canvas_traits/webgl.rs
Expand Up @@ -177,6 +177,7 @@ impl WebGLMsgSender {
}
}

#[typetag::serde]
impl webxr_api::WebGLExternalImageApi for WebGLMsgSender {
fn lock(&self) -> Result<(GLuint, Size2D<i32>, GLsync), webxr_api::Error> {
let (sender, receiver) = webgl_channel().or(Err(webxr_api::Error::CommunicationError))?;
Expand Down
1 change: 1 addition & 0 deletions components/constellation/Cargo.toml
Expand Up @@ -50,6 +50,7 @@ servo_remutex = {path = "../remutex"}
servo_url = {path = "../url"}
webvr_traits = {path = "../webvr_traits"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]}

[target.'cfg(all(not(target_os = "windows"), not(target_os = "ios"), not(target_os="android"), not(target_arch="arm"), not(target_arch="aarch64")))'.dependencies]
gaol = {git = "https://github.com/servo/gaol"}
8 changes: 8 additions & 0 deletions components/constellation/constellation.rs
Expand Up @@ -390,6 +390,9 @@ pub struct Constellation<Message, LTF, STF> {
/// A channel through which messages can be sent to the webvr thread.
webvr_chan: Option<IpcSender<WebVRMsg>>,

/// The XR device registry
webxr_registry: webxr_api::Registry,

/// A channel through which messages can be sent to the canvas paint thread.
canvas_chan: IpcSender<CanvasMsg>,

Expand Down Expand Up @@ -455,6 +458,9 @@ pub struct InitialConstellationState {

/// A channel to the webgl thread.
pub webvr_chan: Option<IpcSender<WebVRMsg>>,

/// The XR device registry
pub webxr_registry: webxr_api::Registry,
}

/// Data needed for webdriver
Expand Down Expand Up @@ -751,6 +757,7 @@ where
}),
webgl_threads: state.webgl_threads,
webvr_chan: state.webvr_chan,
webxr_registry: state.webxr_registry,
canvas_chan: CanvasPaintThread::start(),
pending_approval_navigations: HashMap::new(),
pressed_mouse_buttons: 0,
Expand Down Expand Up @@ -997,6 +1004,7 @@ where
.as_ref()
.map(|threads| threads.pipeline()),
webvr_chan: self.webvr_chan.clone(),
webxr_registry: self.webxr_registry.clone(),
});

let pipeline = match result {
Expand Down
6 changes: 6 additions & 0 deletions components/constellation/pipeline.rs
Expand Up @@ -188,6 +188,9 @@ pub struct InitialPipelineState {

/// A channel to the webvr thread.
pub webvr_chan: Option<IpcSender<WebVRMsg>>,

/// The XR device registry
pub webxr_registry: webxr_api::Registry,
}

pub struct NewPipeline {
Expand Down Expand Up @@ -305,6 +308,7 @@ impl Pipeline {
webrender_document: state.webrender_document,
webgl_chan: state.webgl_chan,
webvr_chan: state.webvr_chan,
webxr_registry: state.webxr_registry,
};

// Spawn the child process.
Expand Down Expand Up @@ -510,6 +514,7 @@ pub struct UnprivilegedPipelineContent {
webrender_document: webrender_api::DocumentId,
webgl_chan: Option<WebGLPipeline>,
webvr_chan: Option<IpcSender<WebVRMsg>>,
webxr_registry: webxr_api::Registry,
}

impl UnprivilegedPipelineContent {
Expand Down Expand Up @@ -554,6 +559,7 @@ impl UnprivilegedPipelineContent {
content_process_shutdown_chan: self.script_content_process_shutdown_chan,
webgl_chan: self.webgl_chan,
webvr_chan: self.webvr_chan,
webxr_registry: self.webxr_registry,
webrender_document: self.webrender_document,
webrender_api_sender: self.webrender_api_sender.clone(),
layout_is_busy: layout_thread_busy_flag.clone(),
Expand Down
1 change: 1 addition & 0 deletions components/script/Cargo.toml
Expand Up @@ -111,6 +111,7 @@ uuid = {version = "0.7", features = ["v4"]}
xml5ever = {version = "0.14"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}
webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]}

[target.'cfg(not(target_os = "ios"))'.dependencies]
mozangle = "0.2"
1 change: 1 addition & 0 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -485,6 +485,7 @@ unsafe_no_jsmanaged_fields!(WebGLVersion);
unsafe_no_jsmanaged_fields!(WebGLSLVersion);
unsafe_no_jsmanaged_fields!(MediaList);
unsafe_no_jsmanaged_fields!(WebVRGamepadData, WebVRGamepadState, WebVRGamepadHand);
unsafe_no_jsmanaged_fields!(webxr_api::Registry);
unsafe_no_jsmanaged_fields!(ScriptToConstellationChan);
unsafe_no_jsmanaged_fields!(InteractiveMetrics);
unsafe_no_jsmanaged_fields!(InteractiveWindow);
Expand Down
4 changes: 4 additions & 0 deletions components/script/script_thread.rs
Expand Up @@ -626,6 +626,9 @@ pub struct ScriptThread {
/// A handle to the webvr thread, if available
webvr_chan: Option<IpcSender<WebVRMsg>>,

/// The WebXR device registry
webxr_registry: webxr_api::Registry,

/// The worklet thread pool
worklet_thread_pool: DomRefCell<Option<Rc<WorkletThreadPool>>>,

Expand Down Expand Up @@ -1212,6 +1215,7 @@ impl ScriptThread {

webgl_chan: state.webgl_chan,
webvr_chan: state.webvr_chan,
webxr_registry: state.webxr_registry,

worklet_thread_pool: Default::default(),

Expand Down
1 change: 1 addition & 0 deletions components/script_traits/Cargo.toml
Expand Up @@ -39,3 +39,4 @@ time = "0.1.12"
url = "1.2"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}
webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]}
2 changes: 2 additions & 0 deletions components/script_traits/lib.rs
Expand Up @@ -628,6 +628,8 @@ pub struct InitialScriptState {
pub webgl_chan: Option<WebGLPipeline>,
/// A channel to the webvr thread, if available.
pub webvr_chan: Option<IpcSender<WebVRMsg>>,
/// The XR device registry
pub webxr_registry: webxr_api::Registry,
/// The Webrender document ID associated with this thread.
pub webrender_document: DocumentId,
/// FIXME(victor): The Webrender API sender in this constellation's pipeline
Expand Down
6 changes: 5 additions & 1 deletion components/servo/lib.rs
Expand Up @@ -287,7 +287,8 @@ 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();
let mut webxr_registry =
webxr_api::Registry::new().expect("Failed to create WebXR device registry");
if pref!(dom.webvr.enabled) || pref!(dom.webxr.enabled) {
embedder.register_webxr(&mut webxr_registry);
}
Expand Down Expand Up @@ -319,6 +320,7 @@ where
webrender_api_sender,
window.gl(),
webvr_services,
webxr_registry,
);

// Send the constellation's swmanager sender to service worker manager thread
Expand Down Expand Up @@ -628,6 +630,7 @@ fn create_constellation(
webrender_api_sender: webrender_api::RenderApiSender,
window_gl: Rc<dyn gl::Gl>,
webvr_services: Option<VRServiceManager>,
webxr_registry: webxr_api::Registry,
) -> (Sender<ConstellationMsg>, SWManagerSenders) {
// Global configuration options, parsed from the command line.
let opts = opts::get();
Expand Down Expand Up @@ -708,6 +711,7 @@ fn create_constellation(
webrender_api_sender,
webgl_threads,
webvr_chan,
webxr_registry,
};
let (constellation_chan, from_swmanager_sender) = Constellation::<
script_layout_interface::message::Msg,
Expand Down

0 comments on commit 9eb75d4

Please sign in to comment.