diff --git a/components/script/dom/webglrenderbuffer.rs b/components/script/dom/webglrenderbuffer.rs index de4eaa2d2c89..9e3c516cfbde 100644 --- a/components/script/dom/webglrenderbuffer.rs +++ b/components/script/dom/webglrenderbuffer.rs @@ -5,13 +5,14 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl use canvas_traits::CanvasMsg; use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::js::Root; use dom::bindings::reflector::reflect_dom_object; use dom::globalscope::GlobalScope; use dom::webglobject::WebGLObject; use ipc_channel::ipc::{self, IpcSender}; use std::cell::Cell; -use webrender_traits::{WebGLCommand, WebGLRenderbufferId}; +use webrender_traits::{WebGLCommand, WebGLRenderbufferId, WebGLResult, WebGLError}; #[dom_struct] pub struct WebGLRenderbuffer { @@ -19,6 +20,7 @@ pub struct WebGLRenderbuffer { id: WebGLRenderbufferId, ever_bound: Cell, is_deleted: Cell, + internal_format: Cell>, #[ignore_heap_size_of = "Defined in ipc-channel"] renderer: IpcSender, } @@ -33,6 +35,7 @@ impl WebGLRenderbuffer { ever_bound: Cell::new(false), is_deleted: Cell::new(false), renderer: renderer, + internal_format: Cell::new(None), } } @@ -81,4 +84,28 @@ impl WebGLRenderbuffer { pub fn ever_bound(&self) -> bool { self.ever_bound.get() } + + pub fn storage(&self, internal_format: u32, width: i32, height: i32) -> WebGLResult<()> { + // Validate the internal_format, and save it for completeness + // validation. + match internal_format { + constants::RGBA4 | + constants::DEPTH_STENCIL | + constants::DEPTH_COMPONENT16 | + constants::STENCIL_INDEX8 => + self.internal_format.set(Some(internal_format)), + + _ => return Err(WebGLError::InvalidEnum), + }; + + // FIXME: Check that w/h are < MAX_RENDERBUFFER_SIZE + + // FIXME: Invalidate completeness after the call + + let msg = CanvasMsg::WebGL(WebGLCommand::RenderbufferStorage(constants::RENDERBUFFER, + internal_format, width, height)); + self.renderer.send(msg).unwrap(); + + Ok(()) + } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index c93e80d805ee..a40de7da9c8c 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -2569,6 +2569,39 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { None => return constants::FRAMEBUFFER_COMPLETE, } } + + fn RenderbufferStorage(&self, target: u32, internal_format: u32, + width: i32, height: i32) { + // From the GLES 2.0.25 spec: + // + // "target must be RENDERBUFFER." + if target != constants::RENDERBUFFER { + return self.webgl_error(InvalidOperation) + } + + // From the GLES 2.0.25 spec: + // + // "If either width or height is greater than the value of + // MAX_RENDERBUFFER_SIZE , the error INVALID_VALUE is + // generated." + // + // and we have to throw out negative-size values as well just + // like for TexImage. + // + // FIXME: Handle max_renderbuffer_size, which doesn't seem to + // be in limits. + if width < 0 || height < 0 { + return self.webgl_error(InvalidValue); + } + + match self.bound_renderbuffer.get() { + Some(rb) => handle_potential_webgl_error!(self, rb.storage(internal_format, width, height)), + None => self.webgl_error(InvalidOperation), + }; + + // FIXME: We need to clear the renderbuffer before it can be + // accessed. See https://github.com/servo/servo/issues/13710 + } } pub trait LayoutCanvasWebGLRenderingContextHelpers { diff --git a/components/script/dom/webidls/WebGLRenderingContext.webidl b/components/script/dom/webidls/WebGLRenderingContext.webidl index 06bd03a9fd7f..913eb6445459 100644 --- a/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -626,8 +626,8 @@ interface WebGLRenderingContextBase void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, object? pixels); - //void renderbufferStorage(GLenum target, GLenum internalformat, - // GLsizei width, GLsizei height); + void renderbufferStorage(GLenum target, GLenum internalformat, + GLsizei width, GLsizei height); void sampleCoverage(GLclampf value, GLboolean invert); void scissor(GLint x, GLint y, GLsizei width, GLsizei height); diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/context/methods.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/context/methods.html.ini index a498d1b39a50..6b1b2a64df36 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/context/methods.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/context/methods.html.ini @@ -86,9 +86,6 @@ [WebGL test #29: Property either does not exist or is not a function: readPixels] expected: FAIL - [WebGL test #30: Property either does not exist or is not a function: renderbufferStorage] - expected: FAIL - [WebGL test #31: Property either does not exist or is not a function: sampleCoverage] expected: FAIL @@ -227,9 +224,6 @@ [WebGL test #25: Property either does not exist or is not a function: readPixels] expected: FAIL - [WebGL test #26: Property either does not exist or is not a function: renderbufferStorage] - expected: FAIL - [WebGL test #27: Property either does not exist or is not a function: sampleCoverage] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/invalid-passed-params.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/invalid-passed-params.html.ini index 7902ca6a6eb9..6199e0354ce5 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/invalid-passed-params.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/invalid-passed-params.html.ini @@ -45,12 +45,6 @@ [WebGL test #23: getError expected: NO_ERROR. Was INVALID_VALUE : after evaluating: context.texSubImage2D(context.TEXTURE_2D, 0, 0, 0, 2, 2, context.RGBA, context.UNSIGNED_BYTE, pixels)] expected: FAIL - [WebGL test #30: context.renderbufferStorage(context.RENDERBUFFER, context.RGBA4, -2, -2) threw exception TypeError: context.renderbufferStorage is not a function] - expected: FAIL - - [WebGL test #31: context.renderbufferStorage(context.RENDERBUFFER, context.RGBA4, 16, 16) threw exception TypeError: context.renderbufferStorage is not a function] - expected: FAIL - [WebGL test #44: context.getError() should be 1281. Was 0.] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/object-deletion-behaviour.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/object-deletion-behaviour.html.ini index 9bb30e508802..d878ff93ddb2 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/object-deletion-behaviour.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/object-deletion-behaviour.html.ini @@ -60,9 +60,6 @@ [WebGL test #74: gl.isRenderbuffer(rbo) should be false. Threw exception TypeError: gl.isRenderbuffer is not a function] expected: FAIL - [WebGL test #83: gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16) threw exception TypeError: gl.renderbufferStorage is not a function] - expected: FAIL - [WebGL test #85: gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo) threw exception TypeError: gl.framebufferRenderbuffer is not a function] expected: FAIL @@ -72,18 +69,12 @@ [WebGL test #51: getError expected: NO_ERROR. Was INVALID_OPERATION : after evaluating: gl.bindTexture(gl.TEXTURE_2D, t)] expected: FAIL - [WebGL test #87: gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16) threw exception TypeError: gl.renderbufferStorage is not a function] - expected: FAIL - [WebGL test #89: gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo) threw exception TypeError: gl.framebufferRenderbuffer is not a function] expected: FAIL [WebGL test #94: gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0) threw exception TypeError: gl.framebufferTexture2D is not a function] expected: FAIL - [WebGL test #98: gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16) threw exception TypeError: gl.renderbufferStorage is not a function] - expected: FAIL - [WebGL test #100: gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo) threw exception TypeError: gl.framebufferRenderbuffer is not a function] expected: FAIL @@ -126,9 +117,6 @@ [WebGL test #156: getError expected: NO_ERROR. Was INVALID_ENUM : after evaluating: gl.bindFramebuffer(gl.FRAMEBUFFER, fbo)] expected: FAIL - [WebGL test #171: gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 16, 16) threw exception TypeError: gl.renderbufferStorage is not a function] - expected: FAIL - [WebGL test #172: gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rbo) threw exception TypeError: gl.framebufferRenderbuffer is not a function] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/uninitialized-test.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/uninitialized-test.html.ini index a6a8447f2dc1..b7ebd19cea09 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/uninitialized-test.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/misc/uninitialized-test.html.ini @@ -1,6 +1,6 @@ [uninitialized-test.html] type: testharness - expected: ERROR + disabled: https://github.com/servo/servo/issues/13710 + [WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] expected: FAIL - diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/renderbuffers/renderbuffer-initialization.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/renderbuffers/renderbuffer-initialization.html.ini index 2d57461b214e..890fbb6f19f7 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/renderbuffers/renderbuffer-initialization.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/renderbuffers/renderbuffer-initialization.html.ini @@ -1,9 +1,12 @@ [renderbuffer-initialization.html] type: testharness - expected: ERROR + disabled: https://github.com/servo/servo/issues/13710 + [WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] expected: FAIL [WebGL test #1: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] expected: FAIL + [WebGL test #2: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] + expected: FAIL