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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<html>
<head>
<script type="text/javascript">
var canvas;
var w, h;
var gl;
var extension;
function testHorizontalBands() {
gl.enable(gl.SCISSOR_TEST);
gl.clearColor(1, 0, 0, 1);
gl.scissor(0, 0, w, h/2);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.clearColor(0, 1, 0, 1);
gl.scissor(0, h/2, w, h/2);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.disable(gl.SCISSOR_TEST);
var size = w * h * 4;
var array = new Uint8Array(size);
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, array);
return array[0] == 255 && array[1] == 0 &&
array[size - 4] == 0 && array[size - 3] == 255;
}
function testContextLost(e) {
e.preventDefault();
if (extension) {
setTimeout(function() {
extension.restoreContext();
}, 0);
}
}
function testContextRestored() {
gl = canvas.getContext("experimental-webgl");
if (!gl || gl.isContextLost()) {
// Might just be blocked because of infobar.
return;
}
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
var a = new Uint8Array(w * h * 4);
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, a);
window.domAutomationController.setAutomationId(1);
if (a[0] == 0 && a[1] == 0 && a[2] == 255)
window.domAutomationController.send("SUCCESS");
else
window.domAutomationController.send("FAILED");
}
function contextLostTest(kind)
{
switch (kind) {
case "WEBGL_lose_context": {
extension = gl.getExtension("WEBKIT_WEBGL_lose_context") ||
gl.getExtension("WEBGL_lose_context");
extension.loseContext();
break;
}
case "kill":
// nothing -- the browser test navigates to about:gpucrash and kills
// the GPU process.
break;
}
}
function onLoad() {
canvas = document.getElementById("canvas1");
w = canvas.width;
h = canvas.height;
if (!canvas) {
document.title = "FAILED: canvas element not found";
return;
}
canvas.addEventListener("webglcontextlost", testContextLost, false);
canvas.addEventListener("webglcontextrestored", testContextRestored, false);
gl = canvas.getContext("experimental-webgl");
if (!gl) {
document.title = "FAILED: could not get webgl context for canvas";
return;
}
if (!testHorizontalBands()) {
document.title = "FAILED: did not render correctly";
return;
}
var query = /query=(.*)/.exec(window.location.href);
if (query) {
contextLostTest(query[1]);
} else {
var renderer = gl.getParameter(gl.RENDERER);
document.title = "SUCCESS: " + renderer;
}
}
</script>
</head>
<body onload="onLoad()">
<canvas id="canvas1" width="16px" height="32px">
</canvas>
</body>
</html>
|