diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/vr.rs | 7 | ||||
-rw-r--r-- | components/script/dom/vrdisplay.rs | 34 | ||||
-rw-r--r-- | components/script/dom/vrdisplayevent.rs | 7 |
3 files changed, 46 insertions, 2 deletions
diff --git a/components/script/dom/vr.rs b/components/script/dom/vr.rs index 9497405e8c9..d906d0e9964 100644 --- a/components/script/dom/vr.rs +++ b/components/script/dom/vr.rs @@ -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); + } } }; } diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs index b9b65264c44..da5c12e8c54 100644 --- a/components/script/dom/vrdisplay.rs +++ b/components/script/dom/vrdisplay.rs @@ -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(); + } } }; } diff --git a/components/script/dom/vrdisplayevent.rs b/components/script/dom/vrdisplayevent.rs index 956229ead4c..4db24687dcc 100644 --- a/components/script/dom/vrdisplayevent.rs +++ b/components/script/dom/vrdisplayevent.rs @@ -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 |