diff options
-rw-r--r-- | components/script/dom/vrdisplay.rs | 24 | ||||
-rw-r--r-- | components/script/dom/webidls/XRSession.webidl | 4 | ||||
-rw-r--r-- | components/script/dom/xrsession.rs | 10 |
3 files changed, 34 insertions, 4 deletions
diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs index 39bea7170dc..741cdd4818c 100644 --- a/components/script/dom/vrdisplay.rs +++ b/components/script/dom/vrdisplay.rs @@ -5,14 +5,15 @@ use canvas_traits::webgl::{webgl_channel, WebGLReceiver, WebVRCommand}; use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::cell::DomRefCell; -use crate::dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceBinding::PerformanceMethods; +use crate::dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use crate::dom::bindings::codegen::Bindings::VRDisplayBinding; use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods; use crate::dom::bindings::codegen::Bindings::VRDisplayBinding::VREye; use crate::dom::bindings::codegen::Bindings::VRLayerBinding::VRLayer; use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::FrameRequestCallback; -use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; +use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRFrameRequestCallback; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::num::Finite; use crate::dom::bindings::refcounted::Trusted; @@ -67,6 +68,8 @@ pub struct VRDisplay { /// List of request animation frame callbacks #[ignore_malloc_size_of = "closures are hard"] raf_callback_list: DomRefCell<Vec<(u32, Option<Rc<FrameRequestCallback>>)>>, + #[ignore_malloc_size_of = "closures are hard"] + xr_raf_callback_list: DomRefCell<Vec<(u32, Option<Rc<XRFrameRequestCallback>>)>>, // Compositor VRFrameData synchonization frame_data_status: Cell<VRFrameDataStatus>, #[ignore_malloc_size_of = "closures are hard"] @@ -122,6 +125,7 @@ impl VRDisplay { layer_ctx: MutNullableDom::default(), next_raf_id: Cell::new(1), raf_callback_list: DomRefCell::new(vec![]), + xr_raf_callback_list: DomRefCell::new(vec![]), frame_data_status: Cell::new(VRFrameDataStatus::Waiting), frame_data_receiver: DomRefCell::new(None), running_display_raf: Cell::new(false), @@ -692,6 +696,22 @@ impl VRDisplay { self.init_present(); } } + + pub fn xr_raf(&self, callback: Rc<XRFrameRequestCallback>) -> u32 { + let raf_id = self.next_raf_id.get(); + self.next_raf_id.set(raf_id + 1); + self.xr_raf_callback_list + .borrow_mut() + .push((raf_id, Some(callback))); + raf_id + } + + pub fn xr_cancel_raf(&self, handle: i32) { + let mut list = self.xr_raf_callback_list.borrow_mut(); + if let Some(pair) = list.iter_mut().find(|pair| pair.0 == handle as u32) { + pair.1 = None; + } + } } // WebVR Spec: If the number of values in the leftBounds/rightBounds arrays diff --git a/components/script/dom/webidls/XRSession.webidl b/components/script/dom/webidls/XRSession.webidl index 546a7dcab2f..6a3a2e52c1f 100644 --- a/components/script/dom/webidls/XRSession.webidl +++ b/components/script/dom/webidls/XRSession.webidl @@ -27,8 +27,8 @@ callback XRFrameRequestCallback = void (DOMHighResTimeStamp time, XRFrame frame) // FrozenArray<XRInputSource> getInputSources(); - // long requestAnimationFrame(XRFrameRequestCallback callback); - // void cancelAnimationFrame(long handle); + long requestAnimationFrame(XRFrameRequestCallback callback); + void cancelAnimationFrame(long handle); // Promise<void> end(); diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index c652b80a3f9..ac19b825d4c 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -4,6 +4,7 @@ use crate::dom::bindings::codegen::Bindings::XRBinding::XRSessionMode; use crate::dom::bindings::codegen::Bindings::XRSessionBinding; +use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRFrameRequestCallback; use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRSessionMethods; use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerMethods; use crate::dom::bindings::inheritance::Castable; @@ -17,6 +18,7 @@ use crate::dom::xrlayer::XRLayer; use crate::dom::xrwebgllayer::XRWebGLLayer; use dom_struct::dom_struct; use std::cell::Cell; +use std::rc::Rc; #[dom_struct] pub struct XRSession { @@ -82,4 +84,12 @@ impl XRSessionMethods for XRSession { fn GetBaseLayer(&self) -> Option<DomRoot<XRLayer>> { self.base_layer.get() } + + fn RequestAnimationFrame(&self, callback: Rc<XRFrameRequestCallback>) -> i32 { + self.display.xr_raf(callback) as i32 + } + + fn CancelAnimationFrame(&self, frame: i32) { + self.display.xr_cancel_raf(frame) + } } |