1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body onload="start();">
<canvas id="webgl" width="200" height="200"></canvas>
<script>
/*
* crbug.com/438986
* window.createImageBitmap(HTMLCanvasElement) copies the back buffer of WebGL.
* So createImageBitmap(HTMLCanvasElement) must create transparent ImageBuffer
* 1 frame after WebGL draws contents.
*/
window.jsTestIsAsync = true;
var canvas = document.createElement("canvas");
canvas.width = 200;
canvas.height = 200;
var ctx = canvas.getContext("2d");
function shouldBeGreen(x, y) {
d = ctx.getImageData(x, y, 1, 1).data;
shouldBeTrue("d[0] == 0");
shouldBeTrue("d[1] == 255");
shouldBeTrue("d[2] == 0");
shouldBeTrue("d[3] == 255");
}
function shouldBeTransparent(x, y) {
d = ctx.getImageData(x, y, 1, 1).data;
shouldBeTrue("d[0] == 0");
shouldBeTrue("d[1] == 0");
shouldBeTrue("d[2] == 0");
shouldBeTrue("d[3] == 0");
}
function start() {
debug("Check the imageBitmap of webgl.")
var webgl_canvas = document.getElementById("webgl");
var gl = webgl_canvas.getContext("webgl", {preserveDrawingBuffer: false});
gl.clearColor(0.0, 1.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
createImageBitmapAndCheck(webgl_canvas, false).then(function() {
if (window.testRunner) {
testRunner.layoutAndPaintAsyncThen(asyncTest);
} else {
window.requestAnimationFrame(asyncTest);
}
});
}
function createImageBitmapAndCheck(webgl_canvas, discarded) {
return createImageBitmap(webgl_canvas).then(function (imageBitmap) {
ctx.clearRect(0, 0, 200, 200);
ctx.drawImage(imageBitmap, 0, 0);
if (!discarded) {
shouldBeGreen(50, 50);
shouldBeGreen(150, 150);
} else {
shouldBeTransparent(50, 50);
shouldBeTransparent(150, 150);
}
}, function() {
testFailed("Promise was rejected.");
finishJSTest();
});
}
function asyncTest() {
debug("Check the imageBitmap of webgl in the next frame. drawingBuffer is discarded.")
var webgl_canvas = document.getElementById("webgl");
createImageBitmapAndCheck(webgl_canvas, true).then(function() {
finishJSTest();
});
}
</script>
</body>
</html>
|