• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
35
36function startPerfTest() {
37    CanvasRunner.start({
38        description: "This bench test checks the speed on texSubImage2D(Video) on Webgl.",
39        preRun: preRun,
40        doRun: doRun,
41        ensureComplete: ensureComplete,
42        postRun: postRun});
43}
44
45var flipYAndPremultipyAlphas =
46  [[ false, false ],
47   [ false, true  ],
48   [ true,  false ],
49   [ true,  true  ]];
50var optionIndex = 0;
51var tex = null;
52
53function preRun() {
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);
57    optionIndex = 0;
58}
59
60function doRun() {
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);
65}
66
67function ensureComplete() {
68    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
69}
70
71function postRun() {
72    gl.deleteTexture(tex);
73}
74
75window.onload = function () {
76    setSize(1, 1);
77    addPlayCallback(videoElement);
78}
79
80</script>
81</body>
82</html>
83