servo: Merge #14847 - webgl: implement bufferData (from anholt:webgl-bufferdata); r=emilio

<!-- Please describe your changes on the following line: -->

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.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [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).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 4216c16879efb6e87b3ba3b7b4d5c2aeb8e2739d
This commit is contained in:
Eric Anholt 2017-01-05 02:11:29 -08:00
Родитель d934174175
Коммит eaf4d76084
3 изменённых файлов: 44 добавлений и 4 удалений

Просмотреть файл

@ -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',

Просмотреть файл

@ -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<()> {

Просмотреть файл

@ -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);