4 <video id="video" loop></video>
5 <script src="../resources/runner.js"></script>
6 <script src="resources/canvas_runner.js"></script>
8 var videoElement = document.getElementById("video");
9 var canvas3D = document.createElement('canvas');
10 var gl = canvas3D.getContext('experimental-webgl');
12 CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this platform!\n");
14 function setSize(width, height) {
15 canvas3D.width = width;
16 canvas3D.height = height;
19 function 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");
26 videoElement.src = "../resources/bear-1280x720.mp4";
29 function startVideo() {
30 // loop can emit this event again.
31 videoElement.removeEventListener("canplaythrough", startVideo, true);
35 function startPerfTest() {
37 description: "This bench test checks the speed on texImage2D(Video) on Webgl.",
40 ensureComplete: ensureComplete,
44 var flipYAndPremultipyAlphas =
53 tex = gl.createTexture();
54 gl.bindTexture(gl.TEXTURE_2D, tex);
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);
65 function ensureComplete() {
66 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
70 gl.deleteTexture(tex);
73 window.onload = function () {
75 addPlayCallback(videoElement);