Added magicleap webxr back end

This commit is contained in:
Alan Jeffrey 2019-07-31 17:06:00 -05:00
parent 196c511d5e
commit 1ca495b321
7 changed files with 50 additions and 11 deletions

10
Cargo.lock generated
View file

@ -2528,6 +2528,8 @@ dependencies = [
"servo-egl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "servo-egl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"simpleservo 0.0.1", "simpleservo 0.0.1",
"smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"webxr 0.0.1 (git+https://github.com/servo/webxr)",
"webxr-api 0.0.1 (git+https://github.com/servo/webxr)",
] ]
[[package]] [[package]]
@ -4518,6 +4520,7 @@ dependencies = [
"libservo 0.0.1", "libservo 0.0.1",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-media 0.1.0 (git+https://github.com/servo/media)", "servo-media 0.1.0 (git+https://github.com/servo/media)",
"webxr-api 0.0.1 (git+https://github.com/servo/webxr)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -5539,9 +5542,11 @@ dependencies = [
[[package]] [[package]]
name = "webxr" name = "webxr"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/webxr#96c964c8939ca3ee8425fb8b29dd6fa6096a0bdd" source = "git+https://github.com/servo/webxr#f67b762424af7c75c0bbce817d0e55ff51baf4cc"
dependencies = [ dependencies = [
"bindgen 0.49.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5551,11 +5556,12 @@ dependencies = [
[[package]] [[package]]
name = "webxr-api" name = "webxr-api"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/webxr#96c964c8939ca3ee8425fb8b29dd6fa6096a0bdd" source = "git+https://github.com/servo/webxr#f67b762424af7c75c0bbce817d0e55ff51baf4cc"
dependencies = [ dependencies = [
"euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View file

@ -23,6 +23,8 @@ layout-2020 = ["simpleservo/layout-2020"]
libservo = { path = "../../components/servo", features = ["no_static_freetype"] } libservo = { path = "../../components/servo", features = ["no_static_freetype"] }
simpleservo = { path = "../libsimpleservo/api", features = ["no_static_freetype"] } simpleservo = { path = "../libsimpleservo/api", features = ["no_static_freetype"] }
rust-webvr = { version = "0.13", features = ["magicleap"] } rust-webvr = { version = "0.13", features = ["magicleap"] }
webxr-api = { git = "https://github.com/servo/webxr", features = ["ipc"] }
webxr = { git = "https://github.com/servo/webxr", features = ["ipc", "magicleap"] }
libc = "0.2" libc = "0.2"
log = "0.4" log = "0.4"
servo-egl = "0.2" servo-egl = "0.2"

View file

@ -29,6 +29,7 @@ use std::rc::Rc;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::time::Instant; use std::time::Instant;
use webxr::magicleap::MagicLeapDiscovery;
#[repr(u32)] #[repr(u32)]
pub enum MLLogLevel { pub enum MLLogLevel {
@ -106,7 +107,7 @@ pub unsafe extern "C" fn init_servo(
url_update: MLURLUpdate, url_update: MLURLUpdate,
keyboard: MLKeyboard, keyboard: MLKeyboard,
url: *const c_char, url: *const c_char,
args: *const c_char, default_args: *const c_char,
width: u32, width: u32,
height: u32, height: u32,
hidpi: f32, hidpi: f32,
@ -117,7 +118,6 @@ pub unsafe extern "C" fn init_servo(
let gl = gl_glue::egl::init().expect("EGL initialization failure"); let gl = gl_glue::egl::init().expect("EGL initialization failure");
let url = CStr::from_ptr(url).to_str().unwrap_or("about:blank");
let coordinates = Coordinates::new( let coordinates = Coordinates::new(
0, 0,
0, 0,
@ -126,34 +126,52 @@ pub unsafe extern "C" fn init_servo(
width as i32, width as i32,
height as i32, height as i32,
); );
let args = if args.is_null() {
vec![] let mut url = CStr::from_ptr(url).to_str().unwrap_or("about:blank");
} else {
CStr::from_ptr(args) // If the URL has a space in it, then treat everything before the space as arguments
let args = if let Some(i) = url.rfind(' ') {
let (front, back) = url.split_at(i);
url = back;
front.split(' ').map(|s| s.to_owned()).collect()
} else if !default_args.is_null() {
CStr::from_ptr(default_args)
.to_str() .to_str()
.unwrap_or("") .unwrap_or("")
.split(' ') .split(' ')
.map(|s| s.to_owned()) .map(|s| s.to_owned())
.collect() .collect()
} else {
Vec::new()
}; };
info!("got args: {:?}", args); info!("got args: {:?}", args);
let vr_init = if landscape { let vr_init = if !landscape {
VRInitOptions::None
} else {
let name = String::from("Magic Leap VR Display"); let name = String::from("Magic Leap VR Display");
let (service, heartbeat) = MagicLeapVRService::new(name, ctxt, gl.gl_wrapper.clone()) let (service, heartbeat) = MagicLeapVRService::new(name, ctxt, gl.gl_wrapper.clone())
.expect("Failed to create VR service"); .expect("Failed to create VR service");
let service = Box::new(service); let service = Box::new(service);
let heartbeat = Box::new(heartbeat); let heartbeat = Box::new(heartbeat);
VRInitOptions::VRService(service, heartbeat) VRInitOptions::VRService(service, heartbeat)
} else {
VRInitOptions::None
}; };
let xr_discovery: Option<Box<dyn webxr_api::Discovery>> = if !landscape {
let discovery = MagicLeapDiscovery::new(ctxt, gl.gl_wrapper.clone());
Some(Box::new(discovery))
} else {
None
};
let opts = InitOptions { let opts = InitOptions {
args, args,
url: Some(url.to_string()), url: Some(url.to_string()),
density: hidpi, density: hidpi,
enable_subpixel_text_antialiasing: false, enable_subpixel_text_antialiasing: false,
vr_init, vr_init,
xr_discovery,
coordinates, coordinates,
gl_context_pointer: Some(gl.gl_context), gl_context_pointer: Some(gl.gl_context),
native_display_pointer: Some(gl.display), native_display_pointer: Some(gl.display),

View file

@ -10,6 +10,7 @@ publish = false
libservo = { path = "../../../components/servo" } libservo = { path = "../../../components/servo" }
log = "0.4" log = "0.4"
servo-media = { git = "https://github.com/servo/media" } servo-media = { git = "https://github.com/servo/media" }
webxr-api = { git = "https://github.com/servo/webxr" }
[target.'cfg(not(target_os = "macos"))'.dependencies] [target.'cfg(not(target_os = "macos"))'.dependencies]
libc = "0.2" libc = "0.2"

View file

@ -48,6 +48,7 @@ pub struct InitOptions {
pub coordinates: Coordinates, pub coordinates: Coordinates,
pub density: f32, pub density: f32,
pub vr_init: VRInitOptions, pub vr_init: VRInitOptions,
pub xr_discovery: Option<Box<dyn webxr_api::Discovery>>,
pub enable_subpixel_text_antialiasing: bool, pub enable_subpixel_text_antialiasing: bool,
pub gl_context_pointer: Option<*const c_void>, pub gl_context_pointer: Option<*const c_void>,
pub native_display_pointer: Option<*const c_void>, pub native_display_pointer: Option<*const c_void>,
@ -198,6 +199,7 @@ pub fn init(
let embedder_callbacks = Box::new(ServoEmbedderCallbacks { let embedder_callbacks = Box::new(ServoEmbedderCallbacks {
vr_init: init_opts.vr_init, vr_init: init_opts.vr_init,
xr_discovery: init_opts.xr_discovery,
waker, waker,
}); });
@ -576,6 +578,7 @@ impl ServoGlue {
struct ServoEmbedderCallbacks { struct ServoEmbedderCallbacks {
waker: Box<dyn EventLoopWaker>, waker: Box<dyn EventLoopWaker>,
xr_discovery: Option<Box<dyn webxr_api::Discovery>>,
vr_init: VRInitOptions, vr_init: VRInitOptions,
} }
@ -607,6 +610,13 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
} }
} }
fn register_webxr(&mut self, registry: &mut webxr_api::MainThreadRegistry) {
debug!("EmbedderMethods::register_xr");
if let Some(discovery) = self.xr_discovery.take() {
registry.register(discovery);
}
}
fn create_event_loop_waker(&mut self) -> Box<dyn EventLoopWaker> { fn create_event_loop_waker(&mut self) -> Box<dyn EventLoopWaker> {
debug!("EmbedderMethods::create_event_loop_waker"); debug!("EmbedderMethods::create_event_loop_waker");
self.waker.clone() self.waker.clone()

View file

@ -143,6 +143,7 @@ unsafe fn init(
} else { } else {
VRInitOptions::VRExternal(opts.vr_pointer) VRInitOptions::VRExternal(opts.vr_pointer)
}, },
xr_discovery: None,
enable_subpixel_text_antialiasing: opts.enable_subpixel_text_antialiasing, enable_subpixel_text_antialiasing: opts.enable_subpixel_text_antialiasing,
gl_context_pointer: gl_context, gl_context_pointer: gl_context,
native_display_pointer: display, native_display_pointer: display,

View file

@ -745,6 +745,7 @@ fn get_options(env: &JNIEnv, opts: JObject) -> Result<(InitOptions, bool, Option
} else { } else {
VRInitOptions::VRExternal(vr_pointer) VRInitOptions::VRExternal(vr_pointer)
}, },
xr_discovery: None,
gl_context_pointer: None, gl_context_pointer: None,
native_display_pointer: None, native_display_pointer: None,
}; };