From b21ff75bef4134bc175535d88fb538cc396db3dd Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Mon, 26 Mar 2018 20:21:31 -0700 Subject: [PATCH] Bug 1446412 - Don't query GL for RED_BITS and friends queries. - r=kvark There's no reason to ask GL since we should know the answers. Also GL is tricky on how it handles these semi-deprecated queries. Official GL stance is "don't ask questions you know the answer to". MozReview-Commit-ID: F7p73eSTrYw --- dom/canvas/WebGLContext.h | 1 - dom/canvas/WebGLContextState.cpp | 151 +++++++++++++------------------ dom/canvas/WebGLFramebuffer.h | 16 ++++ 3 files changed, 81 insertions(+), 87 deletions(-) diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index ff0c0316c1fe..576f434db029 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -1011,7 +1011,6 @@ public: void Disable(GLenum cap) { SetEnabled("disabled", cap, false); } void Enable(GLenum cap) { SetEnabled("enabled", cap, true); } bool GetStencilBits(GLint* const out_stencilBits) const; - bool GetChannelBits(const char* funcName, GLenum pname, GLint* const out_val); virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv); void GetParameter(JSContext* cx, GLenum pname, diff --git a/dom/canvas/WebGLContextState.cpp b/dom/canvas/WebGLContextState.cpp index a101e997215f..735252795335 100644 --- a/dom/canvas/WebGLContextState.cpp +++ b/dom/canvas/WebGLContextState.cpp @@ -74,87 +74,6 @@ WebGLContext::GetStencilBits(GLint* const out_stencilBits) const return true; } -bool -WebGLContext::GetChannelBits(const char* funcName, GLenum pname, GLint* const out_val) -{ - if (mBoundDrawFramebuffer) { - if (!mBoundDrawFramebuffer->ValidateAndInitAttachments(funcName)) - return false; - } - - if (!mBoundDrawFramebuffer) { - switch (pname) { - case LOCAL_GL_RED_BITS: - case LOCAL_GL_GREEN_BITS: - case LOCAL_GL_BLUE_BITS: - *out_val = 8; - break; - - case LOCAL_GL_ALPHA_BITS: - *out_val = (mOptions.alpha ? 8 : 0); - break; - - case LOCAL_GL_DEPTH_BITS: - *out_val = (mOptions.depth ? 24 : 0); - break; - - case LOCAL_GL_STENCIL_BITS: - *out_val = (mOptions.stencil ? 8 : 0); - break; - - default: - MOZ_CRASH("GFX: bad pname"); - } - return true; - } - - if (!gl->IsCoreProfile()) { - gl->fGetIntegerv(pname, out_val); - return true; - } - - GLenum fbAttachment = 0; - GLenum fbPName = 0; - switch (pname) { - case LOCAL_GL_RED_BITS: - fbAttachment = LOCAL_GL_COLOR_ATTACHMENT0; - fbPName = LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE; - break; - - case LOCAL_GL_GREEN_BITS: - fbAttachment = LOCAL_GL_COLOR_ATTACHMENT0; - fbPName = LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE; - break; - - case LOCAL_GL_BLUE_BITS: - fbAttachment = LOCAL_GL_COLOR_ATTACHMENT0; - fbPName = LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE; - break; - - case LOCAL_GL_ALPHA_BITS: - fbAttachment = LOCAL_GL_COLOR_ATTACHMENT0; - fbPName = LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE; - break; - - case LOCAL_GL_DEPTH_BITS: - fbAttachment = LOCAL_GL_DEPTH_ATTACHMENT; - fbPName = LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE; - break; - - case LOCAL_GL_STENCIL_BITS: - fbAttachment = LOCAL_GL_STENCIL_ATTACHMENT; - fbPName = LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE; - break; - - default: - MOZ_CRASH("GFX: bad pname"); - } - - gl->fGetFramebufferAttachmentParameteriv(LOCAL_GL_DRAW_FRAMEBUFFER, fbAttachment, - fbPName, out_val); - return true; -} - JS::Value WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) { @@ -397,12 +316,72 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) case LOCAL_GL_ALPHA_BITS: case LOCAL_GL_DEPTH_BITS: case LOCAL_GL_STENCIL_BITS: { - // Deprecated and removed in GL Core profiles, so special handling required. - GLint val; - if (!GetChannelBits(funcName, pname, &val)) - return JS::NullValue(); + const auto format = [&]() -> const webgl::FormatInfo* { + if (mBoundDrawFramebuffer) { + const auto& fb = *mBoundDrawFramebuffer; + const auto& attachment = [&]() { + switch (pname) { + case LOCAL_GL_DEPTH_BITS: + return fb.AnyDepthAttachment(); - return JS::Int32Value(val); + case LOCAL_GL_STENCIL_BITS: + return fb.AnyStencilAttachment(); + + default: + return fb.ColorAttachment0(); + } + }(); + if (!attachment.HasImage()) + return nullptr; + return attachment.Format()->format; + } + + auto effFormat = webgl::EffectiveFormat::RGB8; + switch (pname) { + case LOCAL_GL_DEPTH_BITS: + if (mOptions.depth) { + effFormat = webgl::EffectiveFormat::DEPTH24_STENCIL8; + } + break; + + case LOCAL_GL_STENCIL_BITS: + if (mOptions.stencil) { + effFormat = webgl::EffectiveFormat::DEPTH24_STENCIL8; + } + break; + + default: + if (mOptions.alpha) { + effFormat = webgl::EffectiveFormat::RGBA8; + } + break; + } + return webgl::GetFormat(effFormat); + }(); + int32_t ret = 0; + if (format) { + switch (pname) { + case LOCAL_GL_RED_BITS: + ret = format->r; + break; + case LOCAL_GL_GREEN_BITS: + ret = format->g; + break; + case LOCAL_GL_BLUE_BITS: + ret = format->b; + break; + case LOCAL_GL_ALPHA_BITS: + ret = format->a; + break; + case LOCAL_GL_DEPTH_BITS: + ret = format->d; + break; + case LOCAL_GL_STENCIL_BITS: + ret = format->s; + break; + } + } + return JS::Int32Value(ret); } case LOCAL_GL_MAX_TEXTURE_SIZE: diff --git a/dom/canvas/WebGLFramebuffer.h b/dom/canvas/WebGLFramebuffer.h index b606f5fd6146..305b23b03b8f 100644 --- a/dom/canvas/WebGLFramebuffer.h +++ b/dom/canvas/WebGLFramebuffer.h @@ -258,6 +258,22 @@ public: #undef GETTER + const auto& ColorAttachment0() const { + return mColorAttachments[0]; + } + + const auto& AnyDepthAttachment() const { + if (mDepthStencilAttachment.IsDefined()) + return mDepthStencilAttachment; + return mDepthAttachment; + } + + const auto& AnyStencilAttachment() const { + if (mDepthStencilAttachment.IsDefined()) + return mDepthStencilAttachment; + return mStencilAttachment; + } + //////////////// // Invalidation