diff options
author | Alan Jeffrey <ajeffrey@mozilla.com> | 2019-07-31 17:06:00 -0500 |
---|---|---|
committer | Alan Jeffrey <ajeffrey@mozilla.com> | 2019-08-02 12:14:11 -0500 |
commit | 1ca495b32153a2ec7abc4627a14ea03f7f769d85 (patch) | |
tree | 7e7aaa1d26dc52cd729f9fb1f3b924acf71c568d | |
parent | 196c511d5ebf81b3fe202c5e0c5c1972a6408ab7 (diff) | |
download | servo-1ca495b32153a2ec7abc4627a14ea03f7f769d85.tar.gz servo-1ca495b32153a2ec7abc4627a14ea03f7f769d85.zip |
Added magicleap webxr back end
-rw-r--r-- | Cargo.lock | 10 | ||||
-rw-r--r-- | ports/libmlservo/Cargo.toml | 2 | ||||
-rw-r--r-- | ports/libmlservo/src/lib.rs | 36 | ||||
-rw-r--r-- | ports/libsimpleservo/api/Cargo.toml | 1 | ||||
-rw-r--r-- | ports/libsimpleservo/api/src/lib.rs | 10 | ||||
-rw-r--r-- | ports/libsimpleservo/capi/src/lib.rs | 1 | ||||
-rw-r--r-- | ports/libsimpleservo/jniapi/src/lib.rs | 1 |
7 files changed, 50 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock index e1301f6a7d2..e20e9fd11b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", ] diff --git a/ports/libmlservo/Cargo.toml b/ports/libmlservo/Cargo.toml index e4c67e9be2b..d99e1b6cf4c 100644 --- a/ports/libmlservo/Cargo.toml +++ b/ports/libmlservo/Cargo.toml @@ -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" diff --git a/ports/libmlservo/src/lib.rs b/ports/libmlservo/src/lib.rs index 029691c67e1..8dd8c7748cb 100644 --- a/ports/libmlservo/src/lib.rs +++ b/ports/libmlservo/src/lib.rs @@ -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), diff --git a/ports/libsimpleservo/api/Cargo.toml b/ports/libsimpleservo/api/Cargo.toml index 375023232c9..4bbdda8545e 100644 --- a/ports/libsimpleservo/api/Cargo.toml +++ b/ports/libsimpleservo/api/Cargo.toml @@ -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" diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs index 02c80a2f402..b928a07010f 100644 --- a/ports/libsimpleservo/api/src/lib.rs +++ b/ports/libsimpleservo/api/src/lib.rs @@ -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() diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs index 6407752286c..9b14c8bc394 100644 --- a/ports/libsimpleservo/capi/src/lib.rs +++ b/ports/libsimpleservo/capi/src/lib.rs @@ -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, diff --git a/ports/libsimpleservo/jniapi/src/lib.rs b/ports/libsimpleservo/jniapi/src/lib.rs index d67c2588947..a79aa2a91b2 100644 --- a/ports/libsimpleservo/jniapi/src/lib.rs +++ b/ports/libsimpleservo/jniapi/src/lib.rs @@ -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, }; |