Auto merge of #22940 - asajeffrey:webvr-start-stop, r=Manishearth

Call start_present and stop_present on VRDisplay

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

We never call `start_present` or `stop_present` on `VRDisplay`s. Not calling `start_present` isn't so bad, since displays can keep track of their own state, but not calling `stop_present` means the display never gets told to reclaim resources.

---
<!-- 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 #22924
- [X] These changes do not require tests because it's all internal APIs

<!-- 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/22940)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-02-26 00:41:35 -05:00 committed by GitHub
commit 694a1ed2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ use msg::constellation_msg::PipelineId;
use rust_webvr::VRServiceManager; use rust_webvr::VRServiceManager;
use script_traits::ConstellationMsg; use script_traits::ConstellationMsg;
use servo_config::prefs::PREFS; use servo_config::prefs::PREFS;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::{thread, time}; use std::{thread, time};
use webvr_traits::webvr::*; use webvr_traits::webvr::*;
@ -378,7 +379,9 @@ impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
fn handle(&mut self, cmd: webgl::WebVRCommand, texture: Option<(u32, Size2D<i32>)>) { fn handle(&mut self, cmd: webgl::WebVRCommand, texture: Option<(u32, Size2D<i32>)>) {
match cmd { match cmd {
webgl::WebVRCommand::Create(compositor_id) => { webgl::WebVRCommand::Create(compositor_id) => {
self.create_compositor(compositor_id); if let Some(compositor) = self.create_compositor(compositor_id) {
unsafe { (*compositor.0).start_present(None) };
}
}, },
webgl::WebVRCommand::SyncPoses(compositor_id, near, far, sender) => { webgl::WebVRCommand::SyncPoses(compositor_id, near, far, sender) => {
if let Some(compositor) = self.compositors.get(&compositor_id) { if let Some(compositor) = self.compositors.get(&compositor_id) {
@ -408,7 +411,9 @@ impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
} }
}, },
webgl::WebVRCommand::Release(compositor_id) => { webgl::WebVRCommand::Release(compositor_id) => {
self.compositors.remove(&compositor_id); if let Some(compositor) = self.compositors.remove(&compositor_id) {
unsafe { (*compositor.0).stop_present() };
}
}, },
} }
} }
@ -416,10 +421,13 @@ impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
impl WebVRCompositorHandler { impl WebVRCompositorHandler {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn create_compositor(&mut self, display_id: webgl::WebVRDeviceId) { fn create_compositor(
&mut self,
display_id: webgl::WebVRDeviceId,
) -> Option<&mut WebVRCompositor> {
let sender = match self.webvr_thread_sender { let sender = match self.webvr_thread_sender {
Some(ref s) => s, Some(ref s) => s,
None => return, None => return None,
}; };
sender sender
@ -428,13 +436,14 @@ impl WebVRCompositorHandler {
let display = self.webvr_thread_receiver.recv().unwrap(); let display = self.webvr_thread_receiver.recv().unwrap();
match display { match display {
Some(display) => { Some(display) => match self.compositors.entry(display_id) {
self.compositors.insert(display_id, display); Entry::Vacant(entry) => return Some(entry.insert(display)),
}, Entry::Occupied(_) => error!("VRDisplay already presenting"),
None => {
error!("VRDisplay not found when creating a new VRCompositor");
}, },
None => error!("VRDisplay not found when creating a new VRCompositor"),
}; };
None
} }
// This is done on only a per-platform basis on initialization. // This is done on only a per-platform basis on initialization.