From f6fa4f7bf5d29397302559fbafd22a5d0a1576bc Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Mon, 25 May 2015 12:50:15 +0100 Subject: [PATCH] Bug 1167423 - patch 5 - Handle return values of FallibleTArray functions in WebGL2Context, r=smaug --- dom/canvas/WebGL2Context.h | 6 ++-- dom/canvas/WebGL2ContextFramebuffers.cpp | 37 +++++++++++++++++++----- dom/webidl/WebGL2RenderingContext.webidl | 5 ++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/dom/canvas/WebGL2Context.h b/dom/canvas/WebGL2Context.h index 9ea73007f4e..ce8b15ce3e7 100644 --- a/dom/canvas/WebGL2Context.h +++ b/dom/canvas/WebGL2Context.h @@ -10,6 +10,7 @@ namespace mozilla { +class ErrorResult; class WebGLSampler; class WebGLSync; class WebGLTransformFeedback; @@ -56,9 +57,10 @@ public: GLbitfield mask, GLenum filter); void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); void GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat, GLenum pname, JS::MutableHandleValue retval); - void InvalidateFramebuffer(GLenum target, const dom::Sequence& attachments); + void InvalidateFramebuffer(GLenum target, const dom::Sequence& attachments, + ErrorResult& aRv); void InvalidateSubFramebuffer (GLenum target, const dom::Sequence& attachments, GLint x, GLint y, - GLsizei width, GLsizei height); + GLsizei width, GLsizei height, ErrorResult& aRv); void ReadBuffer(GLenum mode); void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); diff --git a/dom/canvas/WebGL2ContextFramebuffers.cpp b/dom/canvas/WebGL2ContextFramebuffers.cpp index f6083363c36..1d074f14607 100644 --- a/dom/canvas/WebGL2ContextFramebuffers.cpp +++ b/dom/canvas/WebGL2ContextFramebuffers.cpp @@ -343,26 +343,38 @@ WebGL2Context::GetInternalformatParameter(JSContext*, GLenum target, GLenum inte // Map attachments intended for the default buffer, to attachments for a non- // default buffer. -static void +static bool TranslateDefaultAttachments(const dom::Sequence& in, dom::Sequence* out) { for (size_t i = 0; i < in.Length(); i++) { switch (in[i]) { case LOCAL_GL_COLOR: - out->AppendElement(LOCAL_GL_COLOR_ATTACHMENT0); + if (!out->AppendElement(LOCAL_GL_COLOR_ATTACHMENT0)) { + return false; + } break; + case LOCAL_GL_DEPTH: - out->AppendElement(LOCAL_GL_DEPTH_ATTACHMENT); + if (!out->AppendElement(LOCAL_GL_DEPTH_ATTACHMENT)) { + return false; + } break; + case LOCAL_GL_STENCIL: - out->AppendElement(LOCAL_GL_STENCIL_ATTACHMENT); + if (!out->AppendElement(LOCAL_GL_STENCIL_ATTACHMENT)) { + return false; + } break; } } + + return true; } void -WebGL2Context::InvalidateFramebuffer(GLenum target, const dom::Sequence& attachments) +WebGL2Context::InvalidateFramebuffer(GLenum target, + const dom::Sequence& attachments, + ErrorResult& aRv) { if (IsContextLost()) return; @@ -407,7 +419,11 @@ WebGL2Context::InvalidateFramebuffer(GLenum target, const dom::Sequence& if (!fb && !isDefaultFB) { dom::Sequence tmpAttachments; - TranslateDefaultAttachments(attachments, &tmpAttachments); + if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + return; + } + gl->fInvalidateFramebuffer(target, tmpAttachments.Length(), tmpAttachments.Elements()); } else { gl->fInvalidateFramebuffer(target, attachments.Length(), attachments.Elements()); @@ -416,7 +432,8 @@ WebGL2Context::InvalidateFramebuffer(GLenum target, const dom::Sequence& void WebGL2Context::InvalidateSubFramebuffer(GLenum target, const dom::Sequence& attachments, - GLint x, GLint y, GLsizei width, GLsizei height) + GLint x, GLint y, GLsizei width, GLsizei height, + ErrorResult& aRv) { if (IsContextLost()) return; @@ -461,7 +478,11 @@ WebGL2Context::InvalidateSubFramebuffer(GLenum target, const dom::Sequence tmpAttachments; - TranslateDefaultAttachments(attachments, &tmpAttachments); + if (!TranslateDefaultAttachments(attachments, &tmpAttachments)) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + return; + } + gl->fInvalidateSubFramebuffer(target, tmpAttachments.Length(), tmpAttachments.Elements(), x, y, width, height); } else { diff --git a/dom/webidl/WebGL2RenderingContext.webidl b/dom/webidl/WebGL2RenderingContext.webidl index 382aa21e7ec..a98a6d127bc 100644 --- a/dom/webidl/WebGL2RenderingContext.webidl +++ b/dom/webidl/WebGL2RenderingContext.webidl @@ -329,9 +329,14 @@ interface WebGL2RenderingContext : WebGLRenderingContext GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); void framebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); any getInternalformatParameter(GLenum target, GLenum internalformat, GLenum pname); + + [Throws] void invalidateFramebuffer(GLenum target, sequence attachments); + + [Throws] void invalidateSubFramebuffer (GLenum target, sequence attachments, GLint x, GLint y, GLsizei width, GLsizei height); + void readBuffer(GLenum src); /* Renderbuffer objects */