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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var webglCanvas = document.getElementById("webgl-canvas");
6 var glAttribs = {
7 alpha: false,
8 };
9 var gl = webglCanvas.getContext("webgl", glAttribs);
10 gl.clearColor(1.0, 0.0, 0.0, 1.0);
11 gl.enable(gl.DEPTH_TEST);
12 gl.enable(gl.CULL_FACE);
13
14 var vrDisplay = null;
15 var frameData = null;
16
17 function onResize() {
18 if (vrDisplay && vrDisplay.isPresenting) {
19 var leftEye = vrDisplay.getEyeParameters("left");
20 var rightEye = vrDisplay.getEyeParameters("right");
21
22 webglCanvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
23 webglCanvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
24 } else {
25 webglCanvas.width = webglCanvas.offsetWidth * window.devicePixelRatio;
26 webglCanvas.height = webglCanvas.offsetHeight * window.devicePixelRatio;
27 }
28 }
29 window.addEventListener("resize", onResize, false);
30 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.
31
32 function onVrPresentChange() {
33 onResize();
34 }
35 window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false);
36
37 function onVrRequestPresent() {
38 vrDisplay.requestPresent([{source: webglCanvas}]).then( () => {
39 asyncCounter++;
Lei Lei 2017/02/16 22:04:50 Do you still need asyncCounter?
bsheedy 2017/02/16 23:30:14 No, done.
40 }, (err) => {
41 asyncCounter++;
42 });
43 }
44 webglCanvas.onclick = onVrRequestPresent;
45 window.addEventListener('vrdisplayactivate', onVrRequestPresent, false);
46
47 if (navigator.getVRDisplays) {
48 frameData = new VRFrameData();
49 navigator.getVRDisplays().then( (displays) => {
50 if (displays.length > 0) {
51 vrDisplay = displays[0];
52 }
53 }).then( () => {
54 vrDisplayPromiseDone = true;
55 });
56 }
57
58 function onAnimationFrame(t) {
59 if (vrDisplay == null) {
60 window.requestAnimationFrame(onAnimationFrame);
61 gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
62 return;
63 }
64 vrDisplay.requestAnimationFrame(onAnimationFrame);
65 // If presenting, set canvas to blue. Otherwise, red.
66 if (vrDisplay.isPresenting) {
67 vrDisplay.getFrameData(frameData);
68
69 gl.clearColor(0.0, 0.0, 1.0, 1.0);
70 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
71
72 gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height);
73 gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5,
74 webglCanvas.height);
75
76 vrDisplay.submitFrame();
77 } else {
78 gl.clearColor(1.0, 0.0, 0.0, 1.0);
79 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
80
81 gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
82 }
83 }
84 window.requestAnimationFrame(onAnimationFrame);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698