From 36f39ce27afc83abc21295ee61d2a0485a2071ab Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 22 Mar 2018 15:13:27 +0100 Subject: [PATCH 1/9] Change WebGL function signatures accepting typed arrays --- .../script/dom/webgl2renderingcontext.rs | 80 +++++++++---------- .../script/dom/webglrenderingcontext.rs | 39 ++++----- .../dom/webidls/WebGLRenderingContext.webidl | 46 +++-------- 3 files changed, 66 insertions(+), 99 deletions(-) diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 71ec9388d87..698be5fb25b 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2Rende use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; +use dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferView; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::reflector::{reflect_dom_object, Reflector}; use dom::bindings::root::{Dom, DomRoot, LayoutDom}; @@ -30,6 +31,8 @@ use dom_struct::dom_struct; use euclid::Size2D; use js::jsapi::{JSContext, JSObject}; use js::jsval::JSVal; +use js::rust::CustomAutoRooterGuard; +use js::typedarray::ArrayBufferView; use offscreen_gl_context::GLContextAttributes; use script_layout_interface::HTMLCanvasDataSource; use std::ptr::NonNull; @@ -235,25 +238,23 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { self.base.BufferData_(target, size, usage) } - #[allow(unsafe_code)] /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 - unsafe fn BufferSubData(&self, cx: *mut JSContext, target: u32, offset: i64, data: *mut JSObject) -> Fallible<()> { - self.base.BufferSubData(cx, target, offset, data) + fn BufferSubData(&self, target: u32, offset: i64, data: Option) { + self.base.BufferSubData(target, offset, data) } - #[allow(unsafe_code)] /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - unsafe fn CompressedTexImage2D(&self, cx: *mut JSContext, target: u32, level: i32, internal_format: u32, - width: i32, height: i32, border: i32, pixels: *mut JSObject) -> Fallible<()> { - self.base.CompressedTexImage2D(cx, target, level, internal_format, width, height, border, pixels) + fn CompressedTexImage2D(&self, target: u32, level: i32, internal_format: u32, + width: i32, height: i32, border: i32, + pixels: CustomAutoRooterGuard) { + self.base.CompressedTexImage2D(target, level, internal_format, width, height, border, pixels) } - #[allow(unsafe_code)] /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - unsafe fn CompressedTexSubImage2D(&self, cx: *mut JSContext, target: u32, level: i32, - xoffset: i32, yoffset: i32, width: i32, height: i32, - format: u32, pixels: *mut JSObject) -> Fallible<()> { - self.base.CompressedTexSubImage2D(cx, target, level, xoffset, yoffset, width, height, format, pixels) + fn CompressedTexSubImage2D(&self, target: u32, level: i32, xoffset: i32, + yoffset: i32, width: i32, height: i32, format: u32, + pixels: CustomAutoRooterGuard) { + self.base.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, pixels) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 @@ -533,11 +534,10 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { self.base.PolygonOffset(factor, units) } - #[allow(unsafe_code)] /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12 - unsafe fn ReadPixels(&self, cx: *mut JSContext, x: i32, y: i32, width: i32, height: i32, - format: u32, pixel_type: u32, pixels: *mut JSObject) -> Fallible<()> { - self.base.ReadPixels(cx, x, y, width, height, format, pixel_type, pixels) + fn ReadPixels(&self, x: i32, y: i32, width: i32, height: i32, format: u32, pixel_type: u32, + pixels: CustomAutoRooterGuard>) { + self.base.ReadPixels(x, y, width, height, format, pixel_type, pixels) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 @@ -820,19 +820,17 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - #[allow(unsafe_code)] - unsafe fn TexImage2D(&self, - cx: *mut JSContext, - target: u32, - level: i32, - internal_format: u32, - width: i32, - height: i32, - border: i32, - format: u32, - data_type: u32, - data_ptr: *mut JSObject) -> Fallible<()> { - self.base.TexImage2D(cx, target, level, internal_format, width, height, border, format, data_type, data_ptr) + fn TexImage2D(&self, + target: u32, + level: i32, + internal_format: u32, + width: i32, + height: i32, + border: i32, + format: u32, + data_type: u32, + pixels: CustomAutoRooterGuard>) -> Fallible<()> { + self.base.TexImage2D(target, level, internal_format, width, height, border, format, data_type, pixels) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 @@ -862,19 +860,17 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - #[allow(unsafe_code)] - unsafe fn TexSubImage2D(&self, - cx: *mut JSContext, - target: u32, - level: i32, - xoffset: i32, - yoffset: i32, - width: i32, - height: i32, - format: u32, - data_type: u32, - data_ptr: *mut JSObject) -> Fallible<()> { - self.base.TexSubImage2D(cx, target, level, xoffset, yoffset, width, height, format, data_type, data_ptr) + fn TexSubImage2D(&self, + target: u32, + level: i32, + xoffset: i32, + yoffset: i32, + width: i32, + height: i32, + format: u32, + data_type: u32, + pixels: CustomAutoRooterGuard>) -> Fallible<()> { + self.base.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, data_type, pixels) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 37d117a93fd..cd72cc2ff99 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -15,6 +15,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGL use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; +use dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferView; use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; @@ -49,7 +50,8 @@ use half::f16; use js::conversions::ConversionBehavior; use js::jsapi::{JSContext, JSObject, Type}; use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue}; -use js::typedarray::{TypedArray, TypedArrayElement, Float32, Int32}; +use js::typedarray::{ArrayBufferView, TypedArray, TypedArrayElement, Float32, Int32}; +use js::rust::CustomAutoRooterGuard; use net_traits::image::base::PixelFormat; use net_traits::image_cache::ImageResponse; use offscreen_gl_context::{GLContextAttributes, GLLimits}; @@ -1706,9 +1708,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { Ok(()) } - #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 - unsafe fn BufferSubData(&self, cx: *mut JSContext, target: u32, offset: i64, data: *mut JSObject) -> Fallible<()> { + fn BufferSubData(&self, target: u32, offset: i64, data: Option) { if data.is_null() { return Ok(self.webgl_error(InvalidValue)); } @@ -1742,23 +1743,20 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { Ok(()) } - #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - unsafe fn CompressedTexImage2D(&self, cx: *mut JSContext, _target: u32, _level: i32, _internal_format: u32, - _width: i32, _height: i32, _border: i32, pixels: *mut JSObject) -> Fallible<()> { - let _data = fallible_array_buffer_view_to_vec(cx, pixels)?; + fn CompressedTexImage2D(&self, _target: u32, _level: i32, _internal_format: u32, + _width: i32, _height: i32, _border: i32, + _data: CustomAutoRooterGuard) { // FIXME: No compressed texture format is currently supported, so error out as per // https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT self.webgl_error(InvalidEnum); Ok(()) } - #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - unsafe fn CompressedTexSubImage2D(&self, cx: *mut JSContext, _target: u32, _level: i32, - _xoffset: i32, _yoffset: i32, _width: i32, _height: i32, - _format: u32, pixels: *mut JSObject) -> Fallible<()> { - let _data = fallible_array_buffer_view_to_vec(cx, pixels)?; + fn CompressedTexSubImage2D(&self, _target: u32, _level: i32, _xoffset: i32, + _yoffset: i32, _width: i32, _height: i32, _format: u32, + _data: CustomAutoRooterGuard) { // FIXME: No compressed texture format is currently supported, so error out as per // https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT self.webgl_error(InvalidEnum); @@ -2609,10 +2607,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { self.send_command(WebGLCommand::PolygonOffset(factor, units)) } - #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12 - unsafe fn ReadPixels(&self, cx: *mut JSContext, x: i32, y: i32, width: i32, height: i32, - format: u32, pixel_type: u32, pixels: *mut JSObject) -> Fallible<()> { + fn ReadPixels(&self, x: i32, y: i32, width: i32, height: i32, format: u32, pixel_type: u32, + pixels: CustomAutoRooterGuard>) { if pixels.is_null() { return Ok(self.webgl_error(InvalidValue)); } @@ -3238,9 +3235,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - #[allow(unsafe_code)] - unsafe fn TexImage2D(&self, - cx: *mut JSContext, + fn TexImage2D(&self, target: u32, level: i32, internal_format: u32, @@ -3249,7 +3244,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { border: i32, format: u32, data_type: u32, - data_ptr: *mut JSObject) -> Fallible<()> { + pixels: CustomAutoRooterGuard>) -> Fallible<()> { if !self.extension_manager.is_tex_type_enabled(data_type) { return Ok(self.webgl_error(InvalidEnum)); } @@ -3410,9 +3405,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - #[allow(unsafe_code)] - unsafe fn TexSubImage2D(&self, - cx: *mut JSContext, + fn TexSubImage2D(&self, target: u32, level: i32, xoffset: i32, @@ -3421,7 +3414,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { height: i32, format: u32, data_type: u32, - data_ptr: *mut JSObject) -> Fallible<()> { + pixels: CustomAutoRooterGuard>) -> Fallible<()> { let data = if data_ptr.is_null() { None } else { diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl index 819e0d82179..b65582af929 100644 --- a/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -28,6 +28,7 @@ typedef (ImageData or HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) TexImageSource; +typedef (ArrayBuffer or ArrayBufferView) BufferDataSource; dictionary WebGLContextAttributes { @@ -488,21 +489,15 @@ interface WebGLRenderingContextBase void blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); - // typedef (ArrayBuffer or ArrayBufferView) BufferDataSource; - // FIXME(dmarcos) The function below is the original function in the webIdl: + // FIXME(xanewok) from CodegenRust.py: + // 'No support for unions as distinguishing arguments yet' for below + // original WebIDL function definition // void bufferData(GLenum target, BufferDataSource? data, GLenum usage); - // The Code generator doesn't handle BufferDataSource so we're using 'object?' - // in the meantime, and marking the function as [Throws], so we can handle - // the type error from inside. [Throws] void bufferData(GLenum target, object? data, GLenum usage); - // FIXME: Codegen requires that this have [Throws] to match the other one. [Throws] void bufferData(GLenum target, GLsizeiptr size, GLenum usage); - - //void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data); - [Throws] - void bufferSubData(GLenum target, GLintptr offset, object? data); + void bufferSubData(GLenum target, GLintptr offset, BufferDataSource? data); [WebGLHandlesContextLoss] GLenum checkFramebufferStatus(GLenum target); void clear(GLbitfield mask); @@ -512,25 +507,13 @@ interface WebGLRenderingContextBase void colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void compileShader(WebGLShader shader); - // FIXME(simartin) The Code generator doesn't handle ArrayBufferView so we're - // using 'object' in the meantime, and marking the function as Throws to - // handle the type error from inside. - // void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, - // GLsizei width, GLsizei height, GLint border, - // ArrayBufferView data); - [Throws] void compressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, - object data); - // void compressedTexSubImage2D(GLenum target, GLint level, - // GLint xoffset, GLint yoffset, - // GLsizei width, GLsizei height, GLenum format, - // ArrayBufferView data); - [Throws] + ArrayBufferView data); void compressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, - object data); + ArrayBufferView data); // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 void copyTexImage2D(GLenum target, GLint level, GLenum internalformat, @@ -623,11 +606,8 @@ interface WebGLRenderingContextBase void pixelStorei(GLenum pname, GLint param); void polygonOffset(GLfloat factor, GLfloat units); - //void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, - // GLenum format, GLenum type, ArrayBufferView? pixels); - [Throws] void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, object? pixels); + GLenum format, GLenum type, ArrayBufferView? pixels); void renderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height); @@ -643,14 +623,11 @@ interface WebGLRenderingContextBase void stencilOp(GLenum fail, GLenum zfail, GLenum zpass); void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass); - //void texImage2D(GLenum target, GLint level, GLenum internalformat, - // GLsizei width, GLsizei height, GLint border, GLenum format, - // GLenum type, ArrayBufferView? pixels); - // FIXME: SM interface arguments + // FIXME: Codegen requires that this have [Throws] to match the other one. [Throws] void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, - GLenum type, object? data); + GLenum type, ArrayBufferView? pixels); [Throws] void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, TexImageSource source); // May throw DOMException @@ -661,10 +638,11 @@ interface WebGLRenderingContextBase void texParameterf(GLenum target, GLenum pname, GLfloat param); void texParameteri(GLenum target, GLenum pname, GLint param); + // FIXME: Codegen requires that this have [Throws] to match the other one. [Throws] void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum format, GLenum type, object? data); + GLenum format, GLenum type, ArrayBufferView? pixels); [Throws] void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, TexImageSource source); // May throw DOMException From c1c74ed96c035922f11c97eea020a676a562fb55 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 22 Mar 2018 17:38:32 +0100 Subject: [PATCH 2/9] Adapt function bodies for usage with typed array args --- .../script/dom/webglrenderingcontext.rs | 128 ++++++++---------- 1 file changed, 54 insertions(+), 74 deletions(-) diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index cd72cc2ff99..5ce6efd03a3 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -825,15 +825,13 @@ impl WebGLRenderingContext { } // TODO(emilio): Move this logic to a validator. - #[allow(unsafe_code)] - unsafe fn validate_tex_image_2d_data(&self, + fn validate_tex_image_2d_data(&self, width: u32, height: u32, format: TexFormat, data_type: TexDataType, unpacking_alignment: u32, - data: *mut JSObject, - cx: *mut JSContext) + data: &Option) -> Result { let element_size = data_type.element_size(); let components_per_element = data_type.components_per_element(); @@ -846,21 +844,16 @@ impl WebGLRenderingContext { // or UNSIGNED_SHORT_5_5_5_1, a Uint16Array must be supplied. // or FLOAT, a Float32Array must be supplied. // If the types do not match, an INVALID_OPERATION error is generated. - typedarray!(in(cx) let typedarray_u8: Uint8Array = data); - typedarray!(in(cx) let typedarray_u16: Uint16Array = data); - typedarray!(in(cx) let typedarray_f32: Float32Array = data); - let received_size = if data.is_null() { - element_size - } else { - if typedarray_u16.is_ok() { - 2 - } else if typedarray_u8.is_ok() { - 1 - } else if typedarray_f32.is_ok() { - 4 - } else { - self.webgl_error(InvalidOperation); - return Err(()); + let received_size = match *data { + None => element_size, + Some(ref buffer) => match buffer.get_array_type() { + Type::Uint8 => 1, + Type::Uint16 => 2, + Type::Float32 => 4, + _ => { + self.webgl_error(InvalidOperation); + return Err(()); + } } }; @@ -1709,38 +1702,35 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 + #[allow(unsafe_code)] fn BufferSubData(&self, target: u32, offset: i64, data: Option) { - if data.is_null() { - return Ok(self.webgl_error(InvalidValue)); - } - - typedarray!(in(cx) let array_buffer: ArrayBuffer = data); - let data_vec = match array_buffer { - Ok(mut data) => data.as_slice().to_vec(), - Err(_) => fallible_array_buffer_view_to_vec(cx, data)?, + let data_vec = match data { + // Typed array is rooted, so we can safely temporarily retrieve its slice + Some(ArrayBufferOrArrayBufferView::ArrayBuffer(mut inner)) => unsafe { inner.as_slice().to_vec() }, + Some(ArrayBufferOrArrayBufferView::ArrayBufferView(mut inner)) => unsafe { inner.as_slice().to_vec() }, + // Spec: If data is null then an INVALID_VALUE error is generated. + None => return self.webgl_error(InvalidValue), }; let bound_buffer = match target { constants::ARRAY_BUFFER => self.bound_buffer_array.get(), constants::ELEMENT_ARRAY_BUFFER => self.bound_buffer_element_array.get(), - _ => return Ok(self.webgl_error(InvalidEnum)), + _ => return self.webgl_error(InvalidEnum), }; let bound_buffer = match bound_buffer { Some(bound_buffer) => bound_buffer, - None => return Ok(self.webgl_error(InvalidOperation)), + None => return self.webgl_error(InvalidOperation), }; if offset < 0 { - return Ok(self.webgl_error(InvalidValue)); + return self.webgl_error(InvalidValue); } if (offset as usize) + data_vec.len() > bound_buffer.capacity() { - return Ok(self.webgl_error(InvalidValue)); + return self.webgl_error(InvalidValue); } self.send_command(WebGLCommand::BufferSubData(target, offset as isize, data_vec)); - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 @@ -1750,7 +1740,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // FIXME: No compressed texture format is currently supported, so error out as per // https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT self.webgl_error(InvalidEnum); - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 @@ -1760,8 +1749,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // FIXME: No compressed texture format is currently supported, so error out as per // https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT self.webgl_error(InvalidEnum); - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 @@ -2608,25 +2595,24 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12 + #[allow(unsafe_code)] fn ReadPixels(&self, x: i32, y: i32, width: i32, height: i32, format: u32, pixel_type: u32, - pixels: CustomAutoRooterGuard>) { - if pixels.is_null() { - return Ok(self.webgl_error(InvalidValue)); - } - - typedarray!(in(cx) let mut pixels_data: ArrayBufferView = pixels); - let (array_type, data) = match { pixels_data.as_mut() } { - Ok(data) => (data.get_array_type(), data.as_mut_slice()), - Err(_) => return Err(Error::Type("Not an ArrayBufferView".to_owned())), + mut pixels: CustomAutoRooterGuard>) { + let (array_type, data) = match *pixels { + // Spec: If data is null then an INVALID_VALUE error is generated. + None => return self.webgl_error(InvalidValue), + // The typed array is rooted and we should have a unique reference to it, + // so retrieving its mutable slice is safe here + Some(ref mut data) => (data.get_array_type(), unsafe { data.as_mut_slice() }), }; if !self.validate_framebuffer_complete() { - return Ok(()); + return; } match array_type { Type::Uint8 => (), - _ => return Ok(self.webgl_error(InvalidOperation)), + _ => return self.webgl_error(InvalidOperation), } // From the WebGL specification, 5.14.12 Reading back pixels @@ -2647,7 +2633,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // always report RGBA/UNSIGNED_BYTE as our only supported // format. if format != constants::RGBA || pixel_type != constants::UNSIGNED_BYTE { - return Ok(self.webgl_error(InvalidOperation)); + return self.webgl_error(InvalidOperation); } let cpp = 4; @@ -2657,12 +2643,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // INVALID_OPERATION error is generated." let stride = match width.checked_mul(cpp) { Some(stride) => stride, - _ => return Ok(self.webgl_error(InvalidOperation)), + _ => return self.webgl_error(InvalidOperation), }; match height.checked_mul(stride) { Some(size) if size <= data.len() as i32 => {} - _ => return Ok(self.webgl_error(InvalidOperation)), + _ => return self.webgl_error(InvalidOperation), } // "For any pixel lying outside the frame buffer, the @@ -2688,7 +2674,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } if width < 0 || height < 0 { - return Ok(self.webgl_error(InvalidValue)); + return self.webgl_error(InvalidValue); } match self.get_current_framebuffer_size() { @@ -2700,7 +2686,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { height = fb_height - y; } } - _ => return Ok(self.webgl_error(InvalidOperation)), + _ => return self.webgl_error(InvalidOperation), }; let (sender, receiver) = webgl_channel().unwrap(); @@ -2714,8 +2700,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { result[(i * width * cpp + j) as usize]; } } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 @@ -3235,6 +3219,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 + #[allow(unsafe_code)] fn TexImage2D(&self, target: u32, level: i32, @@ -3244,17 +3229,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { border: i32, format: u32, data_type: u32, - pixels: CustomAutoRooterGuard>) -> Fallible<()> { + mut pixels: CustomAutoRooterGuard>) -> Fallible<()> { if !self.extension_manager.is_tex_type_enabled(data_type) { return Ok(self.webgl_error(InvalidEnum)); } - let data = if data_ptr.is_null() { - None - } else { - Some(fallible_array_buffer_view_to_vec(cx, data_ptr)?) - }; - let validator = TexImage2DValidator::new(self, target, level, internal_format, width, height, border, format, data_type); @@ -3278,16 +3257,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { let expected_byte_length = match { self.validate_tex_image_2d_data(width, height, format, data_type, - unpacking_alignment, data_ptr, cx) } { + unpacking_alignment, &*pixels) } { Ok(byte_length) => byte_length, Err(()) => return Ok(()), }; // If data is null, a buffer of sufficient size // initialized to 0 is passed. - let buff = match data { + let buff = match *pixels { None => vec![0u8; expected_byte_length as usize], - Some(data) => data, + Some(ref mut data) => { + // Since the typed array is rooted, this is safe to perform + unsafe { data.as_slice().to_vec() } + } }; // From the WebGL spec: @@ -3405,6 +3387,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 + #[allow(unsafe_code)] fn TexSubImage2D(&self, target: u32, level: i32, @@ -3414,13 +3397,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { height: i32, format: u32, data_type: u32, - pixels: CustomAutoRooterGuard>) -> Fallible<()> { - let data = if data_ptr.is_null() { - None - } else { - Some(fallible_array_buffer_view_to_vec(cx, data_ptr)?) - }; - + mut pixels: CustomAutoRooterGuard>) -> Fallible<()> { let validator = TexImage2DValidator::new(self, target, level, format, width, height, 0, format, data_type); @@ -3443,16 +3420,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { let expected_byte_length = match { self.validate_tex_image_2d_data(width, height, format, data_type, - unpacking_alignment, data_ptr, cx) } { + unpacking_alignment, &*pixels) } { Ok(byte_length) => byte_length, Err(()) => return Ok(()), }; // If data is null, a buffer of sufficient size // initialized to 0 is passed. - let buff = match data { + let buff = match *pixels { None => vec![0u8; expected_byte_length as usize], - Some(data) => data, + Some(ref mut data) => { + // Since the typed array is rooted, this is safe to perform + unsafe { data.as_slice().to_vec() } + } }; // From the WebGL spec: From 20f21cb5f85c48e7106177db6aa41fa54365d6cc Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 22 Mar 2018 20:38:26 +0100 Subject: [PATCH 3/9] Adapt uniform[fv] and similar to accept typed array args --- .../dom/bindings/codegen/CodegenRust.py | 6 +- .../script/dom/webgl2renderingcontext.rs | 244 +++++++---- .../script/dom/webglrenderingcontext.rs | 413 +++++++++--------- .../dom/webidls/WebGLRenderingContext.webidl | 130 +++--- 4 files changed, 414 insertions(+), 379 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 24054de8e95..6e0632fe97d 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -418,11 +418,15 @@ class CGMethodCall(CGThing): template = info.template declType = info.declType + argName = "arg%d" % distinguishingIndex + testCode = instantiateJSToNativeConversionTemplate( template, {"val": distinguishingArg}, declType, - "arg%d" % distinguishingIndex) + argName) + if type_needs_auto_root(type): + testCode.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (argName, argName))) # Indent by 4, since we need to indent further than our "do" statement caseBody.append(CGIndenter(testCode, 4)) diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 698be5fb25b..e0ae2e22585 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -32,7 +32,7 @@ use euclid::Size2D; use js::jsapi::{JSContext, JSObject}; use js::jsval::JSVal; use js::rust::CustomAutoRooterGuard; -use js::typedarray::ArrayBufferView; +use js::typedarray::{ArrayBufferView, Float32Array, Int32Array}; use offscreen_gl_context::GLContextAttributes; use script_layout_interface::HTMLCanvasDataSource; use std::ptr::NonNull; @@ -597,161 +597,197 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform1f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, val: f32) { - self.base.Uniform1f(uniform, val) + self.base.Uniform1f(location, val) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform1i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, val: i32) { - self.base.Uniform1i(uniform, val) + self.base.Uniform1i(location, val) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform1iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform1iv(cx, uniform, data) + fn Uniform1iv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform1iv(location, v) + } + + fn Uniform1iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + self.base.Uniform1iv_(location, v); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform1fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform1fv(cx, uniform, data) + fn Uniform1fv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform1fv(location, v); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform1fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + self.base.Uniform1fv_(location, v); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform2f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: f32, y: f32) { - self.base.Uniform2f(uniform, x, y) + self.base.Uniform2f(location, x, y) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform2fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform2fv(cx, uniform, data) + fn Uniform2fv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform2fv(location, v) + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform2fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + self.base.Uniform2fv_(location, v); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform2i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: i32, y: i32) { - self.base.Uniform2i(uniform, x, y) + self.base.Uniform2i(location, x, y) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform2iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform2iv(cx, uniform, data) + fn Uniform2iv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform2iv(location, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform2iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + self.base.Uniform2iv_(location, v); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform3f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: f32, y: f32, z: f32) { - self.base.Uniform3f(uniform, x, y, z) + self.base.Uniform3f(location, x, y, z) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform3fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform3fv(cx, uniform, data) + fn Uniform3fv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform3fv(location, v) + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform3fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + self.base.Uniform3fv_(location, v); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform3i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: i32, y: i32, z: i32) { - self.base.Uniform3i(uniform, x, y, z) + self.base.Uniform3i(location, x, y, z) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform3iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform3iv(cx, uniform, data) + fn Uniform3iv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform3iv(location, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform3iv_(&self, + location: Option<&WebGLUniformLocation>, + v: Vec) { + self.base.Uniform3iv_(location, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform4i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: i32, y: i32, z: i32, w: i32) { - self.base.Uniform4i(uniform, x, y, z, w) + self.base.Uniform4i(location, x, y, z, w) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform4iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform4iv(cx, uniform, data) + fn Uniform4iv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform4iv(location, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform4iv_(&self, + location: Option<&WebGLUniformLocation>, + v: Vec) { + self.base.Uniform4iv_(location, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform4f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: f32, y: f32, z: f32, w: f32) { - self.base.Uniform4f(uniform, x, y, z, w) + self.base.Uniform4f(location, x, y, z, w) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn Uniform4fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - self.base.Uniform4fv(cx, uniform, data) + fn Uniform4fv(&self, + location: Option<&WebGLUniformLocation>, + v: CustomAutoRooterGuard) { + self.base.Uniform4fv(location, v) + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform4fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + self.base.Uniform4fv_(location, v); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn UniformMatrix2fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, + fn UniformMatrix2fv(&self, + location: Option<&WebGLUniformLocation>, transpose: bool, - data: *mut JSObject) -> Fallible<()> { - self.base.UniformMatrix2fv(cx, uniform, transpose, data) + v: CustomAutoRooterGuard) { + self.base.UniformMatrix2fv(location, transpose, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn UniformMatrix3fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - transpose: bool, - data: *mut JSObject) -> Fallible<()> { - self.base.UniformMatrix3fv(cx, uniform, transpose, data) + fn UniformMatrix2fv_(&self, location: Option<&WebGLUniformLocation>, transpose: bool, value: Vec) { + self.base.UniformMatrix2fv_(location, transpose, value); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn UniformMatrix4fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, + fn UniformMatrix3fv(&self, + location: Option<&WebGLUniformLocation>, transpose: bool, - data: *mut JSObject) -> Fallible<()> { - self.base.UniformMatrix4fv(cx, uniform, transpose, data) + v: CustomAutoRooterGuard) { + self.base.UniformMatrix3fv(location, transpose, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn UniformMatrix3fv_(&self, location: Option<&WebGLUniformLocation>, transpose: bool, value: Vec) { + self.base.UniformMatrix3fv_(location, transpose, value); + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn UniformMatrix4fv(&self, + location: Option<&WebGLUniformLocation>, + transpose: bool, + v: CustomAutoRooterGuard) { + self.base.UniformMatrix4fv(location, transpose, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn UniformMatrix4fv_(&self, location: Option<&WebGLUniformLocation>, transpose: bool, value: Vec) { + self.base.UniformMatrix4fv_(location, transpose, value); } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 @@ -770,9 +806,13 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn VertexAttrib1fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - self.base.VertexAttrib1fv(cx, indx, data) + fn VertexAttrib1fv(&self, indx: u32, v: CustomAutoRooterGuard) { + self.base.VertexAttrib1fv(indx, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib1fv_(&self, indx: u32, v: Vec) { + self.base.VertexAttrib1fv_(indx, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -781,9 +821,13 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn VertexAttrib2fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - self.base.VertexAttrib2fv(cx, indx, data) + fn VertexAttrib2fv(&self, indx: u32, v: CustomAutoRooterGuard) { + self.base.VertexAttrib2fv(indx, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib2fv_(&self, indx: u32, v: Vec) { + self.base.VertexAttrib2fv_(indx, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -792,9 +836,13 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn VertexAttrib3fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - self.base.VertexAttrib3fv(cx, indx, data) + fn VertexAttrib3fv(&self, indx: u32, v: CustomAutoRooterGuard) { + self.base.VertexAttrib3fv(indx, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib3fv_(&self, indx: u32, v: Vec) { + self.base.VertexAttrib3fv_(indx, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -803,9 +851,13 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] - unsafe fn VertexAttrib4fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - self.base.VertexAttrib4fv(cx, indx, data) + fn VertexAttrib4fv(&self, indx: u32, v: CustomAutoRooterGuard) { + self.base.VertexAttrib4fv(indx, v) + } + + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib4fv_(&self, indx: u32, v: Vec) { + self.base.VertexAttrib4fv_(indx, v) } /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 5ce6efd03a3..8725e515861 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -47,10 +47,9 @@ use dom_struct::dom_struct; use euclid::Size2D; use fnv::FnvHashMap; use half::f16; -use js::conversions::ConversionBehavior; use js::jsapi::{JSContext, JSObject, Type}; use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue}; -use js::typedarray::{ArrayBufferView, TypedArray, TypedArrayElement, Float32, Int32}; +use js::typedarray::{ArrayBufferView, TypedArray, TypedArrayElement, Float32Array, Int32Array}; use js::rust::CustomAutoRooterGuard; use net_traits::image::base::PixelFormat; use net_traits::image_cache::ImageResponse; @@ -1160,38 +1159,6 @@ impl Drop for WebGLRenderingContext { } } -// FIXME: After [1] lands and the relevant Servo and codegen PR too, we should -// convert all our raw JSObject pointers to proper types. -// -// [1]: https://github.com/servo/rust-mozjs/pull/304 -#[allow(unsafe_code)] -unsafe fn typed_array_or_sequence_to_vec(cx: *mut JSContext, - sequence_or_abv: *mut JSObject, - config: ::Config) - -> Result, Error> - where T: TypedArrayElement, - T::Element: FromJSValConvertible + Clone, - ::Config: Clone, -{ - // TODO(servo/rust-mozjs#330): replace this with a macro that supports generic types. - let typed_array: Option> = - TypedArray::from(sequence_or_abv).ok(); - if let Some(mut typed_array) = typed_array { - return Ok(typed_array.as_slice().to_vec()); - } - assert!(!sequence_or_abv.is_null()); - rooted!(in(cx) let mut val = UndefinedValue()); - sequence_or_abv.to_jsval(cx, val.handle_mut()); - - match Vec::::from_jsval(cx, val.handle(), config) { - Ok(ConversionResult::Success(v)) => Ok(v), - Ok(ConversionResult::Failure(error)) => Err(Error::Type(error.into_owned())), - // FIXME: What to do here? Generated code only aborts the execution of - // the script. - Err(err) => panic!("unexpected conversion error: {:?}", err), - } -} - #[allow(unsafe_code)] unsafe fn fallible_array_buffer_view_to_vec(cx: *mut JSContext, abv: *mut JSObject) -> Result, Error> { @@ -2802,279 +2769,302 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform1f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, val: f32) { - if self.validate_uniform_parameters(uniform, UniformSetterType::Float, &[val]) { - self.send_command(WebGLCommand::Uniform1f(uniform.unwrap().id(), val)) + if self.validate_uniform_parameters(location, UniformSetterType::Float, &[val]) { + self.send_command(WebGLCommand::Uniform1f(location.unwrap().id(), val)) } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform1i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, val: i32) { - if self.validate_uniform_parameters(uniform, UniformSetterType::Int, &[val]) { - self.send_command(WebGLCommand::Uniform1i(uniform.unwrap().id(), val)) + if self.validate_uniform_parameters(location, UniformSetterType::Int, &[val]) { + self.send_command(WebGLCommand::Uniform1i(location.unwrap().id(), val)) } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform1iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ConversionBehavior::Default)?; + fn Uniform1iv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, UniformSetterType::Int, &data_vec) { - self.send_command(WebGLCommand::Uniform1iv(uniform.unwrap().id(), data_vec)) + self.Uniform1iv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform1iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::Int, &v) { + self.send_command(WebGLCommand::Uniform1iv(location.unwrap().id(), v)) } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform1fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn Uniform1fv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, UniformSetterType::Float, &data_vec) { - self.send_command(WebGLCommand::Uniform1fv(uniform.unwrap().id(), data_vec)); + self.Uniform1fv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform1fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::Float, &v) { + self.send_command(WebGLCommand::Uniform1fv(location.unwrap().id(), v)); } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform2f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: f32, y: f32) { - if self.validate_uniform_parameters(uniform, UniformSetterType::FloatVec2, &[x, y]) { - self.send_command(WebGLCommand::Uniform2f(uniform.unwrap().id(), x, y)); + if self.validate_uniform_parameters(location, UniformSetterType::FloatVec2, &[x, y]) { + self.send_command(WebGLCommand::Uniform2f(location.unwrap().id(), x, y)); } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform2fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn Uniform2fv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, + self.Uniform2fv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform2fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::FloatVec2, - &data_vec) { - self.send_command(WebGLCommand::Uniform2fv(uniform.unwrap().id(), data_vec)); + &v) { + self.send_command(WebGLCommand::Uniform2fv(location.unwrap().id(), v)); } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform2i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: i32, y: i32) { - if self.validate_uniform_parameters(uniform, + if self.validate_uniform_parameters(location, UniformSetterType::IntVec2, &[x, y]) { - self.send_command(WebGLCommand::Uniform2i(uniform.unwrap().id(), x, y)); + self.send_command(WebGLCommand::Uniform2i(location.unwrap().id(), x, y)); } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform2iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ConversionBehavior::Default)?; + fn Uniform2iv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, + self.Uniform2iv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform2iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::IntVec2, - &data_vec) { - self.send_command(WebGLCommand::Uniform2iv(uniform.unwrap().id(), data_vec)); + &v) { + self.send_command(WebGLCommand::Uniform2iv(location.unwrap().id(), v)); } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform3f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: f32, y: f32, z: f32) { - if self.validate_uniform_parameters(uniform, + if self.validate_uniform_parameters(location, UniformSetterType::FloatVec3, &[x, y, z]) { - self.send_command(WebGLCommand::Uniform3f(uniform.unwrap().id(), x, y, z)); + self.send_command(WebGLCommand::Uniform3f(location.unwrap().id(), x, y, z)); } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform3fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn Uniform3fv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, + self.Uniform3fv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform3fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::FloatVec3, - &data_vec) { - self.send_command(WebGLCommand::Uniform3fv(uniform.unwrap().id(), data_vec)) + &v) { + self.send_command(WebGLCommand::Uniform3fv(location.unwrap().id(), v)) } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform3i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: i32, y: i32, z: i32) { - if self.validate_uniform_parameters(uniform, + if self.validate_uniform_parameters(location, UniformSetterType::IntVec3, &[x, y, z]) { - self.send_command(WebGLCommand::Uniform3i(uniform.unwrap().id(), x, y, z)) + self.send_command(WebGLCommand::Uniform3i(location.unwrap().id(), x, y, z)) } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform3iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ConversionBehavior::Default)?; + fn Uniform3iv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, + self.Uniform3iv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform3iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::IntVec3, - &data_vec) { - self.send_command(WebGLCommand::Uniform3iv(uniform.unwrap().id(), data_vec)) + &v) { + self.send_command(WebGLCommand::Uniform3iv(location.unwrap().id(), v)) } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform4i(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: i32, y: i32, z: i32, w: i32) { - if self.validate_uniform_parameters(uniform, + if self.validate_uniform_parameters(location, UniformSetterType::IntVec4, &[x, y, z, w]) { - self.send_command(WebGLCommand::Uniform4i(uniform.unwrap().id(), x, y, z, w)) + self.send_command(WebGLCommand::Uniform4i(location.unwrap().id(), x, y, z, w)) } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform4iv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ConversionBehavior::Default)?; + fn Uniform4iv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, + self.Uniform4iv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform4iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::IntVec4, - &data_vec) { - self.send_command(WebGLCommand::Uniform4iv(uniform.unwrap().id(), data_vec)) + &v) { + self.send_command(WebGLCommand::Uniform4iv(location.unwrap().id(), v)) } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform4f(&self, - uniform: Option<&WebGLUniformLocation>, + location: Option<&WebGLUniformLocation>, x: f32, y: f32, z: f32, w: f32) { - if self.validate_uniform_parameters(uniform, + if self.validate_uniform_parameters(location, UniformSetterType::FloatVec4, &[x, y, z, w]) { - self.send_command(WebGLCommand::Uniform4f(uniform.unwrap().id(), x, y, z, w)) + self.send_command(WebGLCommand::Uniform4f(location.unwrap().id(), x, y, z, w)) } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn Uniform4fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn Uniform4fv(&self, + location: Option<&WebGLUniformLocation>, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - if self.validate_uniform_parameters(uniform, + self.Uniform4fv_(location, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn Uniform4fv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::FloatVec4, - &data_vec) { - self.send_command(WebGLCommand::Uniform4fv(uniform.unwrap().id(), data_vec)) + &v) { + self.send_command(WebGLCommand::Uniform4fv(location.unwrap().id(), v)) } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn UniformMatrix2fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, + fn UniformMatrix2fv(&self, + location: Option<&WebGLUniformLocation>, transpose: bool, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; - if self.validate_uniform_parameters(uniform, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; + + self.UniformMatrix2fv_(location, transpose, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn UniformMatrix2fv_(&self, + location: Option<&WebGLUniformLocation>, + transpose: bool, + value: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::FloatMat2, - &data_vec) { - self.send_command(WebGLCommand::UniformMatrix2fv(uniform.unwrap().id(), transpose, data_vec)); + &value) { + self.send_command(WebGLCommand::UniformMatrix2fv(location.unwrap().id(), transpose, value)); } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn UniformMatrix3fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, + fn UniformMatrix3fv(&self, + location: Option<&WebGLUniformLocation>, transpose: bool, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; - if self.validate_uniform_parameters(uniform, + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; + + self.UniformMatrix3fv_(location, transpose, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn UniformMatrix3fv_(&self, + location: Option<&WebGLUniformLocation>, + transpose: bool, + value: Vec) { + if self.validate_uniform_parameters(location, UniformSetterType::FloatMat3, - &data_vec) { - self.send_command(WebGLCommand::UniformMatrix3fv(uniform.unwrap().id(), transpose, data_vec)); + &value) { + self.send_command(WebGLCommand::UniformMatrix3fv(location.unwrap().id(), transpose, value)); } - - Ok(()) } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn UniformMatrix4fv(&self, - cx: *mut JSContext, - uniform: Option<&WebGLUniformLocation>, + fn UniformMatrix4fv(&self, + location: Option<&WebGLUniformLocation>, transpose: bool, - data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; - if self.validate_uniform_parameters(uniform, - UniformSetterType::FloatMat4, - &data_vec) { - self.send_command(WebGLCommand::UniformMatrix4fv(uniform.unwrap().id(), transpose, data_vec)); - } + mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; - Ok(()) + self.UniformMatrix4fv_(location, transpose, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn UniformMatrix4fv_(&self, + location: Option<&WebGLUniformLocation>, + transpose: bool, + value: Vec) { + if self.validate_uniform_parameters(location, + UniformSetterType::FloatMat4, + &value) { + self.send_command(WebGLCommand::UniformMatrix4fv(location.unwrap().id(), transpose, value)); + } } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9 @@ -3101,14 +3091,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn VertexAttrib1fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn VertexAttrib1fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; + if data_vec.len() < 1 { - return Ok(self.webgl_error(InvalidOperation)); + return self.webgl_error(InvalidOperation); } - self.vertex_attrib(indx, data_vec[0], 0f32, 0f32, 1f32); - Ok(()) + + self.VertexAttrib1fv_(indx, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib1fv_(&self, indx: u32, values: Vec) { + self.vertex_attrib(indx, values[0], 0f32, 0f32, 1f32); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3118,14 +3113,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn VertexAttrib2fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn VertexAttrib2fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; + if data_vec.len() < 2 { - return Ok(self.webgl_error(InvalidOperation)); + return self.webgl_error(InvalidOperation); } - self.vertex_attrib(indx, data_vec[0], data_vec[1], 0f32, 1f32); - Ok(()) + + self.VertexAttrib2fv_(indx, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib2fv_(&self, indx: u32, values: Vec) { + self.vertex_attrib(indx, values[0], values[1], 0f32, 1f32); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3135,14 +3135,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn VertexAttrib3fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn VertexAttrib3fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; + if data_vec.len() < 3 { - return Ok(self.webgl_error(InvalidOperation)); + return self.webgl_error(InvalidOperation); } - self.vertex_attrib(indx, data_vec[0], data_vec[1], data_vec[2], 1f32); - Ok(()) + + self.VertexAttrib3fv_(indx, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib3fv_(&self, indx: u32, values: Vec) { + self.vertex_attrib(indx, values[0], values[1], values[2], 1f32); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3152,15 +3157,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 #[allow(unsafe_code)] - unsafe fn VertexAttrib4fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> { - assert!(!data.is_null()); - let data_vec = typed_array_or_sequence_to_vec::(cx, data, ())?; + fn VertexAttrib4fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { + let data_vec = unsafe { v.as_slice().to_vec() }; + if data_vec.len() < 4 { - return Ok(self.webgl_error(InvalidOperation)); + return self.webgl_error(InvalidOperation); } - self.vertex_attrib(indx, data_vec[0], data_vec[1], data_vec[2], data_vec[3]); - Ok(()) + self.VertexAttrib4fv_(indx, data_vec); + } + + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 + fn VertexAttrib4fv_(&self, indx: u32, values: Vec) { + self.vertex_attrib(indx, values[0], values[1], values[2], values[3]); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl index b65582af929..9921adf2504 100644 --- a/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -648,98 +648,68 @@ interface WebGLRenderingContextBase GLenum format, GLenum type, TexImageSource source); // May throw DOMException void uniform1f(WebGLUniformLocation? location, GLfloat x); - //void uniform1fv(WebGLUniformLocation? location, Float32Array v); - //void uniform1fv(WebGLUniformLocation? location, sequence v); - [Throws] - void uniform1fv(WebGLUniformLocation? location, object v); - void uniform1i(WebGLUniformLocation? location, GLint x); - //void uniform1iv(WebGLUniformLocation? location, Int32Array v); - //void uniform1iv(WebGLUniformLocation? location, sequence v); - [Throws] - void uniform1iv(WebGLUniformLocation? location, object v); - void uniform2f(WebGLUniformLocation? location, GLfloat x, GLfloat y); - //void uniform2fv(WebGLUniformLocation? location, Float32Array v); - //void uniform2fv(WebGLUniformLocation? location, sequence v); - [Throws] - void uniform2fv(WebGLUniformLocation? location, object v); - //void uniform2i(WebGLUniformLocation? location, GLint x, GLint y); - void uniform2i(WebGLUniformLocation? location, GLint x, GLint y); - //void uniform2iv(WebGLUniformLocation? location, Int32Array v); - //void uniform2iv(WebGLUniformLocation? location, sequence v); - [Throws] - void uniform2iv(WebGLUniformLocation? location, object v); - void uniform3f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z); - [Throws] - void uniform3fv(WebGLUniformLocation? location, object v); - //void uniform3fv(WebGLUniformLocation? location, Float32Array v); - //void uniform3fv(WebGLUniformLocation? location, sequence v); - void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z); - //void uniform3iv(WebGLUniformLocation? location, Int32Array v); - //void uniform3iv(WebGLUniformLocation? location, sequence v); - [Throws] - void uniform3iv(WebGLUniformLocation? location, object v); - void uniform4f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); - // FIXME(dmarcos) The function below is the original function in the webIdl: - //void uniform4fv(WebGLUniformLocation? location, Float32Array v); - // The Code genearator doesn't handle typed arrays, so we use object - // instead, and handle the type error ourselves. - [Throws] - void uniform4fv(WebGLUniformLocation? location, object v); - //void uniform4fv(WebGLUniformLocation? location, sequence v); - void uniform4i(WebGLUniformLocation? location, GLint x, GLint y, GLint z, GLint w); - //void uniform4iv(WebGLUniformLocation? location, Int32Array v); - //void uniform4iv(WebGLUniformLocation? location, sequence v); - // See FIXME above - [Throws] - void uniform4iv(WebGLUniformLocation? location, object v); + void uniform1fv(WebGLUniformLocation? location, Float32Array v); + void uniform1fv(WebGLUniformLocation? location, sequence v); + + void uniform1i(WebGLUniformLocation? location, GLint x); + void uniform1iv(WebGLUniformLocation? location, Int32Array v); + void uniform1iv(WebGLUniformLocation? location, sequence v); + + void uniform2f(WebGLUniformLocation? location, GLfloat x, GLfloat y); + void uniform2fv(WebGLUniformLocation? location, Float32Array v); + void uniform2fv(WebGLUniformLocation? location, sequence v); + + void uniform2i(WebGLUniformLocation? location, GLint x, GLint y); + void uniform2iv(WebGLUniformLocation? location, Int32Array v); + void uniform2iv(WebGLUniformLocation? location, sequence v); + + void uniform3f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z); + void uniform3fv(WebGLUniformLocation? location, Float32Array v); + void uniform3fv(WebGLUniformLocation? location, sequence v); + + void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z); + void uniform3iv(WebGLUniformLocation? location, Int32Array v); + void uniform3iv(WebGLUniformLocation? location, sequence v); + + void uniform4f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void uniform4fv(WebGLUniformLocation? location, Float32Array v); + void uniform4fv(WebGLUniformLocation? location, sequence v); + + void uniform4i(WebGLUniformLocation? location, GLint x, GLint y, GLint z, GLint w); + void uniform4iv(WebGLUniformLocation? location, Int32Array v); + void uniform4iv(WebGLUniformLocation? location, sequence v); - //void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, - // Float32Array value); - //void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, - // sequence value); - [Throws] void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, - object v); - //void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, - // Float32Array value); - //void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, - // sequence value); - [Throws] + Float32Array value); + void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, + sequence value); void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, - object v); - //void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, - // Float32Array value); - //void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, - // sequence value); - [Throws] + Float32Array value); + void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, + sequence value); void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, - object v); + Float32Array value); + void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, + sequence value); void useProgram(WebGLProgram? program); void validateProgram(WebGLProgram program); - // FIXME(dmarcos) - // The code generator doesn't handle Float32Array so we're using 'object' void vertexAttrib1f(GLuint indx, GLfloat x); - //void vertexAttrib1fv(GLuint indx, Float32Array values); - [Throws] - void vertexAttrib1fv(GLuint indx, object values); - //void vertexAttrib1fv(GLuint indx, sequence values); + void vertexAttrib1fv(GLuint indx, Float32Array values); + void vertexAttrib1fv(GLuint indx, sequence values); + void vertexAttrib2f(GLuint indx, GLfloat x, GLfloat y); - //void vertexAttrib2fv(GLuint indx, Float32Array values); - [Throws] - void vertexAttrib2fv(GLuint indx, object values); - //void vertexAttrib2fv(GLuint indx, sequence values); + void vertexAttrib2fv(GLuint indx, Float32Array values); + void vertexAttrib2fv(GLuint indx, sequence values); + void vertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z); - //void vertexAttrib3fv(GLuint indx, Float32Array values); - [Throws] - void vertexAttrib3fv(GLuint indx, object values); - //void vertexAttrib3fv(GLuint indx, sequence values); + void vertexAttrib3fv(GLuint indx, Float32Array values); + void vertexAttrib3fv(GLuint indx, sequence values); + void vertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w); - //void vertexAttrib4fv(GLuint indx, Float32Array values); - [Throws] - void vertexAttrib4fv(GLuint indx, object values); - //void vertexAttrib4fv(GLuint indx, sequence values); + void vertexAttrib4fv(GLuint indx, Float32Array values); + void vertexAttrib4fv(GLuint indx, sequence values); void vertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset); From daceeb400294ce157b2901f0d2effd63b9aabf27 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 23 Mar 2018 02:01:51 +0100 Subject: [PATCH 4/9] Appease test-tidy --- components/script/dom/webgl2renderingcontext.rs | 3 ++- components/script/dom/webglrenderingcontext.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index e0ae2e22585..dd0701ace99 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -8,8 +8,8 @@ use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding; use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextMethods; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; -use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; use dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferView; +use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::reflector::{reflect_dom_object, Reflector}; use dom::bindings::root::{Dom, DomRoot, LayoutDom}; @@ -616,6 +616,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { self.base.Uniform1iv(location, v) } + /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn Uniform1iv_(&self, location: Option<&WebGLUniformLocation>, v: Vec) { self.base.Uniform1iv_(location, v); } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 8725e515861..d9f1893f357 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -14,9 +14,9 @@ use dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2Rende use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes}; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; -use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; use dom::bindings::codegen::UnionTypes::ArrayBufferOrArrayBufferView; -use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible}; +use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; +use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; @@ -49,8 +49,8 @@ use fnv::FnvHashMap; use half::f16; use js::jsapi::{JSContext, JSObject, Type}; use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UndefinedValue}; -use js::typedarray::{ArrayBufferView, TypedArray, TypedArrayElement, Float32Array, Int32Array}; use js::rust::CustomAutoRooterGuard; +use js::typedarray::{ArrayBufferView, Float32Array, Int32Array}; use net_traits::image::base::PixelFormat; use net_traits::image_cache::ImageResponse; use offscreen_gl_context::{GLContextAttributes, GLLimits}; From cb85a95478082b81be86b66244061ff1b9fc2815 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 23 Mar 2018 11:04:47 +0100 Subject: [PATCH 5/9] Fix sanity check in vertex attrib --- .../script/dom/webglrenderingcontext.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index d9f1893f357..3f498def960 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -3094,15 +3094,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { fn VertexAttrib1fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { let data_vec = unsafe { v.as_slice().to_vec() }; - if data_vec.len() < 1 { - return self.webgl_error(InvalidOperation); - } - self.VertexAttrib1fv_(indx, data_vec); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn VertexAttrib1fv_(&self, indx: u32, values: Vec) { + if values.len() < 1 { + return self.webgl_error(InvalidOperation); + } + self.vertex_attrib(indx, values[0], 0f32, 0f32, 1f32); } @@ -3116,15 +3116,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { fn VertexAttrib2fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { let data_vec = unsafe { v.as_slice().to_vec() }; - if data_vec.len() < 2 { - return self.webgl_error(InvalidOperation); - } - self.VertexAttrib2fv_(indx, data_vec); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn VertexAttrib2fv_(&self, indx: u32, values: Vec) { + if values.len() < 2 { + return self.webgl_error(InvalidOperation); + } + self.vertex_attrib(indx, values[0], values[1], 0f32, 1f32); } @@ -3138,15 +3138,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { fn VertexAttrib3fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { let data_vec = unsafe { v.as_slice().to_vec() }; - if data_vec.len() < 3 { - return self.webgl_error(InvalidOperation); - } - self.VertexAttrib3fv_(indx, data_vec); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn VertexAttrib3fv_(&self, indx: u32, values: Vec) { + if values.len() < 3 { + return self.webgl_error(InvalidOperation); + } + self.vertex_attrib(indx, values[0], values[1], values[2], 1f32); } @@ -3160,15 +3160,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { fn VertexAttrib4fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { let data_vec = unsafe { v.as_slice().to_vec() }; - if data_vec.len() < 4 { - return self.webgl_error(InvalidOperation); - } - self.VertexAttrib4fv_(indx, data_vec); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 fn VertexAttrib4fv_(&self, indx: u32, values: Vec) { + if values.len() < 4 { + return self.webgl_error(InvalidOperation); + } + self.vertex_attrib(indx, values[0], values[1], values[2], values[3]); } From c42127b683ccf2aa81858da77f56c993189e0bc1 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 23 Mar 2018 17:42:51 +0100 Subject: [PATCH 6/9] Fix indentation --- components/script/dom/webglrenderingcontext.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 3f498def960..194fe8a7d57 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -825,12 +825,12 @@ impl WebGLRenderingContext { // TODO(emilio): Move this logic to a validator. fn validate_tex_image_2d_data(&self, - width: u32, - height: u32, - format: TexFormat, - data_type: TexDataType, - unpacking_alignment: u32, - data: &Option) + width: u32, + height: u32, + format: TexFormat, + data_type: TexDataType, + unpacking_alignment: u32, + data: &Option) -> Result { let element_size = data_type.element_size(); let components_per_element = data_type.components_per_element(); From 2437a8472e3c2f9201fa4fc3fca06537ebf52d62 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 23 Mar 2018 18:06:55 +0100 Subject: [PATCH 7/9] Unify argument auto rooting in codegen --- .../dom/bindings/codegen/CodegenRust.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 6e0632fe97d..de991f35ed9 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -418,15 +418,12 @@ class CGMethodCall(CGThing): template = info.template declType = info.declType - argName = "arg%d" % distinguishingIndex - testCode = instantiateJSToNativeConversionTemplate( template, {"val": distinguishingArg}, declType, - argName) - if type_needs_auto_root(type): - testCode.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (argName, argName))) + "arg%d" % distinguishingIndex, + needsAutoRoot=type_needs_auto_root(type)) # Indent by 4, since we need to indent further than our "do" statement caseBody.append(CGIndenter(testCode, 4)) @@ -1215,7 +1212,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, def instantiateJSToNativeConversionTemplate(templateBody, replacements, - declType, declName): + declType, declName, + needsAutoRoot=False): """ Take the templateBody and declType as returned by getJSToNativeConversionInfo, a set of replacements as required by the @@ -1240,6 +1238,8 @@ def instantiateJSToNativeConversionTemplate(templateBody, replacements, else: result.append(conversion) + if needsAutoRoot: + result.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (declName, declName))) # Add an empty CGGeneric to get an extra newline after the argument # conversion. result.append(CGGeneric("")) @@ -1322,11 +1322,8 @@ class CGArgumentConverter(CGThing): arg = "arg%d" % index self.converter = instantiateJSToNativeConversionTemplate( - template, replacementVariables, declType, arg) - - # The auto rooting is done only after the conversion is performed - if type_needs_auto_root(argument.type): - self.converter.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (arg, arg))) + template, replacementVariables, declType, arg, + needsAutoRoot=type_needs_auto_root(argument.type)) else: assert argument.optional From fbfcc762e12d5be050334b172e27bb33966fe2f3 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 23 Mar 2018 18:38:39 +0100 Subject: [PATCH 8/9] Add codegen test for function overloads taking typed array args --- components/script/dom/testbinding.rs | 3 +++ components/script/dom/webidls/TestBinding.webidl | 3 +++ 2 files changed, 6 insertions(+) diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index a5bb29a7e76..2beaa4d8897 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -472,6 +472,9 @@ impl TestBindingMethods for TestBinding { fn PassStringSequence(&self, _: Vec) {} fn PassInterfaceSequence(&self, _: Vec>) {} + fn PassOverloaded(&self, _: CustomAutoRooterGuard) {} + fn PassOverloaded_(&self, _: DOMString) {} + fn PassNullableBoolean(&self, _: Option) {} fn PassNullableByte(&self, _: Option) {} fn PassNullableOctet(&self, _: Option) {} diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index 1a1c86293cb..f95f4505ffb 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -275,6 +275,9 @@ interface TestBinding { void passStringSequence(sequence seq); void passInterfaceSequence(sequence seq); + void passOverloaded(ArrayBuffer arg); + void passOverloaded(DOMString arg); + void passNullableBoolean(boolean? arg); void passNullableByte(byte? arg); void passNullableOctet(octet? arg); From 80c6891f339c52778ee7133b3b3f8ae9c8c350e5 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 23 Mar 2018 19:37:25 +0100 Subject: [PATCH 9/9] Use safe to_vec() for typed arrays in WebGL bindings --- .../script/dom/webglrenderingcontext.rs | 96 ++++--------------- 1 file changed, 21 insertions(+), 75 deletions(-) diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 194fe8a7d57..d9d993e5b21 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1165,7 +1165,7 @@ unsafe fn fallible_array_buffer_view_to_vec(cx: *mut JSContext, abv: *mut JSObje assert!(!abv.is_null()); typedarray!(in(cx) let array_buffer_view: ArrayBufferView = abv); match array_buffer_view { - Ok(mut v) => Ok(v.as_slice().to_vec()), + Ok(mut v) => Ok(v.to_vec()), Err(_) => Err(Error::Type("Not an ArrayBufferView".to_owned())), } } @@ -1609,7 +1609,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { typedarray!(in(cx) let array_buffer: ArrayBuffer = data); let data_vec = match array_buffer { - Ok(mut data) => data.as_slice().to_vec(), + Ok(mut data) => data.to_vec(), Err(_) => fallible_array_buffer_view_to_vec(cx, data)?, }; @@ -1669,12 +1669,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 - #[allow(unsafe_code)] fn BufferSubData(&self, target: u32, offset: i64, data: Option) { let data_vec = match data { // Typed array is rooted, so we can safely temporarily retrieve its slice - Some(ArrayBufferOrArrayBufferView::ArrayBuffer(mut inner)) => unsafe { inner.as_slice().to_vec() }, - Some(ArrayBufferOrArrayBufferView::ArrayBufferView(mut inner)) => unsafe { inner.as_slice().to_vec() }, + Some(ArrayBufferOrArrayBufferView::ArrayBuffer(mut inner)) => inner.to_vec(), + Some(ArrayBufferOrArrayBufferView::ArrayBufferView(mut inner)) => inner.to_vec(), // Spec: If data is null then an INVALID_VALUE error is generated. None => return self.webgl_error(InvalidValue), }; @@ -2786,13 +2785,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform1iv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform1iv_(location, data_vec); + self.Uniform1iv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2803,13 +2799,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform1fv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform1fv_(location, data_vec); + self.Uniform1fv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2829,13 +2822,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform2fv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform2fv_(location, data_vec); + self.Uniform2fv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2859,13 +2849,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform2iv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform2iv_(location, data_vec); + self.Uniform2iv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2889,13 +2876,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform3fv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform3fv_(location, data_vec); + self.Uniform3fv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2919,13 +2903,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform3iv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform3iv_(location, data_vec); + self.Uniform3iv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2950,13 +2931,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform4iv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform4iv_(location, data_vec); + self.Uniform4iv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2980,13 +2958,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn Uniform4fv(&self, location: Option<&WebGLUniformLocation>, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.Uniform4fv_(location, data_vec); + self.Uniform4fv_(location, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -2999,14 +2974,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn UniformMatrix2fv(&self, location: Option<&WebGLUniformLocation>, transpose: bool, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.UniformMatrix2fv_(location, transpose, data_vec); + self.UniformMatrix2fv_(location, transpose, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3022,14 +2994,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn UniformMatrix3fv(&self, location: Option<&WebGLUniformLocation>, transpose: bool, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.UniformMatrix3fv_(location, transpose, data_vec); + self.UniformMatrix3fv_(location, transpose, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3045,14 +3014,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn UniformMatrix4fv(&self, location: Option<&WebGLUniformLocation>, transpose: bool, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.UniformMatrix4fv_(location, transpose, data_vec); + self.UniformMatrix4fv_(location, transpose, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3090,11 +3056,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn VertexAttrib1fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.VertexAttrib1fv_(indx, data_vec); + self.VertexAttrib1fv_(indx, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3112,11 +3075,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn VertexAttrib2fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.VertexAttrib2fv_(indx, data_vec); + self.VertexAttrib2fv_(indx, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3134,11 +3094,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn VertexAttrib3fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.VertexAttrib3fv_(indx, data_vec); + self.VertexAttrib3fv_(indx, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3156,11 +3113,8 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 - #[allow(unsafe_code)] fn VertexAttrib4fv(&self, indx: u32, mut v: CustomAutoRooterGuard) { - let data_vec = unsafe { v.as_slice().to_vec() }; - - self.VertexAttrib4fv_(indx, data_vec); + self.VertexAttrib4fv_(indx, v.to_vec()); } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10 @@ -3228,7 +3182,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - #[allow(unsafe_code)] fn TexImage2D(&self, target: u32, level: i32, @@ -3275,10 +3228,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // initialized to 0 is passed. let buff = match *pixels { None => vec![0u8; expected_byte_length as usize], - Some(ref mut data) => { - // Since the typed array is rooted, this is safe to perform - unsafe { data.as_slice().to_vec() } - } + Some(ref mut data) => data.to_vec(), }; // From the WebGL spec: @@ -3396,7 +3346,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { } // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 - #[allow(unsafe_code)] fn TexSubImage2D(&self, target: u32, level: i32, @@ -3438,10 +3387,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // initialized to 0 is passed. let buff = match *pixels { None => vec![0u8; expected_byte_length as usize], - Some(ref mut data) => { - // Since the typed array is rooted, this is safe to perform - unsafe { data.as_slice().to_vec() } - } + Some(ref mut data) => data.to_vec(), }; // From the WebGL spec: