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 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.JniInterface; | 14 import org.chromium.chromoting.jni.Client; |
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 Loading... |
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; |
| 65 |
64 private int mVertexShaderHandle; | 66 private int mVertexShaderHandle; |
65 private int mFragmentShaderHandle; | 67 private int mFragmentShaderHandle; |
66 private int mProgramHandle; | 68 private int mProgramHandle; |
67 private int mCombinedMatrixHandle; | 69 private int mCombinedMatrixHandle; |
68 private int mTextureUniformHandle; | 70 private int mTextureUniformHandle; |
69 private int mPositionHandle; | 71 private int mPositionHandle; |
70 private int mTransparentHandle; | 72 private int mTransparentHandle; |
71 private int mTextureDataHandle; | 73 private int mTextureDataHandle; |
72 private int mTextureCoordinateHandle; | 74 private int mTextureCoordinateHandle; |
73 private FloatBuffer mPosition; | 75 private FloatBuffer mPosition; |
74 private float mHalfWidth; | 76 private float mHalfWidth; |
75 | 77 |
76 // Lock to allow multithreaded access to mHalfWidth. | 78 // Lock to allow multithreaded access to mHalfWidth. |
77 private final Object mHalfWidthLock = new Object(); | 79 private final Object mHalfWidthLock = new Object(); |
78 | 80 |
79 private Bitmap mVideoFrame; | 81 private Bitmap mVideoFrame; |
80 | 82 |
81 // Lock to allow multithreaded access to mVideoFrame. | 83 // Lock to allow multithreaded access to mVideoFrame. |
82 private final Object mVideoFrameLock = new Object(); | 84 private final Object mVideoFrameLock = new Object(); |
83 | 85 |
84 // Flag to indicate whether to reload the desktop texture. | 86 // Flag to indicate whether to reload the desktop texture. |
85 private boolean mReloadTexture; | 87 private boolean mReloadTexture; |
86 | 88 |
87 // Lock to allow multithreaded access to mReloadTexture. | 89 // Lock to allow multithreaded access to mReloadTexture. |
88 private final Object mReloadTextureLock = new Object(); | 90 private final Object mReloadTextureLock = new Object(); |
89 | 91 |
90 public Desktop() { | 92 public Desktop(Client client) { |
| 93 mClient = client; |
91 mVertexShaderHandle = | 94 mVertexShaderHandle = |
92 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADE
R); | 95 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADE
R); |
93 mFragmentShaderHandle = | 96 mFragmentShaderHandle = |
94 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_S
HADER); | 97 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_S
HADER); |
95 mProgramHandle = ShaderHelper.createAndLinkProgram(mVertexShaderHandle, | 98 mProgramHandle = ShaderHelper.createAndLinkProgram(mVertexShaderHandle, |
96 mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordin
ate", | 99 mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordin
ate", |
97 "u_CombinedMatrix", "u_Texture"}); | 100 "u_CombinedMatrix", "u_Texture"}); |
98 mCombinedMatrixHandle = | 101 mCombinedMatrixHandle = |
99 GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix"); | 102 GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix"); |
100 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 Loading... |
213 * so that both eyes will have the same texture. | 216 * so that both eyes will have the same texture. |
214 */ | 217 */ |
215 public void maybeLoadDesktopTexture() { | 218 public void maybeLoadDesktopTexture() { |
216 synchronized (mReloadTextureLock) { | 219 synchronized (mReloadTextureLock) { |
217 if (!mReloadTexture) { | 220 if (!mReloadTexture) { |
218 return; | 221 return; |
219 } | 222 } |
220 } | 223 } |
221 | 224 |
222 // TODO(shichengfeng): Record the time desktop drawing takes. | 225 // TODO(shichengfeng): Record the time desktop drawing takes. |
223 Bitmap bitmap = JniInterface.getVideoFrame(); | 226 Bitmap bitmap = mClient.getVideoFrame(); |
224 | 227 |
225 if (bitmap == null) { | 228 if (bitmap == null) { |
226 // 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 |
227 // been decoded. | 230 // been decoded. |
228 return; | 231 return; |
229 } | 232 } |
230 | 233 |
231 updateVideoFrame(bitmap); | 234 updateVideoFrame(bitmap); |
232 | 235 |
233 synchronized (mReloadTextureLock) { | 236 synchronized (mReloadTextureLock) { |
234 mReloadTexture = false; | 237 mReloadTexture = false; |
235 } | 238 } |
236 } | 239 } |
237 | 240 |
238 /** | 241 /** |
239 * Inform this object that a new video frame should be rendered. | 242 * Inform this object that a new video frame should be rendered. |
240 * Called from native display thread. | 243 * Called from native display thread. |
241 */ | 244 */ |
242 public void reloadTexture() { | 245 public void reloadTexture() { |
243 synchronized (mReloadTextureLock) { | 246 synchronized (mReloadTextureLock) { |
244 mReloadTexture = true; | 247 mReloadTexture = true; |
245 } | 248 } |
246 } | 249 } |
247 } | 250 } |
OLD | NEW |