mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Support for ExternalVR implementation
This commit is contained in:
parent
b7e9bab267
commit
c055b74e13
11 changed files with 66 additions and 13 deletions
|
@ -14,6 +14,7 @@ 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;
|
||||
|
@ -145,6 +146,11 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
|
|
@ -107,7 +107,7 @@ use std::cmp::max;
|
|||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use webrender::{RendererKind, ShaderPrecacheFlags};
|
||||
use webvr::{WebVRCompositorHandler, WebVRThread};
|
||||
use webvr::{VRExternalShmemPtr, WebVRCompositorHandler, WebVRThread};
|
||||
|
||||
pub use gleam::gl;
|
||||
pub use msg::constellation_msg::TopLevelBrowsingContextId as BrowserId;
|
||||
|
@ -216,6 +216,10 @@ where
|
|||
// can't defer it after `create_constellation` has started.
|
||||
script::init();
|
||||
|
||||
let webvr_shmem = window
|
||||
.get_vrexternal_pointer()
|
||||
.map(|ptr| VRExternalShmemPtr::new(ptr));
|
||||
|
||||
// Create the constellation, which maintains the engine
|
||||
// pipelines, including the script and layout threads, as well
|
||||
// as the navigation context.
|
||||
|
@ -232,6 +236,7 @@ where
|
|||
webrender_document,
|
||||
webrender_api_sender,
|
||||
window.gl(),
|
||||
webvr_shmem,
|
||||
);
|
||||
|
||||
// Send the constellation's swmanager sender to service worker manager thread
|
||||
|
@ -510,6 +515,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>,
|
||||
) -> (Sender<ConstellationMsg>, SWManagerSenders) {
|
||||
let bluetooth_thread: IpcSender<BluetoothRequest> =
|
||||
BluetoothThreadFactory::new(embedder_proxy.clone());
|
||||
|
@ -532,7 +538,7 @@ fn create_constellation(
|
|||
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);
|
||||
let (webvr_thread, constellation_sender) = WebVRThread::spawn(sender, webvr_shmem);
|
||||
handler.set_webvr_thread_sender(webvr_thread.clone());
|
||||
(
|
||||
Some(webvr_thread),
|
||||
|
|
|
@ -21,7 +21,7 @@ euclid = "0.19"
|
|||
ipc-channel = "0.11"
|
||||
log = "0.4"
|
||||
msg = {path = "../msg"}
|
||||
rust-webvr = {version = "0.9", features = ["openvr"]}
|
||||
rust-webvr = {version = "0.9", features = ["openvr", "vrexternal"]}
|
||||
script_traits = {path = "../script_traits"}
|
||||
servo_config = {path = "../config"}
|
||||
webvr_traits = {path = "../webvr_traits" }
|
||||
|
|
|
@ -9,3 +9,4 @@ extern crate log;
|
|||
|
||||
mod webvr_thread;
|
||||
pub use crate::webvr_thread::{WebVRCompositorHandler, WebVRThread};
|
||||
pub use rust_webvr::api::VRExternalShmemPtr;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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;
|
||||
|
@ -52,9 +53,13 @@ impl WebVRThread {
|
|||
sender: IpcSender<WebVRMsg>,
|
||||
constellation_chan: Sender<ConstellationMsg>,
|
||||
vr_compositor_chan: WebVRCompositorSender,
|
||||
webvr_shmem: Option<VRExternalShmemPtr>,
|
||||
) -> WebVRThread {
|
||||
let mut service = VRServiceManager::new();
|
||||
service.register_defaults();
|
||||
if let Some(ptr) = webvr_shmem {
|
||||
service.register_vrexternal(ptr);
|
||||
}
|
||||
WebVRThread {
|
||||
receiver: receiver,
|
||||
sender: sender,
|
||||
|
@ -69,6 +74,7 @@ impl WebVRThread {
|
|||
|
||||
pub fn spawn(
|
||||
vr_compositor_chan: WebVRCompositorSender,
|
||||
webvr_shmem: Option<VRExternalShmemPtr>,
|
||||
) -> (IpcSender<WebVRMsg>, Sender<Sender<ConstellationMsg>>) {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
let (constellation_sender, constellation_receiver) = unbounded();
|
||||
|
@ -82,6 +88,7 @@ impl WebVRThread {
|
|||
sender_clone,
|
||||
constellation_chan,
|
||||
vr_compositor_chan,
|
||||
webvr_shmem,
|
||||
)
|
||||
.start();
|
||||
})
|
||||
|
@ -157,7 +164,7 @@ impl WebVRThread {
|
|||
) {
|
||||
match self.access_check(pipeline, display_id) {
|
||||
Ok(display) => sender
|
||||
.send(Ok(display.borrow().inmediate_frame_data(near, far)))
|
||||
.send(Ok(display.borrow().immediate_frame_data(near, far)))
|
||||
.unwrap(),
|
||||
Err(msg) => sender.send(Err(msg.into())).unwrap(),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue