2011-05-18 Kenneth Russell <kbr@google.com>
authorkbr@google.com <kbr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 May 2011 23:43:51 +0000 (23:43 +0000)
committerkbr@google.com <kbr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 May 2011 23:43:51 +0000 (23:43 +0000)
        Reviewed by James Robinson.

        [chromium] Disable blending in compositor for WebGL layers with alpha=false
        https://bugs.webkit.org/show_bug.cgi?id=61091

        * compositing/webgl/webgl-no-alpha.html: Added.
        * platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.png: Added.
        * platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.txt: Added.
        * platform/mac-wk2/Skipped:
        * platform/mac/compositing/webgl/webgl-no-alpha-expected.png: Added.
        * platform/mac/compositing/webgl/webgl-no-alpha-expected.txt: Added.
2011-05-18  Kenneth Russell  <kbr@google.com>

        Reviewed by James Robinson.

        [chromium] Disable blending in compositor for WebGL layers with alpha=false
        https://bugs.webkit.org/show_bug.cgi?id=61091

        Test: compositing/webgl/webgl-no-alpha.html

        * platform/graphics/chromium/CanvasLayerChromium.cpp:
        (WebCore::CanvasLayerChromium::CanvasLayerChromium):
        (WebCore::CanvasLayerChromium::pushPropertiesTo):
        * platform/graphics/chromium/CanvasLayerChromium.h:
        * platform/graphics/chromium/WebGLLayerChromium.cpp:
        (WebCore::WebGLLayerChromium::setContext):
        * platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp:
        (WebCore::CCCanvasLayerImpl::CCCanvasLayerImpl):
        (WebCore::CCCanvasLayerImpl::draw):
        * platform/graphics/chromium/cc/CCCanvasLayerImpl.h:
        (WebCore::CCCanvasLayerImpl::setHasAlpha):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@86905 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/ChangeLog
LayoutTests/compositing/webgl/webgl-no-alpha.html [new file with mode: 0644]
LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.png [new file with mode: 0644]
LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/Skipped
LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.h
Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCCanvasLayerImpl.h

index f0a6248..f311274 100644 (file)
@@ -1,3 +1,17 @@
+2011-05-18  Kenneth Russell  <kbr@google.com>
+
+        Reviewed by James Robinson.
+
+        [chromium] Disable blending in compositor for WebGL layers with alpha=false
+        https://bugs.webkit.org/show_bug.cgi?id=61091
+
+        * compositing/webgl/webgl-no-alpha.html: Added.
+        * platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.png: Added.
+        * platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.txt: Added.
+        * platform/mac-wk2/Skipped:
+        * platform/mac/compositing/webgl/webgl-no-alpha-expected.png: Added.
+        * platform/mac/compositing/webgl/webgl-no-alpha-expected.txt: Added.
+
 2011-05-18  Jeremy Noble  <jer.noble@apple.com>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/compositing/webgl/webgl-no-alpha.html b/LayoutTests/compositing/webgl/webgl-no-alpha.html
new file mode 100644 (file)
index 0000000..9ba9282
--- /dev/null
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <style type="text/css" media="screen">
+      body {
+        outline: 10px solid transparent; /* affects layer sizes */
+      }
+      canvas {
+        margin: 20px;
+        width: 200px;
+        height: 200px;
+        padding: 0 20px;
+      }
+    
+      .compare {
+        margin-left: 40px;
+        margin-top: 20px;
+        width: 200px;
+        height: 200px;
+        background-color: rgba(0, 255, 0, 1.0);
+      }
+    </style>
+    <script>
+        if (window.layoutTestController) {
+            layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
+            layoutTestController.dumpAsText(true);
+        }
+
+        function initWebGL(canvasName, vshader, fshader, attribs, clearColor, clearDepth)
+        {
+            var canvas = document.getElementById(canvasName);
+            var gl = canvas.getContext("experimental-webgl", {alpha: false});
+            if (!gl) {
+                alert("No WebGL context found");
+                return null;
+            }
+
+            gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+            gl.clearDepth(clearDepth);
+
+            return gl;
+        }
+
+        function drawCanvas(canvasID)
+        {
+          var gl = initWebGL(canvasID, "", "", [], [ 0, 1, 0, 0 ], 1);
+          gl.viewport(0, 0, 200, 200);
+          gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+        }
+
+        function init()
+        {
+          drawCanvas('canvas');
+        }
+    </script>
+  </head>
+  <body onload="init()">
+   
+    <div class="compare"></div>
+    <canvas id="canvas" width="200" height="200"></canvas>
+
+    <!-- Top and bottom should look the same. -->
+  </body>
+</html>
diff --git a/LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.png b/LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.png
new file mode 100644 (file)
index 0000000..1b88999
Binary files /dev/null and b/LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.png differ
diff --git a/LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.txt b/LayoutTests/platform/chromium-gpu/compositing/webgl/webgl-no-alpha-expected.txt
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index 2b35e30..57865dc 100644 (file)
@@ -861,6 +861,7 @@ fast/canvas/webgl/context-lost.html
 fast/canvas/webgl/uninitialized-test.html
 compositing/webgl/webgl-background-color.html
 compositing/webgl/webgl-reflection.html
+compositing/webgl/webgl-no-alpha.html
 compositing/webgl/webgl-nonpremultiplied-blend.html
 fast/canvas/webgl/array-buffer-crash.html
 fast/canvas/webgl/array-buffer-view-crash.html
