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

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

Issue 1537183002: Refactor Chromoting JNI code to use jni/Client (Java changes only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Suppress FindBugs warning Created 4 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
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.JniInterface; 18 import org.chromium.chromoting.jni.Client;
19 19
20 import javax.microedition.khronos.egl.EGLConfig; 20 import javax.microedition.khronos.egl.EGLConfig;
21 21
22 /** 22 /**
23 * Renderer for Cardboard view. 23 * Renderer for Cardboard view.
24 */ 24 */
25 public class CardboardRenderer implements CardboardView.StereoRenderer { 25 public class CardboardRenderer implements CardboardView.StereoRenderer {
26 private static final String TAG = "cr.CardboardRenderer"; 26 private static final String TAG = "cr.CardboardRenderer";
27 27
28 private static final int BYTE_PER_FLOAT = 4; 28 private static final int BYTE_PER_FLOAT = 4;
(...skipping 29 matching lines...) Expand all
58 // the camera position. 58 // the camera position.
59 // If the user triggers the button while looking faraway, this will cause th e 59 // 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. 60 // desktop to be re-positioned in the center of the view.
61 private static final float FARAWAY_ANGLE_RATIO = 1.6777f; 61 private static final float FARAWAY_ANGLE_RATIO = 1.6777f;
62 62
63 // Small number used to avoid division-overflow or other problems with 63 // Small number used to avoid division-overflow or other problems with
64 // floating-point imprecision. 64 // floating-point imprecision.
65 private static final float EPSILON = 1e-5f; 65 private static final float EPSILON = 1e-5f;
66 66
67 private final Activity mActivity; 67 private final Activity mActivity;
68 private final Client mClient;
68 69
69 private float mCameraPosition; 70 private float mCameraPosition;
70 71
71 // Lock to allow multithreaded access to mCameraPosition. 72 // Lock to allow multithreaded access to mCameraPosition.
72 private final Object mCameraPositionLock = new Object(); 73 private final Object mCameraPositionLock = new Object();
73 74
74 private float[] mCameraMatrix; 75 private float[] mCameraMatrix;
75 private float[] mViewMatrix; 76 private float[] mViewMatrix;
76 private float[] mProjectionMatrix; 77 private float[] mProjectionMatrix;
77 78
(...skipping 18 matching lines...) Expand all
96 private Photosphere mPhotosphere; 97 private Photosphere mPhotosphere;
97 private Cursor mCursor; 98 private Cursor mCursor;
98 99
99 // Lock for eye position related operations. 100 // Lock for eye position related operations.
100 // This protects access to mEyeDesktopPosition. 101 // This protects access to mEyeDesktopPosition.
101 private final Object mEyeDesktopPositionLock = new Object(); 102 private final Object mEyeDesktopPositionLock = new Object();
102 103
103 // Flag to indicate whether to show menu bar. 104 // Flag to indicate whether to show menu bar.
104 private boolean mMenuBarVisible; 105 private boolean mMenuBarVisible;
105 106
106 public CardboardRenderer(Activity activity) { 107 public CardboardRenderer(Activity activity, Client client) {
107 mActivity = activity; 108 mActivity = activity;
109 mClient = client;
108 mCameraPosition = 0.0f; 110 mCameraPosition = 0.0f;
109 111
110 mCameraMatrix = new float[16]; 112 mCameraMatrix = new float[16];
111 mViewMatrix = new float[16]; 113 mViewMatrix = new float[16];
112 mProjectionMatrix = new float[16]; 114 mProjectionMatrix = new float[16];
113 mDesktopModelMatrix = new float[16]; 115 mDesktopModelMatrix = new float[16];
114 mDesktopCombinedMatrix = new float[16]; 116 mDesktopCombinedMatrix = new float[16];
115 mEyePointModelMatrix = new float[16]; 117 mEyePointModelMatrix = new float[16];
116 mEyePointCombinedMatrix = new float[16]; 118 mEyePointCombinedMatrix = new float[16];
117 mPhotosphereCombinedMatrix = new float[16]; 119 mPhotosphereCombinedMatrix = new float[16];
118 120
119 mForwardVector = new float[3]; 121 mForwardVector = new float[3];
120 } 122 }
121 123
122 private void initializeRedrawCallback() { 124 private void initializeRedrawCallback() {
123 mActivity.runOnUiThread(new Runnable() { 125 mActivity.runOnUiThread(new Runnable() {
124 public void run() { 126 public void run() {
125 JniInterface.provideRedrawCallback(new Runnable() { 127 mClient.provideRedrawCallback(new Runnable() {
126 @Override 128 @Override
127 public void run() { 129 public void run() {
128 mDesktop.reloadTexture(); 130 mDesktop.reloadTexture();
129 mCursor.reloadTexture(); 131 mCursor.reloadTexture();
130 } 132 }
131 }); 133 });
132 134
133 JniInterface.redrawGraphics(); 135 mClient.redrawGraphics();
134 } 136 }
135 }); 137 });
136 } 138 }
137 139
138 @Override 140 @Override
139 public void onSurfaceCreated(EGLConfig config) { 141 public void onSurfaceCreated(EGLConfig config) {
140 // Set the background clear color to black. 142 // Set the background clear color to black.
141 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 143 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
142 144
143 // Use culling to remove back faces. 145 // Use culling to remove back faces.
144 GLES20.glEnable(GLES20.GL_CULL_FACE); 146 GLES20.glEnable(GLES20.GL_CULL_FACE);
145 147
146 // Enable depth testing. 148 // Enable depth testing.
147 GLES20.glEnable(GLES20.GL_DEPTH_TEST); 149 GLES20.glEnable(GLES20.GL_DEPTH_TEST);
148 150
149 mDesktop = new Desktop(); 151 mDesktop = new Desktop(mClient);
150 mMenuBar = new MenuBar(mActivity); 152 mMenuBar = new MenuBar(mActivity);
151 mPhotosphere = new Photosphere(mActivity); 153 mPhotosphere = new Photosphere(mActivity);
152 mCursor = new Cursor(); 154 mCursor = new Cursor(mClient);
153 155
154 initializeRedrawCallback(); 156 initializeRedrawCallback();
155 } 157 }
156 158
157 @Override 159 @Override
158 public void onSurfaceChanged(int width, int height) { 160 public void onSurfaceChanged(int width, int height) {
159 } 161 }
160 162
161 @Override 163 @Override
162 public void onNewFrame(HeadTransform headTransform) { 164 public void onNewFrame(HeadTransform headTransform) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 synchronized (mCameraPositionLock) { 424 synchronized (mCameraPositionLock) {
423 theta = Math.atan(mDesktop.getHalfWidth() 425 theta = Math.atan(mDesktop.getHalfWidth()
424 / (DESKTOP_POSITION_Z - mCameraPosition)); 426 / (DESKTOP_POSITION_Z - mCameraPosition));
425 } 427 }
426 428
427 // Calculate current looking angle. 429 // Calculate current looking angle.
428 double phi = Math.atan(mForwardVector[0] / mForwardVector[2]); 430 double phi = Math.atan(mForwardVector[0] / mForwardVector[2]);
429 431
430 return Math.abs(phi) > FARAWAY_ANGLE_RATIO * Math.abs(theta); 432 return Math.abs(phi) > FARAWAY_ANGLE_RATIO * Math.abs(theta);
431 } 433 }
432 } 434 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698