Support attaching RAF callbacks

This commit is contained in:
Manish Goregaokar 2018-12-21 15:49:39 -08:00
parent 28dff81dbf
commit 1b11a3063c
3 changed files with 34 additions and 4 deletions

View file

@ -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

View file

@ -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();

View file

@ -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)
}
}