summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikchen <erikchen@chromium.org>2016-03-16 15:32:26 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-16 22:35:24 +0000
commit4e7ecf36fb2af3e3677c085de5b1ea6e7e75f3be (patch)
tree13a62ad99cb0ea622967a3fbf958c97752f095f3
parent8ce1943be5284c67fb79cae9bf1576624fba97b6 (diff)
downloadchromium_src-4e7ecf36fb2af3e3677c085de5b1ea6e7e75f3be.zip
chromium_src-4e7ecf36fb2af3e3677c085de5b1ea6e7e75f3be.tar.gz
chromium_src-4e7ecf36fb2af3e3677c085de5b1ea6e7e75f3be.tar.bz2
Re-enable IOSurface Canvas2D.
Previously, WebExternalTextureLayerImpl inferred the size of the texture from the bounds of the WebLayer, but the two are not necessarily the same. This CL passes the texture size through WebExternalTextureMailbox. This CL also adds a pixel test. BUG=595063 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1804243002 Cr-Commit-Position: refs/heads/master@{#381570}
-rw-r--r--cc/blink/web_external_texture_layer_impl.cc6
-rw-r--r--content/test/data/gpu/pixel_canvas2d_webgl.html72
-rw-r--r--content/test/data/gpu/pixel_webgl.html90
-rw-r--r--content/test/data/gpu/pixel_webgl_util.js95
-rw-r--r--content/test/gpu/gpu_tests/pixel_expectations.py6
-rw-r--r--content/test/gpu/page_sets/pixel_tests.py17
-rw-r--r--third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp5
-rw-r--r--third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.h4
-rw-r--r--third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp1
-rw-r--r--third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp1
-rw-r--r--third_party/WebKit/public/platform/WebExternalTextureMailbox.h15
11 files changed, 209 insertions, 103 deletions
diff --git a/cc/blink/web_external_texture_layer_impl.cc b/cc/blink/web_external_texture_layer_impl.cc
index 03f6e18..e08f9e3 100644
--- a/cc/blink/web_external_texture_layer_impl.cc
+++ b/cc/blink/web_external_texture_layer_impl.cc
@@ -87,8 +87,10 @@ bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
memcpy(&sync_token, client_mailbox.syncToken, sizeof(sync_token));
gfx::Size size;
- if (client_mailbox.allowOverlay)
- size = gfx::Size(layer_->bounds().width, layer_->bounds().height);
+ if (client_mailbox.allowOverlay) {
+ size = gfx::Size(client_mailbox.textureSize.width,
+ client_mailbox.textureSize.height);
+ }
*mailbox =
cc::TextureMailbox(name, sync_token, client_mailbox.textureTarget, size,
diff --git a/content/test/data/gpu/pixel_canvas2d_webgl.html b/content/test/data/gpu/pixel_canvas2d_webgl.html
new file mode 100644
index 0000000..2eea10a
--- /dev/null
+++ b/content/test/data/gpu/pixel_canvas2d_webgl.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+
+<!-- READ BEFORE UPDATING:
+If this test is updated make sure to increment the "revision" value of the
+associated test in content/test/gpu/page_sets/pixel_tests.py. This will ensure
+that the baseline images are regenerated on the next run.
+-->
+
+<html>
+<head>
+<title>Accelerated Retina Canvas 2D and WebGL Test: Red Box and Green Triangle over Black Background</title>
+<style type="text/css">
+.nomargin {
+ margin: 0px auto;
+}
+</style>
+
+<script src="pixel_webgl_util.js"></script>
+
+<script>
+var g_swapsBeforeAck = 15;
+var gl;
+
+function main()
+{
+ draw();
+ waitForFinish();
+}
+
+function draw()
+{
+ var canvas = document.getElementById("c");
+ canvas.style.width = canvas.style.height = "150px";
+ var c2d = canvas.getContext("2d");
+ c2d.clearRect(0, 0, canvas.width, canvas.height);
+ c2d.fillStyle = "rgba(255, 0, 0, 0.5)";
+ c2d.fillRect(50, 50, 100, 100);
+
+ var webglCanvas = document.getElementById("c2");
+ gl = initGL(webglCanvas);
+ if (!setup(gl)) {
+ domAutomationController.setAutomationId(1);
+ domAutomationController.send("FAILURE");
+ }
+}
+
+function waitForFinish()
+{
+ if (g_swapsBeforeAck == 0) {
+ domAutomationController.setAutomationId(1);
+ domAutomationController.send("SUCCESS");
+ } else {
+ g_swapsBeforeAck--;
+ document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1;
+ drawTriangle(gl);
+ window.webkitRequestAnimationFrame(waitForFinish);
+ }
+}
+</script>
+</head>
+<body onload="main()">
+<div style="position:relative; width:400px; height:400px; background-color:black">
+</div>
+<div id="container" style="position:absolute; top:0px; left:0px">
+<!--
+Canvas acceleration requires that the canvas be at least 256x257.
+-->
+<canvas id="c" width="300" height="300" class="nomargin"></canvas>
+<canvas id="c2" width="300" height="300" class="nomargin"></canvas>
+</div>
+</body>
+</html>
diff --git a/content/test/data/gpu/pixel_webgl.html b/content/test/data/gpu/pixel_webgl.html
index 68fab9e..b1f60f1 100644
--- a/content/test/data/gpu/pixel_webgl.html
+++ b/content/test/data/gpu/pixel_webgl.html
@@ -15,21 +15,7 @@ that the baseline images are regenerated on the next run.
}
</style>
-<script id="shader-vs" type="x-shader/x-vertex">
-attribute vec3 pos;
-void main(void)
-{
- gl_Position = vec4(pos, 1.0);
-}
-</script>
-
-<script id="shader-fs" type="x-shader/x-fragment">
-precision mediump float;
-void main(void)
-{
- gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
-}
-</script>
+<script src="pixel_webgl_util.js"></script>
<script>
var g_swapsBeforeAck = 15;
@@ -54,85 +40,13 @@ function drawSomeFrames()
domAutomationController.send("SUCCESS");
} else {
g_swapsBeforeAck--;
- draw(gl);
+ drawTriangle(gl);
window.webkitRequestAnimationFrame(drawSomeFrames);
}
}
-function initGL(canvas)
-{
- var gl = null;
- try {
- gl = canvas.getContext("experimental-webgl");
- } catch (e) {}
- if (!gl) {
- try {
- gl = canvas.getContext("webgl");
- } catch (e) { }
- }
- return gl;
-}
-
-function setupShader(gl, source, type) {
- var shader = gl.createShader(type);
- gl.shaderSource(shader, source);
- gl.compileShader(shader);
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
- return null;
- return shader;
-}
-function setupProgram(gl, vs_id, fs_id) {
- var vs_node = document.getElementById(vs_id);
- var fs_node = document.getElementById(fs_id);
- if (!vs_node || !fs_node)
- return null;
- var vs = setupShader(gl, vs_node.text, gl.VERTEX_SHADER);
- var fs = setupShader(gl, fs_node.text, gl.FRAGMENT_SHADER);
- if (!vs || !fs)
- return null;
- var program = gl.createProgram();
- gl.attachShader(program, vs);
- gl.attachShader(program, fs);
- gl.linkProgram(program);
- if (!gl.getProgramParameter(program, gl.LINK_STATUS))
- return null;
- gl.useProgram(program);
- return program;
-}
-function setupBuffer(gl) {
- var buffer = gl.createBuffer();
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
- var vertexData = [
- 0.0, 0.6, 0.0, // Vertex 1 position
- -0.6, -0.6, 0.0, // Vertex 2 position
- 0.6, -0.6, 0.0, // Vertex 3 position
- ];
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexData), gl.STATIC_DRAW);
-}
-
-function setup(gl) {
- var program = setupProgram(gl, "shader-vs", "shader-fs");
- if (!program)
- return false;
- var posAttr = gl.getAttribLocation(program, "pos");
- gl.enableVertexAttribArray(posAttr);
- setupBuffer(gl);
- var stride = 3 * Float32Array.BYTES_PER_ELEMENT;
- gl.vertexAttribPointer(posAttr, 3, gl.FLOAT, false, stride, 0);
- gl.clearColor(0.0, 0.0, 0.0, 0.0);
- gl.viewport(0, 0, 200, 200);
- gl.disable(gl.DEPTH_TEST);
- if (gl.getError() != gl.NO_ERROR)
- return false;
- return true;
-}
-
-function draw(gl) {
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
- gl.drawArrays(gl.TRIANGLES, 0, 3);
-}
</script>
</head>
<body onload="main()">
diff --git a/content/test/data/gpu/pixel_webgl_util.js b/content/test/data/gpu/pixel_webgl_util.js
new file mode 100644
index 0000000..b87e176
--- /dev/null
+++ b/content/test/data/gpu/pixel_webgl_util.js
@@ -0,0 +1,95 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// READ BEFORE UPDATING:
+// If this file is updated, make sure to increment the "revision" value of any
+// tests that use this file in content/test/gpu/page_sets/pixel_tests.py. This
+// will ensure that the baseline images are regenerated on the next run.
+
+var vertexShader = [
+ "attribute vec3 pos;",
+ "void main(void)",
+ "{",
+ " gl_Position = vec4(pos, 1.0);",
+ "}"
+].join("\n");
+
+var fragmentShader = [
+ "precision mediump float;",
+ "void main(void)",
+ "{",
+ " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);",
+ "}"
+].join("\n");
+
+function initGL(canvas)
+{
+ var gl = null;
+ try {
+ gl = canvas.getContext("experimental-webgl");
+ } catch (e) {}
+ if (!gl) {
+ try {
+ gl = canvas.getContext("webgl");
+ } catch (e) { }
+ }
+ return gl;
+}
+
+function setupShader(gl, source, type) {
+ var shader = gl.createShader(type);
+ gl.shaderSource(shader, source);
+ gl.compileShader(shader);
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
+ return null;
+ return shader;
+}
+
+function setupProgram(gl, vs_id, fs_id) {
+ var vs = setupShader(gl, vertexShader, gl.VERTEX_SHADER);
+ var fs = setupShader(gl, fragmentShader, gl.FRAGMENT_SHADER);
+ if (!vs || !fs)
+ return null;
+ var program = gl.createProgram();
+ gl.attachShader(program, vs);
+ gl.attachShader(program, fs);
+ gl.linkProgram(program);
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS))
+ return null;
+ gl.useProgram(program);
+ return program;
+}
+
+function setupBuffer(gl) {
+ var buffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+ var vertexData = [
+ 0.0, 0.6, 0.0, // Vertex 1 position
+ -0.6, -0.6, 0.0, // Vertex 2 position
+ 0.6, -0.6, 0.0, // Vertex 3 position
+ ];
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexData), gl.STATIC_DRAW);
+}
+
+function setup(gl) {
+ var program = setupProgram(gl, "shader-vs", "shader-fs");
+ if (!program)
+ return false;
+ var posAttr = gl.getAttribLocation(program, "pos");
+ gl.enableVertexAttribArray(posAttr);
+ setupBuffer(gl);
+ var stride = 3 * Float32Array.BYTES_PER_ELEMENT;
+ gl.vertexAttribPointer(posAttr, 3, gl.FLOAT, false, stride, 0);
+ gl.clearColor(0.0, 0.0, 0.0, 0.0);
+ gl.viewport(0, 0, 200, 200);
+ gl.disable(gl.DEPTH_TEST);
+ if (gl.getError() != gl.NO_ERROR)
+ return false;
+ return true;
+}
+
+function drawTriangle(gl) {
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+}
diff --git a/content/test/gpu/gpu_tests/pixel_expectations.py b/content/test/gpu/gpu_tests/pixel_expectations.py
index 0683818..6ddedf1 100644
--- a/content/test/gpu/gpu_tests/pixel_expectations.py
+++ b/content/test/gpu/gpu_tests/pixel_expectations.py
@@ -26,3 +26,9 @@ class PixelExpectations(GpuTestExpectations):
# TODO(erikchen): Remove suppression after generating reference images.
self.Fail('Pixel.IOSurface2DCanvas', ['mac'], bug=579664)
+
+ # TODO(erikchen): Remove suppression after generating reference images.
+ self.Fail('Pixel.IOSurface2DCanvasWebGL', ['mac'], bug=595063)
+
+ # TODO(erikchen): Remove suppression after generating reference images.
+ self.Fail('Pixel.2DCanvasWebGL', bug=595063)
diff --git a/content/test/gpu/page_sets/pixel_tests.py b/content/test/gpu/page_sets/pixel_tests.py
index 4b1d3f1..3be192a 100644
--- a/content/test/gpu/page_sets/pixel_tests.py
+++ b/content/test/gpu/page_sets/pixel_tests.py
@@ -71,6 +71,14 @@ class PixelTestsStorySet(story_set_module.StorySet):
story_set=self,
shared_page_state_class=IOSurface2DCanvasSharedPageState,
expectations=expectations))
+ self.AddStory(PixelTestsPage(
+ url='file://../../data/gpu/pixel_canvas2d_webgl.html',
+ name=base_name + '.IOSurface2DCanvasWebGL',
+ test_rect=[0, 0, 400, 400],
+ revision=1,
+ story_set=self,
+ shared_page_state_class=IOSurface2DCanvasSharedPageState,
+ expectations=expectations))
def _AddAllPages(self, expectations, base_name, use_es3):
if use_es3:
@@ -117,6 +125,15 @@ class PixelTestsStorySet(story_set_module.StorySet):
expectations=expectations,
expected_colors='../../data/gpu/pixel_scissor_expectations.json'))
+ self.AddStory(PixelTestsPage(
+ url='file://../../data/gpu/pixel_canvas2d_webgl.html',
+ name=base_name + '.2DCanvasWebGL',
+ test_rect=[0, 0, 400, 400],
+ revision=1,
+ story_set=self,
+ shared_page_state_class=shared_page_state_class,
+ expectations=expectations))
+
@property
def allow_mixed_story_states(self):
# Return True here in order to be able to add the same tests with
diff --git a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
index 5e7d0d3..21d3da2 100644
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
@@ -274,11 +274,11 @@ Canvas2DLayerBridge::ImageInfo Canvas2DLayerBridge::createIOSurfaceBackedTexture
void Canvas2DLayerBridge::deleteCHROMIUMImage(ImageInfo info)
{
- WebGraphicsContext3D* webContext = context();
- if (webContext->isContextLost())
+ if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR)
return;
GLenum target = GC3D_TEXTURE_RECTANGLE_ARB;
+ WebGraphicsContext3D* webContext = context();
webContext->bindTexture(target, info.m_textureId);
webContext->releaseTexImage2DCHROMIUM(target, info.m_imageId);
webContext->destroyImageCHROMIUM(info.m_imageId);
@@ -309,6 +309,7 @@ bool Canvas2DLayerBridge::prepareMailboxFromImage(PassRefPtr<SkImage> image, Web
createMailboxInfo();
MailboxInfo& mailboxInfo = m_mailboxes.first();
mailboxInfo.m_mailbox.nearestNeighbor = getGLFilter() == GL_NEAREST;
+ mailboxInfo.m_mailbox.textureSize = WebSize(m_size.width(), m_size.height());
GrContext* grContext = m_contextProvider->grContext();
if (!grContext) {
diff --git a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.h b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.h
index dcb87d5..df6f231 100644
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.h
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.h
@@ -60,9 +60,7 @@ class SharedContextRateLimiter;
#define CANVAS2D_HIBERNATION_ENABLED 0
// IOSurfaces are a primitive only present on OS X.
-// Temporarily disable IOSurfaces while investigating a compositing bug.
-// https://crbug.com/595063
-#define USE_IOSURFACE_FOR_2D_CANVAS 0
+#define USE_IOSURFACE_FOR_2D_CANVAS 1
#else
#define CANVAS2D_HIBERNATION_ENABLED 1
#define USE_IOSURFACE_FOR_2D_CANVAS 0
diff --git a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
index 8b76f1e..64a4543 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
@@ -207,6 +207,7 @@ bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
return false;
OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureMailbox);
+ mailbox->textureSize = WebSize(textureImage->width(), textureImage->height());
// Contexts may be in a different share group. We must transfer the texture through a mailbox first
sharedContext->genMailboxCHROMIUM(mailbox->name);
diff --git a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp
index 3b361f7..6234643 100644
--- a/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp
@@ -306,6 +306,7 @@ bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt
frontColorBufferMailbox->mailbox.validSyncToken = m_context->genSyncTokenCHROMIUM(fenceSync, frontColorBufferMailbox->mailbox.syncToken);
frontColorBufferMailbox->mailbox.allowOverlay = frontColorBufferMailbox->textureInfo.imageId != 0;
frontColorBufferMailbox->mailbox.textureTarget = frontColorBufferMailbox->textureInfo.parameters.target;
+ frontColorBufferMailbox->mailbox.textureSize = WebSize(m_size.width(), m_size.height());
setBufferClearNeeded(true);
// set m_parentDrawingBuffer to make sure 'this' stays alive as long as it has live mailboxes
diff --git a/third_party/WebKit/public/platform/WebExternalTextureMailbox.h b/third_party/WebKit/public/platform/WebExternalTextureMailbox.h
index bd57a36..0bb41cf 100644
--- a/third_party/WebKit/public/platform/WebExternalTextureMailbox.h
+++ b/third_party/WebKit/public/platform/WebExternalTextureMailbox.h
@@ -31,21 +31,20 @@
#ifndef WebExternalTextureMailbox_h
#define WebExternalTextureMailbox_h
+#include "WebSize.h"
+
namespace blink {
struct WebExternalTextureMailbox {
signed char name[64];
signed char syncToken[24];
- bool validSyncToken;
- bool allowOverlay;
- bool nearestNeighbor;
- unsigned textureTarget;
+ bool validSyncToken = false;
+ bool allowOverlay = false;
+ bool nearestNeighbor = false;
+ unsigned textureTarget = 0;
+ WebSize textureSize;
WebExternalTextureMailbox()
- : validSyncToken(false)
- , allowOverlay(false)
- , nearestNeighbor(false)
- , textureTarget(0)
{
memset(name, 0, sizeof(name));
memset(syncToken, 0, sizeof(syncToken));