blob: e86456a61b3596d195562232c99f49b6451ff22f [file] [log] [blame]
<!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('webgl');
if(!gl)
CanvasRunner.logFatalError("WebGL is not supported or enabled on this platform!");
function setSize(width, height) {
canvas3D.width = width;
canvas3D.height = height;
}
function startPerfTest() {
CanvasRunner.start({
description: "This bench test checks the speed on texSubImage2D(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);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, videoElement.videoWidth, videoElement.videoHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
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.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 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);
videoElement.src = "resources/bear-1280x720-long.mp4";
if(!videoElement.canPlayType('video/mp4').replace(/no/, '')) {
CanvasRunner.logFatalError("video/mp4 is unsupported");
};
CanvasRunner.startPlayingAndWaitForVideo(videoElement, startPerfTest);
}
</script>
</body>
</html>