From a062c405674a1578312a1110a8c765ce9efdf927 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Wed, 13 Feb 2019 17:16:02 -0600 Subject: [PATCH] Allow the embedder to register their own VRServices --- Cargo.lock | 15 +++++----- components/compositing/Cargo.toml | 1 + components/compositing/windowing.rs | 9 ++---- components/servo/lib.rs | 44 ++++++++++++++++------------- components/webvr/Cargo.toml | 2 +- components/webvr/lib.rs | 1 + components/webvr/webvr_thread.rs | 12 ++------ components/webvr_traits/Cargo.toml | 2 +- ports/libsimpleservo/api/src/lib.rs | 7 +++-- 9 files changed, 48 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dbac8ae545..2be3d585c2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -616,6 +616,7 @@ dependencies = [ "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "webrender 0.58.0 (git+https://github.com/servo/webrender)", "webrender_api 0.58.0 (git+https://github.com/servo/webrender)", + "webvr 0.0.1", ] [[package]] @@ -3310,7 +3311,7 @@ dependencies = [ [[package]] name = "rust-webvr" -version = "0.9.17" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3320,12 +3321,12 @@ dependencies = [ "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "ovr-mobile-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-webvr-api 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-webvr-api 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rust-webvr-api" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "android_injected_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4837,7 +4838,7 @@ dependencies = [ "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", - "rust-webvr 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-webvr 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "script_traits 0.0.1", "servo_config 0.0.1", "webvr_traits 0.0.1", @@ -4849,7 +4850,7 @@ version = "0.0.1" dependencies = [ "ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", - "rust-webvr-api 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-webvr-api 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5327,8 +5328,8 @@ dependencies = [ "checksum regex-syntax 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fbc557aac2b708fe84121caf261346cc2eed71978024337e42eb46b8a252ac6e" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum ron 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "da06feaa07f69125ab9ddc769b11de29090122170b402547f64b86fe16ebc399" -"checksum rust-webvr 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c44fadb2f8b67a3ee909c158e0bdd0c1c2f21cab7d37c8f30cd8955419ece9a7" -"checksum rust-webvr-api 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "daf1b163d8522d2b25ec99de77785573dbd2db4825df515d241d3d5408b958d5" +"checksum rust-webvr 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4251e156fc27e2ce17a747e3270ee6940c754145cead0cf5da29792328baf473" +"checksum rust-webvr-api 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d54f1423df09c01a1937133229d3617bf40cdbc473f0decd98b6013e6c2fef5" "checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rusttype 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b8eb11f5b0a98c8eca2fb1483f42646d8c340e83e46ab416f8a063a0fd0eeb20" diff --git a/components/compositing/Cargo.toml b/components/compositing/Cargo.toml index 90edfbe0d6b..426746838b3 100644 --- a/components/compositing/Cargo.toml +++ b/components/compositing/Cargo.toml @@ -39,6 +39,7 @@ style_traits = {path = "../style_traits"} time = "0.1.17" webrender = {git = "https://github.com/servo/webrender", features = ["capture"]} webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} +webvr = {path = "../webvr"} [build-dependencies] toml = "0.4.5" diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index af7e6079213..091eb661a5e 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -14,11 +14,11 @@ use script_traits::{MouseButton, TouchEventType, TouchId}; use servo_geometry::DeviceIndependentPixel; use servo_url::ServoUrl; use std::fmt::{Debug, Error, Formatter}; -use std::os::raw::c_void; #[cfg(feature = "gl")] use std::rc::Rc; use style_traits::DevicePixel; use webrender_api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, ScrollLocation}; +use webvr::VRServiceManager; #[derive(Clone)] pub enum MouseWindowEvent { @@ -146,11 +146,8 @@ pub trait WindowMethods { /// will want to avoid blocking on UI events, and just /// run the event loop at the vsync interval. fn set_animation_state(&self, _state: AnimationState); - /// Provide a c_void pointer to a VRExternal shared memory. - /// See: https://github.com/servo/rust-webvr/tree/master/rust-webvr/src/api/vrexternal - fn get_vrexternal_pointer(&self) -> Option<*mut c_void> { - None - } + /// Register services with a VRServiceManager. + fn register_vr_services(&self, _: &mut VRServiceManager) {} } #[derive(Clone, Copy, Debug)] diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 660ed29a4f9..16fb675cfe4 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -107,7 +107,7 @@ use std::cmp::max; use std::path::PathBuf; use std::rc::Rc; use webrender::{RendererKind, ShaderPrecacheFlags}; -use webvr::{VRExternalShmemPtr, WebVRCompositorHandler, WebVRThread}; +use webvr::{VRServiceManager, WebVRCompositorHandler, WebVRThread}; pub use gleam::gl; pub use msg::constellation_msg::TopLevelBrowsingContextId as BrowserId; @@ -216,9 +216,14 @@ where // can't defer it after `create_constellation` has started. script::init(); - let webvr_shmem = window - .get_vrexternal_pointer() - .map(|ptr| VRExternalShmemPtr::new(ptr)); + let webvr_services = if PREFS.is_webvr_enabled() { + let mut services = VRServiceManager::new(); + services.register_defaults(); + window.register_vr_services(&mut services); + Some(services) + } else { + None + }; // Create the constellation, which maintains the engine // pipelines, including the script and layout threads, as well @@ -236,7 +241,7 @@ where webrender_document, webrender_api_sender, window.gl(), - webvr_shmem, + webvr_services, ); // Send the constellation's swmanager sender to service worker manager thread @@ -515,7 +520,7 @@ fn create_constellation( webrender_document: webrender_api::DocumentId, webrender_api_sender: webrender_api::RenderApiSender, window_gl: Rc, - webvr_shmem: Option, + webvr_services: Option, ) -> (Sender, SWManagerSenders) { let bluetooth_thread: IpcSender = BluetoothThreadFactory::new(embedder_proxy.clone()); @@ -535,19 +540,20 @@ fn create_constellation( let resource_sender = public_resource_threads.sender(); - let (webvr_chan, webvr_constellation_sender, webvr_compositor) = if PREFS.is_webvr_enabled() { - // WebVR initialization - let (mut handler, sender) = WebVRCompositorHandler::new(); - let (webvr_thread, constellation_sender) = WebVRThread::spawn(sender, webvr_shmem); - handler.set_webvr_thread_sender(webvr_thread.clone()); - ( - Some(webvr_thread), - Some(constellation_sender), - Some(handler), - ) - } else { - (None, None, None) - }; + let (webvr_chan, webvr_constellation_sender, webvr_compositor) = + if let Some(services) = webvr_services { + // WebVR initialization + let (mut handler, sender) = WebVRCompositorHandler::new(); + let (webvr_thread, constellation_sender) = WebVRThread::spawn(sender, services); + handler.set_webvr_thread_sender(webvr_thread.clone()); + ( + Some(webvr_thread), + Some(constellation_sender), + Some(handler), + ) + } else { + (None, None, None) + }; // GLContext factory used to create WebGL Contexts let gl_factory = if opts::get().should_use_osmesa() { diff --git a/components/webvr/Cargo.toml b/components/webvr/Cargo.toml index 91c8cbef95d..54fee3d2716 100644 --- a/components/webvr/Cargo.toml +++ b/components/webvr/Cargo.toml @@ -21,7 +21,7 @@ euclid = "0.19" ipc-channel = "0.11" log = "0.4" msg = {path = "../msg"} -rust-webvr = {version = "0.9", features = ["openvr", "vrexternal"]} +rust-webvr = {version = "0.10", features = ["openvr", "vrexternal"]} script_traits = {path = "../script_traits"} servo_config = {path = "../config"} webvr_traits = {path = "../webvr_traits" } diff --git a/components/webvr/lib.rs b/components/webvr/lib.rs index a075f3ffd86..e1acd062357 100644 --- a/components/webvr/lib.rs +++ b/components/webvr/lib.rs @@ -10,3 +10,4 @@ extern crate log; mod webvr_thread; pub use crate::webvr_thread::{WebVRCompositorHandler, WebVRThread}; pub use rust_webvr::api::VRExternalShmemPtr; +pub use rust_webvr::VRServiceManager; diff --git a/components/webvr/webvr_thread.rs b/components/webvr/webvr_thread.rs index 1f897689b87..0528afe5be4 100644 --- a/components/webvr/webvr_thread.rs +++ b/components/webvr/webvr_thread.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use crate::VRExternalShmemPtr; use canvas_traits::webgl; use crossbeam_channel::{unbounded, Receiver, Sender}; use euclid::Size2D; @@ -53,13 +52,8 @@ impl WebVRThread { sender: IpcSender, constellation_chan: Sender, vr_compositor_chan: WebVRCompositorSender, - webvr_shmem: Option, + service: VRServiceManager, ) -> WebVRThread { - let mut service = VRServiceManager::new(); - service.register_defaults(); - if let Some(ptr) = webvr_shmem { - service.register_vrexternal(ptr); - } WebVRThread { receiver: receiver, sender: sender, @@ -74,7 +68,7 @@ impl WebVRThread { pub fn spawn( vr_compositor_chan: WebVRCompositorSender, - webvr_shmem: Option, + service: VRServiceManager, ) -> (IpcSender, Sender>) { let (sender, receiver) = ipc::channel().unwrap(); let (constellation_sender, constellation_receiver) = unbounded(); @@ -88,7 +82,7 @@ impl WebVRThread { sender_clone, constellation_chan, vr_compositor_chan, - webvr_shmem, + service, ) .start(); }) diff --git a/components/webvr_traits/Cargo.toml b/components/webvr_traits/Cargo.toml index 614e104d5c3..7228e4e621d 100644 --- a/components/webvr_traits/Cargo.toml +++ b/components/webvr_traits/Cargo.toml @@ -13,5 +13,5 @@ path = "lib.rs" [dependencies] ipc-channel = "0.11" msg = {path = "../msg"} -rust-webvr-api = {version = "0.9", features = ["serde-serialization"]} +rust-webvr-api = {version = "0.10", features = ["serde-serialization"]} serde = "1.0" diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs index 7209f83d59d..f805951c2d2 100644 --- a/ports/libsimpleservo/api/src/lib.rs +++ b/ports/libsimpleservo/api/src/lib.rs @@ -18,6 +18,7 @@ use servo::script_traits::{MouseButton, TouchEventType, TouchId}; use servo::servo_config::opts; use servo::servo_config::prefs::{PrefValue, PREFS}; use servo::servo_url::ServoUrl; +use servo::webvr::{VRExternalShmemPtr, VRServiceManager}; use servo::{self, gl, webrender_api, BrowserId, Servo}; use std::cell::{Cell, RefCell}; use std::mem; @@ -535,8 +536,10 @@ impl WindowMethods for ServoCallbacks { } } - fn get_vrexternal_pointer(&self) -> Option<*mut c_void> { - self.vr_pointer.clone() + fn register_vr_services(&self, services: &mut VRServiceManager) { + if let Some(ptr) = self.vr_pointer { + services.register_vrexternal(VRExternalShmemPtr::new(ptr)); + } } }