1<!DOCTYPE html> 2<html> 3<body> 4<video id="video" loop></video> 5<script src="../resources/runner.js"></script> 6<script src="resources/canvas_runner.js"></script> 7<script> 8var videoElement = document.getElementById("video"); 9var canvas3D = document.createElement('canvas'); 10var gl = canvas3D.getContext('experimental-webgl'); 11if(!gl) 12 CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this platform!\n"); 13 14function setSize(width, height) { 15 canvas3D.width = width; 16 canvas3D.height = height; 17} 18 19function addPlayCallback(videoElement) { 20 // This logic makes sure this perf test starts after playing the video. 21 videoElement.addEventListener("canplaythrough", startVideo, true); 22 videoElement.addEventListener("play", startPerfTest, true); 23 videoElement.addEventListener('error', function(ev) { 24 CanvasRunner.logFatalError("\nmp4 codec is not supported on this platform. Received error event:" + ev.target.error.code + "\n"); 25 }, false); 26 videoElement.src = "../resources/bear-1280x720.mp4"; 27} 28 29function startVideo() { 30 // loop can emit this event again. 31 videoElement.removeEventListener("canplaythrough", startVideo, true); 32 videoElement.play(); 33} 34 35function startPerfTest() { 36 CanvasRunner.start({ 37 description: "This bench test checks the speed on texImage2D(Video) on Webgl.", 38 preRun: preRun, 39 doRun: doRun, 40 ensureComplete: ensureComplete, 41 postRun: postRun}); 42} 43 44var flipYAndPremultipyAlphas = 45 [[ false, false ], 46 [ false, true ], 47 [ true, false ], 48 [ true, true ]]; 49var optionIndex = 0; 50var tex = null; 51 52function preRun() { 53 tex = gl.createTexture(); 54 gl.bindTexture(gl.TEXTURE_2D, tex); 55 optionIndex = 0; 56} 57 58function doRun() { 59 var i = optionIndex++ % flipYAndPremultipyAlphas.length; 60 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipYAndPremultipyAlphas[i][0]); 61 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, flipYAndPremultipyAlphas[i][1]); 62 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, videoElement); 63} 64 65function ensureComplete() { 66 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4)); 67} 68 69function postRun() { 70 gl.deleteTexture(tex); 71} 72 73window.onload = function () { 74 setSize(1, 1); 75 addPlayCallback(videoElement); 76} 77 78</script> 79</body> 80</html> 81