Commit cf378d00 authored by xidachen's avatar xidachen Committed by Commit bot

Return a transparent black ImageBitmap when mailbox is invalid

In Webgl's transferToImageBitmap(), we create an ImageBitmap from the
drawingBuffer's mailbox. When calling transferToImageBitmap() twice, the
mailbox is invalid in the second call. In this case, we should return
an ImageBitmap that is the same size as the drawingBuffer but should be
transparent black.

Corresponding layout test has been updated to reflect this case.

BUG=627374
CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2139353003
Cr-Commit-Position: refs/heads/master@{#405132}
parent 5de5bf32
<!DOCTYPE html>
<html>
<body>
<canvas id='output' width='100' height='100' style='background:red'></canvas>
<canvas id='output1' width='100' height='100' style='background:red'></canvas>
<canvas id='output2' width='100' height='100' style='background:blue'></canvas>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<canvas id='output1' width='100' height='100' style='background:red'></canvas>
<canvas id='output2' width='100' height='100'></canvas>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<canvas id='output1' width = '100' height = '100'></canvas>
<canvas id='output2' width = '100' height = '100'></canvas>
<script>
if (window.testRunner) {
testRunner.waitUntilDone();
}
var width = 100;
var height = 100;
var aCanvas = new OffscreenCanvas(width, height);
var gl = aCanvas.getContext('webgl');
gl.clearColor(1.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
var image1 = aCanvas.transferToImageBitmap();
var image2 = aCanvas.transferToImageBitmap();
var canvas1 = document.getElementById("output1");
var ctx1 = canvas1.getContext('bitmaprenderer');
ctx1.transferFromImageBitmap(image1);
var canvas2 = document.getElementById('output2');
var ctx2 = canvas2.getContext('bitmaprenderer');
ctx2.transferFromImageBitmap(image2);
if (window.testRunner) {
testRunner.notifyDone();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<canvas id='output' width = '100' height = '100'></canvas>
<canvas id='output1' width = '100' height = '100'></canvas>
<canvas id='output2' width = '100' height = '100'></canvas>
<script>
if (window.testRunner) {
testRunner.waitUntilDone();
......@@ -13,11 +14,18 @@ var aCanvas = new OffscreenCanvas(width, height);
var gl = aCanvas.getContext('webgl');
gl.clearColor(1.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
var image = aCanvas.transferToImageBitmap();
var image1 = aCanvas.transferToImageBitmap();
gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
var image2 = aCanvas.transferToImageBitmap();
var canvas1 = document.getElementById("output1");
var ctx1 = canvas1.getContext('bitmaprenderer');
ctx1.transferFromImageBitmap(image1);
var canvas = document.getElementById("output");
var ctx = canvas.getContext('bitmaprenderer');
ctx.transferFromImageBitmap(image);
var canvas2 = document.getElementById('output2');
var ctx2 = canvas2.getContext('bitmaprenderer');
ctx2.transferFromImageBitmap(image2);
if (window.testRunner) {
testRunner.notifyDone();
......
......@@ -642,7 +642,15 @@ ImageBitmap* WebGLRenderingContextBase::transferToImageBitmapBase()
return nullptr;
WebExternalTextureMailbox mailbox;
drawingBuffer()->prepareMailbox(&mailbox, 0);
ImageBitmap* imageBitmap = ImageBitmap::create(mailbox);
ImageBitmap* imageBitmap;
// If the mailbox is invalid, return an transparent black ImageBitmap.
// The only situation this could happen is when two or more calls to transferToImageBitmap are made back-to-back.
if (mailbox.textureSize.width == 0 && mailbox.textureSize.height == 0) {
sk_sp<SkSurface>surface = SkSurface::MakeRasterN32Premul(drawingBuffer()->size().width(), drawingBuffer()->size().height());
imageBitmap = ImageBitmap::create(StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())));
} else {
imageBitmap = ImageBitmap::create(mailbox);
}
// TODO(xidachen): Create a small pool of recycled textures from ImageBitmapRenderingContext's
// transferFromImageBitmap, and try to use them in DrawingBuffer.
return imageBitmap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment