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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/cardboard/Desktop.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 static org.chromium.chromoting.cardboard.CardboardUtil.makeFloatBuffer; 7 import static org.chromium.chromoting.cardboard.CardboardUtil.makeFloatBuffer;
8 import static org.chromium.chromoting.cardboard.CardboardUtil.makeRectangularTex tureBuffer; 8 import static org.chromium.chromoting.cardboard.CardboardUtil.makeRectangularTex tureBuffer;
9 9
10 import android.graphics.Bitmap; 10 import android.graphics.Bitmap;
11 import android.graphics.Point; 11 import android.graphics.Point;
12 import android.opengl.GLES20; 12 import android.opengl.GLES20;
13 13
14 import org.chromium.chromoting.jni.Client; 14 import org.chromium.chromoting.jni.Display;
15 15
16 import java.nio.FloatBuffer; 16 import java.nio.FloatBuffer;
17 17
18 /** 18 /**
19 * Chromoting Cardboard activity desktop, which is used to display host desktop. 19 * Chromoting Cardboard activity desktop, which is used to display host desktop.
20 */ 20 */
21 public class Desktop { 21 public class Desktop {
22 private static final String VERTEX_SHADER = 22 private static final String VERTEX_SHADER =
23 "uniform mat4 u_CombinedMatrix;" 23 "uniform mat4 u_CombinedMatrix;"
24 + "attribute vec4 a_Position;" 24 + "attribute vec4 a_Position;"
(...skipping 29 matching lines...) Expand all
54 54
55 private static final int POSITION_DATA_SIZE = 3; 55 private static final int POSITION_DATA_SIZE = 3;
56 private static final int TEXTURE_COORDINATE_DATA_SIZE = 2; 56 private static final int TEXTURE_COORDINATE_DATA_SIZE = 2;
57 57
58 // Fix the desktop height and adjust width accordingly. 58 // Fix the desktop height and adjust width accordingly.
59 private static final float HALF_HEIGHT = 1.0f; 59 private static final float HALF_HEIGHT = 1.0f;
60 60
61 // Number of vertices passed to glDrawArrays(). 61 // Number of vertices passed to glDrawArrays().
62 private static final int VERTICES_NUMBER = 6; 62 private static final int VERTICES_NUMBER = 6;
63 63
64 private final Client mClient; 64 private final Display mDisplay;
65 65
66 private int mVertexShaderHandle; 66 private int mVertexShaderHandle;
67 private int mFragmentShaderHandle; 67 private int mFragmentShaderHandle;
68 private int mProgramHandle; 68 private int mProgramHandle;
69 private int mCombinedMatrixHandle; 69 private int mCombinedMatrixHandle;
70 private int mTextureUniformHandle; 70 private int mTextureUniformHandle;
71 private int mPositionHandle; 71 private int mPositionHandle;
72 private int mTransparentHandle; 72 private int mTransparentHandle;
73 private int mTextureDataHandle; 73 private int mTextureDataHandle;
74 private int mTextureCoordinateHandle; 74 private int mTextureCoordinateHandle;
75 private FloatBuffer mPosition; 75 private FloatBuffer mPosition;
76 private float mHalfWidth; 76 private float mHalfWidth;
77 77
78 // Lock to allow multithreaded access to mHalfWidth. 78 // Lock to allow multithreaded access to mHalfWidth.
79 private final Object mHalfWidthLock = new Object(); 79 private final Object mHalfWidthLock = new Object();
80 80
81 private Bitmap mVideoFrame; 81 private Bitmap mVideoFrame;
82 82
83 // Lock to allow multithreaded access to mVideoFrame. 83 // Lock to allow multithreaded access to mVideoFrame.
84 private final Object mVideoFrameLock = new Object(); 84 private final Object mVideoFrameLock = new Object();
85 85
86 // Flag to indicate whether to reload the desktop texture. 86 // Flag to indicate whether to reload the desktop texture.
87 private boolean mReloadTexture; 87 private boolean mReloadTexture;
88 88
89 // Lock to allow multithreaded access to mReloadTexture. 89 // Lock to allow multithreaded access to mReloadTexture.
90 private final Object mReloadTextureLock = new Object(); 90 private final Object mReloadTextureLock = new Object();
91 91
92 public Desktop(Client client) { 92 public Desktop(Display display) {
93 mClient = client; 93 mDisplay = display;
94 mVertexShaderHandle = 94 mVertexShaderHandle =
95 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADE R); 95 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADE R);
96 mFragmentShaderHandle = 96 mFragmentShaderHandle =
97 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_S HADER); 97 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_S HADER);
98 mProgramHandle = ShaderHelper.createAndLinkProgram(mVertexShaderHandle, 98 mProgramHandle = ShaderHelper.createAndLinkProgram(mVertexShaderHandle,
99 mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordin ate", 99 mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordin ate",
100 "u_CombinedMatrix", "u_Texture"}); 100 "u_CombinedMatrix", "u_Texture"});
101 mCombinedMatrixHandle = 101 mCombinedMatrixHandle =
102 GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix"); 102 GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix");
103 mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_T exture"); 103 mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_T exture");
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 * so that both eyes will have the same texture. 216 * so that both eyes will have the same texture.
217 */ 217 */
218 public void maybeLoadDesktopTexture() { 218 public void maybeLoadDesktopTexture() {
219 synchronized (mReloadTextureLock) { 219 synchronized (mReloadTextureLock) {
220 if (!mReloadTexture) { 220 if (!mReloadTexture) {
221 return; 221 return;
222 } 222 }
223 } 223 }
224 224
225 // TODO(shichengfeng): Record the time desktop drawing takes. 225 // TODO(shichengfeng): Record the time desktop drawing takes.
226 Bitmap bitmap = mClient.getDisplay().getVideoFrame(); 226 Bitmap bitmap = mDisplay.getVideoFrame();
227 227
228 if (bitmap == null) { 228 if (bitmap == null) {
229 // This can happen if the client is connected, but a complete video frame has not yet 229 // This can happen if the client is connected, but a complete video frame has not yet
230 // been decoded. 230 // been decoded.
231 return; 231 return;
232 } 232 }
233 233
234 updateVideoFrame(bitmap); 234 updateVideoFrame(bitmap);
235 235
236 synchronized (mReloadTextureLock) { 236 synchronized (mReloadTextureLock) {
237 mReloadTexture = false; 237 mReloadTexture = false;
238 } 238 }
239 } 239 }
240 240
241 /** 241 /**
242 * Inform this object that a new video frame should be rendered. 242 * Inform this object that a new video frame should be rendered.
243 * Called from native display thread. 243 * Called from native display thread.
244 */ 244 */
245 public void reloadTexture() { 245 public void reloadTexture() {
246 synchronized (mReloadTextureLock) { 246 synchronized (mReloadTextureLock) {
247 mReloadTexture = true; 247 mReloadTexture = true;
248 } 248 }
249 } 249 }
250 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698