Auto merge of #22953 - asajeffrey:webvr-glwindow, r=paulrouget

Use a test VRDisplay that renders to a GL window

<!-- Please describe your changes on the following line: -->

Add a `dom.webvr.test` pref that registers a new VR display, which registers to a GL window.

The matching webvr PR is https://github.com/servo/rust-webvr/pull/66.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #22795
- [X] These changes do not require tests because we need a followup PR to support reftests which use the VR display

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22953)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-03-05 15:02:24 -05:00 committed by GitHub
commit 55347aa39f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 95 additions and 13 deletions

View file

@ -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_traits = {path = "../webvr_traits"}
webvr = {path = "../webvr"}
[build-dependencies]

View file

@ -43,6 +43,7 @@ use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor};
use time::{now, precise_time_ns, precise_time_s};
use webrender_api::{self, DeviceIntPoint, DevicePoint, HitTestFlags, HitTestResult};
use webrender_api::{LayoutVector2D, ScrollLocation};
use webvr_traits::WebVRMainThreadHeartbeat;
#[derive(Debug, PartialEq)]
enum UnableToComposite {
@ -176,6 +177,9 @@ pub struct IOCompositor<Window: WindowMethods> {
/// The webrender interface, if enabled.
webrender_api: webrender_api::RenderApi,
/// Some VR displays want to be sent a heartbeat from the main thread.
webvr_heartbeats: Vec<Box<dyn WebVRMainThreadHeartbeat>>,
/// Map of the pending paint metrics per layout thread.
/// The layout thread for each specific pipeline expects the compositor to
/// paint frames with specific given IDs (epoch). Once the compositor paints
@ -283,6 +287,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
webrender: state.webrender,
webrender_document: state.webrender_document,
webrender_api: state.webrender_api,
webvr_heartbeats: state.webvr_heartbeats,
pending_paint_metrics: HashMap::new(),
}
}
@ -919,7 +924,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
pipeline_ids.push(*pipeline_id);
}
}
let animation_state = if pipeline_ids.is_empty() {
let animation_state = if pipeline_ids.is_empty() && !self.webvr_heartbeats_racing() {
windowing::AnimationState::Idle
} else {
windowing::AnimationState::Animating
@ -930,6 +935,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
fn webvr_heartbeats_racing(&self) -> bool {
self.webvr_heartbeats.iter().any(|hb| hb.heart_racing())
}
fn tick_animations_for_pipeline(&mut self, pipeline_id: PipelineId) {
let animation_callbacks_running = self
.pipeline_details(pipeline_id)
@ -1345,6 +1354,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
CompositionRequest::CompositeNow(_) => self.composite(),
}
// Send every VR display that wants one a main-thread heartbeat
for webvr_heartbeat in &mut self.webvr_heartbeats {
webvr_heartbeat.heartbeat();
}
if !self.pending_scroll_zoom_events.is_empty() && !self.waiting_for_results_of_scroll {
self.process_pending_scroll_events()
}

View file

@ -18,6 +18,7 @@ use script_traits::{AnimationState, ConstellationMsg, EventResult};
use std::fmt::{Debug, Error, Formatter};
use style_traits::viewport::ViewportConstraints;
use webrender_api::{self, DeviceIntPoint, DeviceIntSize};
use webvr_traits::WebVRMainThreadHeartbeat;
/// Sends messages to the compositor.
pub struct CompositorProxy {
@ -153,4 +154,5 @@ pub struct InitialCompositorState {
pub webrender: webrender::Renderer,
pub webrender_document: webrender_api::DocumentId,
pub webrender_api: webrender_api::RenderApi,
pub webvr_heartbeats: Vec<Box<WebVRMainThreadHeartbeat>>,
}

View file

@ -19,6 +19,7 @@ use std::rc::Rc;
use style_traits::DevicePixel;
use webrender_api::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, ScrollLocation};
use webvr::VRServiceManager;
use webvr_traits::WebVRMainThreadHeartbeat;
#[derive(Clone)]
pub enum MouseWindowEvent {
@ -147,7 +148,12 @@ pub trait WindowMethods {
/// run the event loop at the vsync interval.
fn set_animation_state(&self, _state: AnimationState);
/// Register services with a VRServiceManager.
fn register_vr_services(&self, _: &mut VRServiceManager) {}
fn register_vr_services(
&self,
_: &mut VRServiceManager,
_: &mut Vec<Box<WebVRMainThreadHeartbeat>>,
) {
}
}
#[derive(Clone, Copy, Debug)]

View file

@ -258,10 +258,11 @@ where
// can't defer it after `create_constellation` has started.
script::init();
let mut webvr_heartbeats = Vec::new();
let webvr_services = if PREFS.is_webvr_enabled() {
let mut services = VRServiceManager::new();
services.register_defaults();
window.register_vr_services(&mut services);
window.register_vr_services(&mut services, &mut webvr_heartbeats);
Some(services)
} else {
None
@ -308,6 +309,7 @@ where
webrender,
webrender_document,
webrender_api,
webvr_heartbeats,
},
);

View file

@ -22,7 +22,7 @@ gleam = "0.6"
ipc-channel = "0.11"
log = "0.4"
msg = {path = "../msg"}
rust-webvr = {version = "0.10", features = ["openvr", "vrexternal"]}
rust-webvr = {version = "0.10.2", features = ["openvr", "vrexternal"]}
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}
webvr_traits = {path = "../webvr_traits" }

View file

@ -10,4 +10,5 @@ extern crate log;
mod webvr_thread;
pub use crate::webvr_thread::{WebVRCompositorHandler, WebVRThread};
pub use rust_webvr::api::VRExternalShmemPtr;
pub use rust_webvr::VRMainThreadHeartbeat;
pub use rust_webvr::VRServiceManager;

View file

@ -27,5 +27,6 @@ pub use rust_webvr_api::VRGamepadEvent as WebVRGamepadEvent;
pub use rust_webvr_api::VRGamepadHand as WebVRGamepadHand;
pub use rust_webvr_api::VRGamepadState as WebVRGamepadState;
pub use rust_webvr_api::VRLayer as WebVRLayer;
pub use rust_webvr_api::VRMainThreadHeartbeat as WebVRMainThreadHeartbeat;
pub use rust_webvr_api::VRPose as WebVRPose;
pub use rust_webvr_api::VRStageParameters as WebVRStageParameters;