Auto merge of #13337 - ofekd:implement-webgl-isEnabled, r=emilio

Implement WebGLRenderingContext::isEnabled

Implemented WebGLRenderingContext::isEnabled

- Please note the return value of the implementation, not sure about returning `false` on `InvalidEnum`.
- the `webgl/conformance-1.0.3/conformance/state/gl-enable-enum-test.html` wpt test is disabled on linux but was enabled on my machine and run to validate expectations.
- the `/webgl/conformance-1.0.3/conformance/context/methods.html` test is disabled everywhere. Enabling and running on my machine showed incorrect expectations beyond `isEnabled`. The test was temporarily edited to test just for `isEnabled` and it ran successfully.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #13040

- [X] There are tests for these changes (please read details above)
- [ ] These changes do not require tests because _____

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13337)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-22 11:05:55 -05:00 committed by GitHub
commit f09595e8af
4 changed files with 37 additions and 77 deletions

View file

@ -511,6 +511,19 @@ impl WebGLRenderingContext {
.send(CanvasMsg::WebGL(msg))
.unwrap()
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14
fn validate_feature_enum(&self, cap: u32) -> bool {
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,
_ => {
self.webgl_error(InvalidEnum);
false
},
}
}
}
impl Drop for WebGLRenderingContext {
@ -1114,27 +1127,19 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn Enable(&self, cap: u32) {
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 =>
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::Enable(cap)))
.unwrap(),
_ => self.webgl_error(InvalidEnum),
if self.validate_feature_enum(cap) {
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::Enable(cap)))
.unwrap();
}
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn Disable(&self, cap: u32) {
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 =>
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::Disable(cap)))
.unwrap(),
_ => self.webgl_error(InvalidEnum),
if self.validate_feature_enum(cap) {
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::Disable(cap)))
.unwrap()
}
}
@ -1455,6 +1460,20 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
buffer.map_or(false, |buf| buf.target().is_some() && !buf.is_deleted())
}
// TODO: We could write this without IPC, recording the calls to `enable` and `disable`.
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn IsEnabled(&self, cap: u32) -> bool {
if self.validate_feature_enum(cap) {
let (sender, receiver) = ipc::channel().unwrap();
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::IsEnabled(cap, sender)))
.unwrap();
return receiver.recv().unwrap();
}
false
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.6
fn IsFramebuffer(&self, frame_buffer: Option<&WebGLFramebuffer>) -> bool {
frame_buffer.map_or(false, |buf| buf.target().is_some() && !buf.is_deleted())

View file

@ -603,7 +603,7 @@ interface WebGLRenderingContextBase
void hint(GLenum target, GLenum mode);
[WebGLHandlesContextLoss] GLboolean isBuffer(WebGLBuffer? buffer);
//[WebGLHandlesContextLoss] GLboolean isEnabled(GLenum cap);
[WebGLHandlesContextLoss] GLboolean isEnabled(GLenum cap);
[WebGLHandlesContextLoss] GLboolean isFramebuffer(WebGLFramebuffer? framebuffer);
[WebGLHandlesContextLoss] GLboolean isProgram(WebGLProgram? program);
[WebGLHandlesContextLoss] GLboolean isRenderbuffer(WebGLRenderbuffer? renderbuffer);