| <!DOCTYPE html> |
| <html> |
| <body> |
| <video id="video" loop></video> |
| <script src="../resources/runner.js"></script> |
| <script src="resources/canvas_runner.js"></script> |
| <script> |
| var videoElement = document.getElementById("video"); |
| var canvas3D = document.createElement('canvas'); |
| var gl = canvas3D.getContext('experimental-webgl'); |
| if(!gl) |
| CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this platform!\n"); |
| |
| function setSize(width, height) { |
| canvas3D.width = width; |
| canvas3D.height = height; |
| } |
| |
| function addPlayCallback(videoElement) { |
| // This logic makes sure this perf test starts after playing the video. |
| videoElement.addEventListener("canplaythrough", startVideo, true); |
| videoElement.addEventListener("play", startPerfTest, true); |
| videoElement.addEventListener('error', function(ev) { |
| CanvasRunner.logFatalError("\nmp4 codec is not supported on this platform. Received error event:" + ev.target.error.code + "\n"); |
| }, false); |
| videoElement.src = "../resources/bear-1280x720.mp4"; |
| } |
| |
| function startVideo() { |
| // loop can emit this event again. |
| videoElement.removeEventListener("canplaythrough", startVideo, true); |
| videoElement.play(); |
| } |
| |
| function startPerfTest() { |
| CanvasRunner.start({ |
| description: "This bench test checks the speed on texImage2D(Video) on Webgl.", |
| preRun: preRun, |
| doRun: doRun, |
| ensureComplete: ensureComplete, |
| postRun: postRun}); |
| } |
| |
| var flipYAndPremultipyAlphas = |
| [[ false, false ], |
| [ false, true ], |
| [ true, false ], |
| [ true, true ]]; |
| var optionIndex = 0; |
| var tex = null; |
| |
| function preRun() { |
| tex = gl.createTexture(); |
| gl.bindTexture(gl.TEXTURE_2D, tex); |
| optionIndex = 0; |
| } |
| |
| function doRun() { |
| var i = optionIndex++ % flipYAndPremultipyAlphas.length; |
| gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipYAndPremultipyAlphas[i][0]); |
| gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, flipYAndPremultipyAlphas[i][1]); |
| gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, videoElement); |
| } |
| |
| function ensureComplete() { |
| gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); |
| } |
| |
| function postRun() { |
| gl.deleteTexture(tex); |
| } |
| |
| window.onload = function () { |
| setSize(1, 1); |
| addPlayCallback(videoElement); |
| } |
| |
| </script> |
| </body> |
| </html> |