- Revision
- 197008
- Author
- [email protected]
- Date
- 2016-02-23 17:21:55 -0800 (Tue, 23 Feb 2016)
Log Message
[WebGL] iOS doesn't respect the alpha:false context creation attribute
https://bugs.webkit.org/show_bug.cgi?id=154617
<rdar://problem/13417023>
Reviewed by Sam Weinig.
Source/WebCore:
On iOS we were not respecting the alpha:false context creation
attribute, which meant you always got output that could
have an alpha channel.
The good news is that now we're setting the opaque flag on
the CALayer, there should be a performance improvement when
compositing WebGL into the page.
Test: fast/canvas/webgl/context-attributes-alpha.html
* platform/graphics/mac/GraphicsContext3DMac.mm:
(WebCore::GraphicsContext3D::GraphicsContext3D): Don't tell the layer
to be transparent.
(WebCore::GraphicsContext3D::setRenderbufferStorageFromDrawable): Do it
here instead, but based on the value of the alpha attribute.
LayoutTests:
Add a test that draws contexts with and without alpha, and then a reference
version that hard-codes the non-alpha colors.
* fast/canvas/webgl/context-attributes-alpha-expected.html: Added.
* fast/canvas/webgl/context-attributes-alpha.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (197007 => 197008)
--- trunk/LayoutTests/ChangeLog 2016-02-24 00:53:29 UTC (rev 197007)
+++ trunk/LayoutTests/ChangeLog 2016-02-24 01:21:55 UTC (rev 197008)
@@ -1,3 +1,17 @@
+2016-02-23 Dean Jackson <[email protected]>
+
+ [WebGL] iOS doesn't respect the alpha:false context creation attribute
+ https://bugs.webkit.org/show_bug.cgi?id=154617
+ <rdar://problem/13417023>
+
+ Reviewed by Sam Weinig.
+
+ Add a test that draws contexts with and without alpha, and then a reference
+ version that hard-codes the non-alpha colors.
+
+ * fast/canvas/webgl/context-attributes-alpha-expected.html: Added.
+ * fast/canvas/webgl/context-attributes-alpha.html: Added.
+
2016-02-23 Daniel Bates <[email protected]>
CSP: Enable base-uri directive by default
Added: trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha-expected.html (0 => 197008)
--- trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha-expected.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha-expected.html 2016-02-24 01:21:55 UTC (rev 197008)
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<head>
+<meta name="viewport" content="width=device-width">
+<style>
+body {
+ margin: 0;
+ background-size: 100px 100px;
+ background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"><rect width="0.5" height="0.5" fill="blue"/><rect x="0.5" y="0.5" width="0.5" height="0.5" fill="orange"/><rect x="0" y="0.5" width="0.5" height="0.5" fill="yellow"/><rect x="0.5" y="0" width="0.5" height="0.5" fill="pink"/></svg>');
+}
+canvas {
+ width: 200px;
+ height: 200px;
+}
+</style>
+</head>
+<script id="vertexShaderSource" type="text/glsl">
+attribute vec4 position;
+void main() {
+ gl_Position = position;
+}
+</script>
+<script id="fragmentShaderSource1" type="text/glsl">
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+void main() {
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);
+}
+</script>
+<script id="fragmentShaderSource2" type="text/glsl">
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+void main() {
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+</script>
+<script>
+
+function drawTriangle(canvas, alpha) {
+ canvas.width = 200;
+ canvas.height = 200;
+ var gl = canvas.getContext("webgl", { alpha: true });
+ var vertexShader = gl.createShader(gl.VERTEX_SHADER);
+ gl.shaderSource(vertexShader, document.getElementById("vertexShaderSource").textContent);
+ gl.compileShader(vertexShader);
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
+ console.error("Vertex Shader failed to compile.");
+ console.log(gl.getShaderInfoLog(vertexShader));
+ return;
+ }
+ var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
+ var fragmentShaderSourceID = "fragmentShaderSource" + (alpha ? "1" : "2");
+ gl.shaderSource(fragmentShader, document.getElementById(fragmentShaderSourceID).textContent);
+ gl.compileShader(fragmentShader);
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
+ console.error("Fragment Shader failed to compile.");
+ console.log(gl.getShaderInfoLog(fragmentShader));
+ return;
+ }
+ var program = gl.createProgram();
+ gl.attachShader(program, vertexShader);
+ gl.attachShader(program, fragmentShader);
+ gl.linkProgram(program);
+
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ console.error("Unable to link shaders into program.");
+ return;
+ }
+ gl.useProgram(program);
+ var positionAttribute = gl.getAttribLocation(program, "position");
+ gl.enableVertexAttribArray(positionAttribute);
+ var vertices = new Float32Array([
+ -0.5, -0.5,
+ 0.5, -0.5,
+ 0, 0.5
+ ]);
+ var triangleBuffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
+ gl.clearColor(0, 1, 0, alpha ? 0.5 : 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
+ gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+}
+
+window.addEventListener("load", function () {
+ var canvases = document.querySelectorAll("canvas");
+ drawTriangle(canvases[0], true);
+ drawTriangle(canvases[1], false);
+}, false);
+</script>
+<body>
+ <canvas></canvas><canvas></canvas>
+</body>
\ No newline at end of file
Property changes on: trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha-expected.html
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Added: trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha.html (0 => 197008)
--- trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha.html 2016-02-24 01:21:55 UTC (rev 197008)
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<head>
+<meta name="viewport" content="width=device-width">
+<style>
+body {
+ margin: 0;
+ background-size: 100px 100px;
+ background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"><rect width="0.5" height="0.5" fill="blue"/><rect x="0.5" y="0.5" width="0.5" height="0.5" fill="orange"/><rect x="0" y="0.5" width="0.5" height="0.5" fill="yellow"/><rect x="0.5" y="0" width="0.5" height="0.5" fill="pink"/></svg>');
+}
+canvas {
+ width: 200px;
+ height: 200px;
+}
+</style>
+</head>
+<script id="vertexShaderSource" type="text/glsl">
+attribute vec4 position;
+void main() {
+ gl_Position = position;
+}
+</script>
+<script id="fragmentShaderSource" type="text/glsl">
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+void main() {
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);
+}
+</script>
+<script>
+
+function drawTriangle(canvas, alpha) {
+ canvas.width = 200;
+ canvas.height = 200;
+ var gl = canvas.getContext("webgl", { alpha: alpha });
+ var vertexShader = gl.createShader(gl.VERTEX_SHADER);
+ gl.shaderSource(vertexShader, document.getElementById("vertexShaderSource").textContent);
+ gl.compileShader(vertexShader);
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
+ console.error("Vertex Shader failed to compile.");
+ console.log(gl.getShaderInfoLog(vertexShader));
+ return;
+ }
+ var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
+ gl.shaderSource(fragmentShader, document.getElementById("fragmentShaderSource").textContent);
+ gl.compileShader(fragmentShader);
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
+ console.error("Fragment Shader failed to compile.");
+ console.log(gl.getShaderInfoLog(fragmentShader));
+ return;
+ }
+ var program = gl.createProgram();
+ gl.attachShader(program, vertexShader);
+ gl.attachShader(program, fragmentShader);
+ gl.linkProgram(program);
+
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
+ console.error("Unable to link shaders into program.");
+ return;
+ }
+ gl.useProgram(program);
+ var positionAttribute = gl.getAttribLocation(program, "position");
+ gl.enableVertexAttribArray(positionAttribute);
+ var vertices = new Float32Array([
+ -0.5, -0.5,
+ 0.5, -0.5,
+ 0, 0.5
+ ]);
+ var triangleBuffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
+ gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
+ gl.clearColor(0, 1, 0, 0.5);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ gl.bindBuffer(gl.ARRAY_BUFFER, triangleBuffer);
+ gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+}
+
+window.addEventListener("load", function () {
+ var canvases = document.querySelectorAll("canvas");
+ drawTriangle(canvases[0], true);
+ drawTriangle(canvases[1], false);
+}, false);
+</script>
+<body>
+ <canvas></canvas><canvas></canvas>
+</body>
\ No newline at end of file
Property changes on: trunk/LayoutTests/fast/canvas/webgl/context-attributes-alpha.html
___________________________________________________________________
Added: svn:mime-type
Added: svn:keywords
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (197007 => 197008)
--- trunk/Source/WebCore/ChangeLog 2016-02-24 00:53:29 UTC (rev 197007)
+++ trunk/Source/WebCore/ChangeLog 2016-02-24 01:21:55 UTC (rev 197008)
@@ -1,3 +1,27 @@
+2016-02-23 Dean Jackson <[email protected]>
+
+ [WebGL] iOS doesn't respect the alpha:false context creation attribute
+ https://bugs.webkit.org/show_bug.cgi?id=154617
+ <rdar://problem/13417023>
+
+ Reviewed by Sam Weinig.
+
+ On iOS we were not respecting the alpha:false context creation
+ attribute, which meant you always got output that could
+ have an alpha channel.
+
+ The good news is that now we're setting the opaque flag on
+ the CALayer, there should be a performance improvement when
+ compositing WebGL into the page.
+
+ Test: fast/canvas/webgl/context-attributes-alpha.html
+
+ * platform/graphics/mac/GraphicsContext3DMac.mm:
+ (WebCore::GraphicsContext3D::GraphicsContext3D): Don't tell the layer
+ to be transparent.
+ (WebCore::GraphicsContext3D::setRenderbufferStorageFromDrawable): Do it
+ here instead, but based on the value of the alpha attribute.
+
2016-02-23 Daniel Bates <[email protected]>
CSP: Enable base-uri directive by default
Modified: trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm (197007 => 197008)
--- trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm 2016-02-24 00:53:29 UTC (rev 197007)
+++ trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm 2016-02-24 01:21:55 UTC (rev 197008)
@@ -227,9 +227,6 @@
// Create the WebGLLayer
BEGIN_BLOCK_OBJC_EXCEPTIONS
m_webGLLayer = adoptNS([[WebGLLayer alloc] initWithGraphicsContext3D:this]);
-#if PLATFORM(IOS)
- [m_webGLLayer setOpaque:0];
-#endif
#ifndef NDEBUG
[m_webGLLayer setName:@"WebGL Layer"];
#endif
@@ -345,7 +342,9 @@
bool GraphicsContext3D::setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height)
{
[m_webGLLayer setBounds:CGRectMake(0, 0, width, height)];
- return [m_contextObj renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast<NSObject<EAGLDrawable>*>(m_webGLLayer.get())];
+ [m_webGLLayer setOpaque:(m_internalColorFormat != GL_RGBA8)];
+
+ return [m_contextObj renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast<id<EAGLDrawable>>(m_webGLLayer.get())];
}
#endif