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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/cardboard/CardboardRenderer.java

Issue 2100943004: [Remoting Android] Make JniClient own JniDisplayHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 5 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting.cardboard; 5 package org.chromium.chromoting.cardboard;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.graphics.Point; 8 import android.graphics.Point;
9 import android.graphics.PointF; 9 import android.graphics.PointF;
10 import android.opengl.GLES20; 10 import android.opengl.GLES20;
11 import android.opengl.Matrix; 11 import android.opengl.Matrix;
12 12
13 import com.google.vrtoolkit.cardboard.CardboardView; 13 import com.google.vrtoolkit.cardboard.CardboardView;
14 import com.google.vrtoolkit.cardboard.Eye; 14 import com.google.vrtoolkit.cardboard.Eye;
15 import com.google.vrtoolkit.cardboard.HeadTransform; 15 import com.google.vrtoolkit.cardboard.HeadTransform;
16 import com.google.vrtoolkit.cardboard.Viewport; 16 import com.google.vrtoolkit.cardboard.Viewport;
17 17
18 import org.chromium.chromoting.jni.Client; 18 import org.chromium.chromoting.jni.Client;
19 import org.chromium.chromoting.jni.Display;
19 20
20 import javax.microedition.khronos.egl.EGLConfig; 21 import javax.microedition.khronos.egl.EGLConfig;
21 22
22 /** 23 /**
23 * Renderer for Cardboard view. 24 * Renderer for Cardboard view.
24 */ 25 */
25 public class CardboardRenderer implements CardboardView.StereoRenderer { 26 public class CardboardRenderer implements CardboardView.StereoRenderer {
26 private static final String TAG = "cr.CardboardRenderer"; 27 private static final String TAG = "cr.CardboardRenderer";
27 28
28 private static final int BYTE_PER_FLOAT = 4; 29 private static final int BYTE_PER_FLOAT = 4;
(...skipping 30 matching lines...) Expand all
59 // If the user triggers the button while looking faraway, this will cause th e 60 // If the user triggers the button while looking faraway, this will cause th e
60 // desktop to be re-positioned in the center of the view. 61 // desktop to be re-positioned in the center of the view.
61 private static final float FARAWAY_ANGLE_RATIO = 1.6777f; 62 private static final float FARAWAY_ANGLE_RATIO = 1.6777f;
62 63
63 // Small number used to avoid division-overflow or other problems with 64 // Small number used to avoid division-overflow or other problems with
64 // floating-point imprecision. 65 // floating-point imprecision.
65 private static final float EPSILON = 1e-5f; 66 private static final float EPSILON = 1e-5f;
66 67
67 private final Activity mActivity; 68 private final Activity mActivity;
68 private final Client mClient; 69 private final Client mClient;
70 private final Display mDisplay;
69 71
70 private float mCameraPosition; 72 private float mCameraPosition;
71 73
72 // Lock to allow multithreaded access to mCameraPosition. 74 // Lock to allow multithreaded access to mCameraPosition.
73 private final Object mCameraPositionLock = new Object(); 75 private final Object mCameraPositionLock = new Object();
74 76
75 private float[] mCameraMatrix; 77 private float[] mCameraMatrix;
76 private float[] mViewMatrix; 78 private float[] mViewMatrix;
77 private float[] mProjectionMatrix; 79 private float[] mProjectionMatrix;
78 80
(...skipping 21 matching lines...) Expand all
100 // Lock for eye position related operations. 102 // Lock for eye position related operations.
101 // This protects access to mEyeDesktopPosition. 103 // This protects access to mEyeDesktopPosition.
102 private final Object mEyeDesktopPositionLock = new Object(); 104 private final Object mEyeDesktopPositionLock = new Object();
103 105
104 // Flag to indicate whether to show menu bar. 106 // Flag to indicate whether to show menu bar.
105 private boolean mMenuBarVisible; 107 private boolean mMenuBarVisible;
106 108
107 public CardboardRenderer(Activity activity, Client client) { 109 public CardboardRenderer(Activity activity, Client client) {
108 mActivity = activity; 110 mActivity = activity;
109 mClient = client; 111 mClient = client;
112 mDisplay = (Display) client.getDisplay();
110 mCameraPosition = 0.0f; 113 mCameraPosition = 0.0f;
111 114
112 mCameraMatrix = new float[16]; 115 mCameraMatrix = new float[16];
113 mViewMatrix = new float[16]; 116 mViewMatrix = new float[16];
114 mProjectionMatrix = new float[16]; 117 mProjectionMatrix = new float[16];
115 mDesktopModelMatrix = new float[16]; 118 mDesktopModelMatrix = new float[16];
116 mDesktopCombinedMatrix = new float[16]; 119 mDesktopCombinedMatrix = new float[16];
117 mEyePointModelMatrix = new float[16]; 120 mEyePointModelMatrix = new float[16];
118 mEyePointCombinedMatrix = new float[16]; 121 mEyePointCombinedMatrix = new float[16];
119 mPhotosphereCombinedMatrix = new float[16]; 122 mPhotosphereCombinedMatrix = new float[16];
120 123
121 mForwardVector = new float[3]; 124 mForwardVector = new float[3];
122 } 125 }
123 126
124 private void initializeRedrawCallback() { 127 private void initializeRedrawCallback() {
125 mActivity.runOnUiThread(new Runnable() { 128 mActivity.runOnUiThread(new Runnable() {
126 public void run() { 129 public void run() {
127 mClient.getDisplay().provideRedrawCallback(new Runnable() { 130 mDisplay.provideRedrawCallback(new Runnable() {
128 @Override 131 @Override
129 public void run() { 132 public void run() {
130 mDesktop.reloadTexture(); 133 mDesktop.reloadTexture();
131 mCursor.reloadTexture(); 134 mCursor.reloadTexture();
132 } 135 }
133 }); 136 });
134 137
135 mClient.getDisplay().redrawGraphics(); 138 mDisplay.redrawGraphics();
136 } 139 }
137 }); 140 });
138 } 141 }
139 142
140 @Override 143 @Override
141 public void onSurfaceCreated(EGLConfig config) { 144 public void onSurfaceCreated(EGLConfig config) {
142 // Set the background clear color to black. 145 // Set the background clear color to black.
143 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 146 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
144 147
145 // Use culling to remove back faces. 148 // Use culling to remove back faces.
146 GLES20.glEnable(GLES20.GL_CULL_FACE); 149 GLES20.glEnable(GLES20.GL_CULL_FACE);
147 150
148 // Enable depth testing. 151 // Enable depth testing.
149 GLES20.glEnable(GLES20.GL_DEPTH_TEST); 152 GLES20.glEnable(GLES20.GL_DEPTH_TEST);
150 153
151 mDesktop = new Desktop(mClient); 154 mDesktop = new Desktop(mDisplay);
152 mMenuBar = new MenuBar(mActivity); 155 mMenuBar = new MenuBar(mActivity);
153 mPhotosphere = new Photosphere(mActivity); 156 mPhotosphere = new Photosphere(mActivity);
154 mCursor = new Cursor(mClient); 157 mCursor = new Cursor(mClient);
155 158
156 initializeRedrawCallback(); 159 initializeRedrawCallback();
157 } 160 }
158 161
159 @Override 162 @Override
160 public void onSurfaceChanged(int width, int height) { 163 public void onSurfaceChanged(int width, int height) {
161 } 164 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 theta = Math.atan(mDesktop.getHalfWidth() 428 theta = Math.atan(mDesktop.getHalfWidth()
426 / (DESKTOP_POSITION_Z - mCameraPosition)); 429 / (DESKTOP_POSITION_Z - mCameraPosition));
427 } 430 }
428 431
429 // Calculate current looking angle. 432 // Calculate current looking angle.
430 double phi = Math.atan(mForwardVector[0] / mForwardVector[2]); 433 double phi = Math.atan(mForwardVector[0] / mForwardVector[2]);
431 434
432 return Math.abs(phi) > FARAWAY_ANGLE_RATIO * Math.abs(theta); 435 return Math.abs(phi) > FARAWAY_ANGLE_RATIO * Math.abs(theta);
433 } 436 }
434 } 437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698