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)",
"simpleservo 0.0.1",
"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]]
@ -4518,6 +4520,7 @@ dependencies = [
"libservo 0.0.1",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"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)",
]
@ -5539,9 +5542,11 @@ dependencies = [
[[package]]
name = "webxr"
version = "0.0.1"
source = "git+https://github.com/servo/webxr#96c964c8939ca3ee8425fb8b29dd6fa6096a0bdd"
source = "git+https://github.com/servo/webxr#f67b762424af7c75c0bbce817d0e55ff51baf4cc"
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)",
"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)",
"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)",
@ -5551,11 +5556,12 @@ dependencies = [
[[package]]
name = "webxr-api"
version = "0.0.1"
source = "git+https://github.com/servo/webxr#96c964c8939ca3ee8425fb8b29dd6fa6096a0bdd"
source = "git+https://github.com/servo/webxr#f67b762424af7c75c0bbce817d0e55ff51baf4cc"
dependencies = [
"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)",
"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)",
]

View file

@ -23,6 +23,8 @@ layout-2020 = ["simpleservo/layout-2020"]
libservo = { path = "../../components/servo", features = ["no_static_freetype"] }
simpleservo = { path = "../libsimpleservo/api", features = ["no_static_freetype"] }
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"
log = "0.4"
servo-egl = "0.2"

View file

@ -29,6 +29,7 @@ use std::rc::Rc;
use std::thread;
use std::time::Duration;
use std::time::Instant;
use webxr::magicleap::MagicLeapDiscovery;
#[repr(u32)]
pub enum MLLogLevel {
@ -106,7 +107,7 @@ pub unsafe extern "C" fn init_servo(
url_update: MLURLUpdate,
keyboard: MLKeyboard,
url: *const c_char,
args: *const c_char,
default_args: *const c_char,
width: u32,
height: u32,
hidpi: f32,
@ -117,7 +118,6 @@ pub unsafe extern "C" fn init_servo(
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(
0,
0,
@ -126,34 +126,52 @@ pub unsafe extern "C" fn init_servo(
width as i32,
height as i32,
);
let args = if args.is_null() {
vec![]
} else {
CStr::from_ptr(args)
let mut url = CStr::from_ptr(url).to_str().unwrap_or("about:blank");
// 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()
.unwrap_or("")
.split(' ')
.map(|s| s.to_owned())
.collect()
} else {
Vec::new()
};
info!("got args: {:?}", args);
let vr_init = if landscape {
VRInitOptions::None
} else {
let vr_init = if !landscape {
let name = String::from("Magic Leap VR Display");
let (service, heartbeat) = MagicLeapVRService::new(name, ctxt, gl.gl_wrapper.clone())
.expect("Failed to create VR service");
let service = Box::new(service);
let heartbeat = Box::new(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 {
args,
url: Some(url.to_string()),
density: hidpi,
enable_subpixel_text_antialiasing: false,
vr_init,
xr_discovery,
coordinates,
gl_context_pointer: Some(gl.gl_context),
native_display_pointer: Some(gl.display),

View file

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

View file

@ -48,6 +48,7 @@ pub struct InitOptions {
pub coordinates: Coordinates,
pub density: f32,
pub vr_init: VRInitOptions,
pub xr_discovery: Option<Box<dyn webxr_api::Discovery>>,
pub enable_subpixel_text_antialiasing: bool,
pub gl_context_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 {
vr_init: init_opts.vr_init,
xr_discovery: init_opts.xr_discovery,
waker,
});
@ -576,6 +578,7 @@ impl ServoGlue {
struct ServoEmbedderCallbacks {
waker: Box<dyn EventLoopWaker>,
xr_discovery: Option<Box<dyn webxr_api::Discovery>>,
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> {
debug!("EmbedderMethods::create_event_loop_waker");
self.waker.clone()

View file

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

View file

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