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