forked from servo/servo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af1cd38
commit 9e2f5f1
Showing
21 changed files
with
518 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use canvas_traits::webgl::{WebGLFramebufferId, WebGLMsg, WebGLMsgSender, WebVRCommand, WebVRDeviceId}; | ||
use dom::bindings::codegen::Bindings::VRViewBinding; | ||
use dom::bindings::codegen::Bindings::VRViewBinding::{VRAttributes, VRViewMethods, VRViewport}; | ||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; | ||
use dom::bindings::root::{MutNullableDom, DomRoot}; | ||
use dom::globalscope::GlobalScope; | ||
use dom_struct::dom_struct; | ||
use dom::webglframebuffer::{OpaqueFBOMessages, WebGLFramebuffer}; | ||
use webvr_traits::WebVRFramebuffer; | ||
|
||
#[dom_struct] | ||
pub struct VRView { | ||
reflector_: Reflector, | ||
renderer: WebGLMsgSender, | ||
device_id: WebVRDeviceId, | ||
#[ignore_malloc_size_of = "Defined in rust-webvr"] | ||
fbo: WebVRFramebuffer, | ||
webgl_fbo: MutNullableDom<WebGLFramebuffer>, | ||
} | ||
|
||
impl VRView { | ||
fn new_inherited(renderer: WebGLMsgSender, | ||
device_id: WebVRDeviceId, | ||
fbo: WebVRFramebuffer) -> VRView { | ||
VRView { | ||
reflector_: Reflector::new(), | ||
renderer, | ||
device_id, | ||
fbo, | ||
webgl_fbo: Default::default(), | ||
} | ||
} | ||
|
||
pub fn new(global: &GlobalScope, | ||
renderer: WebGLMsgSender, | ||
device_id: WebVRDeviceId, | ||
fbo: WebVRFramebuffer) -> DomRoot<VRView> { | ||
reflect_dom_object(Box::new(VRView::new_inherited(renderer, device_id, fbo)), | ||
global, | ||
VRViewBinding::Wrap) | ||
} | ||
} | ||
|
||
impl VRViewMethods for VRView { | ||
// https://w3c.github.io/webvr/#interface-interface-vrfieldofview | ||
#[allow(unsafe_code)] | ||
fn Framebuffer(&self) -> DomRoot<WebGLFramebuffer> { | ||
self.webgl_fbo.or_init(|| { | ||
let fbo_id = unsafe { | ||
// Generate a dummy FBO id that avoids collisions with the real WebGL FBOs. | ||
WebGLFramebufferId::new(self.device_id * 1000 + self.fbo.eye_index) | ||
}; | ||
let bind_msg = WebGLMsg::WebVRCommand(self.renderer.context_id(), | ||
WebVRCommand::BindFramebuffer(self.device_id, | ||
self.fbo.eye_index)); | ||
let unbind_msg = Some(WebGLMsg::WebVRCommand(self.renderer.context_id(), | ||
WebVRCommand::UnbindFramebuffer(self.device_id, | ||
self.fbo.eye_index))); | ||
let opaque_messages = OpaqueFBOMessages { | ||
bind_msg, unbind_msg | ||
}; | ||
|
||
WebGLFramebuffer::new_opaque(self.global().as_window(), | ||
self.renderer.clone(), | ||
fbo_id, | ||
opaque_messages) | ||
}) | ||
} | ||
|
||
fn GetViewport(&self) -> VRViewport { | ||
VRViewport { | ||
x: Some(self.fbo.viewport.x), | ||
y: Some(self.fbo.viewport.y), | ||
width: Some(self.fbo.viewport.width), | ||
height: Some(self.fbo.viewport.height), | ||
} | ||
} | ||
|
||
fn GetAttributes(&self) -> VRAttributes { | ||
VRAttributes { | ||
depth: self.fbo.attributes.depth, | ||
multiview: self.fbo.attributes.multiview, | ||
antialias: self.fbo.attributes.multisampling, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
use dom::bindings::codegen::Bindings::VRViewListBinding; | ||
use dom::bindings::codegen::Bindings::VRViewListBinding::VRViewListMethods; | ||
use dom::bindings::reflector::{Reflector, reflect_dom_object}; | ||
use dom::bindings::root::{Dom, DomRoot}; | ||
use dom::vrview::VRView; | ||
use dom::window::Window; | ||
use dom_struct::dom_struct; | ||
|
||
#[dom_struct] | ||
pub struct VRViewList { | ||
reflector_: Reflector, | ||
views: Vec<Dom<VRView>>, | ||
} | ||
|
||
impl VRViewList { | ||
fn new_inherited(views: &[&VRView]) -> VRViewList { | ||
VRViewList { | ||
reflector_: Reflector::new(), | ||
views: views.iter().map(|VRView| Dom::from_ref(*VRView)).collect(), | ||
} | ||
} | ||
|
||
pub fn new(window: &Window, views: &[&VRView]) -> DomRoot<VRViewList> { | ||
reflect_dom_object(Box::new(VRViewList::new_inherited(views)), | ||
window, VRViewListBinding::Wrap) | ||
} | ||
} | ||
|
||
impl VRViewListMethods for VRViewList { | ||
/// https://w3c.github.io/VRView-events/#widl-VRViewList-length | ||
fn Length(&self) -> u32 { | ||
self.views.len() as u32 | ||
} | ||
|
||
/// https://w3c.github.io/VRView-events/#widl-VRViewList-item-getter-VRView-unsigned-long-index | ||
fn Item(&self, index: u32) -> Option<DomRoot<VRView>> { | ||
self.views.get(index as usize).map(|js| DomRoot::from_ref(&**js)) | ||
} | ||
|
||
/// https://w3c.github.io/VRView-events/#widl-VRViewList-item-getter-VRView-unsigned-long-index | ||
fn IndexedGetter(&self, index: u32) -> Option<DomRoot<VRView>> { | ||
self.Item(index) | ||
} | ||
} |
Oops, something went wrong.