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.graphics.PointF; | 12 import android.graphics.PointF; |
13 import android.opengl.GLES20; | 13 import android.opengl.GLES20; |
14 | 14 |
15 import org.chromium.chromoting.InputStub; | 15 import org.chromium.chromoting.InputStub; |
16 import org.chromium.chromoting.jni.Client; | 16 import org.chromium.chromoting.jni.Client; |
| 17 import org.chromium.chromoting.jni.Display; |
17 | 18 |
18 import java.nio.FloatBuffer; | 19 import java.nio.FloatBuffer; |
19 | 20 |
20 /** | 21 /** |
21 * Cardboard activity desktop cursor that is used to render the image of the mou
se | 22 * Cardboard activity desktop cursor that is used to render the image of the mou
se |
22 * cursor onto the desktop. | 23 * cursor onto the desktop. |
23 */ | 24 */ |
24 public class Cursor { | 25 public class Cursor { |
25 private static final String VERTEX_SHADER = | 26 private static final String VERTEX_SHADER = |
26 "uniform mat4 u_CombinedMatrix;" | 27 "uniform mat4 u_CombinedMatrix;" |
(...skipping 19 matching lines...) Expand all Loading... |
46 private static final int POSITION_COORDINATE_DATA_SIZE = 3; | 47 private static final int POSITION_COORDINATE_DATA_SIZE = 3; |
47 private static final int TEXTURE_COORDINATE_DATA_SIZE = 2; | 48 private static final int TEXTURE_COORDINATE_DATA_SIZE = 2; |
48 | 49 |
49 // Number of vertices passed to glDrawArrays(). | 50 // Number of vertices passed to glDrawArrays(). |
50 private static final int VERTICES_NUMBER = 6; | 51 private static final int VERTICES_NUMBER = 6; |
51 | 52 |
52 // Threshold to determine whether to send the mouse move event. | 53 // Threshold to determine whether to send the mouse move event. |
53 private static final float CURSOR_MOVE_THRESHOLD = 1.0f; | 54 private static final float CURSOR_MOVE_THRESHOLD = 1.0f; |
54 | 55 |
55 private final Client mClient; | 56 private final Client mClient; |
| 57 private final Display mDisplay; |
56 | 58 |
57 private FloatBuffer mPositionCoordinates; | 59 private FloatBuffer mPositionCoordinates; |
58 | 60 |
59 private int mVertexShaderHandle; | 61 private int mVertexShaderHandle; |
60 private int mFragmentShaderHandle; | 62 private int mFragmentShaderHandle; |
61 private int mProgramHandle; | 63 private int mProgramHandle; |
62 private int mCombinedMatrixHandle; | 64 private int mCombinedMatrixHandle; |
63 private int mTextureUniformHandle; | 65 private int mTextureUniformHandle; |
64 private int mPositionHandle; | 66 private int mPositionHandle; |
65 private int mTextureDataHandle; | 67 private int mTextureDataHandle; |
66 private int mTextureCoordinateHandle; | 68 private int mTextureCoordinateHandle; |
67 | 69 |
68 // Flag to indicate whether to reload the desktop texture. | 70 // Flag to indicate whether to reload the desktop texture. |
69 private boolean mReloadTexture; | 71 private boolean mReloadTexture; |
70 | 72 |
71 // Lock to allow multithreaded access to mReloadTexture. | 73 // Lock to allow multithreaded access to mReloadTexture. |
72 private final Object mReloadTextureLock = new Object(); | 74 private final Object mReloadTextureLock = new Object(); |
73 | 75 |
74 private Bitmap mCursorBitmap; | 76 private Bitmap mCursorBitmap; |
75 | 77 |
76 // Half width and half height of the cursor. | 78 // Half width and half height of the cursor. |
77 private PointF mHalfFrameSize; | 79 private PointF mHalfFrameSize; |
78 | 80 |
79 private PointF mCursorPosition; | 81 private PointF mCursorPosition; |
80 | 82 |
81 public Cursor(Client client) { | 83 public Cursor(Client client) { |
82 mClient = client; | 84 mClient = client; |
| 85 mDisplay = (Display) client.getDisplay(); |
83 mHalfFrameSize = new PointF(0.0f, 0.0f); | 86 mHalfFrameSize = new PointF(0.0f, 0.0f); |
84 mCursorPosition = new PointF(0.0f, 0.0f); | 87 mCursorPosition = new PointF(0.0f, 0.0f); |
85 | 88 |
86 mVertexShaderHandle = | 89 mVertexShaderHandle = |
87 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADE
R); | 90 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADE
R); |
88 mFragmentShaderHandle = | 91 mFragmentShaderHandle = |
89 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_S
HADER); | 92 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_S
HADER); |
90 mProgramHandle = ShaderHelper.createAndLinkProgram(mVertexShaderHandle, | 93 mProgramHandle = ShaderHelper.createAndLinkProgram(mVertexShaderHandle, |
91 mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordin
ate", | 94 mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordin
ate", |
92 "u_CombinedMatrix", "u_Texture"}); | 95 "u_CombinedMatrix", "u_Texture"}); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 * Link the texture data for cursor if {@link mReloadTexture} is true. | 136 * Link the texture data for cursor if {@link mReloadTexture} is true. |
134 * Invoked from {@link com.google.vrtoolkit.cardboard.CardboardView.StereoRe
nderer.onNewFrame} | 137 * Invoked from {@link com.google.vrtoolkit.cardboard.CardboardView.StereoRe
nderer.onNewFrame} |
135 */ | 138 */ |
136 public void maybeLoadTexture(Desktop desktop) { | 139 public void maybeLoadTexture(Desktop desktop) { |
137 synchronized (mReloadTextureLock) { | 140 synchronized (mReloadTextureLock) { |
138 if (!mReloadTexture || !desktop.hasVideoFrame()) { | 141 if (!mReloadTexture || !desktop.hasVideoFrame()) { |
139 return; | 142 return; |
140 } | 143 } |
141 } | 144 } |
142 | 145 |
143 Bitmap cursorBitmap = mClient.getDisplay().getCursorBitmap(); | 146 Bitmap cursorBitmap = mDisplay.getCursorBitmap(); |
144 | 147 |
145 if (cursorBitmap == mCursorBitmap) { | 148 if (cursorBitmap == mCursorBitmap) { |
146 // Case when cursor image has not changed. | 149 // Case when cursor image has not changed. |
147 synchronized (mReloadTextureLock) { | 150 synchronized (mReloadTextureLock) { |
148 mReloadTexture = false; | 151 mReloadTexture = false; |
149 } | 152 } |
150 return; | 153 return; |
151 } | 154 } |
152 | 155 |
153 mCursorBitmap = cursorBitmap; | 156 mCursorBitmap = cursorBitmap; |
154 updatePosition(desktop, mCursorBitmap, mClient.getDisplay().getCursorHot
spot()); | 157 updatePosition(desktop, mCursorBitmap, mDisplay.getCursorHotspot()); |
155 | 158 |
156 TextureHelper.linkTexture(mTextureDataHandle, cursorBitmap); | 159 TextureHelper.linkTexture(mTextureDataHandle, cursorBitmap); |
157 | 160 |
158 synchronized (mReloadTextureLock) { | 161 synchronized (mReloadTextureLock) { |
159 mReloadTexture = false; | 162 mReloadTexture = false; |
160 } | 163 } |
161 } | 164 } |
162 | 165 |
163 public boolean hasImageFrame() { | 166 public boolean hasImageFrame() { |
164 return mCursorBitmap != null; | 167 return mCursorBitmap != null; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 239 |
237 /* | 240 /* |
238 * Clean cursor related opengl data. | 241 * Clean cursor related opengl data. |
239 */ | 242 */ |
240 public void cleanup() { | 243 public void cleanup() { |
241 GLES20.glDeleteShader(mVertexShaderHandle); | 244 GLES20.glDeleteShader(mVertexShaderHandle); |
242 GLES20.glDeleteShader(mFragmentShaderHandle); | 245 GLES20.glDeleteShader(mFragmentShaderHandle); |
243 GLES20.glDeleteTextures(1, new int[] {mTextureDataHandle}, 0); | 246 GLES20.glDeleteTextures(1, new int[] {mTextureDataHandle}, 0); |
244 } | 247 } |
245 } | 248 } |
OLD | NEW |