summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeun young Park <keunyoung@google.com>2012-01-09 12:41:51 -0800
committerKeun young Park <keunyoung@google.com>2012-01-09 13:21:12 -0800
commit6cb78e547641bcab6f18ec34badca0840e000992 (patch)
treeeafc10922915481e8f7cfdbcb45355472c9306ec /src
parent2b1168acefb6a4104bb7f008df6ac51fcd1de7ec (diff)
downloadreplicaisland-6cb78e547641bcab6f18ec34badca0840e000992.tar.gz
Changes to use replica island in CTS OpenGl performance testics-mr0
- add localization to make build work - changed start level to repeat Gl rendering - add position reset in Buffer access to fix crash issue after too fast task switch - add watchdog timer to detect Gl rendering freeze Change-Id: Iaf16ecdda6dec3b268d3322a405666aec92db6bf
Diffstat (limited to 'src')
-rw-r--r--src/com/replica/replicaisland/AndouKun.java23
-rw-r--r--src/com/replica/replicaisland/GLSurfaceView.java12
-rw-r--r--src/com/replica/replicaisland/Grid.java10
-rw-r--r--src/com/replica/replicaisland/RenderingWatchDog.java91
4 files changed, 117 insertions, 19 deletions
diff --git a/src/com/replica/replicaisland/AndouKun.java b/src/com/replica/replicaisland/AndouKun.java
index 23ca928..8914d1b 100644
--- a/src/com/replica/replicaisland/AndouKun.java
+++ b/src/com/replica/replicaisland/AndouKun.java
@@ -142,18 +142,17 @@ public class AndouKun extends Activity implements SensorEventListener {
mPrefsEditor = prefs.edit();
// Make sure that old game information is cleared when we start a new game.
- if (getIntent().getBooleanExtra("newGame", false)) {
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LEVEL_ROW);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LEVEL_INDEX);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LEVEL_COMPLETED);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LINEAR_MODE);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_TOTAL_GAME_TIME);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_PEARLS_COLLECTED);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_PEARLS_TOTAL);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_ROBOTS_DESTROYED);
- mPrefsEditor.remove(PreferenceConstants.PREFERENCE_DIFFICULTY);
- mPrefsEditor.commit();
- }
+ // CTS: clear settings to force start from beginning
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LEVEL_ROW);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LEVEL_INDEX);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LEVEL_COMPLETED);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_LINEAR_MODE);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_TOTAL_GAME_TIME);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_PEARLS_COLLECTED);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_PEARLS_TOTAL);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_ROBOTS_DESTROYED);
+ mPrefsEditor.remove(PreferenceConstants.PREFERENCE_DIFFICULTY);
+ mPrefsEditor.commit();
mLevelRow = prefs.getInt(PreferenceConstants.PREFERENCE_LEVEL_ROW, 0);
diff --git a/src/com/replica/replicaisland/GLSurfaceView.java b/src/com/replica/replicaisland/GLSurfaceView.java
index 2eb5737..e2dd46a 100644
--- a/src/com/replica/replicaisland/GLSurfaceView.java
+++ b/src/com/replica/replicaisland/GLSurfaceView.java
@@ -479,6 +479,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* Must not be called before a renderer has been set.
*/
public void onPause() {
+ mWatchDog.stop();
mGLThread.onPause();
}
@@ -490,6 +491,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* Must not be called before a renderer has been set.
*/
public void onResume() {
+ mWatchDog.start();
mGLThread.onResume();
}
@@ -1281,11 +1283,9 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
// Thus, in "safe mode," I force two swaps to occur before
// issuing any GL commands. Don't ask me how long it took
// to figure this out.
- if (framesSinceResetHack > 1 || !mSafeMode) {
- mRenderer.onDrawFrame(gl);
- } else {
- DebugLog.w("GLThread", "Safe Mode Wait...");
- }
+ // CTS: do not use safe mode.
+ mWatchDog.reset();
+ mRenderer.onDrawFrame(gl);
framesSinceResetHack++;
@@ -1661,6 +1661,6 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
private GLWrapper mGLWrapper;
private int mDebugFlags;
private int mEGLContextClientVersion;
-
+ private final RenderingWatchDog mWatchDog = new RenderingWatchDog();
}
diff --git a/src/com/replica/replicaisland/Grid.java b/src/com/replica/replicaisland/Grid.java
index 783c1bb..f6182e4 100644
--- a/src/com/replica/replicaisland/Grid.java
+++ b/src/com/replica/replicaisland/Grid.java
@@ -26,6 +26,8 @@ import java.nio.IntBuffer;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
+import android.util.Log;
+
/**
* A 2D rectangular mesh. Can be drawn textured or untextured.
* This version is modified from the original Grid.java (found in
@@ -341,7 +343,10 @@ class Grid {
gl11.glGenBuffers(1, buffer, 0);
mVertBufferIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex);
- final int vertexSize = mVertexBuffer.capacity() * mCoordinateSize;
+ final int vertexSize = mVertexBuffer.capacity() * mCoordinateSize;
+ // too fast task switching leaves buffers in the middle pos which
+ // crashes app
+ mVertexBuffer.position(0);
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertexSize,
mVertexBuffer, GL11.GL_STATIC_DRAW);
@@ -352,6 +357,7 @@ class Grid {
mTextureCoordBufferIndex);
final int texCoordSize =
mTexCoordBuffer.capacity() * mCoordinateSize;
+ mTexCoordBuffer.position(0);
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoordSize,
mTexCoordBuffer, GL11.GL_STATIC_DRAW);
@@ -365,6 +371,8 @@ class Grid {
mIndexBufferIndex);
// A char is 2 bytes.
final int indexSize = mIndexBuffer.capacity() * 2;
+
+ mIndexBuffer.position(0);
gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, indexSize, mIndexBuffer,
GL11.GL_STATIC_DRAW);
diff --git a/src/com/replica/replicaisland/RenderingWatchDog.java b/src/com/replica/replicaisland/RenderingWatchDog.java
new file mode 100644
index 0000000..6a77750
--- /dev/null
+++ b/src/com/replica/replicaisland/RenderingWatchDog.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.replica.replicaisland;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import android.util.Log;
+
+import junit.framework.Assert;
+
+/**
+ * class for checking if rendering function is alive or not.
+ * panic if watch-dog is not reset over certain amount of time
+ */
+public class RenderingWatchDog implements Runnable {
+ /** panic if watch-dog is not reset over this amount of time */
+ private static final long DEFAULT_TIMEOUT_IN_MSECS = 10 * 1000;
+ private static final String TAG = "RenderingWatchDog";
+ private Thread mThread;
+ private Semaphore mSemaphore;
+ private volatile boolean mStopRequested;
+ private final long mTimeoutInMilliSecs;
+
+ public RenderingWatchDog() {
+ this(DEFAULT_TIMEOUT_IN_MSECS);
+ }
+
+ public RenderingWatchDog(long timeoutInMilliSecs) {
+ mTimeoutInMilliSecs = timeoutInMilliSecs;
+ }
+
+ /** start watch-dog */
+ public void start() {
+ Log.i(TAG, "start");
+ mStopRequested = false;
+ mSemaphore = new Semaphore(0);
+ mThread = new Thread(this);
+ mThread.start();
+ }
+
+ /** stop watch-dog */
+ public void stop() {
+ Log.i(TAG, "stop");
+ if (mThread == null) {
+ return; // already finished
+ }
+ mStopRequested = true;
+ mSemaphore.release();
+ try {
+ mThread.join();
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ mThread = null;
+ mSemaphore = null;
+ }
+
+ /** resets watch-dog, thus prevent it from panic */
+ public void reset() {
+ if (!mStopRequested) { // stop requested, but rendering still on-going
+ mSemaphore.release();
+ }
+ }
+
+ @Override
+ public void run() {
+ while (!mStopRequested) {
+ try {
+ Assert.assertTrue("Watchdog timed-out",
+ mSemaphore.tryAcquire(mTimeoutInMilliSecs, TimeUnit.MILLISECONDS));
+ } catch (InterruptedException e) {
+ // this thread will not be interrupted,
+ // but if it happens, just check the exit condition.
+ }
+ }
+ }
+}