Bug 1446412 - Don't query GL for RED_BITS and friends queries. - r=kvark
☠☠ backed out by dc273da372bd ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 26 Mar 2018 20:21:31 -0700
changeset 466407 e3334509e606348f90f524a96adfb8e9dbcf8789
parent 466406 456f52fb9f925597b11917f3c4c4d4cea94024c4
child 466408 d9b7fe99807c6325bc73db92b548e29f37889898
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark
bugs1446412
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/canvas/WebGLContextState.cpp
dom/canvas/WebGLFramebuffer.h
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1006,17 +1006,16 @@ public:
 // -----------------------------------------------------------------------------
 // State and State Requests (WebGLContextState.cpp)
 private:
     void SetEnabled(const char* funcName, GLenum cap, bool enabled);
 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,
                       JS::MutableHandle<JS::Value> retval, ErrorResult& rv)
     {
         retval.set(GetParameter(cx, pname, rv));
     }
 
--- a/dom/canvas/WebGLContextState.cpp
+++ b/dom/canvas/WebGLContextState.cpp
@@ -69,97 +69,16 @@ WebGLContext::GetStencilBits(GLint* cons
         }
     } else if (mOptions.stencil) {
         *out_stencilBits = 8;
     }
 
     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)
 {
     const char funcName[] = "getParameter";
 
     if (IsContextLost())
         return JS::NullValue();
 
@@ -392,22 +311,82 @@ WebGLContext::GetParameter(JSContext* cx
         }
 
         case LOCAL_GL_RED_BITS:
         case LOCAL_GL_GREEN_BITS:
         case LOCAL_GL_BLUE_BITS:
         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();
+
+                        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;
 
-            return JS::Int32Value(val);
+                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:
             return JS::Int32Value(mGLMaxTextureSize);
 
         case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE:
             return JS::Int32Value(mGLMaxCubeMapTextureSize);
 
--- a/dom/canvas/WebGLFramebuffer.h
+++ b/dom/canvas/WebGLFramebuffer.h
@@ -253,16 +253,32 @@ public:
     GETTER(StencilAttachment)
     GETTER(DepthStencilAttachment)
     GETTER(ColorDrawBuffers)
     GETTER(ColorReadBuffer)
     GETTER(ResolvedCompleteData)
 
 #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
 
     bool IsResolvedComplete() const { return bool(mResolvedCompleteData); }
     void InvalidateFramebufferStatus(const char* funcName);
     void RefreshResolvedData();
 
     ////////////////