Bug 912196 - Workaround no-alpha-with-ANGLE in WebGL, not GLContext. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 08 Oct 2014 16:30:01 -0700
changeset 212596 f9105d35ba70fe45f391f6ee291f9458c05c10e6
parent 212595 a9fc09c6af9436b0efa4a73daafd225071fda1fa
child 212597 942e71d1f271f59951d5970875e039f5d2b9cbbc
push idunknown
push userunknown
push dateunknown
reviewerskamidphish
bugs912196
milestone36.0a1
Bug 912196 - Workaround no-alpha-with-ANGLE in WebGL, not GLContext. - r=kamidphish
dom/canvas/WebGLContext.cpp
dom/canvas/WebGLContextState.cpp
gfx/gl/SharedSurfaceANGLE.cpp
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -664,16 +664,22 @@ CreateOffscreen(GLContext* gl,
     baseCaps.depth = options.depth;
     baseCaps.premultAlpha = options.premultipliedAlpha;
     baseCaps.preserve = options.preserveDrawingBuffer;
     baseCaps.stencil = options.stencil;
 
     if (!baseCaps.alpha)
         baseCaps.premultAlpha = true;
 
+    if (gl->IsANGLE()) {
+        // We can't use no-alpha formats on ANGLE yet because of:
+        // https://code.google.com/p/angleproject/issues/detail?id=764
+        baseCaps.alpha = true;
+    }
+
     // we should really have this behind a
     // |gfxPlatform::GetPlatform()->GetScreenDepth() == 16| check, but
     // for now it's just behind a pref for testing/evaluation.
     baseCaps.bpp16 = Preferences::GetBool("webgl.prefer-16bpp", false);
 
 #ifdef MOZ_WIDGET_GONK
     baseCaps.surfaceAllocator = surfAllocator;
 #endif
@@ -923,29 +929,29 @@ WebGLContext::SetDimensions(int32_t sWid
 
     // Clear immediately, because we need to present the cleared initial
     // buffer.
     mBackbufferNeedsClear = true;
     ClearBackbufferIfNeeded();
 
     mShouldPresent = true;
 
+    if (gl->WorkAroundDriverBugs()) {
+        if (!mOptions.alpha && gl->Caps().alpha) {
+            mNeedsFakeNoAlpha = true;
+        }
+    }
+
     MOZ_ASSERT(gl->Caps().color);
     MOZ_ASSERT(gl->Caps().alpha == mOptions.alpha);
     MOZ_ASSERT(gl->Caps().depth == mOptions.depth);
     MOZ_ASSERT(gl->Caps().stencil == mOptions.stencil);
     MOZ_ASSERT(gl->Caps().antialias == mOptions.antialias);
     MOZ_ASSERT(gl->Caps().preserve == mOptions.preserveDrawingBuffer);
 
-    if (gl->WorkAroundDriverBugs() && gl->IsANGLE()) {
-        if (!mOptions.alpha) {
-            mNeedsFakeNoAlpha = true;
-        }
-    }
-
     AssertCachedBindings();
     AssertCachedState();
 
     reporter.SetSuccessful();
     return NS_OK;
 }
 
 void
@@ -1840,17 +1846,16 @@ bool WebGLContext::TexImageFromVideoElem
     }
     srcImage = nullptr;
     container->UnlockCurrentImage();
     return ok;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
-
 WebGLContext::ScopedMaskWorkaround::ScopedMaskWorkaround(WebGLContext& webgl)
     : mWebGL(webgl)
     , mNeedsChange(NeedsChange(webgl))
 {
     if (mNeedsChange) {
         mWebGL.gl->fColorMask(mWebGL.mColorWriteMask[0],
                               mWebGL.mColorWriteMask[1],
                               mWebGL.mColorWriteMask[2],
--- a/dom/canvas/WebGLContextState.cpp
+++ b/dom/canvas/WebGLContextState.cpp
@@ -307,22 +307,28 @@ WebGLContext::GetParameter(JSContext* cx
         case LOCAL_GL_SAMPLES:
         case LOCAL_GL_MAX_VERTEX_ATTRIBS:
         case LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
         case LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
         case LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS:
         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: {
             GLint i = 0;
             gl->fGetIntegerv(pname, &i);
             return JS::Int32Value(i);
         }
+        case LOCAL_GL_ALPHA_BITS: {
+            GLint i = 0;
+            if (!mNeedsFakeNoAlpha) {
+                gl->fGetIntegerv(pname, &i);
+            }
+            return JS::Int32Value(i);
+        }
         case LOCAL_GL_FRAGMENT_SHADER_DERIVATIVE_HINT: {
             if (IsExtensionEnabled(WebGLExtensionID::OES_standard_derivatives)) {
                 GLint i = 0;
                 gl->fGetIntegerv(pname, &i);
                 return JS::Int32Value(i);
             } else {
                 break;
             }
--- a/gfx/gl/SharedSurfaceANGLE.cpp
+++ b/gfx/gl/SharedSurfaceANGLE.cpp
@@ -284,34 +284,26 @@ ChooseConfig(GLContext* gl, GLLibraryEGL
         return EGL_NO_CONFIG;
     }
 
     // The requests passed to ChooseConfig are treated as minimums. If you ask
     // for 0 bits of alpha, we might still get 8 bits.
     EGLConfig config = EGL_NO_CONFIG;
     for (int i = 0; i < foundConfigs; i++) {
         EGLConfig cur = configs[i];
-        if (!DoesAttribBitsMatchCapBool(egl, cur, LOCAL_EGL_DEPTH_SIZE,
+        if (!DoesAttribBitsMatchCapBool(egl, cur, LOCAL_EGL_ALPHA_SIZE,
+                                        caps.alpha) ||
+            !DoesAttribBitsMatchCapBool(egl, cur, LOCAL_EGL_DEPTH_SIZE,
                                         caps.depth) ||
             !DoesAttribBitsMatchCapBool(egl, cur, LOCAL_EGL_STENCIL_SIZE,
                                         caps.stencil))
         {
             continue;
         }
 
-        // We can't enforce alpha on ANGLE yet because of:
-        // https://code.google.com/p/angleproject/issues/detail?id=764
-        if (!gl->IsANGLE()) {
-            if (!DoesAttribBitsMatchCapBool(egl, cur, LOCAL_EGL_ALPHA_SIZE,
-                                            caps.alpha))
-            {
-                continue;
-            }
-        }
-
         config = cur;
         break;
     }
 
     if (config == EGL_NO_CONFIG) {
         NS_WARNING("No acceptable EGLConfig found.");
         return EGL_NO_CONFIG;
     }