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