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

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: Fix copyright header 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 var vrDisplay = null;
11 var frameData = null;
12
13 function onResize() {
14 if (vrDisplay && vrDisplay.isPresenting) {
15 var leftEye = vrDisplay.getEyeParameters("left");
16 var rightEye = vrDisplay.getEyeParameters("right");
17
18 webglCanvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
19 webglCanvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
20 } else {
21 webglCanvas.width = webglCanvas.offsetWidth * window.devicePixelRatio;
22 webglCanvas.height = webglCanvas.offsetHeight * window.devicePixelRatio;
23 }
24 }
25
26 function onVrPresentChange() {
27 onResize();
28 }
29
30 function onVrRequestPresent() {
31 vrDisplay.requestPresent([{source: webglCanvas}]);
32 }
33
34 function onAnimationFrame(t) {
35 if (vrDisplay == null) {
36 window.requestAnimationFrame(onAnimationFrame);
37 gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
38 return;
39 }
40 vrDisplay.requestAnimationFrame(onAnimationFrame);
41 // If presenting, set canvas to blue. Otherwise, red.
42 if (vrDisplay.isPresenting) {
43 vrDisplay.getFrameData(frameData);
44
45 gl.clearColor(0.0, 0.0, 1.0, 1.0);
46 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
47
48 gl.viewport(0, 0, webglCanvas.width * 0.5, webglCanvas.height);
49 gl.viewport(webglCanvas.width * 0.5, 0, webglCanvas.width * 0.5,
50 webglCanvas.height);
51
52 vrDisplay.submitFrame();
53 } else {
54 gl.clearColor(1.0, 0.0, 0.0, 1.0);
55 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
56
57 gl.viewport(0, 0, webglCanvas.width, webglCanvas.height);
58 }
59 }
60
61 if (navigator.getVRDisplays) {
62 frameData = new VRFrameData();
63 navigator.getVRDisplays().then( (displays) => {
64 if (displays.length > 0) {
65 vrDisplay = displays[0];
66 }
67 }).then( () => {
68 vrDisplayPromiseDone = true;
69 });
70 }
71
72 gl.clearColor(1.0, 0.0, 0.0, 1.0);
73 gl.enable(gl.DEPTH_TEST);
74 gl.enable(gl.CULL_FACE);
75 window.addEventListener("resize", onResize, false);
76 window.addEventListener("vrdisplaypresentchange", onVrPresentChange, false);
77 window.addEventListener('vrdisplayactivate', onVrRequestPresent, false);
78 window.requestAnimationFrame(onAnimationFrame);
79 webglCanvas.onclick = onVrRequestPresent;
80 onResize();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698