Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4399)

Unified Diff: chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js

Issue 2588703003: Add WebVR WebVR E2E test capabilities via Android instrumentation (Closed)
Patch Set: Simplify Javascript code slightly Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js
diff --git a/chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js b/chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js
new file mode 100644
index 0000000000000000000000000000000000000000..54d4eab653e28f3dc196d816181bcad4bec22888
--- /dev/null
+++ b/chrome/test/data/android/webvr_instrumentation/resources/webvr_boilerplate.js
@@ -0,0 +1,84 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var webglCanvas = document.getElementById("webgl-canvas");
+var glAttribs = {
+ alpha: false,
+};
+var gl = webglCanvas.getContext("webgl", glAttribs);
+gl.clearColor(1.0, 0.0, 0.0, 1.0);
+gl.enable(gl.DEPTH_TEST);
+gl.enable(gl.CULL_FACE);
+
+var vrDisplay = null;
+var frameData = null;
+
+function onResize() {
+ if (vrDisplay && vrDisplay.isPresenting) {
+ var leftEye = vrDisplay.getEyeParameters("left");
+ var rightEye = vrDisplay.getEyeParameters("right");
+
+ webglCanvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
+ webglCanvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
+ } else {
+ webglCanvas.width = webglCanvas.offsetWidth * window.devicePixelRatio;
+ webglCanvas.height = webglCanvas.offsetHeight * window.devicePixelRatio;
+ }
+}
+window.addEventListener("resize", onResize, false);
+onResize();
Lei Lei 2017/02/16 22:04:50 How about adding those code in window.onload inste
bsheedy 2017/02/16 23:30:14 Done.
+
+function onVrPresentChange() {
+ onResize();
+}
+window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false);
+
+function onVrRequestPresent() {
+ vrDisplay.requestPresent([{source: webglCanvas}]).then( () => {
+ asyncCounter++;
Lei Lei 2017/02/16 22:04:50 Do you still need asyncCounter?
bsheedy 2017/02/16 23:30:14 No, done.
+ }, (err) => {
+ asyncCounter++;
+ });
+}
+webglCanvas.onclick = onVrRequestPresent;
+window.addEventListener('vrdisplayactivate', onVrRequestPresent, false);
+
+if (navigator.getVRDisplays) {
+ frameData = new VRFrameData();
+ navigator.getVRDisplays().then( (displays) => {
+ if (displays.length > 0) {
+ vrDisplay = displays[0];
+ }
+ }).then( () => {
+ vrDisplayPromiseDone = true;
+ });
+}
+
+function onAnimationFrame(t) {
+ if (vrDisplay == null) {
+ window.requestAnimationFrame(onAnimationFrame);
+ gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
+ return;
+ }
+ vrDisplay.requestAnimationFrame(onAnimationFrame);
+ // If presenting, set canvas to blue. Otherwise, red.
+ if (vrDisplay.isPresenting) {
+ vrDisplay.getFrameData(frameData);
+
+ gl.clearColor(0.0, 0.0, 1.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height);
+ gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5,
+ webglCanvas.height);
+
+ vrDisplay.submitFrame();
+ } else {
+ gl.clearColor(1.0, 0.0, 0.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
+ }
+}
+window.requestAnimationFrame(onAnimationFrame);

Powered by Google App Engine
This is Rietveld 408576698