diff --git a/LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.png b/LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.png
new file mode 100644 (file)
index 0000000..60a749f
Binary files /dev/null and b/LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.png differ
diff --git a/LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.txt b/LayoutTests/platform/mac/compositing/webgl/webgl-no-alpha-expected.txt
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index e47e89c..6034a74 100644 (file)
@@ -1,3 +1,24 @@
+2011-05-18  Kenneth Russell  <kbr@google.com>
+
+        Reviewed by James Robinson.
+
+        [chromium] Disable blending in compositor for WebGL layers with alpha=false
+        https://bugs.webkit.org/show_bug.cgi?id=61091
+
+        Test: compositing/webgl/webgl-no-alpha.html
+
+        * platform/graphics/chromium/CanvasLayerChromium.cpp:
+        (WebCore::CanvasLayerChromium::CanvasLayerChromium):
+        (WebCore::CanvasLayerChromium::pushPropertiesTo):
+        * platform/graphics/chromium/CanvasLayerChromium.h:
+        * platform/graphics/chromium/WebGLLayerChromium.cpp:
+        (WebCore::WebGLLayerChromium::setContext):
+        * platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp:
+        (WebCore::CCCanvasLayerImpl::CCCanvasLayerImpl):
+        (WebCore::CCCanvasLayerImpl::draw):
+        * platform/graphics/chromium/cc/CCCanvasLayerImpl.h:
+        (WebCore::CCCanvasLayerImpl::setHasAlpha):
+
 2011-05-18  Jeremy Noble  <jer.noble@apple.com>
 
         Reviewed by Darin Adler.
index f294376..0a1d32e 100644 (file)
@@ -44,6 +44,7 @@ CanvasLayerChromium::CanvasLayerChromium(GraphicsLayerChromium* owner)
     : LayerChromium(owner)
     , m_textureChanged(true)
     , m_textureId(0)
+    , m_hasAlpha(true)
     , m_premultipliedAlpha(true)
 {
 }
@@ -63,6 +64,7 @@ void CanvasLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
 
     CCCanvasLayerImpl* canvasLayer = static_cast<CCCanvasLayerImpl*>(layer);
     canvasLayer->setTextureId(m_textureId);
+    canvasLayer->setHasAlpha(m_hasAlpha);
     canvasLayer->setPremultipliedAlpha(m_premultipliedAlpha);
 }
 
index cb2ccc9..23230ac 100644 (file)
@@ -54,6 +54,7 @@ protected:
 
     bool m_textureChanged;
     unsigned m_textureId;
+    bool m_hasAlpha;
     bool m_premultipliedAlpha;
 };
 
index 6a17758..220528c 100644 (file)
@@ -121,7 +121,9 @@ void WebGLLayerChromium::setContext(const GraphicsContext3D* context)
         m_textureUpdated = true;
     }
     m_textureId = textureId;
-    m_premultipliedAlpha = m_context->getContextAttributes().premultipliedAlpha;
+    GraphicsContext3D::Attributes attributes = m_context->getContextAttributes();
+    m_hasAlpha = attributes.alpha;
+    m_premultipliedAlpha = attributes.premultipliedAlpha;
     m_contextSupportsRateLimitingExtension = m_context->getExtensions()->supports("GL_CHROMIUM_rate_limit_offscreen_context");
 }
 
index e83499b..215c6a9 100644 (file)
@@ -39,6 +39,7 @@ namespace WebCore {
 CCCanvasLayerImpl::CCCanvasLayerImpl(LayerChromium* owner, int id)
     : CCLayerImpl(owner, id)
     , m_textureId(0)
+    , m_hasAlpha(true)
     , m_premultipliedAlpha(true)
 {
 }
@@ -55,15 +56,22 @@ void CCCanvasLayerImpl::draw(const IntRect&)
     GraphicsContext3D* context = layerRenderer()->context();
     GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
     GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId));
-    GC3Denum sfactor = m_premultipliedAlpha ? GraphicsContext3D::ONE : GraphicsContext3D::SRC_ALPHA;
-    GLC(context, context->blendFunc(sfactor, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
+    if (!m_hasAlpha) {
+        // Even though the WebGL layer's texture was likely allocated
+        // as GL_RGB, disable blending anyway for better robustness.
+        context->disable(GraphicsContext3D::BLEND);
+    } else {
+        GC3Denum sfactor = m_premultipliedAlpha ? GraphicsContext3D::ONE : GraphicsContext3D::SRC_ALPHA;
+        GLC(context, context->blendFunc(sfactor, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
+    }
     layerRenderer()->useShader(program->program());
     GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0));
     LayerChromium::drawTexturedQuad(context, layerRenderer()->projectionMatrix(), drawTransform(),
                                     bounds().width(), bounds().height(), drawOpacity(),
                                     program->vertexShader().matrixLocation(),
                                     program->fragmentShader().alphaLocation());
-
+    if (!m_hasAlpha)
+        context->enable(GraphicsContext3D::BLEND);
 }
 
 
index 7c109e3..2aba47e 100644 (file)
@@ -47,11 +47,13 @@ public:
     virtual void dumpLayerProperties(TextStream&, int indent) const;
 
     void setTextureId(unsigned id) { m_textureId = id; }
+    void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; }
     void setPremultipliedAlpha(bool premultipliedAlpha) { m_premultipliedAlpha = premultipliedAlpha; }
 private:
     CCCanvasLayerImpl(LayerChromium*, int);
 
     unsigned m_textureId;
+    bool m_hasAlpha;
     bool m_premultipliedAlpha;
 };