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('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);
36 function startPerfTest() {
38 description
: "This bench test checks the speed on texSubImage2D(Video) on Webgl.",
41 ensureComplete
: ensureComplete
,
45 var flipYAndPremultipyAlphas
=
54 tex
= gl
.createTexture();
55 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
56 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, videoElement
.videoWidth
, videoElement
.videoHeight
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, null);
61 var i
= optionIndex
++ % flipYAndPremultipyAlphas
.length
;
62 gl
.pixelStorei(gl
.UNPACK_FLIP_Y_WEBGL
, flipYAndPremultipyAlphas
[i
][0]);
63 gl
.pixelStorei(gl
.UNPACK_PREMULTIPLY_ALPHA_WEBGL
, flipYAndPremultipyAlphas
[i
][1]);
64 gl
.texSubImage2D(gl
.TEXTURE_2D
, 0, 0, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, videoElement
);
67 function ensureComplete() {
68 gl
.readPixels(0, 0, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, new Uint8Array(4));
72 gl
.deleteTexture(tex
);
75 window
.onload = function () {
77 addPlayCallback(videoElement
);