Auto merge of #21461 - jdm:webgltmp2, r=nox

Various webgl fixes for framebuffer attachment test

These changes resolve all panics on macOS when running framebuffer-object-attachment.html in headless and headful testing.

---
- [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 OR
- [x] Fixes #13710. Fixes #20570.

<!-- 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/21461)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-12 16:36:08 -04:00 committed by GitHub
commit 26745b2741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 655 additions and 177 deletions

View file

@ -39,7 +39,7 @@ use dom::webgl_validations::types::{TexDataType, TexFormat, TexImageTarget};
use dom::webglactiveinfo::WebGLActiveInfo;
use dom::webglbuffer::WebGLBuffer;
use dom::webglcontextevent::WebGLContextEvent;
use dom::webglframebuffer::{WebGLFramebuffer, WebGLFramebufferAttachmentRoot};
use dom::webglframebuffer::{WebGLFramebuffer, WebGLFramebufferAttachmentRoot, CompleteForRendering};
use dom::webglobject::WebGLObject;
use dom::webglprogram::WebGLProgram;
use dom::webglrenderbuffer::WebGLRenderbuffer;
@ -339,10 +339,14 @@ impl WebGLRenderingContext {
// this: clear() and getParameter(IMPLEMENTATION_COLOR_READ_*).
fn validate_framebuffer(&self) -> WebGLResult<()> {
match self.bound_framebuffer.get() {
Some(ref fb) if fb.check_status() != constants::FRAMEBUFFER_COMPLETE => {
Err(InvalidFramebufferOperation)
Some(fb) => match fb.check_status_for_rendering() {
CompleteForRendering::Complete => Ok(()),
CompleteForRendering::Incomplete =>
Err(InvalidFramebufferOperation),
CompleteForRendering::MissingColorAttachment =>
Err(InvalidOperation),
},
_ => Ok(()),
None => Ok(()),
}
}
@ -1057,6 +1061,21 @@ impl WebGLRenderingContext {
_ => Err(InvalidEnum),
}
}
pub fn initialize_framebuffer(&self, clear_bits: u32) {
if clear_bits == 0 {
return;
}
self.send_command(WebGLCommand::InitializeFramebuffer {
color: clear_bits & constants::COLOR_BUFFER_BIT != 0,
depth: clear_bits & constants::DEPTH_BUFFER_BIT != 0,
stencil: clear_bits & constants::STENCIL_BUFFER_BIT != 0,
});
}
pub fn bound_framebuffer(&self) -> Option<DomRoot<WebGLFramebuffer>> {
self.bound_framebuffer.get()
}
}
impl Drop for WebGLRenderingContext {
@ -1572,6 +1591,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
renderbuffer.bind(target);
}
_ => {
if renderbuffer.is_some() {
self.webgl_error(InvalidOperation);
}
self.bound_renderbuffer.set(None);
// Unbind the currently bound renderbuffer
self.send_command(WebGLCommand::BindRenderbuffer(target, None));
@ -1971,20 +1994,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
handle_potential_webgl_error!(self, self.validate_ownership(renderbuffer), return);
handle_object_deletion!(self, self.bound_renderbuffer, renderbuffer,
Some(WebGLCommand::BindRenderbuffer(constants::RENDERBUFFER, None)));
// From the GLES 2.0.25 spec, page 113:
//
// "If a renderbuffer object is deleted while its
// image is attached to the currently bound
// framebuffer, then it is as if
// FramebufferRenderbuffer had been called, with a
// renderbuffer of 0, for each attachment point to
// which this image was attached in the currently
// bound framebuffer."
//
if let Some(fb) = self.bound_framebuffer.get() {
fb.detach_renderbuffer(renderbuffer);
}
renderbuffer.delete()
}
}
@ -2020,18 +2029,6 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
));
}
// From the GLES 2.0.25 spec, page 113:
//
// "If a texture object is deleted while its image is
// attached to the currently bound framebuffer, then
// it is as if FramebufferTexture2D had been called,
// with a texture of 0, for each attachment point to
// which this image was attached in the currently
// bound framebuffer."
if let Some(fb) = self.bound_framebuffer.get() {
fb.detach_texture(texture);
}
texture.delete()
}
}
@ -2723,10 +2720,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn StencilMaskSeparate(&self, face: u32, mask: u32) {
match face {
constants::FRONT | constants::BACK | constants::FRONT_AND_BACK =>
constants::FRONT |
constants::BACK |
constants::FRONT_AND_BACK =>
self.send_command(WebGLCommand::StencilMaskSeparate(face, mask)),
_ => return self.webgl_error(InvalidEnum),
}
};
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3