Skip to content

Commit

Permalink
Add active and animationFrame flags to XRFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jul 11, 2019
1 parent 7a8640e commit 0b88c56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions components/script/dom/xrframe.rs
Expand Up @@ -15,6 +15,7 @@ use crate::dom::xrsession::XRSession;
use crate::dom::xrspace::XRSpace;
use crate::dom::xrviewerpose::XRViewerPose;
use dom_struct::dom_struct;
use std::cell::Cell;
use webxr_api::Frame;

#[dom_struct]
Expand All @@ -23,6 +24,8 @@ pub struct XRFrame {
session: Dom<XRSession>,
#[ignore_malloc_size_of = "defined in rust-webvr"]
data: Frame,
active: Cell<bool>,
animation_frame: Cell<bool>,
}

impl XRFrame {
Expand All @@ -31,6 +34,8 @@ impl XRFrame {
reflector_: Reflector::new(),
session: Dom::from_ref(session),
data,
active: Cell::new(false),
animation_frame: Cell::new(false),
}
}

Expand All @@ -41,6 +46,16 @@ impl XRFrame {
XRFrameBinding::Wrap,
)
}

/// https://immersive-web.github.io/webxr/#xrframe-active
pub fn set_active(&self, active: bool) {
self.active.set(active);
}

/// https://immersive-web.github.io/webxr/#xrframe-animationframe
pub fn set_animation_frame(&self, animation_frame: bool) {
self.animation_frame.set(animation_frame);
}
}

impl XRFrameMethods for XRFrame {
Expand All @@ -57,6 +72,11 @@ impl XRFrameMethods for XRFrame {
if self.session != reference.upcast::<XRSpace>().session() {
return Err(Error::InvalidState);
}

if !self.active.get() || !self.animation_frame.get() {
return Err(Error::InvalidState);
}

let pose = reference.get_viewer_pose(&self.data);
Ok(Some(XRViewerPose::new(&self.global(), &self.session, pose)))
}
Expand All @@ -70,6 +90,9 @@ impl XRFrameMethods for XRFrame {
if self.session != space.session() || self.session != relative_to.session() {
return Err(Error::InvalidState);
}
if !self.active.get() {
return Err(Error::InvalidState);
}
let space = space.get_pose(&self.data);
let relative_to = relative_to.get_pose(&self.data);
let pose = relative_to.inverse().pre_mul(&space);
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/xrsession.rs
Expand Up @@ -140,7 +140,9 @@ impl XRSession {
let mut callbacks = mem::replace(&mut *self.raf_callback_list.borrow_mut(), vec![]);

let frame = XRFrame::new(&self.global(), self, frame);
// Step 6-7: XXXManishearth set `active`/`animationFrame` bools on `frame` to true
// Step 6,7
frame.set_active(true);
frame.set_animation_frame(true);

// Step 8
for (_, callback) in callbacks.drain(..) {
Expand Down

0 comments on commit 0b88c56

Please sign in to comment.