Skip to content

Commit

Permalink
Added framebuffer and related attributes to XRWebGLLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Jul 18, 2019
1 parent dc1da02 commit aa0a72d
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions components/script/dom/bindings/error.rs
Expand Up @@ -84,6 +84,8 @@ pub enum Error {
InvalidModification,
/// NotReadableError DOMException
NotReadable,
/// OperationError DOMException
Operation,

/// TypeError JavaScript Error
Type(String),
Expand Down Expand Up @@ -136,6 +138,7 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: &GlobalScope, resu
Error::TypeMismatch => DOMErrorName::TypeMismatchError,
Error::InvalidModification => DOMErrorName::InvalidModificationError,
Error::NotReadable => DOMErrorName::NotReadableError,
Error::Operation => DOMErrorName::OperationError,
Error::Type(message) => {
assert!(!JS_IsExceptionPending(cx));
throw_type_error(cx, &message);
Expand Down
11 changes: 9 additions & 2 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -57,8 +57,8 @@ use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
use encoding_rs::{Decoder, Encoding};
use euclid::Length as EuclidLength;
use euclid::{
Point2D, Rect, RigidTransform3D, Rotation3D, Transform2D, Transform3D, TypedRigidTransform3D,
TypedScale, TypedSize2D, Vector2D,
Point2D, Rect, RigidTransform3D, Rotation3D, Transform2D, Transform3D, TypedRect,
TypedRigidTransform3D, TypedScale, TypedSize2D, Vector2D,
};
use html5ever::buffer_queue::BufferQueue;
use html5ever::{LocalName, Namespace, Prefix, QualName};
Expand Down Expand Up @@ -647,6 +647,13 @@ unsafe impl<U> JSTraceable for TypedSize2D<u32, U> {
}
}

unsafe impl<U> JSTraceable for TypedRect<i32, U> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}

unsafe impl JSTraceable for StyleLocked<FontFaceRule> {
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing.
Expand Down
5 changes: 5 additions & 0 deletions components/script/dom/domexception.rs
Expand Up @@ -37,6 +37,7 @@ pub enum DOMErrorName {
InvalidNodeTypeError = DOMExceptionConstants::INVALID_NODE_TYPE_ERR,
DataCloneError = DOMExceptionConstants::DATA_CLONE_ERR,
NotReadableError = DOMExceptionConstants::NOT_READABLE_ERR,
OperationError = DOMExceptionConstants::OPERATION_ERR,
}

impl DOMErrorName {
Expand Down Expand Up @@ -64,6 +65,7 @@ impl DOMErrorName {
"InvalidNodeTypeError" => Some(DOMErrorName::InvalidNodeTypeError),
"DataCloneError" => Some(DOMErrorName::DataCloneError),
"NotReadableError" => Some(DOMErrorName::NotReadableError),
"OperationError" => Some(DOMErrorName::OperationError),
_ => None,
}
}
Expand Down Expand Up @@ -107,6 +109,9 @@ impl DOMException {
},
DOMErrorName::DataCloneError => "The object can not be cloned.",
DOMErrorName::NotReadableError => "The I/O read operation failed.",
DOMErrorName::OperationError => {
"The operation failed for an operation-specific reason."
},
};

