aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-05-29 15:42:07 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-05-30 19:04:08 -0700
commita89d2c64103f19ab7de16f09599ca526583926af (patch)
tree4a4b6331964e41d72a5680306fe464498b959fbe
parentc689866d3545c5adadcdbf19362894faf52d660e (diff)
downloadservo-a89d2c64103f19ab7de16f09599ca526583926af.tar.gz
servo-a89d2c64103f19ab7de16f09599ca526583926af.zip
Support creating and messaging mock display
-rw-r--r--components/webvr/webvr_thread.rs26
-rw-r--r--components/webvr_traits/Cargo.toml2
-rw-r--r--components/webvr_traits/lib.rs1
-rw-r--r--components/webvr_traits/webvr_traits.rs2
4 files changed, 30 insertions, 1 deletions
diff --git a/components/webvr/webvr_thread.rs b/components/webvr/webvr_thread.rs
index e90ddbf7df5..2cd4c81ab35 100644
--- a/components/webvr/webvr_thread.rs
+++ b/components/webvr/webvr_thread.rs
@@ -14,6 +14,7 @@ use script_traits::ConstellationMsg;
use servo_config::pref;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
+use std::sync::mpsc;
use std::{thread, time};
use webvr_traits::webvr::*;
use webvr_traits::{WebVRMsg, WebVRPoseInformation, WebVRResult};
@@ -46,6 +47,7 @@ pub struct WebVRThread {
vr_compositor_chan: WebVRCompositorSender,
polling_events: bool,
presenting: HashMap<u32, PipelineId>,
+ mock: Option<mpsc::Sender<MockVRControlMsg>>,
}
impl WebVRThread {
@@ -65,6 +67,7 @@ impl WebVRThread {
vr_compositor_chan: vr_compositor_chan,
polling_events: false,
presenting: HashMap::new(),
+ mock: None,
}
}
@@ -131,6 +134,13 @@ impl WebVRThread {
WebVRMsg::GetGamepadsForDisplay(display_id, sender) => {
self.handle_get_gamepads_for_display(display_id, sender);
},
+
+ WebVRMsg::CreateMockDisplay => {
+ self.handle_create_mock();
+ },
+ WebVRMsg::MessageMockDisplay(msg) => {
+ self.handle_message_mock_display(msg);
+ },
WebVRMsg::Exit => break,
}
}
@@ -302,6 +312,22 @@ impl WebVRThread {
sender.send(Ok(data)).unwrap();
}
+ fn handle_create_mock(&mut self) {
+ if self.mock.is_some() {
+ warn!("Mock display already created");
+ return;
+ }
+ self.mock = Some(self.service.register_mock_with_remote());
+ }
+
+ fn handle_message_mock_display(&mut self, msg: MockVRControlMsg) {
+ self.mock
+ .as_ref()
+ .expect("Mock Display not yet set up")
+ .send(msg)
+ .expect("Could not send message to mock display");
+ }
+
fn poll_events(&mut self, sender: IpcSender<bool>) {
loop {
let events = self.service.poll_events();
diff --git a/components/webvr_traits/Cargo.toml b/components/webvr_traits/Cargo.toml
index 9d4dc375d5c..72a7e632fd3 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.11.3", features = ["ipc"]}
+rust-webvr-api = {version = "0.11.1", features = ["ipc"]}
serde = "1.0"
diff --git a/components/webvr_traits/lib.rs b/components/webvr_traits/lib.rs
index f96fee056e7..d5d99f98a3b 100644
--- a/components/webvr_traits/lib.rs
+++ b/components/webvr_traits/lib.rs
@@ -11,6 +11,7 @@ mod webvr_traits;
pub use crate::webvr_traits::{WebVRMsg, WebVRResult};
pub use rust_webvr_api as webvr;
+pub use rust_webvr_api::MockVRControlMsg;
pub use rust_webvr_api::VRDisplayCapabilities as WebVRDisplayCapabilities;
pub use rust_webvr_api::VRDisplayData as WebVRDisplayData;
pub use rust_webvr_api::VRDisplayEvent as WebVRDisplayEvent;
diff --git a/components/webvr_traits/webvr_traits.rs b/components/webvr_traits/webvr_traits.rs
index d21e6c3ff16..3123c8b5faf 100644
--- a/components/webvr_traits/webvr_traits.rs
+++ b/components/webvr_traits/webvr_traits.rs
@@ -26,6 +26,8 @@ pub enum WebVRMsg {
RequestPresent(PipelineId, u32, IpcSender<WebVRResult<()>>),
ExitPresent(PipelineId, u32, Option<IpcSender<WebVRResult<()>>>),
CreateCompositor(u32),
+ CreateMockDisplay,
+ MessageMockDisplay(MockVRControlMsg),
GetGamepads(
Vec<u32>,
IpcSender<WebVRResult<Vec<(Option<VRGamepadData>, VRGamepadState)>>>,