mirror of
https://github.com/servo/servo.git
synced 2025-06-20 23:28:59 +01:00
Support creating and messaging mock display
This commit is contained in:
parent
c689866d35
commit
a89d2c6410
4 changed files with 30 additions and 1 deletions
|
@ -14,6 +14,7 @@ use script_traits::ConstellationMsg;
|
||||||
use servo_config::pref;
|
use servo_config::pref;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::sync::mpsc;
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
use webvr_traits::webvr::*;
|
use webvr_traits::webvr::*;
|
||||||
use webvr_traits::{WebVRMsg, WebVRPoseInformation, WebVRResult};
|
use webvr_traits::{WebVRMsg, WebVRPoseInformation, WebVRResult};
|
||||||
|
@ -46,6 +47,7 @@ pub struct WebVRThread {
|
||||||
vr_compositor_chan: WebVRCompositorSender,
|
vr_compositor_chan: WebVRCompositorSender,
|
||||||
polling_events: bool,
|
polling_events: bool,
|
||||||
presenting: HashMap<u32, PipelineId>,
|
presenting: HashMap<u32, PipelineId>,
|
||||||
|
mock: Option<mpsc::Sender<MockVRControlMsg>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebVRThread {
|
impl WebVRThread {
|
||||||
|
@ -65,6 +67,7 @@ impl WebVRThread {
|
||||||
vr_compositor_chan: vr_compositor_chan,
|
vr_compositor_chan: vr_compositor_chan,
|
||||||
polling_events: false,
|
polling_events: false,
|
||||||
presenting: HashMap::new(),
|
presenting: HashMap::new(),
|
||||||
|
mock: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +134,13 @@ impl WebVRThread {
|
||||||
WebVRMsg::GetGamepadsForDisplay(display_id, sender) => {
|
WebVRMsg::GetGamepadsForDisplay(display_id, sender) => {
|
||||||
self.handle_get_gamepads_for_display(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,
|
WebVRMsg::Exit => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,6 +312,22 @@ impl WebVRThread {
|
||||||
sender.send(Ok(data)).unwrap();
|
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>) {
|
fn poll_events(&mut self, sender: IpcSender<bool>) {
|
||||||
loop {
|
loop {
|
||||||
let events = self.service.poll_events();
|
let events = self.service.poll_events();
|
||||||
|
|
|
@ -13,5 +13,5 @@ path = "lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ipc-channel = "0.11"
|
ipc-channel = "0.11"
|
||||||
msg = {path = "../msg"}
|
msg = {path = "../msg"}
|
||||||
rust-webvr-api = {version = "0.11.3", features = ["ipc"]}
|
rust-webvr-api = {version = "0.11.1", features = ["ipc"]}
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
|
|
@ -11,6 +11,7 @@ mod webvr_traits;
|
||||||
|
|
||||||
pub use crate::webvr_traits::{WebVRMsg, WebVRResult};
|
pub use crate::webvr_traits::{WebVRMsg, WebVRResult};
|
||||||
pub use rust_webvr_api as webvr;
|
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::VRDisplayCapabilities as WebVRDisplayCapabilities;
|
||||||
pub use rust_webvr_api::VRDisplayData as WebVRDisplayData;
|
pub use rust_webvr_api::VRDisplayData as WebVRDisplayData;
|
||||||
pub use rust_webvr_api::VRDisplayEvent as WebVRDisplayEvent;
|
pub use rust_webvr_api::VRDisplayEvent as WebVRDisplayEvent;
|
||||||
|
|
|
@ -26,6 +26,8 @@ pub enum WebVRMsg {
|
||||||
RequestPresent(PipelineId, u32, IpcSender<WebVRResult<()>>),
|
RequestPresent(PipelineId, u32, IpcSender<WebVRResult<()>>),
|
||||||
ExitPresent(PipelineId, u32, Option<IpcSender<WebVRResult<()>>>),
|
ExitPresent(PipelineId, u32, Option<IpcSender<WebVRResult<()>>>),
|
||||||
CreateCompositor(u32),
|
CreateCompositor(u32),
|
||||||
|
CreateMockDisplay,
|
||||||
|
MessageMockDisplay(MockVRControlMsg),
|
||||||
GetGamepads(
|
GetGamepads(
|
||||||
Vec<u32>,
|
Vec<u32>,
|
||||||
IpcSender<WebVRResult<Vec<(Option<VRGamepadData>, VRGamepadState)>>>,
|
IpcSender<WebVRResult<Vec<(Option<VRGamepadData>, VRGamepadState)>>>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue