Auto merge of #17031 - MortimerGoro:update_webvr, r=emilio

Update rust-webvr

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

Required for https://github.com/servo/servo/issues/16556

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/17031)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-25 07:12:11 -05:00 committed by GitHub
commit 3c267d7fdd
7 changed files with 58 additions and 13 deletions

View file

@ -152,6 +152,13 @@ impl VR {
WebVRDisplayEvent::Change(ref display) => {
let display = self.sync_display(&display);
display.handle_webvr_event(&event);
},
WebVRDisplayEvent::Pause(id) |
WebVRDisplayEvent::Resume(id) |
WebVRDisplayEvent::Exit(id) => {
if let Some(display) = self.find_display(id) {
display.handle_webvr_event(&event);
}
}
};
}

View file

@ -71,7 +71,9 @@ pub struct VRDisplay {
frame_data_status: Cell<VRFrameDataStatus>,
#[ignore_heap_size_of = "channels are hard"]
frame_data_receiver: DOMRefCell<Option<IpcReceiver<Result<Vec<u8>, ()>>>>,
running_display_raf: Cell<bool>
running_display_raf: Cell<bool>,
paused: Cell<bool>,
stopped_on_pause: Cell<bool>,
}
unsafe_no_jsmanaged_fields!(WebVRDisplayData);
@ -112,6 +114,12 @@ impl VRDisplay {
frame_data_status: Cell::new(VRFrameDataStatus::Waiting),
frame_data_receiver: DOMRefCell::new(None),
running_display_raf: Cell::new(false),
// Some VR implementations (e.g. Daydream) can be paused in some life cycle situations
// such as showing and hiding the controller pairing screen.
paused: Cell::new(false),
// This flag is set when the Display was presenting when it received a VR Pause event.
// When the VR Resume event is received and the flag is set, VR presentation automatically restarts.
stopped_on_pause: Cell::new(false)
}
}
@ -428,6 +436,30 @@ impl VRDisplay {
// Change event doesn't exist in WebVR spec.
// So we update display data but don't notify JS.
self.update_display(&display);
},
WebVRDisplayEvent::Pause(_) => {
if self.paused.get() {
return;
}
self.paused.set(true);
if self.presenting.get() {
self.stop_present();
self.stopped_on_pause.set(true);
}
},
WebVRDisplayEvent::Resume(_) => {
self.paused.set(false);
if self.stopped_on_pause.get() {
self.stopped_on_pause.set(false);
self.init_present();
}
},
WebVRDisplayEvent::Exit(_) => {
self.stopped_on_pause.set(false);
if self.presenting.get() {
self.stop_present();
}
}
};
}

View file

@ -66,7 +66,12 @@ impl VRDisplayEvent {
WebVRDisplayEvent::Blur(_) => ("blur", None),
WebVRDisplayEvent::Focus(_) => ("focus", None),
WebVRDisplayEvent::PresentChange(_, _) => ("presentchange", None),
WebVRDisplayEvent::Change(_) => panic!("VRDisplayEvent:Change event not available in WebVR")
WebVRDisplayEvent::Change(_) |
WebVRDisplayEvent::Pause(_) |
WebVRDisplayEvent::Resume(_) |
WebVRDisplayEvent::Exit(_) => {
panic!("{:?} event not available in WebVR", event)
}
};
// map to JS enum values