Skip to content

Commit

Permalink
Allow the embedder to register their own VRServices
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Feb 14, 2019
1 parent c80c3f3 commit a062c40
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 45 deletions.
15 changes: 8 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions components/compositing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 3 additions & 6 deletions components/compositing/windowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand Down
44 changes: 25 additions & 19 deletions components/servo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -515,7 +520,7 @@ fn create_constellation(
webrender_document: webrender_api::DocumentId,
webrender_api_sender: webrender_api::RenderApiSender,
window_gl: Rc<dyn gl::Gl>,
webvr_shmem: Option<VRExternalShmemPtr>,
webvr_services: Option<VRServiceManager>,
) -> (Sender<ConstellationMsg>, SWManagerSenders) {
let bluetooth_thread: IpcSender<BluetoothRequest> =
BluetoothThreadFactory::new(embedder_proxy.clone());
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion components/webvr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions components/webvr/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 3 additions & 9 deletions components/webvr/webvr_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,13 +52,8 @@ impl WebVRThread {
sender: IpcSender<WebVRMsg>,
constellation_chan: Sender<ConstellationMsg>,
vr_compositor_chan: WebVRCompositorSender,
webvr_shmem: Option<VRExternalShmemPtr>,
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,
Expand All @@ -74,7 +68,7 @@ impl WebVRThread {

pub fn spawn(
vr_compositor_chan: WebVRCompositorSender,
webvr_shmem: Option<VRExternalShmemPtr>,
service: VRServiceManager,
) -> (IpcSender<WebVRMsg>, Sender<Sender<ConstellationMsg>>) {
let (sender, receiver) = ipc::channel().unwrap();
let (constellation_sender, constellation_receiver) = unbounded();
Expand All @@ -88,7 +82,7 @@ impl WebVRThread {
sender_clone,
constellation_chan,
vr_compositor_chan,
webvr_shmem,
service,
)
.start();
})
Expand Down
2 changes: 1 addition & 1 deletion components/webvr_traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 5 additions & 2 deletions ports/libsimpleservo/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
}

Expand Down

0 comments on commit a062c40

Please sign in to comment.