Skip to content

Commit 832ff70

Browse files
author
Alan Jeffrey
committed
Get XR sessions to track the draw texture, so we render the XR framebuffer rather than the default canvas framebuffer
1 parent b9b0176 commit 832ff70

5 files changed

Lines changed: 45 additions & 26 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ opt-level = 3
2929
mio = { git = "https://github.com/servo/mio.git", branch = "servo" }
3030
iovec = { git = "https://github.com/servo/iovec.git", branch = "servo" }
3131
cmake = { git = "https://github.com/alexcrichton/cmake-rs" }
32-
33-
[patch."https://github.com/servo/webxr"]
34-
webxr = { git = "https://github.com/asajeffrey/webxr", branch = "optional-glsync" }
35-
webxr-api = { git = "https://github.com/asajeffrey/webxr", branch = "optional-glsync" }

components/canvas/webgl_mode/inprocess.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ impl SendableWebGLExternalImages {
117117
}
118118
}
119119

120-
impl webxr_api::WebGLExternalImageApi for SendableWebGLExternalImages {
121-
fn lock(&self, id: usize) -> (u32, Size2D<i32>, Option<gl::GLsync>) {
120+
impl SendableWebGLExternalImages {
121+
fn lock_and_get_current_texture(&self, id: usize) -> (u32, Size2D<i32>, Option<gl::GLsync>) {
122122
if let Some(main_thread) = WebGLMainThread::on_current_thread() {
123123
// If we're on the same thread as WebGL, we can get the data directly
124124
let (image_id, size) = main_thread
@@ -141,6 +141,13 @@ impl webxr_api::WebGLExternalImageApi for SendableWebGLExternalImages {
141141
(image_id, size, Some(gl_sync as gl::GLsync))
142142
}
143143
}
144+
}
145+
146+
impl webxr_api::WebGLExternalImageApi for SendableWebGLExternalImages {
147+
fn lock(&self, id: usize) -> Option<gl::GLsync> {
148+
let (_, _, gl_sync) = self.lock_and_get_current_texture(id);
149+
gl_sync
150+
}
144151

145152
fn unlock(&self, id: usize) {
146153
if let Some(main_thread) = WebGLMainThread::on_current_thread() {
@@ -178,7 +185,7 @@ impl WebGLExternalImages {
178185

179186
impl WebrenderExternalImageApi for WebGLExternalImages {
180187
fn lock(&mut self, id: u64) -> (u32, Size2D<i32>) {
181-
let (image_id, size, gl_sync) = self.sendable.lock(id as usize);
188+
let (image_id, size, gl_sync) = self.sendable.lock_and_get_current_texture(id as usize);
182189
// The next glWaitSync call is run on the WR thread and it's used to synchronize the two
183190
// flows of OpenGL commands in order to avoid WR using a semi-ready WebGL texture.
184191
// glWaitSync doesn't block WR thread, it affects only internal OpenGL subsystem.

components/script/dom/xrsession.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::compartments::InCompartment;
66
use crate::dom::bindings::callback::ExceptionHandling;
77
use crate::dom::bindings::cell::DomRefCell;
88
use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorBinding::NavigatorMethods;
9+
use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
910
use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
1011
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
1112
use crate::dom::bindings::codegen::Bindings::XRBinding::XRSessionMode;
@@ -29,6 +30,7 @@ use crate::dom::globalscope::GlobalScope;
2930
use crate::dom::node::Node;
3031
use crate::dom::node::NodeDamage;
3132
use crate::dom::promise::Promise;
33+
use crate::dom::webglframebuffer::WebGLFramebufferAttachmentRoot;
3234
use crate::dom::xrframe::XRFrame;
3335
use crate::dom::xrinputsource::XRInputSource;
3436
use crate::dom::xrreferencespace::XRReferenceSpace;
@@ -38,6 +40,7 @@ use crate::dom::xrspace::XRSpace;
3840
use crate::dom::xrwebgllayer::XRWebGLLayer;
3941
use crate::task_source::TaskSource;
4042
use dom_struct::dom_struct;
43+
use euclid::default::Size2D;
4144
use euclid::RigidTransform3D;
4245
use ipc_channel::ipc::IpcSender;
4346
use ipc_channel::router::ROUTER;
@@ -182,10 +185,19 @@ impl XRSession {
182185
// Step 6-7: XXXManishearth handle inlineVerticalFieldOfView
183186

184187
// XXXManishearth handle inline sessions and composition disabled flag
185-
let context = pending
186-
.GetBaseLayer()
187-
.map(|layer| layer.Context().context_id().0);
188-
self.session.borrow_mut().set_webgl_context(context);
188+
if let Some(layer) = pending.GetBaseLayer() {
189+
let attachment = layer.framebuffer().attachment(constants::COLOR_ATTACHMENT0);
190+
if let Some(WebGLFramebufferAttachmentRoot::Texture(texture)) = attachment {
191+
let context = layer.Context().context_id().0;
192+
let texture_id = texture.id().get();
193+
if let Some((width, height)) = layer.framebuffer().size() {
194+
let size = Size2D::new(width, height);
195+
self.session
196+
.borrow_mut()
197+
.set_texture(context, texture_id, size);
198+
}
199+
}
200+
}
189201
}
190202

191203
// Step 2

components/script/dom/xrwebgllayer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ impl XRWebGLLayer {
149149
pub fn session(&self) -> &XRSession {
150150
&self.session
151151
}
152+
153+
pub fn framebuffer(&self) -> &WebGLFramebuffer {
154+
&self.framebuffer
155+
}
152156
}
153157

154158
impl XRWebGLLayerMethods for XRWebGLLayer {

0 commit comments

Comments
 (0)