aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/vrdisplay.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-08-15 16:00:10 -0500
committerGitHub <noreply@github.com>2017-08-15 16:00:10 -0500
commit90f55ea4580e2a15f7d70d0491444f18b972d450 (patch)
treec85f3cb5d55babab03d56dac8b0d10d588b0a0f9 /components/script/dom/vrdisplay.rs
parent2e60b27a2186a8cba4b952960155dfcf3f47d7db (diff)
parent703962fe61d673536eb982b45795ae13748f0f6a (diff)
downloadservo-90f55ea4580e2a15f7d70d0491444f18b972d450.tar.gz
servo-90f55ea4580e2a15f7d70d0491444f18b972d450.zip
Auto merge of #17891 - MortimerGoro:webgl_move, r=glennw,emilio
Improved WebGL architecture <!-- Please describe your changes on the following line: --> Info about the big picture and the goals of the WebGL refactor in this thread: https://groups.google.com/forum/#!topic/mozilla.dev.servo/0WMGz60kKzQ I tried to reduce this PR as much as possible as requested in the thread. I'll do separate PRs for other features (e.g.: Batch messages or use shared memory to improve frame times) or fixes. Some tips to ease the review process: - Most changes in DOM objects follow the same pattern (remove CanvasMsg wrapper and use the new sender method). - WebGLCommands are the same ones as before (moved from webrender_api). So those lines are already reviewed. - See WebGL traits in [components/canvas_traits/webgl.rs](https://github.com/servo/servo/pull/17891/files#diff-8701045d01505418701d0631d4d45562) - See WebGLThread and WR External Image bridge in [components/canvas/webgl_thread.rs](https://github.com/servo/servo/pull/17891/files#diff-281554879f39a2a041f7a69d442a5d2e) - The implementation submitted in this PR creates a single `WebGLThread` for all ScriptThread/Pipelines. See that in [components/canvas/webgl_mode/inprocess.rs](https://github.com/servo/servo/pull/17891/files#diff-250070c6c5a38c7f9fa0f5b3c101f68b) The conformance tests will help to guarantee that we don't miss anything. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17891) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/vrdisplay.rs')
-rw-r--r--components/script/dom/vrdisplay.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs
index 54f06fb928f..a36bd27ad29 100644
--- a/components/script/dom/vrdisplay.rs
+++ b/components/script/dom/vrdisplay.rs
@@ -2,7 +2,7 @@
* 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::CanvasMsg;
+use canvas_traits::webgl::{webgl_channel, WebGLReceiver, WebVRCommand};
use core::ops::Deref;
use dom::bindings::callback::ExceptionHandling;
use dom::bindings::cell::DOMRefCell;
@@ -32,8 +32,7 @@ use dom::vrpose::VRPose;
use dom::vrstageparameters::VRStageParameters;
use dom::webglrenderingcontext::WebGLRenderingContext;
use dom_struct::dom_struct;
-use ipc_channel::ipc;
-use ipc_channel::ipc::{IpcSender, IpcReceiver};
+use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::JSContext;
use script_runtime::CommonScriptMsg;
use script_runtime::ScriptThreadEventCategory::WebVREvent;
@@ -43,7 +42,6 @@ use std::mem;
use std::rc::Rc;
use std::sync::mpsc;
use std::thread;
-use webrender_api::VRCompositorCommand;
use webvr_traits::{WebVRDisplayData, WebVRDisplayEvent, WebVRFrameData, WebVRLayer, WebVRMsg};
#[dom_struct]
@@ -71,7 +69,7 @@ pub struct VRDisplay {
// Compositor VRFrameData synchonization
frame_data_status: Cell<VRFrameDataStatus>,
#[ignore_heap_size_of = "channels are hard"]
- frame_data_receiver: DOMRefCell<Option<IpcReceiver<Result<Vec<u8>, ()>>>>,
+ frame_data_receiver: DOMRefCell<Option<WebGLReceiver<Result<Vec<u8>, ()>>>>,
running_display_raf: Cell<bool>,
paused: Cell<bool>,
stopped_on_pause: Cell<bool>,
@@ -386,11 +384,10 @@ impl VRDisplayMethods for VRDisplay {
return;
}
- let api_sender = self.layer_ctx.get().unwrap().ipc_renderer();
- let display_id = self.display.borrow().display_id as u64;
+ let display_id = self.display.borrow().display_id;
let layer = self.layer.borrow();
- let msg = VRCompositorCommand::SubmitFrame(display_id, layer.left_bounds, layer.right_bounds);
- api_sender.send(CanvasMsg::WebVR(msg)).unwrap();
+ let msg = WebVRCommand::SubmitFrame(display_id, layer.left_bounds, layer.right_bounds);
+ self.layer_ctx.get().unwrap().send_vr_command(msg);
}
// https://w3c.github.io/webvr/spec/1.1/#dom-vrdisplay-getlayers
@@ -489,11 +486,11 @@ impl VRDisplay {
fn init_present(&self) {
self.presenting.set(true);
- let (sync_sender, sync_receiver) = ipc::channel().unwrap();
+ let (sync_sender, sync_receiver) = webgl_channel().unwrap();
*self.frame_data_receiver.borrow_mut() = Some(sync_receiver);
- let display_id = self.display.borrow().display_id as u64;
- let api_sender = self.layer_ctx.get().unwrap().ipc_renderer();
+ let display_id = self.display.borrow().display_id;
+ let api_sender = self.layer_ctx.get().unwrap().webgl_sender();
let js_sender = self.global().script_chan();
let address = Trusted::new(&*self);
let near_init = self.depth_near.get();
@@ -511,7 +508,7 @@ impl VRDisplay {
let mut far = far_init;
// Initialize compositor
- api_sender.send(CanvasMsg::WebVR(VRCompositorCommand::Create(display_id))).unwrap();
+ api_sender.send_vr(WebVRCommand::Create(display_id)).unwrap();
loop {
// Run RAF callbacks on JavaScript thread
let msg = box NotifyDisplayRAF {
@@ -521,8 +518,8 @@ impl VRDisplay {
js_sender.send(CommonScriptMsg::RunnableMsg(WebVREvent, msg)).unwrap();
// Run Sync Poses in parallell on Render thread
- let msg = VRCompositorCommand::SyncPoses(display_id, near, far, sync_sender.clone());
- api_sender.send(CanvasMsg::WebVR(msg)).unwrap();
+ let msg = WebVRCommand::SyncPoses(display_id, near, far, sync_sender.clone());
+ api_sender.send_vr(msg).unwrap();
// Wait until both SyncPoses & RAF ends
if let Ok(depth) = raf_receiver.recv().unwrap() {
@@ -541,10 +538,9 @@ impl VRDisplay {
self.presenting.set(false);
*self.frame_data_receiver.borrow_mut() = None;
- let api_sender = self.layer_ctx.get().unwrap().ipc_renderer();
- let display_id = self.display.borrow().display_id as u64;
- let msg = VRCompositorCommand::Release(display_id);
- api_sender.send(CanvasMsg::WebVR(msg)).unwrap();
+ let api_sender = self.layer_ctx.get().unwrap().webgl_sender();
+ let display_id = self.display.borrow().display_id;
+ api_sender.send_vr(WebVRCommand::Release(display_id)).unwrap();
}
// Only called when the JSContext is destroyed while presenting.
@@ -627,7 +623,7 @@ impl Runnable for NotifyDisplayRAF {
}
-// WebVR Spect: If the number of values in the leftBounds/rightBounds arrays
+// WebVR Spec: If the number of values in the leftBounds/rightBounds arrays
// is not 0 or 4 for any of the passed layers the promise is rejected
fn parse_bounds(src: &Option<Vec<Finite<f32>>>, dst: &mut [f32; 4]) -> Result<(), &'static str> {
match *src {