Auto merge of #26339 - szeged:mmatyas__webgl_fns_getbufparam, r=jdm

Add support for WebGL2 buffer types in GetBufferParameter

This makes the new buffer types introduced in WebGL2 usable by the GetBufferParameter call.

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

cc @jdm @zakorgy

---
<!-- 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
- [x] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-04-28 11:46:29 -04:00 committed by GitHub
commit ddd8e2aca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 62 deletions

View file

@ -867,8 +867,10 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn GetBufferParameter(&self, cx: JSContext, target: u32, parameter: u32) -> JSVal {
self.base.GetBufferParameter(cx, target, parameter)
fn GetBufferParameter(&self, _cx: JSContext, target: u32, parameter: u32) -> JSVal {
let buffer =
handle_potential_webgl_error!(self.base, self.bound_buffer(target), return NullValue());
self.base.get_buffer_param(buffer, parameter)
}
#[allow(unsafe_code)]

View file

@ -1873,6 +1873,20 @@ impl WebGLRenderingContext {
Ok(())
});
}
pub fn get_buffer_param(&self, buffer: Option<DomRoot<WebGLBuffer>>, parameter: u32) -> JSVal {
let buffer =
handle_potential_webgl_error!(self, buffer.ok_or(InvalidOperation), return NullValue());
match parameter {
constants::BUFFER_SIZE => Int32Value(buffer.capacity() as i32),
constants::BUFFER_USAGE => Int32Value(buffer.usage() as i32),
_ => {
self.webgl_error(InvalidEnum);
NullValue()
},
}
}
}
#[cfg(not(feature = "webgl_backtrace"))]
@ -1934,21 +1948,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
fn GetBufferParameter(&self, _cx: SafeJSContext, target: u32, parameter: u32) -> JSVal {
let buffer = handle_potential_webgl_error!(
self,
self.bound_buffer(target)
.and_then(|buf| buf.ok_or(InvalidOperation)),
return NullValue()
);
match parameter {
constants::BUFFER_SIZE => Int32Value(buffer.capacity() as i32),
constants::BUFFER_USAGE => Int32Value(buffer.usage() as i32),
_ => {
self.webgl_error(InvalidEnum);
NullValue()
},
}
let buffer =
handle_potential_webgl_error!(self, self.bound_buffer(target), return NullValue());
self.get_buffer_param(buffer, parameter)
}
#[allow(unsafe_code)]