From eaf4d76084e325b44b4d1c1e9acd51a6531cbcb8 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 5 Jan 2017 02:11:29 -0800 Subject: [PATCH] servo: Merge #14847 - webgl: implement bufferData (from anholt:webgl-bufferdata); r=emilio Adds support for the other overload of bufferData, fixing many conformance tests. In the process I had to fix the webidl codegen in the overload-distinguished-by-an-object case. Also includes a little fix for glEnable() validation. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ Source-Repo: https://github.com/servo/servo Source-Revision: 4216c16879efb6e87b3ba3b7b4d5c2aeb8e2739d --- .../dom/bindings/codegen/CodegenRust.py | 9 +++-- .../script/dom/webglrenderingcontext.rs | 34 ++++++++++++++++++- .../dom/webidls/WebGLRenderingContext.webidl | 5 ++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/servo/components/script/dom/bindings/codegen/CodegenRust.py b/servo/components/script/dom/bindings/codegen/CodegenRust.py index 579f84301d30..19d279cc71e2 100644 --- a/servo/components/script/dom/bindings/codegen/CodegenRust.py +++ b/servo/components/script/dom/bindings/codegen/CodegenRust.py @@ -398,7 +398,7 @@ class CGMethodCall(CGThing): return False # First check for null or undefined - pickFirstSignature("%s.isNullOrUndefined()" % distinguishingArg, + pickFirstSignature("%s.get().is_null_or_undefined()" % distinguishingArg, lambda s: (s[1][distinguishingIndex].type.nullable() or s[1][distinguishingIndex].type.isDictionary())) @@ -467,7 +467,11 @@ class CGMethodCall(CGThing): # Check for Date objects # XXXbz Do we need to worry about security wrappers around the Date? - pickFirstSignature("%s.get().is_object() && JS_ObjectIsDate(cx, &%s.get().to_object())" % + pickFirstSignature("%s.get().is_object() && " + "{ rooted!(in(cx) let obj = %s.get().to_object()); " + "let mut is_date = false; " + "assert!(JS_ObjectIsDate(cx, obj.handle(), &mut is_date)); " + "is_date }" % (distinguishingArg, distinguishingArg), lambda s: (s[1][distinguishingIndex].type.isDate() or s[1][distinguishingIndex].type.isObject())) @@ -5468,6 +5472,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::jsapi::JS_NewObject', 'js::jsapi::JS_NewObjectWithGivenProto', 'js::jsapi::JS_NewObjectWithoutMetadata', + 'js::jsapi::JS_ObjectIsDate', 'js::jsapi::JS_SetImmutablePrototype', 'js::jsapi::JS_SetProperty', 'js::jsapi::JS_SetReservedSlot', diff --git a/servo/components/script/dom/webglrenderingcontext.rs b/servo/components/script/dom/webglrenderingcontext.rs index 7ac39c13e1fb..92771d6ef53e 100644 --- a/servo/components/script/dom/webglrenderingcontext.rs +++ b/servo/components/script/dom/webglrenderingcontext.rs @@ -552,7 +552,7 @@ impl WebGLRenderingContext { match cap { constants::BLEND | constants::CULL_FACE | constants::DEPTH_TEST | constants::DITHER | constants::POLYGON_OFFSET_FILL | constants::SAMPLE_ALPHA_TO_COVERAGE | constants::SAMPLE_COVERAGE | - constants::SAMPLE_COVERAGE_INVERT | constants::SCISSOR_TEST => true, + constants::SAMPLE_COVERAGE_INVERT | constants::SCISSOR_TEST | constants::STENCIL_TEST => true, _ => { self.webgl_error(InvalidEnum); false @@ -991,6 +991,38 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { Ok(()) } + // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5 + fn BufferData_(&self, target: u32, size: i64, usage: u32) -> Fallible<()> { + 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)), + }; + + let bound_buffer = match bound_buffer { + Some(bound_buffer) => bound_buffer, + None => return Ok(self.webgl_error(InvalidValue)), + }; + + if size < 0 { + return Ok(self.webgl_error(InvalidValue)); + } + + match usage { + constants::STREAM_DRAW | + constants::STATIC_DRAW | + constants::DYNAMIC_DRAW => (), + _ => return Ok(self.webgl_error(InvalidEnum)), + } + + // FIXME: Allocating a buffer based on user-requested size is + // not great, but we don't have a fallible allocation to try. + let data = vec![0u8; size as usize]; + handle_potential_webgl_error!(self, bound_buffer.buffer_data(target, &data, usage)); + + 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<()> { diff --git a/servo/components/script/dom/webidls/WebGLRenderingContext.webidl b/servo/components/script/dom/webidls/WebGLRenderingContext.webidl index dd91d53d2d7b..ef0be0f94652 100644 --- a/servo/components/script/dom/webidls/WebGLRenderingContext.webidl +++ b/servo/components/script/dom/webidls/WebGLRenderingContext.webidl @@ -489,7 +489,6 @@ interface WebGLRenderingContextBase GLenum srcAlpha, GLenum dstAlpha); // typedef (ArrayBuffer or ArrayBufferView) BufferDataSource; - //void bufferData(GLenum target, GLsizeiptr size, GLenum usage); // FIXME(dmarcos) The function below is the original function in the webIdl: // void bufferData(GLenum target, BufferDataSource? data, GLenum usage); // The Code generator doesn't handle BufferDataSource so we're using 'object?' @@ -497,6 +496,10 @@ interface WebGLRenderingContextBase // 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);