webgl: Update IDL exposed members (#33509)

* Update IDLs to expose on Workers

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update usage of Canvas/OffscreenCanvas union, add label

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update WPT expectations

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Fix match arm

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Add missing spec links

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update expectations

Signed-off-by: Daniel Adams <msub2official@gmail.com>

* Update interfaces.worker.js

Signed-off-by: Daniel Adams <msub2official@gmail.com>

---------

Signed-off-by: Daniel Adams <msub2official@gmail.com>
This commit is contained in:
Daniel Adams 2024-09-22 11:55:31 +00:00 committed by GitHub
parent 8276673bae
commit 3a0d27b231
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 117 additions and 4772 deletions

View file

@ -26,6 +26,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::{
};
use crate::dom::bindings::codegen::Bindings::MediaStreamBinding::MediaStreamMethods;
use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes;
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
use crate::dom::bindings::conversions::ConversionResult;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::inheritance::Castable;
@ -206,7 +207,9 @@ impl HTMLCanvasElement {
let window = window_from_node(self);
let size = self.get_size();
let attrs = Self::get_gl_attributes(cx, options)?;
let context = WebGLRenderingContext::new(&window, self, WebGLVersion::WebGL1, size, attrs)?;
let canvas = HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(DomRoot::from_ref(self));
let context =
WebGLRenderingContext::new(&window, &canvas, WebGLVersion::WebGL1, size, attrs)?;
*self.context.borrow_mut() = Some(CanvasContext::WebGL(Dom::from_ref(&*context)));
Some(context)
}
@ -229,7 +232,8 @@ impl HTMLCanvasElement {
let window = window_from_node(self);
let size = self.get_size();
let attrs = Self::get_gl_attributes(cx, options)?;
let context = WebGL2RenderingContext::new(&window, self, size, attrs)?;
let canvas = HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(DomRoot::from_ref(self));
let context = WebGL2RenderingContext::new(&window, &canvas, size, attrs)?;
*self.context.borrow_mut() = Some(CanvasContext::WebGL2(Dom::from_ref(&*context)));
Some(context)
}

View file

@ -34,6 +34,7 @@ use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{
};
use crate::dom::bindings::codegen::UnionTypes::{
ArrayBufferViewOrArrayBuffer, Float32ArrayOrUnrestrictedFloatSequence,
HTMLCanvasElementOrOffscreenCanvas,
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement, Int32ArrayOrLongSequence,
Uint32ArrayOrUnsignedLongSequence,
};
@ -42,7 +43,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::{HTMLCanvasElement, LayoutCanvasRenderingContextHelpers};
use crate::dom::htmlcanvaselement::LayoutCanvasRenderingContextHelpers;
use crate::dom::promise::Promise;
use crate::dom::webgl_validations::tex_image_2d::{
TexImage2DValidator, TexImage2DValidatorResult, TexStorageValidator, TexStorageValidatorResult,
@ -139,7 +140,7 @@ struct ReadPixelsSizes {
impl WebGL2RenderingContext {
fn new_inherited(
window: &Window,
canvas: &HTMLCanvasElement,
canvas: &HTMLCanvasElementOrOffscreenCanvas,
size: Size2D<u32>,
attrs: GLContextAttributes,
) -> Option<WebGL2RenderingContext> {
@ -186,7 +187,7 @@ impl WebGL2RenderingContext {
#[allow(crown::unrooted_must_root)]
pub fn new(
window: &Window,
canvas: &HTMLCanvasElement,
canvas: &HTMLCanvasElementOrOffscreenCanvas,
size: Size2D<u32>,
attrs: GLContextAttributes,
) -> Option<DomRoot<WebGL2RenderingContext>> {
@ -902,7 +903,7 @@ impl WebGL2RenderingContext {
impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
/// <https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1>
fn Canvas(&self) -> DomRoot<HTMLCanvasElement> {
fn Canvas(&self) -> HTMLCanvasElementOrOffscreenCanvas {
self.base.Canvas()
}

View file

@ -5,14 +5,18 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
use dom_struct::dom_struct;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGLObjectBinding::WebGLObjectMethods;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::Dom;
use crate::dom::bindings::str::USVString;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
#[dom_struct]
pub struct WebGLObject {
reflector_: Reflector,
context: Dom<WebGLRenderingContext>,
label: DomRefCell<USVString>,
}
impl WebGLObject {
@ -20,6 +24,7 @@ impl WebGLObject {
WebGLObject {
reflector_: Reflector::new(),
context: Dom::from_ref(context),
label: DomRefCell::new(USVString::default()),
}
}
@ -27,3 +32,15 @@ impl WebGLObject {
&self.context
}
}
impl WebGLObjectMethods for WebGLObject {
/// <https://registry.khronos.org/webgl/specs/latest/1.0/#5.3>
fn Label(&self) -> USVString {
self.label.borrow().clone()
}
/// <https://registry.khronos.org/webgl/specs/latest/1.0/#5.3>
fn SetLabel(&self, value: USVString) {
*self.label.borrow_mut() = value;
}
}

View file

@ -48,19 +48,18 @@ use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{
WebGLRenderingContextMethods,
};
use crate::dom::bindings::codegen::UnionTypes::{
ArrayBufferViewOrArrayBuffer, Float32ArrayOrUnrestrictedFloatSequence, Int32ArrayOrLongSequence,
ArrayBufferViewOrArrayBuffer, Float32ArrayOrUnrestrictedFloatSequence,
HTMLCanvasElementOrOffscreenCanvas, Int32ArrayOrLongSequence,
};
use crate::dom::bindings::conversions::{DerivedFrom, ToJSValConvertible};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomOnceCell, DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::root::{DomOnceCell, DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::element::cors_setting_for_element;
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::htmlcanvaselement::{
utils as canvas_utils, HTMLCanvasElement, LayoutCanvasRenderingContextHelpers,
};
use crate::dom::htmlcanvaselement::{utils as canvas_utils, LayoutCanvasRenderingContextHelpers};
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage};
use crate::dom::promise::Promise;
use crate::dom::vertexarrayobject::VertexAttribData;
@ -182,7 +181,7 @@ pub struct WebGLRenderingContext {
#[ignore_malloc_size_of = "Defined in surfman"]
#[no_trace]
limits: GLLimits,
canvas: Dom<HTMLCanvasElement>,
canvas: HTMLCanvasElementOrOffscreenCanvas,
#[ignore_malloc_size_of = "Defined in canvas_traits"]
#[no_trace]
last_error: Cell<Option<WebGLError>>,
@ -218,7 +217,7 @@ pub struct WebGLRenderingContext {
impl WebGLRenderingContext {
pub fn new_inherited(
window: &Window,
canvas: &HTMLCanvasElement,
canvas: &HTMLCanvasElementOrOffscreenCanvas,
webgl_version: WebGLVersion,
size: Size2D<u32>,
attrs: GLContextAttributes,
@ -248,7 +247,7 @@ impl WebGLRenderingContext {
webgl_version,
glsl_version: ctx_data.glsl_version,
limits: ctx_data.limits,
canvas: Dom::from_ref(canvas),
canvas: canvas.clone(),
last_error: Cell::new(None),
texture_packing_alignment: Cell::new(4),
texture_unpacking_settings: Cell::new(TextureUnpacking::CONVERT_COLORSPACE),
@ -285,7 +284,7 @@ impl WebGLRenderingContext {
#[allow(crown::unrooted_must_root)]
pub fn new(
window: &Window,
canvas: &HTMLCanvasElement,
canvas: &HTMLCanvasElementOrOffscreenCanvas,
webgl_version: WebGLVersion,
size: Size2D<u32>,
attrs: GLContextAttributes,
@ -301,7 +300,14 @@ impl WebGLRenderingContext {
EventCancelable::Cancelable,
DOMString::from(msg),
);
event.upcast::<Event>().fire(canvas.upcast());
match canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => {
event.upcast::<Event>().fire(canvas.upcast());
},
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(canvas) => {
event.upcast::<Event>().fire(canvas.upcast());
},
}
None
},
}
@ -395,7 +401,12 @@ impl WebGLRenderingContext {
}
pub fn onscreen(&self) -> bool {
self.canvas.upcast::<Node>().is_connected()
match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
canvas.upcast::<Node>().is_connected()
},
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(_) => false,
}
}
#[inline]
@ -535,12 +546,14 @@ impl WebGLRenderingContext {
return;
}
self.canvas
.upcast::<Node>()
.dirty(NodeDamage::OtherNodeDamage);
let document = document_from_node(&*self.canvas);
document.add_dirty_webgl_canvas(self);
match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
canvas.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
let document = document_from_node(&**canvas);
document.add_dirty_webgl_canvas(self);
},
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(_) => {},
}
}
fn vertex_attrib(&self, indx: u32, x: f32, y: f32, z: f32, w: f32) {
@ -648,7 +661,15 @@ impl WebGLRenderingContext {
false,
),
TexImageSource::HTMLImageElement(image) => {
let document = document_from_node(&*self.canvas);
let document = match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
document_from_node(&**canvas)
},
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(ref canvas) => {
// TODO: Support retrieving image pixels here for OffscreenCanvas
return Ok(None);
},
};
if !image.same_origin(document.origin()) {
return Err(Error::Security);
}
@ -658,7 +679,13 @@ impl WebGLRenderingContext {
None => return Ok(None),
};
let window = window_from_node(&*self.canvas);
let window = match self.canvas {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(ref canvas) => {
window_from_node(&**canvas)
},
// This is marked as unreachable as we should have returned already
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(_) => unreachable!(),
};
let cors_setting = cors_setting_for_element(image.upcast());
let img =
@ -1959,8 +1986,8 @@ impl Drop for WebGLRenderingContext {
impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1
fn Canvas(&self) -> DomRoot<HTMLCanvasElement> {
DomRoot::from_ref(&*self.canvas)
fn Canvas(&self) -> HTMLCanvasElementOrOffscreenCanvas {
self.canvas.clone()
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.11

View file

@ -6,7 +6,7 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.7
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLActiveInfo {
readonly attribute GLint size;
readonly attribute GLenum type;

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.4
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLBuffer : WebGLObject {
};

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.7
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLFramebuffer : WebGLObject {
};

View file

@ -6,6 +6,7 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.3
//
[Abstract, Exposed=Window]
[Abstract, Exposed=(Window,Worker)]
interface WebGLObject {
attribute USVString label;
};

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.6
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLProgram : WebGLObject {
};

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.5
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLRenderbuffer : WebGLObject {
};

View file

@ -43,7 +43,7 @@ dictionary WebGLContextAttributes {
GLboolean failIfMajorPerformanceCaveat = false;
};
[Exposed=Window]
[Exposed=(Window,Worker)]
interface mixin WebGLRenderingContextBase
{
@ -465,7 +465,7 @@ interface mixin WebGLRenderingContextBase
const GLenum UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
const GLenum BROWSER_DEFAULT_WEBGL = 0x9244;
readonly attribute HTMLCanvasElement canvas;
readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas;
readonly attribute GLsizei drawingBufferWidth;
readonly attribute GLsizei drawingBufferHeight;
@ -680,7 +680,7 @@ interface mixin WebGLRenderingContextOverloads
undefined uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, Float32List value);
};
[Exposed=(Window)]
[Exposed=(Window,Worker)]
interface WebGLRenderingContext
{
};

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.8
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLShader : WebGLObject {
};

View file

@ -6,7 +6,7 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.7
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLShaderPrecisionFormat {
readonly attribute GLint rangeMin;
readonly attribute GLint rangeMax;

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/#5.9
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLTexture : WebGLObject {
};

View file

@ -6,6 +6,6 @@
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.10
//
[Exposed=Window]
[Exposed=(Window,Worker)]
interface WebGLUniformLocation {
};

View file

@ -15,6 +15,7 @@ use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGL
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::{
XRWebGLLayerInit, XRWebGLLayerMethods, XRWebGLRenderingContext,
};
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
@ -189,7 +190,16 @@ impl XRWebGLLayer {
size.1.try_into().unwrap_or(0),
)
} else {
let size = self.context().Canvas().get_size();
let size = match self.context().Canvas() {
HTMLCanvasElementOrOffscreenCanvas::HTMLCanvasElement(canvas) => canvas.get_size(),
HTMLCanvasElementOrOffscreenCanvas::OffscreenCanvas(canvas) => {
let size = canvas.get_size();
Size2D::new(
size.width.try_into().unwrap_or(0),
size.height.try_into().unwrap_or(0),
)
},
};
Size2D::from_untyped(size)
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -13502,7 +13502,7 @@
]
],
"interfaces.worker.js": [
"2782a452ac10b97c4cd4418fb7ba516325a76fab",
"c8e8ae9921eb01f71a63ebbce42ff589d0a12bf8",
[
"mozilla/interfaces.worker.html",
{}

View file

@ -60,6 +60,17 @@ test_interfaces([
"TextEncoder",
"URL",
"URLSearchParams",
"WebGLActiveInfo",
"WebGLBuffer",
"WebGLFramebuffer",
"WebGLObject",
"WebGLProgram",
"WebGLRenderbuffer",
"WebGLRenderingContext",
"WebGLShader",
"WebGLShaderPrecisionFormat",
"WebGLTexture",
"WebGLUniformLocation",
"WebSocket",
"WeakRef",
"Worker",

View file

@ -1,2 +1,3 @@
[context-creation-worker.html]
expected: ERROR
[WebGL test #0: Some tests failed]
expected: FAIL

View file

@ -1,2 +1,3 @@
[context-creation-worker.html]
expected: ERROR
[WebGL test #0: Some tests failed]
expected: FAIL