OLD | NEW |
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; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 mProjectionMatrix = new float[16]; | 95 mProjectionMatrix = new float[16]; |
96 mDesktopModelMatrix = new float[16]; | 96 mDesktopModelMatrix = new float[16]; |
97 mDesktopCombinedMatrix = new float[16]; | 97 mDesktopCombinedMatrix = new float[16]; |
98 mEyePointModelMatrix = new float[16]; | 98 mEyePointModelMatrix = new float[16]; |
99 mEyePointCombinedMatrix = new float[16]; | 99 mEyePointCombinedMatrix = new float[16]; |
100 mPhotosphereCombinedMatrix = new float[16]; | 100 mPhotosphereCombinedMatrix = new float[16]; |
101 | 101 |
102 mForwardVector = new float[3]; | 102 mForwardVector = new float[3]; |
103 } | 103 } |
104 | 104 |
105 // This can be called on any thread. | 105 private void initializeRedrawCallback() { |
106 public void attachRedrawCallback() { | 106 mActivity.runOnUiThread(new Runnable() { |
107 JniInterface.provideRedrawCallback(new Runnable() { | |
108 @Override | |
109 public void run() { | 107 public void run() { |
110 mDesktop.reloadTexture(); | 108 JniInterface.provideRedrawCallback(new Runnable() { |
111 mCursor.reloadTexture(); | 109 @Override |
| 110 public void run() { |
| 111 mDesktop.reloadTexture(); |
| 112 mCursor.reloadTexture(); |
| 113 } |
| 114 }); |
| 115 |
| 116 JniInterface.redrawGraphics(); |
112 } | 117 } |
113 }); | 118 }); |
114 } | 119 } |
115 | 120 |
116 @Override | 121 @Override |
117 public void onSurfaceCreated(EGLConfig config) { | 122 public void onSurfaceCreated(EGLConfig config) { |
118 // Set the background clear color to black. | 123 // Set the background clear color to black. |
119 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | 124 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
120 | 125 |
121 // Use culling to remove back faces. | 126 // Use culling to remove back faces. |
122 GLES20.glEnable(GLES20.GL_CULL_FACE); | 127 GLES20.glEnable(GLES20.GL_CULL_FACE); |
123 | 128 |
124 // Enable depth testing. | 129 // Enable depth testing. |
125 GLES20.glEnable(GLES20.GL_DEPTH_TEST); | 130 GLES20.glEnable(GLES20.GL_DEPTH_TEST); |
126 | 131 |
127 mDesktop = new Desktop(); | 132 mDesktop = new Desktop(); |
128 mMenuBar = new MenuBar(mActivity); | 133 mMenuBar = new MenuBar(mActivity); |
129 mPhotosphere = new Photosphere(mActivity); | 134 mPhotosphere = new Photosphere(mActivity); |
130 mCursor = new Cursor(); | 135 mCursor = new Cursor(); |
131 | 136 |
132 attachRedrawCallback(); | 137 initializeRedrawCallback(); |
133 } | 138 } |
134 | 139 |
135 @Override | 140 @Override |
136 public void onSurfaceChanged(int width, int height) { | 141 public void onSurfaceChanged(int width, int height) { |
137 } | 142 } |
138 | 143 |
139 @Override | 144 @Override |
140 public void onNewFrame(HeadTransform headTransform) { | 145 public void onNewFrame(HeadTransform headTransform) { |
141 // Position the eye at the origin. | 146 // Position the eye at the origin. |
142 float eyeX = 0.0f; | 147 float eyeX = 0.0f; |
(...skipping 27 matching lines...) Expand all Loading... |
170 @Override | 175 @Override |
171 public void onDrawEye(Eye eye) { | 176 public void onDrawEye(Eye eye) { |
172 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); | 177 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); |
173 | 178 |
174 // Apply the eye transformation to the camera. | 179 // Apply the eye transformation to the camera. |
175 Matrix.multiplyMM(mViewMatrix, 0, eye.getEyeView(), 0, mCameraMatrix, 0)
; | 180 Matrix.multiplyMM(mViewMatrix, 0, eye.getEyeView(), 0, mCameraMatrix, 0)
; |
176 | 181 |
177 mProjectionMatrix = eye.getPerspective(Z_NEAR, Z_FAR); | 182 mProjectionMatrix = eye.getPerspective(Z_NEAR, Z_FAR); |
178 | 183 |
179 drawDesktop(); | 184 drawDesktop(); |
| 185 drawPhotosphere(); |
180 drawMenuBar(); | 186 drawMenuBar(); |
181 drawPhotosphere(); | |
182 drawCursor(); | 187 drawCursor(); |
183 } | 188 } |
184 | 189 |
185 @Override | 190 @Override |
186 public void onRendererShutdown() { | 191 public void onRendererShutdown() { |
187 mDesktop.cleanup(); | 192 mDesktop.cleanup(); |
188 mMenuBar.cleanup(); | 193 mMenuBar.cleanup(); |
189 mPhotosphere.cleanup(); | 194 mPhotosphere.cleanup(); |
190 mCursor.cleanup(); | 195 mCursor.cleanup(); |
191 } | 196 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 mMenuBarVisible = visible; | 375 mMenuBarVisible = visible; |
371 } | 376 } |
372 | 377 |
373 /** | 378 /** |
374 * Return true if menu bar is visible. | 379 * Return true if menu bar is visible. |
375 */ | 380 */ |
376 public boolean isMenuBarVisible() { | 381 public boolean isMenuBarVisible() { |
377 return mMenuBarVisible; | 382 return mMenuBarVisible; |
378 } | 383 } |
379 } | 384 } |
OLD | NEW |