aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/mediasession.rs6
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/webglframebuffer.rs10
-rw-r--r--components/script/dom/webglrenderingcontext.rs2
-rw-r--r--components/script/dom/webgltexture.rs43
-rw-r--r--components/script/dom/webidls/XRLayerEvent.webidl11
-rw-r--r--components/script/dom/xrlayerevent.rs62
-rw-r--r--components/script/dom/xrwebgllayer.rs6
8 files changed, 111 insertions, 30 deletions
diff --git a/components/script/dom/mediasession.rs b/components/script/dom/mediasession.rs
index f77efe3f54f..49112ba921b 100644
--- a/components/script/dom/mediasession.rs
+++ b/components/script/dom/mediasession.rs
@@ -20,7 +20,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::htmlmediaelement::HTMLMediaElement;
use crate::dom::mediametadata::MediaMetadata;
use crate::dom::window::Window;
-use crate::realms::{AlreadyInRealm, InRealm};
+use crate::realms::{enter_realm, InRealm};
use dom_struct::dom_struct;
use embedder_traits::MediaMetadata as EmbedderMediaMetadata;
use embedder_traits::MediaSessionEvent;
@@ -80,8 +80,8 @@ impl MediaSession {
if let Some(media) = self.media_instance.get() {
match action {
MediaSessionActionType::Play => {
- let in_realm_proof = AlreadyInRealm::assert(&self.global());
- media.Play(InRealm::Already(&in_realm_proof));
+ let realm = enter_realm(self);
+ media.Play(InRealm::Entered(&realm));
},
MediaSessionActionType::Pause => {
media.Pause();
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 76ed789e8ad..a4d27057446 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -614,6 +614,7 @@ pub mod xrinputsourceschangeevent;
pub mod xrjointpose;
pub mod xrjointspace;
pub mod xrlayer;
+pub mod xrlayerevent;
pub mod xrmediabinding;
pub mod xrpose;
pub mod xrprojectionlayer;
diff --git a/components/script/dom/webglframebuffer.rs b/components/script/dom/webglframebuffer.rs
index 9539ac90507..8172b1b6c4e 100644
--- a/components/script/dom/webglframebuffer.rs
+++ b/components/script/dom/webglframebuffer.rs
@@ -205,6 +205,9 @@ impl WebGLFramebuffer {
}
pub fn is_deleted(&self) -> bool {
+ // TODO: if a framebuffer has an attachment which is invalid due to
+ // being outside a webxr rAF, should this make the framebuffer invalid?
+ // https://github.com/immersive-web/layers/issues/196
self.is_deleted.get()
}
@@ -447,6 +450,9 @@ impl WebGLFramebuffer {
} else {
self.status.get()
}
+ // TODO: if a framebuffer has an attachment which is invalid due to
+ // being outside a webxr rAF, should this make the framebuffer incomplete?
+ // https://github.com/immersive-web/layers/issues/196
}
pub fn check_status_for_rendering(&self) -> CompleteForRendering {
@@ -497,6 +503,10 @@ impl WebGLFramebuffer {
self.is_initialized.set(true);
}
+ // TODO: if a framebuffer has an attachment which is invalid due to
+ // being outside a webxr rAF, should this make the framebuffer incomplete?
+ // https://github.com/immersive-web/layers/issues/196
+
CompleteForRendering::Complete
}
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 168d31fdf5d..9ef96b1cd19 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -3563,7 +3563,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
fn IsTexture(&self, texture: Option<&WebGLTexture>) -> bool {
texture.map_or(false, |tex| {
- self.validate_ownership(tex).is_ok() && tex.target().is_some() && !tex.is_deleted()
+ self.validate_ownership(tex).is_ok() && tex.target().is_some() && !tex.is_invalid()
})
}
diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs
index 02cedeb5755..7456f772dec 100644
--- a/components/script/dom/webgltexture.rs
+++ b/components/script/dom/webgltexture.rs
@@ -9,11 +9,13 @@ use crate::dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding:
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
+use crate::dom::bindings::root::Dom;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::webgl_validations::types::TexImageTarget;
use crate::dom::webglframebuffer::WebGLFramebuffer;
use crate::dom::webglobject::WebGLObject;
use crate::dom::webglrenderingcontext::{Operation, WebGLRenderingContext};
+use crate::dom::xrsession::XRSession;
use canvas_traits::webgl::{
webgl_channel, TexDataType, TexFormat, TexParameter, TexParameterBool, TexParameterInt,
WebGLResult, WebGLTextureId,
@@ -31,10 +33,11 @@ pub enum TexParameterValue {
// Textures generated for WebXR are owned by the WebXR device, not by the WebGL thread
// so the GL texture should not be deleted when the texture is garbage collected.
-#[derive(Clone, Copy, Debug, Eq, JSTraceable, MallocSizeOf, PartialEq)]
+#[unrooted_must_root_lint::must_root]
+#[derive(JSTraceable, MallocSizeOf)]
enum WebGLTextureOwner {
WebGL,
- WebXR,
+ WebXR(Dom<XRSession>),
}
const MAX_LEVEL_COUNT: usize = 31;
@@ -71,14 +74,16 @@ impl WebGLTexture {
fn new_inherited(
context: &WebGLRenderingContext,
id: WebGLTextureId,
- owner: WebGLTextureOwner,
+ owner: Option<&XRSession>,
) -> Self {
Self {
webgl_object: WebGLObject::new_inherited(context),
id: id,
target: Cell::new(None),
is_deleted: Cell::new(false),
- owner: owner,
+ owner: owner
+ .map(|session| WebGLTextureOwner::WebXR(Dom::from_ref(session)))
+ .unwrap_or(WebGLTextureOwner::WebGL),
immutable_levels: Cell::new(None),
face_count: Cell::new(0),
base_mipmap_level: 0,
@@ -101,22 +106,18 @@ impl WebGLTexture {
pub fn new(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(WebGLTexture::new_inherited(
- context,
- id,
- WebGLTextureOwner::WebGL,
- )),
+ Box::new(WebGLTexture::new_inherited(context, id, None)),
&*context.global(),
)
}
- pub fn new_webxr(context: &WebGLRenderingContext, id: WebGLTextureId) -> DomRoot<Self> {
+ pub fn new_webxr(
+ context: &WebGLRenderingContext,
+ id: WebGLTextureId,
+ session: &XRSession,
+ ) -> DomRoot<Self> {
reflect_dom_object(
- Box::new(WebGLTexture::new_inherited(
- context,
- id,
- WebGLTextureOwner::WebXR,
- )),
+ Box::new(WebGLTexture::new_inherited(context, id, Some(session))),
&*context.global(),
)
}
@@ -129,7 +130,7 @@ impl WebGLTexture {
// NB: Only valid texture targets come here
pub fn bind(&self, target: u32) -> WebGLResult<()> {
- if self.is_deleted.get() {
+ if self.is_invalid() {
return Err(WebGLError::InvalidOperation);
}
@@ -246,7 +247,7 @@ impl WebGLTexture {
}
// We don't delete textures owned by WebXR
- if self.owner == WebGLTextureOwner::WebXR {
+ if let WebGLTextureOwner::WebXR(_) = self.owner {
return;
}
@@ -258,7 +259,13 @@ impl WebGLTexture {
}
}
- pub fn is_deleted(&self) -> bool {
+ pub fn is_invalid(&self) -> bool {
+ // https://immersive-web.github.io/layers/#xrwebglsubimagetype
+ if let WebGLTextureOwner::WebXR(ref session) = self.owner {
+ if session.is_outside_raf() {
+ return true;
+ }
+ }
self.is_deleted.get()
}
diff --git a/components/script/dom/webidls/XRLayerEvent.webidl b/components/script/dom/webidls/XRLayerEvent.webidl
index c90b9bfb27b..9a05272138e 100644
--- a/components/script/dom/webidls/XRLayerEvent.webidl
+++ b/components/script/dom/webidls/XRLayerEvent.webidl
@@ -3,12 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://immersive-web.github.io/layers/#xrlayerevent-interface
-
-// [SecureContext, Exposed=Window]
-// interface XRLayerEvent : Event {
-// constructor(DOMString type, XRLayerEventInit eventInitDict);
-// [SameObject] readonly attribute XRLayer layer;
-// };
+[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
+interface XRLayerEvent : Event {
+ constructor(DOMString type, XRLayerEventInit eventInitDict);
+ [SameObject] readonly attribute XRLayer layer;
+};
dictionary XRLayerEventInit : EventInit {
required XRLayer layer;
diff --git a/components/script/dom/xrlayerevent.rs b/components/script/dom/xrlayerevent.rs
new file mode 100644
index 00000000000..d3485fa1c51
--- /dev/null
+++ b/components/script/dom/xrlayerevent.rs
@@ -0,0 +1,62 @@
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+use crate::dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMethods;
+use crate::dom::bindings::codegen::Bindings::XRLayerEventBinding::XRLayerEventInit;
+use crate::dom::bindings::codegen::Bindings::XRLayerEventBinding::XRLayerEventMethods;
+use crate::dom::bindings::reflector::reflect_dom_object;
+use crate::dom::bindings::root::Dom;
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::str::DOMString;
+use crate::dom::event::Event;
+use crate::dom::window::Window;
+use crate::dom::xrlayer::XRLayer;
+use dom_struct::dom_struct;
+use servo_atoms::Atom;
+
+// https://w3c.github.io/uievents/#interface-uievent
+#[dom_struct]
+pub struct XRLayerEvent {
+ event: Event,
+ layer: Dom<XRLayer>,
+}
+
+impl XRLayerEvent {
+ pub fn new_inherited(layer: &XRLayer) -> XRLayerEvent {
+ XRLayerEvent {
+ event: Event::new_inherited(),
+ layer: Dom::from_ref(layer),
+ }
+ }
+
+ pub fn new(window: &Window, layer: &XRLayer) -> DomRoot<XRLayerEvent> {
+ reflect_dom_object(Box::new(XRLayerEvent::new_inherited(layer)), window)
+ }
+
+ #[allow(non_snake_case)]
+ pub fn Constructor(
+ window: &Window,
+ type_: DOMString,
+ init: &XRLayerEventInit,
+ ) -> DomRoot<XRLayerEvent> {
+ let event = XRLayerEvent::new(window, &init.layer);
+ let type_ = Atom::from(type_);
+ let bubbles = init.parent.bubbles;
+ let cancelable = init.parent.cancelable;
+ event.event.init_event(type_, bubbles, cancelable);
+ event
+ }
+}
+
+impl XRLayerEventMethods for XRLayerEvent {
+ // https://immersive-web.github.io/layers/#dom-xrlayerevent-layer
+ fn Layer(&self) -> DomRoot<XRLayer> {
+ DomRoot::from_ref(&self.layer)
+ }
+
+ // https://dom.spec.whatwg.org/#dom-event-istrusted
+ fn IsTrusted(&self) -> bool {
+ self.event.IsTrusted()
+ }
+}
diff --git a/components/script/dom/xrwebgllayer.rs b/components/script/dom/xrwebgllayer.rs
index 7f0a7883961..dd1e4eff57f 100644
--- a/components/script/dom/xrwebgllayer.rs
+++ b/components/script/dom/xrwebgllayer.rs
@@ -193,10 +193,11 @@ impl XRWebGLLayer {
let framebuffer = self.framebuffer.as_ref()?;
let context = framebuffer.upcast::<WebGLObject>().context();
let sub_images = frame.get_sub_images(self.layer_id()?)?;
+ let session = self.session();
// TODO: Cache this texture
let color_texture_id =
WebGLTextureId::maybe_new(sub_images.sub_image.as_ref()?.color_texture)?;
- let color_texture = WebGLTexture::new_webxr(context, color_texture_id);
+ let color_texture = WebGLTexture::new_webxr(context, color_texture_id, session);
let target = self.texture_target();
// Save the current bindings
@@ -230,7 +231,8 @@ impl XRWebGLLayer {
if let Some(id) = sub_images.sub_image.as_ref()?.depth_stencil_texture {
// TODO: Cache this texture
let depth_stencil_texture_id = WebGLTextureId::maybe_new(id)?;
- let depth_stencil_texture = WebGLTexture::new_webxr(context, depth_stencil_texture_id);
+ let depth_stencil_texture =
+ WebGLTexture::new_webxr(context, depth_stencil_texture_id, session);
framebuffer
.texture2d_even_if_opaque(
constants::DEPTH_STENCIL_ATTACHMENT,