Bug 1229481 - Part 3: Add clear color test for WebVR; draft
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 05 May 2017 19:00:25 +0800
changeset 574179 e86cec6b4f96c824f3745c186aab02f5c649d810
parent 574178 5fe906d018a97edd36ee0c4955c294bd0f5bce7c
child 574182 78f8b76f361fd029d452fca655dc4b457a7b30c0
push id57594
push userbmo:dmu@mozilla.com
push dateMon, 08 May 2017 11:11:54 +0000
bugs1229481
milestone55.0a1
Bug 1229481 - Part 3: Add clear color test for WebVR; MozReview-Commit-ID: CnSYFFZS8lP
dom/vr/moz.build
dom/vr/test/reftest/clear_color.html
dom/vr/test/reftest/green.png
dom/vr/test/reftest/reftest.list
dom/vr/test/reftest/webgl-utils.js
dom/vr/test/reftest/white.png
dom/vr/test/reftest/wrapper.html
--- a/dom/vr/moz.build
+++ b/dom/vr/moz.build
@@ -23,9 +23,10 @@ UNIFIED_SOURCES = [
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 LOCAL_INCLUDES += [
     '/dom/base'
 ]
 
-MOCHITEST_MANIFESTS += ['test/mochitest/mochitest.ini']
\ No newline at end of file
+MOCHITEST_MANIFESTS += ['test/mochitest/mochitest.ini']
+REFTEST_MANIFESTS += ['test/reftest/reftest.list']
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/reftest/clear_color.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<meta charset='UTF-8'>
+<!--
+Clear the canvas to green to test that we get pixels to the screen.
+
+If this fails, something is seriously wrong.
+-->
+<html>
+
+<head>
+  <script type='text/javascript' src='webgl-utils.js'></script>
+  <script type='text/javascript' src="../mochitest/VRSimulationDriver.js"></script>
+  <script type='text/javascript'>
+    'use strict';
+
+    var frameData = null;
+    var vrDisplay = null;
+    var webglCanvas = null;
+    var gl = null;
+
+    function setStatus(text) {
+      var elem = document.getElementById('status');
+      elem.innerHTML = text;
+    }
+
+    function initVRMock() {
+      VRServiceTest = navigator.requestVRServiceTest();
+      if (!VRServiceTest) {
+        setStatus('VRServiceTest get failed.');
+        return;
+      }
+
+      VRSimulationDriver.AttachWebVRDisplay().then(() => {
+        // VRSimulationDriver.SetEyeResolution(1332, 1586);
+        VRSimulationDriver.SetEyeResolution(256, 256);
+        VRSimulationDriver.SetEyeParameter("left", -0.029, 0, 0, 41.65, 35.57, 48.00, 43.97);
+        VRSimulationDriver.SetEyeParameter("right", 0.029, 0, 0, 41.65, 43.97, 48.00, 35.57);
+        var poseOrient = new Float32Array([-0.188, -0.007, 0.045, -0.980]);
+        var posePos = new Float32Array([-0.161, 0.076, -0.250]);
+        var poseAngVel = new Float32Array([0.008, -0.002, -0.006]);
+        var poseAngAcc = new Float32Array([3.404, -1.469, -5.901]);
+        var poseLinVel = new Float32Array([0.001, -0.003, -0.002]);
+        var poseLinAcc = new Float32Array([0.007, 0.068, -0.052]);
+        VRSimulationDriver.SetVRDisplayPose(posePos, poseLinVel, poseLinAcc,
+                                            poseOrient, poseAngVel, poseAngAcc);
+        VRSimulationDriver.UpdateVRDisplay();
+      }).then(() => {
+        // Looking for VR displays
+        if (navigator.getVRDisplays) {
+          frameData = new VRFrameData();
+          navigator.getVRDisplays().then(function (displays) {
+            if (displays.length > 0) {
+              vrDisplay = displays[0];
+              gl.clearColor(0.0, 1.0, 0.0, 1.0);
+              gl.clear(gl.COLOR_BUFFER_BIT);
+              vrDisplay.requestPresent([{ source: webglCanvas }]);
+              vrDisplay.requestAnimationFrame(onAnimationFrame);
+            }
+          });
+        }
+      });
+    }
+
+    function onAnimationFrame() {
+      if (!vrDisplay.isPresenting) {
+        return;
+      }
+
+      vrDisplay.requestAnimationFrame(onAnimationFrame);
+      vrDisplay.getFrameData(frameData);
+      gl.clearColor(0.0, 1.0, 0.0, 1.0);
+      gl.clear(gl.COLOR_BUFFER_BIT);
+      // When presenting render a stereo view.
+      //gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height);
+      //cubeSea.render(frameData.leftProjectionMatrix, frameData.leftViewMatrix, stats, t);
+      //gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5, webglCanvas.height);
+      //cubeSea.render(frameData.rightProjectionMatrix, frameData.rightViewMatrix, stats, t);
+      // If we're currently presenting to the VRDisplay we need to
+      // explicitly indicate we're done rendering.
+      vrDisplay.submitFrame();
+
+      setStatus('onAnimationFrame done.');
+      //TODO: settimeout and vrDisplay.exitPresent();
+    }
+
+    function runTest() {
+      webglCanvas = document.getElementById('canvas');
+      gl = initGL(webglCanvas);
+      gl.clearColor(1.0, 1.0, 0.0, 1.0);
+      gl.clear(gl.COLOR_BUFFER_BIT);
+      if (!gl) {
+        setStatus('WebGL context creation failed.');
+        return;
+      }
+      initVRMock();
+    }
+
+  </script>
+</head>
+
+<body onload='runTest();'>
+  <canvas id='canvas' width='256' height='256'></canvas>
+  <div id='status'></div>
+</body>
+
+</html>
\ No newline at end of file
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..348330a558b1afd0ca9bf30407a89240df1db161
GIT binary patch
literal 1358
zc%17D@N?(olHy`uVBq!ia0y~yU}OMc4kjRVS-{>9#48SRcVbv~PUa<$!;<dk>&U>c
zv7h@-A}f&3S>O>_%)r2R7=#&*=dVZs3QCo@MwA5Sr<If^7Ns%-BxdH7==r&ZD3lrN
znd%uD7<?&O2sCN0r;B4qMcmsfjhqYy0!)VA<9GeF)qB9iR#Gj@6x*0rd|JJLiOoSl
zcY@w~CQb>4#w`xJ_WV~)U|_k#^zzfc{su+?5AG$Wf7`<p{pT1}G^%J+(WoLCE7I5h
az~~jt_v!czqYuF1j=|H_&t;ucLK6TKxFTEt
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/reftest/reftest.list
@@ -0,0 +1,4 @@
+# WebVR Reftests
+default-preferences pref(dom.vr.puppet.enabled,true) pref(dom.vr.require-gesture,false) pref(dom.vr.test.enabled,true)
+
+== clear_color.html wrapper.html?green.png
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/reftest/webgl-utils.js
@@ -0,0 +1,82 @@
+"use strict";
+
+function parseArgs() {
+  var query = window.location.search.substring(1);
+
+  var split = query.split("&");
+
+  var args = {}
+  for (var i = 0; i < split.length; i++) {
+    var pair = split[i].split("=");
+
+    var key = pair[0];
+    var value = true;
+    if (pair.length >= 2) {
+      eval("value = " + decodeURIComponent(pair[1]) + ";");
+    }
+
+    args[key] = value;
+  }
+
+  return args;
+}
+
+var gArgs = null;
+function arg(key, defaultVal) {
+  if (gArgs === null) {
+    gArgs = parseArgs();
+  }
+
+  if (!(key in gArgs))
+    return defaultVal;
+
+  return gArgs[key];
+}
+
+function initGL(canvas) {
+  if (arg("nogl"))
+    return null;
+
+  var gl = null;
+
+  var withAA = arg("aa", false);
+  var withAlpha = arg("alpha", false);
+  var withDepth = arg("depth", false);
+  var withPremult = arg("premult", false);
+  var withPreserve = arg("preserve", false);
+  var withStencil = arg("stencil", false);
+
+  try {
+    var argDict = {
+      alpha: withAlpha,
+      depth: withDepth,
+      stencil: withStencil,
+      antialias: withAA,
+      premultipliedAlpha: withPremult,
+      preserveDrawingBuffer: withPreserve,
+    };
+    gl = canvas.getContext("experimental-webgl", argDict);
+  } catch(e) {}
+
+  return gl;
+}
+
+function rAF(func) {
+  var raf = window.requestAnimationFrame;
+  raf(func);
+}
+
+var MAX_WAIT_FOR_COMPOSITE_DELAY_MS = 500;
+
+function waitForComposite(func) {
+  var isDone = false;
+  var doneFunc = function () {
+    if (isDone)
+      return;
+    isDone = true;
+    func();
+  };
+
+  rAF(doneFunc);
+  setTimeout(doneFunc, MAX_WAIT_FOR_COMPOSITE_DELAY_MS);
+}
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..23b21c59cb9c5138b84ade1c728d8fd61889956b
GIT binary patch
literal 1401
zc%17D@N?(olHy`uVBq!ia0y~yU}OMc4kjRVS-{>9#48SRcVbv~PUa<$!;<dk>&U>c
zv7h@-A}f&3S>O>_%)r2R7=#&*=dVZs3QCo@MwA5Sr<If^7Ns%-BxdH7==r&ZD3lrN
znd%uD7<?&O2sG)1r;B4qMcmuVj6gd%nhkzW-{&}k_d!uHPYZ9%3|T8?;RbaNX#t0-
zx(`erm@}D~JkImSG1MvKIxxKad64@6{}Nsf1zY<H#vhGa7#Wv5XV+)2pJ1lY@a4|~
z)(7mD*jOgali$Pe$Kh53!==y7;tlenhK(9FYS^e@^fl}c^PTNFR|<kpd;pe=44$rj
JF6*2UngFV23qb$?
new file mode 100644
--- /dev/null
+++ b/dom/vr/test/reftest/wrapper.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<head>
+<title>Image reftest wrapper</title>
+<style type="text/css">
+  #image1 { background-color: rgb(10, 100, 250); }
+</style>
+<script>
+  // The image is loaded async after the page loads
+  // wait for it to finish loading
+  function onImageLoad() { 
+    document.documentElement.removeAttribute("class");
+  };
+</script>
+</head>
+<body>
+<img id="image1">
+<script>
+  // Use as "wrapper.html?image.png"
+  var imgURL = document.location.search.substr(1);
+  document.images[0].onload = onImageLoad;
+  document.images[0].onerror = onImageLoad;
+  document.images[0].src = imgURL;
+</script>
+</body>
+</html>
+