Skip to content

Commit

Permalink
Initialize a wevxr device registry from Servo
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Jul 2, 2019
1 parent b4ed3b6 commit 91d1b52
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -15,6 +15,8 @@ opt-level = 3
# lto = false

[patch.crates-io]
webxr-api = { git = "https://github.com/servo/webxr.git" }
webxr = { git = "https://github.com/servo/webxr.git" }
# If you need to temporarily test Servo with a local fork of some upstream
# crate, add that here. Use the form:
#
Expand Down
1 change: 1 addition & 0 deletions components/canvas_traits/Cargo.toml
Expand Up @@ -27,3 +27,4 @@ serde_bytes = "0.10"
servo_config = {path = "../config"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}
webxr-api = "0.0.1"
19 changes: 19 additions & 0 deletions components/canvas_traits/webgl.rs
Expand Up @@ -4,6 +4,8 @@

use euclid::{Rect, Size2D};
use gleam::gl;
use gleam::gl::GLsync;
use gleam::gl::GLuint;
use gleam::gl::Gl;
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSharedMemory};
use pixels::PixelFormat;
Expand Down Expand Up @@ -175,6 +177,23 @@ impl WebGLMsgSender {
}
}

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))?;
self.sender
.send(WebGLMsg::Lock(self.ctx_id, sender))
.or(Err(webxr_api::Error::CommunicationError))?;
let (texture, size, sync) = receiver
.recv()
.or(Err(webxr_api::Error::CommunicationError))?;
Ok((texture, size, sync as GLsync))
}

fn unlock(&self) {
let _ = self.sender.send(WebGLMsg::Unlock(self.ctx_id));
}
}

#[derive(Deserialize, Serialize)]
pub struct TruncatedDebug<T>(T);

Expand Down
1 change: 1 addition & 0 deletions components/compositing/Cargo.toml
Expand Up @@ -40,6 +40,7 @@ webrender = {git = "https://github.com/servo/webrender", features = ["capture"]}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webvr_traits = {path = "../webvr_traits"}
webvr = {path = "../webvr"}
webxr-api = "0.0.1"

[build-dependencies]
toml = "0.4.5"
3 changes: 3 additions & 0 deletions components/compositing/windowing.rs
Expand Up @@ -169,6 +169,9 @@ pub trait EmbedderMethods {
_: &mut Vec<Box<dyn WebVRMainThreadHeartbeat>>,
) {
}

/// Register services with a WebXR Registry.
fn register_webxr(&mut self, _: &mut webxr_api::Registry) {}
}

#[derive(Clone, Copy, Debug)]
Expand Down
1 change: 1 addition & 0 deletions components/servo/Cargo.toml
Expand Up @@ -78,6 +78,7 @@ webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webdriver_server = {path = "../webdriver_server", optional = true}
webvr = {path = "../webvr"}
webvr_traits = {path = "../webvr_traits"}
webxr-api = "0.0.1"

[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"}
Expand Down
7 changes: 7 additions & 0 deletions components/servo/lib.rs
Expand Up @@ -285,6 +285,13 @@ where
// can't defer it after `create_constellation` has started.
script::init();

// 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();
if pref!(dom.webvr.enabled) || pref!(dom.webxr.enabled) {
embedder.register_webxr(&mut webxr_registry);
}

let mut webvr_heartbeats = Vec::new();
let webvr_services = if pref!(dom.webvr.enabled) || pref!(dom.webxr.enabled) {
let mut services = VRServiceManager::new();
Expand Down
1 change: 1 addition & 0 deletions ports/glutin/Cargo.toml
Expand Up @@ -55,6 +55,7 @@ libservo = {path = "../../components/servo"}
libc = "0.2"
log = "0.4"
rust-webvr = { version = "0.13", features = ["glwindow"] }
webxr = { version = "0.0.1", features = ["glwindow"] }
tinyfiledialogs = "3.0"

[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
Expand Down

0 comments on commit 91d1b52

Please sign in to comment.