content/canvas/test/reftest/webgl-utils.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 "use strict";
michael@0 2
michael@0 3 function parseArgs() {
michael@0 4 var query = window.location.search.substring(1);
michael@0 5
michael@0 6 var split = query.split("&");
michael@0 7
michael@0 8 var args = {}
michael@0 9 for (var i = 0; i < split.length; i++) {
michael@0 10 var pair = split[i].split("=");
michael@0 11
michael@0 12 var key = pair[0];
michael@0 13 var value = true;
michael@0 14 if (pair.length >= 2) {
michael@0 15 eval("value = " + decodeURIComponent(pair[1]) + ";");
michael@0 16 }
michael@0 17
michael@0 18 args[key] = value;
michael@0 19 }
michael@0 20
michael@0 21 return args;
michael@0 22 }
michael@0 23
michael@0 24 var gArgs = null;
michael@0 25 function arg(key) {
michael@0 26 if (gArgs === null) {
michael@0 27 gArgs = parseArgs();
michael@0 28 }
michael@0 29
michael@0 30 var ret = gArgs[key];
michael@0 31 if (ret === undefined)
michael@0 32 ret = false;
michael@0 33
michael@0 34 return ret;
michael@0 35 }
michael@0 36
michael@0 37 function initGL(canvas) {
michael@0 38 if (arg("nogl"))
michael@0 39 return null;
michael@0 40
michael@0 41 var gl = null;
michael@0 42
michael@0 43 var withAA = arg("aa");
michael@0 44 var withAlpha = arg("alpha");
michael@0 45 var withDepth = arg("depth");
michael@0 46 var withPremult = arg("premult");
michael@0 47 var withPreserve = arg("preserve");
michael@0 48 var withStencil = arg("stencil");
michael@0 49
michael@0 50 try {
michael@0 51 var argDict = {
michael@0 52 alpha: withAlpha,
michael@0 53 depth: withDepth,
michael@0 54 stencil: withStencil,
michael@0 55 antialias: withAA,
michael@0 56 premultipliedAlpha: withPremult,
michael@0 57 preserveDrawingBuffer: withPreserve,
michael@0 58 };
michael@0 59 gl = canvas.getContext("experimental-webgl", argDict);
michael@0 60 } catch(e) {}
michael@0 61
michael@0 62 return gl;
michael@0 63 }
michael@0 64
michael@0 65 function rAF(func) {
michael@0 66 var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame;
michael@0 67 raf(func);
michael@0 68 }
michael@0 69
michael@0 70 var MAX_WAIT_FOR_COMPOSITE_DELAY_MS = 500;
michael@0 71
michael@0 72 function waitForComposite(func) {
michael@0 73 var isDone = false;
michael@0 74 var doneFunc = function () {
michael@0 75 if (isDone)
michael@0 76 return;
michael@0 77 isDone = true;
michael@0 78 func();
michael@0 79 };
michael@0 80
michael@0 81 rAF(doneFunc);
michael@0 82 setTimeout(doneFunc, MAX_WAIT_FOR_COMPOSITE_DELAY_MS);
michael@0 83 }

mercurial