(
Expand Down
12 changes: 12 additions & 0 deletions components/script/dom/fakexrdevice.rs
Expand Up @@ -11,6 +11,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::{TypedPoint2D, TypedRect, TypedSize2D};
use euclid::{TypedRigidTransform3D, TypedRotation3D, TypedTransform3D, TypedVector3D};
use ipc_channel::ipc::IpcSender;
use webxr_api::{MockDeviceMsg, View, Views};
Expand Down Expand Up @@ -71,13 +72,24 @@ pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<Views> {
let offset_l = get_origin(&left.viewOffset)?.inverse();
let offset_r = get_origin(&right.viewOffset)?.inverse();

let size_l = TypedSize2D::new(views[0].resolution.width, views[0].resolution.height);
let size_r = TypedSize2D::new(views[1].resolution.width, views[1].resolution.height);

let origin_l = TypedPoint2D::new(0, 0);
let origin_r = TypedPoint2D::new(size_l.width, 0);

let viewport_l = TypedRect::new(origin_l, size_l);
let viewport_r = TypedRect::new(origin_r, size_r);

let left = View {
projection: proj_l,
transform: offset_l,
viewport: viewport_l,
};
let right = View {
projection: proj_r,
transform: offset_r,
viewport: viewport_r,
};
Ok(Views::Stereo(left, right))
}
Expand Down
3 changes: 3 additions & 0 deletions components/script/dom/webidls/DOMException.webidl
Expand Up @@ -38,7 +38,10 @@ interface DOMException {
const unsigned short TIMEOUT_ERR = 23;
const unsigned short INVALID_NODE_TYPE_ERR = 24;
const unsigned short DATA_CLONE_ERR = 25;
// Only the first 25 errors are given codes in
// https://heycam.github.io/webidl/#idl-DOMException
const unsigned short NOT_READABLE_ERR = 26;
const unsigned short OPERATION_ERR = 27;

// Error code as u16
readonly attribute unsigned short code;
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/webidls/XRWebGLLayer.webidl
Expand Up @@ -30,9 +30,9 @@ interface XRWebGLLayer : XRLayer {
readonly attribute boolean stencil;
readonly attribute boolean alpha;

// readonly attribute WebGLFramebuffer framebuffer;
// readonly attribute unsigned long framebufferWidth;
// readonly attribute unsigned long framebufferHeight;
readonly attribute WebGLFramebuffer framebuffer;
readonly attribute unsigned long framebufferWidth;
readonly attribute unsigned long framebufferHeight;

// // Methods
XRViewport? getViewport(XRView view);
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/xrsession.rs
Expand Up @@ -103,7 +103,7 @@ impl XRSession {
ret
}

pub fn with_session<F: FnOnce(&Session)>(&self, with: F) {
pub fn with_session<R, F: FnOnce(&Session) -> R>(&self, with: F) -> R {
let session = self.session.borrow();
with(&session)
}
Expand Down
32 changes: 11 additions & 21 deletions components/script/dom/xrviewport.rs
Expand Up @@ -8,36 +8,26 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::TypedRect;
use webxr_api::Viewport;

#[dom_struct]
pub struct XRViewport {
reflector_: Reflector,
x: u32,
y: u32,
width: u32,
height: u32,
viewport: TypedRect<i32, Viewport>,
}

impl XRViewport {
fn new_inherited(x: u32, y: u32, width: u32, height: u32) -> XRViewport {
fn new_inherited(viewport: TypedRect<i32, Viewport>) -> XRViewport {
XRViewport {
reflector_: Reflector::new(),
x,
y,
width,
height,
viewport,
}
}

pub fn new(
global: &GlobalScope,
x: u32,
y: u32,
width: u32,
height: u32,
) -> DomRoot<XRViewport> {
pub fn new(global: &GlobalScope, viewport: TypedRect<i32, Viewport>) -> DomRoot<XRViewport> {
reflect_dom_object(
Box::new(XRViewport::new_inherited(x, y, width, height)),
Box::new(XRViewport::new_inherited(viewport)),
global,
XRViewportBinding::Wrap,
)
Expand All @@ -47,21 +37,21 @@ impl XRViewport {
impl XRViewportMethods for XRViewport {
/// https://immersive-web.github.io/webxr/#dom-xrviewport-x
fn X(&self) -> i32 {
self.x as i32
self.viewport.origin.x
}

/// https://immersive-web.github.io/webxr/#dom-xrviewport-y
fn Y(&self) -> i32 {
self.y as i32
self.viewport.origin.y
}

/// https://immersive-web.github.io/webxr/#dom-xrviewport-width
fn Width(&self) -> i32 {
self.width as i32
self.viewport.size.width
}

/// https://immersive-web.github.io/webxr/#dom-xrviewport-height
fn Height(&self) -> i32 {
self.height as i32
self.viewport.size.height
}
}

0 comments on commit aa0a72d

Please sign in to comment.