From 6651db8b564a5c23141856ed96e460897b9743c0 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 12 Aug 2016 23:50:57 -0700 Subject: [PATCH] webgl: Add support for getParameter(GL_FRAMEBUFFER_BINDING). To do this, we need to keep a map of GL names (encapsulated as WebGLFramebufferId) to WebGLFramebuffer objects so that we can return the right type. Fixes #12852 --- .../script/dom/webglrenderingcontext.rs | 24 ++++++ .../gl-disabled-vertex-attrib.html.ini | 9 +- .../copy-tex-image-2d-formats.html.ini | 15 ---- ...b-image-2d-with-array-buffer-view.html.ini | 48 ++++------- .../textures/texture-npot.html.ini | 84 ------------------- 5 files changed, 44 insertions(+), 136 deletions(-) diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index f9025639716..4db5654d738 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -82,6 +82,7 @@ pub struct WebGLRenderingContext { #[ignore_heap_size_of = "Defined in webrender_traits"] last_error: Cell>, texture_unpacking_settings: Cell, + bound_framebuffer: MutNullableHeap>, bound_texture_2d: MutNullableHeap>, bound_texture_cube_map: MutNullableHeap>, bound_buffer_array: MutNullableHeap>, @@ -111,6 +112,7 @@ impl WebGLRenderingContext { canvas: JS::from_ref(canvas), last_error: Cell::new(None), texture_unpacking_settings: Cell::new(CONVERT_COLORSPACE), + bound_framebuffer: MutNullableHeap::new(None), bound_texture_2d: MutNullableHeap::new(None), bound_texture_cube_map: MutNullableHeap::new(None), bound_buffer_array: MutNullableHeap::new(None), @@ -511,6 +513,22 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3 fn GetParameter(&self, cx: *mut JSContext, parameter: u32) -> JSVal { + // Handle the GL_FRAMEBUFFER_BINDING without going all the way + // to the GL, since we would just need to map back from GL's + // returned ID to the WebGLFramebuffer we're tracking. + match parameter { + constants::FRAMEBUFFER_BINDING => { + rooted!(in(cx) let mut rval = NullValue()); + if let Some(bound_fb) = self.bound_framebuffer.get() { + unsafe { + bound_fb.to_jsval(cx, rval.handle_mut()); + } + } + return rval.get() + } + _ => {} + } + let (sender, receiver) = ipc::channel().unwrap(); self.ipc_renderer .send(CanvasMsg::WebGL(WebGLCommand::GetParameter(parameter, sender))) @@ -671,6 +689,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { return self.webgl_error(InvalidOperation); } + self.bound_framebuffer.set(framebuffer); if let Some(framebuffer) = framebuffer { framebuffer.bind(target) } else { @@ -1083,6 +1102,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6 fn DeleteFramebuffer(&self, framebuffer: Option<&WebGLFramebuffer>) { if let Some(framebuffer) = framebuffer { + if let Some(bound_fb) = self.bound_framebuffer.get() { + if bound_fb.id() == framebuffer.id() { + self.bound_framebuffer.set(None); + } + } framebuffer.delete() } } diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-disabled-vertex-attrib.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-disabled-vertex-attrib.html.ini index dfbb5ff9fad..b6bfc0e81f1 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-disabled-vertex-attrib.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/attribs/gl-disabled-vertex-attrib.html.ini @@ -1,11 +1,6 @@ [gl-disabled-vertex-attrib.html] type: testharness - [WebGL test #0: successfullyParsed should be true (of type boolean). Was undefined (of type undefined).] - expected: FAIL - [WebGL test #15: at (0, 0) expected: 0,255,0,255 was 255,255,255,255] - expected: FAIL - - [WebGL test #16: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors] - expected: FAIL + expected: + if os == "mac": FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/copy-tex-image-2d-formats.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/copy-tex-image-2d-formats.html.ini index 18ab3c5a0ca..3bd72604ccd 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/copy-tex-image-2d-formats.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/copy-tex-image-2d-formats.html.ini @@ -1,20 +1,5 @@ [copy-tex-image-2d-formats.html] type: testharness - [WebGL test #3: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors] - expected: FAIL - - [WebGL test #6: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors] - expected: FAIL - - [WebGL test #9: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors] - expected: FAIL - - [WebGL test #12: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors] - expected: FAIL - - [WebGL test #15: getError expected: NO_ERROR. Was INVALID_ENUM : should be no errors] - expected: FAIL - [WebGL test #16: 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/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html.ini index af5ba37c9fa..ccf1ef3349e 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html.ini @@ -36,72 +36,60 @@ [WebGL test #11: at (8, 12) expected: 255,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #12: GL error before texture upload] - expected: FAIL - - [WebGL test #25: GL error before texture upload] - expected: FAIL - [WebGL test #26: at (0, 0) expected: 0,0,0,255 was 255,0,0,255] expected: FAIL - [WebGL test #27: at (0, 8) expected: 255,0,0,255 was 0,255,0,255] + [WebGL test #24: at (0, 0) expected: 0,0,0,255 was 255,0,0,255] expected: FAIL - [WebGL test #28: at (0, 0) expected: 0,0,0,255 was 255,0,0,255] + [WebGL test #25: at (0, 8) expected: 255,0,0,255 was 0,255,0,255] expected: FAIL - [WebGL test #29: at (0, 4) expected: 255,0,0,255 was 0,0,255,255] + [WebGL test #27: at (0, 4) expected: 255,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #30: at (8, 0) expected: 0,0,0,255 was 255,0,0,255] + [WebGL test #28: at (8, 0) expected: 0,0,0,255 was 255,0,0,255] expected: FAIL - [WebGL test #31: at (0, 8) expected: 255,0,0,255 was 0,255,0,255] + [WebGL test #29: at (0, 8) expected: 255,0,0,255 was 0,255,0,255] expected: FAIL - [WebGL test #32: at (0, 0) expected: 0,0,0,255 was 255,0,0,255] + [WebGL test #30: at (0, 0) expected: 0,0,0,255 was 255,0,0,255] expected: FAIL - [WebGL test #33: at (0, 4) expected: 255,0,0,255 was 0,0,255,255] + [WebGL test #31: at (0, 4) expected: 255,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #34: at (8, 0) expected: 0,0,0,255 was 255,0,0,255] + [WebGL test #32: at (8, 0) expected: 0,0,0,255 was 255,0,0,255] expected: FAIL - [WebGL test #35: at (0, 8) expected: 255,0,0,255 was 0,255,0,255] + [WebGL test #33: at (0, 8) expected: 255,0,0,255 was 0,255,0,255] expected: FAIL - [WebGL test #36: at (8, 8) expected: 0,0,0,255 was 255,0,0,255] + [WebGL test #34: at (8, 8) expected: 0,0,0,255 was 255,0,0,255] expected: FAIL - [WebGL test #37: at (8, 12) expected: 255,0,0,255 was 0,0,255,255] + [WebGL test #35: at (8, 12) expected: 255,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #38: GL error before texture upload] + [WebGL test #37: at (0, 8) expected: 0,0,0,255 was 0,255,0,255] expected: FAIL - [WebGL test #40: at (0, 8) expected: 0,0,0,255 was 0,255,0,255] + [WebGL test #39: at (0, 4) expected: 0,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #42: at (0, 4) expected: 0,0,0,255 was 0,0,255,255] + [WebGL test #41: at (0, 8) expected: 0,0,0,255 was 0,255,0,255] expected: FAIL - [WebGL test #44: at (0, 8) expected: 0,0,0,255 was 0,255,0,255] + [WebGL test #43: at (0, 4) expected: 0,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #46: at (0, 4) expected: 0,0,0,255 was 0,0,255,255] + [WebGL test #45: at (0, 8) expected: 0,0,0,255 was 0,255,0,255] expected: FAIL - [WebGL test #48: at (0, 8) expected: 0,0,0,255 was 0,255,0,255] + [WebGL test #47: at (8, 12) expected: 0,0,0,255 was 0,0,255,255] expected: FAIL - [WebGL test #50: at (8, 12) expected: 0,0,0,255 was 0,0,255,255] - expected: FAIL - - [WebGL test #51: GL error before texture upload] - expected: FAIL - - [WebGL test #52: successfullyParsed should be true. Was false.] + [WebGL test #48: successfullyParsed should be true. Was false.] expected: FAIL diff --git a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-npot.html.ini b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-npot.html.ini index 97ff4a8fd16..8a6030370de 100644 --- a/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-npot.html.ini +++ b/tests/wpt/metadata/webgl/conformance-1.0.3/conformance/textures/texture-npot.html.ini @@ -3,117 +3,33 @@ [WebGL test #4: at (0, 0) expected: 0,0,0,255 was 192,0,128,64] expected: FAIL - [WebGL test #5: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #7: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #9: getError expected: INVALID_VALUE. Was INVALID_ENUM : copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE.] - expected: FAIL - - [WebGL test #12: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #14: getError expected: NO_ERROR. Was INVALID_OPERATION : gl.texImage2D with NPOT texture at level 0 should succeed] expected: FAIL - [WebGL test #17: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #19: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #20: at (0, 0) expected: 192,0,128,255 was 0,0,0,255] expected: FAIL - [WebGL test #21: getError expected: INVALID_VALUE. Was INVALID_ENUM : copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE.] - expected: FAIL - - [WebGL test #24: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #26: getError expected: NO_ERROR. Was INVALID_OPERATION : gl.texImage2D with NPOT texture at level 0 should succeed] expected: FAIL - [WebGL test #29: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #31: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #32: at (0, 0) expected: 192,192,192,255 was 0,0,0,255] expected: FAIL - [WebGL test #33: getError expected: INVALID_VALUE. Was INVALID_ENUM : copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE.] - expected: FAIL - - [WebGL test #36: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #38: getError expected: NO_ERROR. Was INVALID_OPERATION : gl.texImage2D with NPOT texture at level 0 should succeed] expected: FAIL - [WebGL test #41: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #43: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #44: at (0, 0) expected: 0,0,0,64 was 0,0,0,255] expected: FAIL - [WebGL test #45: getError expected: INVALID_VALUE. Was INVALID_ENUM : copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE.] - expected: FAIL - - [WebGL test #48: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #50: getError expected: NO_ERROR. Was INVALID_OPERATION : gl.texImage2D with NPOT texture at level 0 should succeed] expected: FAIL - [WebGL test #53: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #55: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #56: at (0, 0) expected: 192,192,192,64 was 0,0,0,255] expected: FAIL - [WebGL test #57: getError expected: INVALID_VALUE. Was INVALID_ENUM : copyTexImage2D with NPOT texture with level > 0 should return INVALID_VALUE.] - expected: FAIL - - [WebGL test #60: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - [WebGL test #64: at (0, 0) expected: 0,0,0,255 was 0,192,128,255] expected: FAIL - [WebGL test #65: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from draw.] - expected: FAIL - - [WebGL test #67: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #69: getError expected: NO_ERROR. Was INVALID_ENUM : gl.texImage2D with POT texture at level 0 should succeed] - expected: FAIL - - [WebGL test #71: getError expected: NO_ERROR. Was INVALID_ENUM : gl.generateMipmap with POT texture should return succeed] - expected: FAIL - [WebGL test #76: at (0, 0) expected: 0,0,0,255 was 0,192,128,255] expected: FAIL - [WebGL test #77: getError returned INVALID_ENUM. Possibly Chromium bug where texture unit is set to 0 instead of GL_TEXTURE0.] - expected: FAIL - - [WebGL test #79: getError expected: NO_ERROR. Was INVALID_ENUM : Should be no errors from setup.] - expected: FAIL - - [WebGL test #81: getError expected: NO_ERROR. Was INVALID_ENUM : gl.texImage2D with POT texture at level 0 should succeed] - expected: FAIL - - [WebGL test #83: getError expected: NO_ERROR. Was INVALID_ENUM : gl.generateMipmap with POT texture should return succeed] - expected: FAIL -