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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/CardboardDesktopRenderer.java

Issue 1305633002: Refactor drawing desktop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor desktop drawing. Created 5 years, 4 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; 5 package org.chromium.chromoting;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.graphics.Bitmap; 8 import android.graphics.Bitmap;
9 import android.graphics.BitmapFactory; 9 import android.graphics.BitmapFactory;
10 import android.graphics.PointF; 10 import android.graphics.PointF;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Top 94 // Top
95 5, 1, 4, 95 5, 1, 4,
96 4, 1, 0, 96 4, 1, 0,
97 97
98 // Bottom 98 // Bottom
99 6, 2, 7, 99 6, 2, 7,
100 7, 2, 3 100 7, 2, 3
101 }); 101 });
102 102
103 private static final String DESKTOP_VERTEX_SHADER =
104 "uniform mat4 u_CombinedMatrix;"
105 + "attribute vec4 a_Position;"
106 + "attribute vec2 a_TexCoordinate;"
107 + "varying vec2 v_TexCoordinate;"
108 + "void main() {"
109 + " v_TexCoordinate = a_TexCoordinate;"
110 + " gl_Position = u_CombinedMatrix * a_Position;"
111 + "}";
112
113 private static final String DESKTOP_FRAGMENT_SHADER =
114 "precision highp float;"
115 + "uniform sampler2D u_Texture;"
116 + "varying vec2 v_TexCoordinate;"
117 + "const float borderWidth = 0.002;"
118 + "void main() {"
119 + " if (v_TexCoordinate.x > (1.0 - borderWidth) || v_TexCoordinate. x < borderWidth"
120 + " || v_TexCoordinate.y > (1.0 - borderWidth)"
121 + " || v_TexCoordinate.y < borderWidth) {"
122 + " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);"
123 + " } else {"
124 + " gl_FragColor = texture2D(u_Texture, v_TexCoordinate);"
125 + " }"
126 + "}";
127
128 private static final String SKYBOX_VERTEX_SHADER = 103 private static final String SKYBOX_VERTEX_SHADER =
129 "uniform mat4 u_CombinedMatrix;" 104 "uniform mat4 u_CombinedMatrix;"
130 + "attribute vec3 a_Position;" 105 + "attribute vec3 a_Position;"
131 + "varying vec3 v_Position;" 106 + "varying vec3 v_Position;"
132 + "void main() {" 107 + "void main() {"
133 + " v_Position = a_Position;" 108 + " v_Position = a_Position;"
134 // Make sure to convert from the right-handed coordinate system of t he 109 // Make sure to convert from the right-handed coordinate system of t he
135 // world to the left-handed coordinate system of the cube map, other wise, 110 // world to the left-handed coordinate system of the cube map, other wise,
136 // our cube map will still work but everything will be flipped. 111 // our cube map will still work but everything will be flipped.
137 + " v_Position.z = -v_Position.z;" 112 + " v_Position.z = -v_Position.z;"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 private float[] mEyePointCombinedMatrix; 157 private float[] mEyePointCombinedMatrix;
183 private float[] mSkyboxModelMatrix; 158 private float[] mSkyboxModelMatrix;
184 private float[] mSkyboxCombinedMatrix; 159 private float[] mSkyboxCombinedMatrix;
185 160
186 // Direction that user is looking towards. 161 // Direction that user is looking towards.
187 private float[] mForwardVector; 162 private float[] mForwardVector;
188 163
189 // Eye position in desktop. 164 // Eye position in desktop.
190 private float[] mEyePositionVector; 165 private float[] mEyePositionVector;
191 166
192 private int mDesktopCombinedMatrixHandle;
193 private int mPositionHandle;
194 private int mTextureDataHandle;
195 private int mTextureUniformHandle;
196 private int mTextureCoordinateHandle;
197 private int mProgramHandle;
198 private int mDesktopVertexShaderHandle;
199 private int mDesktopFragmentShaderHandle;
200 private int mSkyboxVertexShaderHandle; 167 private int mSkyboxVertexShaderHandle;
201 private int mSkyboxFragmentShaderHandle; 168 private int mSkyboxFragmentShaderHandle;
202 private int mSkyboxProgramHandle; 169 private int mSkyboxProgramHandle;
203 private int mSkyboxPositionHandle; 170 private int mSkyboxPositionHandle;
204 private int mSkyboxCombinedMatrixHandle; 171 private int mSkyboxCombinedMatrixHandle;
205 private int mSkyboxTextureUnitHandle; 172 private int mSkyboxTextureUnitHandle;
206 private int mSkyboxTextureDataHandle; 173 private int mSkyboxTextureDataHandle;
174 private CardboardActivityDesktop mDesktop;
207 private CardboardActivityEyePoint mEyePoint; 175 private CardboardActivityEyePoint mEyePoint;
208 176
209 // Flag to indicate whether reload the desktop texture or not. 177 // Flag to indicate whether reload the desktop texture or not.
210 private boolean mReloadTexture; 178 private boolean mReloadTexture;
211 179
212 /** Lock to allow multithreaded access to mReloadTexture. */ 180 /** Lock to allow multithreaded access to mReloadTexture. */
213 private Object mReloadTextureLock = new Object(); 181 private Object mReloadTextureLock = new Object();
214 182
215 // Lock for eye position related operations. 183 // Lock for eye position related operations.
216 // This protects access to mEyePositionVector as well as mDesktop{Height/Wid th}Pixels. 184 // This protects access to mEyePositionVector as well as mDesktop{Height/Wid th}Pixels.
217 private Object mEyePositionLock = new Object(); 185 private Object mEyePositionLock = new Object();
218 186
219 private int mDesktopHeightPixels; 187 private int mDesktopHeightPixels;
220 private int mDesktopWidthPixels; 188 private int mDesktopWidthPixels;
221 189
222 private FloatBuffer mDesktopCoordinates; 190 private FloatBuffer mDesktopCoordinates;
Lambros 2015/08/19 23:17:28 I think this should be moved into the CardboardAct
shichengfeng 2015/08/20 01:02:54 Done.
223 191
224 // Flag to signal that the skybox images are fully decoded and should be loa ded 192 // Flag to signal that the skybox images are fully decoded and should be loa ded
225 // into the OpenGL textures. 193 // into the OpenGL textures.
226 private boolean mLoadSkyboxImagesTexture; 194 private boolean mLoadSkyboxImagesTexture;
227 195
228 // Lock to allow multithreaded access to mLoadSkyboxImagesTexture. 196 // Lock to allow multithreaded access to mLoadSkyboxImagesTexture.
229 private Object mLoadSkyboxImagesTextureLock = new Object(); 197 private Object mLoadSkyboxImagesTextureLock = new Object();
230 198
231 private ChromotingDownloadManager mDownloadManager; 199 private ChromotingDownloadManager mDownloadManager;
232 200
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 public void onSurfaceCreated(EGLConfig config) { 246 public void onSurfaceCreated(EGLConfig config) {
279 // Set the background clear color to black. 247 // Set the background clear color to black.
280 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 248 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
281 249
282 // Use culling to remove back faces. 250 // Use culling to remove back faces.
283 GLES20.glEnable(GLES20.GL_CULL_FACE); 251 GLES20.glEnable(GLES20.GL_CULL_FACE);
284 252
285 // Enable depth testing. 253 // Enable depth testing.
286 GLES20.glEnable(GLES20.GL_DEPTH_TEST); 254 GLES20.glEnable(GLES20.GL_DEPTH_TEST);
287 255
288 // Set handles for desktop drawing.
289 mDesktopVertexShaderHandle =
290 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, DESKTOP_VERT EX_SHADER);
291 mDesktopFragmentShaderHandle =
292 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, DESKTOP_FR AGMENT_SHADER);
293 mProgramHandle = ShaderHelper.createAndLinkProgram(mDesktopVertexShaderH andle,
294 mDesktopFragmentShaderHandle, new String[] {"a_Position", "a_Tex Coordinate"});
295 mDesktopCombinedMatrixHandle =
296 GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix");
297 mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_T exture");
298 mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position ");
299 mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a _TexCoordinate");
300 mTextureDataHandle = TextureHelper.createTextureHandle();
301
302 // Set handlers for skybox drawing. 256 // Set handlers for skybox drawing.
303 GLES20.glEnable(GLES20.GL_TEXTURE_CUBE_MAP); 257 GLES20.glEnable(GLES20.GL_TEXTURE_CUBE_MAP);
304 mSkyboxVertexShaderHandle = 258 mSkyboxVertexShaderHandle =
305 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, SKYBOX_VERTE X_SHADER); 259 ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, SKYBOX_VERTE X_SHADER);
306 mSkyboxFragmentShaderHandle = 260 mSkyboxFragmentShaderHandle =
307 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, SKYBOX_FRA GMENT_SHADER); 261 ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, SKYBOX_FRA GMENT_SHADER);
308 mSkyboxProgramHandle = ShaderHelper.createAndLinkProgram(mSkyboxVertexSh aderHandle, 262 mSkyboxProgramHandle = ShaderHelper.createAndLinkProgram(mSkyboxVertexSh aderHandle,
309 mSkyboxFragmentShaderHandle, 263 mSkyboxFragmentShaderHandle,
310 new String[] {"a_Position", "u_CombinedMatrix", "u_TextureUnit"} ); 264 new String[] {"a_Position", "u_CombinedMatrix", "u_TextureUnit"} );
311 mSkyboxPositionHandle = 265 mSkyboxPositionHandle =
312 GLES20.glGetAttribLocation(mSkyboxProgramHandle, "a_Position"); 266 GLES20.glGetAttribLocation(mSkyboxProgramHandle, "a_Position");
313 mSkyboxCombinedMatrixHandle = 267 mSkyboxCombinedMatrixHandle =
314 GLES20.glGetUniformLocation(mSkyboxProgramHandle, "u_CombinedMat rix"); 268 GLES20.glGetUniformLocation(mSkyboxProgramHandle, "u_CombinedMat rix");
315 mSkyboxTextureUnitHandle = 269 mSkyboxTextureUnitHandle =
316 GLES20.glGetUniformLocation(mSkyboxProgramHandle, "u_TextureUnit "); 270 GLES20.glGetUniformLocation(mSkyboxProgramHandle, "u_TextureUnit ");
317 mSkyboxTextureDataHandle = TextureHelper.createTextureHandle(); 271 mSkyboxTextureDataHandle = TextureHelper.createTextureHandle();
318 272
273 mDesktop = new CardboardActivityDesktop();
319 mEyePoint = new CardboardActivityEyePoint(); 274 mEyePoint = new CardboardActivityEyePoint();
320 } 275 }
321 276
322 @Override 277 @Override
323 public void onSurfaceChanged(int width, int height) { 278 public void onSurfaceChanged(int width, int height) {
324 } 279 }
325 280
326 @Override 281 @Override
327 public void onNewFrame(HeadTransform headTransform) { 282 public void onNewFrame(HeadTransform headTransform) {
328 // Position the eye at the origin. 283 // Position the eye at the origin.
(...skipping 11 matching lines...) Expand all
340 295
341 // Set our up vector. This is where our head would be pointing were we h olding the camera. 296 // Set our up vector. This is where our head would be pointing were we h olding the camera.
342 float upX = 0.0f; 297 float upX = 0.0f;
343 float upY = 1.0f; 298 float upY = 1.0f;
344 float upZ = 0.0f; 299 float upZ = 0.0f;
345 300
346 Matrix.setLookAtM(mCameraMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, look Z, upX, upY, upZ); 301 Matrix.setLookAtM(mCameraMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, look Z, upX, upY, upZ);
347 302
348 headTransform.getForwardVector(mForwardVector, 0); 303 headTransform.getForwardVector(mForwardVector, 0);
349 getLookingPosition(); 304 getLookingPosition();
350 maybeLoadTexture(mTextureDataHandle); 305 maybeLoadDesktopTexture();
351 maybeLoadCubeMapAndCleanImages(mSkyboxTextureDataHandle); 306 maybeLoadCubeMapAndCleanImages(mSkyboxTextureDataHandle);
352 } 307 }
353 308
354 @Override 309 @Override
355 public void onDrawEye(Eye eye) { 310 public void onDrawEye(Eye eye) {
356 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); 311 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
357 312
358 // Apply the eye transformation to the camera. 313 // Apply the eye transformation to the camera.
359 Matrix.multiplyMM(mViewMatrix, 0, eye.getEyeView(), 0, mCameraMatrix, 0) ; 314 Matrix.multiplyMM(mViewMatrix, 0, eye.getEyeView(), 0, mCameraMatrix, 0) ;
360 315
361 mProjectionMatrix = eye.getPerspective(Z_NEAR, Z_FAR); 316 mProjectionMatrix = eye.getPerspective(Z_NEAR, Z_FAR);
362 317
363 drawSkybox(); 318 drawSkybox();
364 drawDesktop(); 319 drawDesktop();
365 drawEyePoint(); 320 drawEyePoint();
366 } 321 }
367 322
368 @Override 323 @Override
369 public void onRendererShutdown() { 324 public void onRendererShutdown() {
370 GLES20.glDeleteShader(mDesktopVertexShaderHandle); 325 mDesktop.cleanup();
371 GLES20.glDeleteShader(mDesktopFragmentShaderHandle);
372 mEyePoint.cleanup(); 326 mEyePoint.cleanup();
373 GLES20.glDeleteShader(mSkyboxVertexShaderHandle); 327 GLES20.glDeleteShader(mSkyboxVertexShaderHandle);
374 GLES20.glDeleteShader(mSkyboxFragmentShaderHandle); 328 GLES20.glDeleteShader(mSkyboxFragmentShaderHandle);
375 GLES20.glDeleteTextures(1, new int[] {mTextureDataHandle}, 0);
376 GLES20.glDeleteTextures(1, new int[] {mSkyboxTextureDataHandle}, 0); 329 GLES20.glDeleteTextures(1, new int[] {mSkyboxTextureDataHandle}, 0);
377 mActivity.runOnUiThread(new Runnable() { 330 mActivity.runOnUiThread(new Runnable() {
378 public void run() { 331 public void run() {
379 mDownloadManager.close(); 332 mDownloadManager.close();
380 } 333 }
381 }); 334 });
382 } 335 }
383 336
384 @Override 337 @Override
385 public void onFinishFrame(Viewport viewport) { 338 public void onFinishFrame(Viewport viewport) {
386 } 339 }
387 340
388 private void drawDesktop() { 341 private void drawDesktop() {
389 GLES20.glUseProgram(mProgramHandle); 342 if (mDesktopCoordinates == null) {
Lambros 2015/08/19 23:17:28 mDesktopCoordinates is no longer used in this meth
shichengfeng 2015/08/20 01:02:53 Done.
343 // This can happen if the client is connected, but a complete video frame has not yet
344 // been decoded.
345 return;
346 }
390 347
391 // Translate the desktop model.
392 Matrix.setIdentityM(mDesktopModelMatrix, 0); 348 Matrix.setIdentityM(mDesktopModelMatrix, 0);
393 Matrix.translateM(mDesktopModelMatrix, 0, DESKTOP_POSITION_X, 349 Matrix.translateM(mDesktopModelMatrix, 0, DESKTOP_POSITION_X,
394 DESKTOP_POSITION_Y, DESKTOP_POSITION_Z); 350 DESKTOP_POSITION_Y, DESKTOP_POSITION_Z);
395 351
396 // Pass in Model View Matrix and Model View Project Matrix. 352 // Pass in Model View Matrix and Model View Project Matrix.
397 Matrix.multiplyMM(mDesktopCombinedMatrix, 0, mViewMatrix, 0, mDesktopMod elMatrix, 0); 353 Matrix.multiplyMM(mDesktopCombinedMatrix, 0, mViewMatrix, 0, mDesktopMod elMatrix, 0);
398 Matrix.multiplyMM(mDesktopCombinedMatrix, 0, mProjectionMatrix, 354 Matrix.multiplyMM(mDesktopCombinedMatrix, 0, mProjectionMatrix,
399 0, mDesktopCombinedMatrix, 0); 355 0, mDesktopCombinedMatrix, 0);
356 mDesktop.setCombinedMatrix(mDesktopCombinedMatrix);
400 357
401 // Pass in model view project matrix. 358 mDesktop.draw();
402 GLES20.glUniformMatrix4fv(mDesktopCombinedMatrixHandle, 1, false,
403 mDesktopCombinedMatrix, 0);
404
405 if (mDesktopCoordinates == null) {
406 // This can happen if the client is connected, but a complete video frame has not yet
407 // been decoded.
408 return;
409 }
410 // Pass in the desktop position.
411 GLES20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20 .GL_FLOAT, false,
412 0, mDesktopCoordinates);
413 GLES20.glEnableVertexAttribArray(mPositionHandle);
414
415 // Pass in texture coordinate.
416 GLES20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_COORDINAT E_DATA_SIZE,
417 GLES20.GL_FLOAT, false, 0, DESKTOP_TEXTURE_COORDINATES);
418 GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
419
420 // Pass in texture data.
421 GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
422 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
423 GLES20.glUniform1i(mTextureUniformHandle, 0);
424
425 // Draw the desktop.
426 int totalPointNumber = 6;
427 GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, totalPointNumber);
428 } 359 }
429 360
430 private void drawEyePoint() { 361 private void drawEyePoint() {
431 if (!isLookingAtDesktop()) { 362 if (!isLookingAtDesktop()) {
432 return; 363 return;
433 } 364 }
434 365
435 float eyePointX = clamp(mEyePositionVector[0], -mHalfDesktopWidth, 366 float eyePointX = clamp(mEyePositionVector[0], -mHalfDesktopWidth,
436 mHalfDesktopWidth); 367 mHalfDesktopWidth);
437 float eyePointY = clamp(mEyePositionVector[1], -HALF_DESKTOP_HEIGHT, 368 float eyePointY = clamp(mEyePositionVector[1], -HALF_DESKTOP_HEIGHT,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 mEyePositionVector[1] = mForwardVector[1] * DESKTOP_POSITION_Z / mForwardVector[2]; 529 mEyePositionVector[1] = mForwardVector[1] * DESKTOP_POSITION_Z / mForwardVector[2];
599 } 530 }
600 mEyePositionVector[2] = DESKTOP_POSITION_Z; 531 mEyePositionVector[2] = DESKTOP_POSITION_Z;
601 } 532 }
602 } 533 }
603 534
604 /** 535 /**
605 * Link desktop texture with textureDataHandle if {@link mReloadTexture} is true. 536 * Link desktop texture with textureDataHandle if {@link mReloadTexture} is true.
606 * @param textureDataHandle the handle we want attach texture to 537 * @param textureDataHandle the handle we want attach texture to
607 */ 538 */
608 private void maybeLoadTexture(int textureDataHandle) { 539 private void maybeLoadDesktopTexture() {
609 synchronized (mReloadTextureLock) { 540 synchronized (mReloadTextureLock) {
610 if (!mReloadTexture) { 541 if (!mReloadTexture) {
611 return; 542 return;
612 } 543 }
613 } 544 }
614 545
615 // TODO(shichengfeng): Record the time desktop drawing takes. 546 // TODO(shichengfeng): Record the time desktop drawing takes.
616 Bitmap bitmap = JniInterface.getVideoFrame(); 547 Bitmap bitmap = JniInterface.getVideoFrame();
617 548
618 if (bitmap == null) { 549 if (bitmap == null) {
619 // This can happen if the client is connected, but a complete video frame has not yet 550 // This can happen if the client is connected, but a complete video frame has not yet
620 // been decoded. 551 // been decoded.
621 return; 552 return;
622 } 553 }
623 554
624 synchronized (mEyePositionLock) { 555 synchronized (mEyePositionLock) {
625 mDesktopHeightPixels = bitmap.getHeight(); 556 mDesktopHeightPixels = bitmap.getHeight();
626 mDesktopWidthPixels = bitmap.getWidth(); 557 mDesktopWidthPixels = bitmap.getWidth();
627 } 558 }
628 559
629 updateDesktopCoordinatesBuffer(bitmap); 560 updateDesktopCoordinatesBuffer(bitmap);
630 TextureHelper.linkTexture(textureDataHandle, bitmap); 561 mDesktop.setTexture(bitmap);
631 562
632 synchronized (mReloadTextureLock) { 563 synchronized (mReloadTextureLock) {
633 mReloadTexture = false; 564 mReloadTexture = false;
634 } 565 }
635 } 566 }
636 567
637 /** 568 /**
638 * Convert float array to a FloatBuffer for use in OpenGL calls. 569 * Convert float array to a FloatBuffer for use in OpenGL calls.
639 */ 570 */
640 private static FloatBuffer makeFloatBuffer(float[] data) { 571 public static FloatBuffer makeFloatBuffer(float[] data) {
641 FloatBuffer result = ByteBuffer 572 FloatBuffer result = ByteBuffer
642 .allocateDirect(data.length * BYTE_PER_FLOAT) 573 .allocateDirect(data.length * BYTE_PER_FLOAT)
643 .order(ByteOrder.nativeOrder()).asFloatBuffer(); 574 .order(ByteOrder.nativeOrder()).asFloatBuffer();
644 result.put(data).position(0); 575 result.put(data).position(0);
645 return result; 576 return result;
646 } 577 }
647 578
648 /** 579 /**
649 * Update the desktop coordinates based on the new bitmap. Note here we fix the 580 * Update the desktop coordinates based on the new bitmap. Note here we fix the
650 * height of the desktop and vary width accordingly. 581 * height of the desktop and vary width accordingly.
651 */ 582 */
652 private void updateDesktopCoordinatesBuffer(Bitmap bitmap) { 583 private void updateDesktopCoordinatesBuffer(Bitmap bitmap) {
Lambros 2015/08/19 23:17:28 Move this inside CardboardActivityDesktop as well.
shichengfeng 2015/08/20 01:02:53 Done.
653 int width = bitmap.getWidth(); 584 int width = bitmap.getWidth();
654 int height = bitmap.getHeight(); 585 int height = bitmap.getHeight();
655 float newHalfDesktopWidth = width * HALF_DESKTOP_HEIGHT / height; 586 float newHalfDesktopWidth = width * HALF_DESKTOP_HEIGHT / height;
656 if (Math.abs(mHalfDesktopWidth - newHalfDesktopWidth) > 0.0001) { 587 if (Math.abs(mHalfDesktopWidth - newHalfDesktopWidth) > 0.0001) {
657 mHalfDesktopWidth = newHalfDesktopWidth; 588 mHalfDesktopWidth = newHalfDesktopWidth;
658 mDesktopCoordinates = makeFloatBuffer(new float[] { 589 mDesktopCoordinates = makeFloatBuffer(new float[] {
659 // Desktop model coordinates. 590 // Desktop model coordinates.
660 -mHalfDesktopWidth, HALF_DESKTOP_HEIGHT, 0.0f, 591 -mHalfDesktopWidth, HALF_DESKTOP_HEIGHT, 0.0f,
661 -mHalfDesktopWidth, -HALF_DESKTOP_HEIGHT, 0.0f, 592 -mHalfDesktopWidth, -HALF_DESKTOP_HEIGHT, 0.0f,
662 mHalfDesktopWidth, HALF_DESKTOP_HEIGHT, 0.0f, 593 mHalfDesktopWidth, HALF_DESKTOP_HEIGHT, 0.0f,
663 -mHalfDesktopWidth, -HALF_DESKTOP_HEIGHT, 0.0f, 594 -mHalfDesktopWidth, -HALF_DESKTOP_HEIGHT, 0.0f,
664 mHalfDesktopWidth, -HALF_DESKTOP_HEIGHT, 0.0f, 595 mHalfDesktopWidth, -HALF_DESKTOP_HEIGHT, 0.0f,
665 mHalfDesktopWidth, HALF_DESKTOP_HEIGHT, 0.0f 596 mHalfDesktopWidth, HALF_DESKTOP_HEIGHT, 0.0f
666 }); 597 });
598 mDesktop.setPosition(mDesktopCoordinates);
667 } 599 }
668 } 600 }
669 601
670 /** 602 /**
671 * Decode all skybox images to Bitmap files and return them. 603 * Decode all skybox images to Bitmap files and return them.
672 * Only call this method when we have complete skybox images. 604 * Only call this method when we have complete skybox images.
673 * @throws DecodeFileException if BitmapFactory fails to decode file. 605 * @throws DecodeFileException if BitmapFactory fails to decode file.
674 */ 606 */
675 private Bitmap[] decodeSkyboxImages() throws DecodeFileException { 607 private Bitmap[] decodeSkyboxImages() throws DecodeFileException {
676 Bitmap[] result = new Bitmap[SKYBOX_IMAGE_NAMES.length]; 608 Bitmap[] result = new Bitmap[SKYBOX_IMAGE_NAMES.length];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 image.recycle(); 641 image.recycle();
710 } 642 }
711 } 643 }
712 644
713 /** 645 /**
714 * Exception when BitmapFactory fails to decode file. 646 * Exception when BitmapFactory fails to decode file.
715 */ 647 */
716 private static class DecodeFileException extends Exception { 648 private static class DecodeFileException extends Exception {
717 } 649 }
718 } 650 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698