Support creating and messaging mock display

This commit is contained in:
Manish Goregaokar 2019-05-29 15:42:07 -07:00
parent c689866d35
commit a89d2c6410
4 changed files with 30 additions and 1 deletions

View file

@ -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();

View file

@ -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"

View file

@ -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;

View file

@ -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)>>>,