summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-10-07 16:40:20 -0700
committerRomain Guy <romainguy@google.com>2012-10-07 16:42:43 -0700
commita042f4a114a5fd728fa3aa8539e377727860f1d9 (patch)
tree035e0ccca6503f9f2e5265e1f0e84d2906778bf6
parenta59bd020f528a5d0b99fb9f812eafb0fed540259 (diff)
downloadandroid_packages_screensavers_Basic-a042f4a114a5fd728fa3aa8539e377727860f1d9.tar.gz
android_packages_screensavers_Basic-a042f4a114a5fd728fa3aa8539e377727860f1d9.tar.bz2
android_packages_screensavers_Basic-a042f4a114a5fd728fa3aa8539e377727860f1d9.zip
Various fixes for the Colors dream
Bug #7171323 1. Various code cleanups 2. Properly destroy TextureView's SurfaceTexture 3. Stop the render thread on destroy (we were leaking threads before this change) 4. Destroy the renderer synchronously 5. Save a bit of memory by not requesting an alpha channel Change-Id: I323e6c87903dbb8a6c79fe384a473b7293caf9ea
-rw-r--r--src/com/android/dreams/basic/Colors.java12
-rw-r--r--src/com/android/dreams/basic/ColorsGLRenderer.java26
2 files changed, 20 insertions, 18 deletions
diff --git a/src/com/android/dreams/basic/Colors.java b/src/com/android/dreams/basic/Colors.java
index 5f16d2c..c31ba8d 100644
--- a/src/com/android/dreams/basic/Colors.java
+++ b/src/com/android/dreams/basic/Colors.java
@@ -33,7 +33,7 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi
static final String TAG = Colors.class.getSimpleName();
static final boolean DEBUG = false;
- public static final void LOG(String fmt, Object... args) {
+ public static void LOG(String fmt, Object... args) {
if (!DEBUG) return;
Log.v(TAG, String.format(fmt, args));
}
@@ -114,9 +114,17 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi
mRenderer.stop();
mRenderer = null;
}
+ mRendererHandlerThread.quit();
}
});
- return false;
+
+ try {
+ mRendererHandlerThread.join();
+ } catch (InterruptedException e) {
+ LOG("Error while waiting for renderer", e);
+ }
+
+ return true;
}
@Override
diff --git a/src/com/android/dreams/basic/ColorsGLRenderer.java b/src/com/android/dreams/basic/ColorsGLRenderer.java
index 3452261..91e4432 100644
--- a/src/com/android/dreams/basic/ColorsGLRenderer.java
+++ b/src/com/android/dreams/basic/ColorsGLRenderer.java
@@ -27,7 +27,6 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
-import javax.microedition.khronos.opengles.GL;
import android.opengl.EGL14;
import android.opengl.GLUtils;
@@ -50,7 +49,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
static final String TAG = ColorsGLRenderer.class.getSimpleName();
static final boolean DEBUG = false;
- private static final void LOG(String fmt, Object... args) {
+ private static void LOG(String fmt, Object... args) {
if (!DEBUG) return;
Log.v(TAG, String.format(fmt, args));
}
@@ -68,10 +67,8 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
// It's so easy to use OpenGLES 2.0!
private EGL10 mEgl;
private EGLDisplay mEglDisplay;
- private EGLConfig mEglConfig;
private EGLContext mEglContext;
private EGLSurface mEglSurface;
- private GL mGL;
public ColorsGLRenderer(SurfaceTexture surface, int width, int height) {
mSurface = surface;
@@ -119,8 +116,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
glViewport(0, 0, mWidth, mHeight);
if (DEBUG) {
- final long t2 = frameTimeNanos;
- final long dt = t2 - mLastFrameTime;
+ final long dt = frameTimeNanos - mLastFrameTime;
final int fps = (int) (1e9f / dt);
if (0 == (mFrameNum % 10)) {
LOG("frame %d fps=%d", mFrameNum, fps);
@@ -128,7 +124,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
if (fps < 40) {
LOG("JANK! (%d ms)", dt);
}
- mLastFrameTime = t2;
+ mLastFrameTime = frameTimeNanos;
}
glClear(GL_COLOR_BUFFER_BIT);
@@ -170,14 +166,14 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
GLUtils.getEGLErrorString(mEgl.eglGetError()));
}
- mEglConfig = chooseEglConfig();
- if (mEglConfig == null) {
+ EGLConfig eglConfig = chooseEglConfig();
+ if (eglConfig == null) {
throw new RuntimeException("eglConfig not initialized");
}
- mEglContext = createContext(mEgl, mEglDisplay, mEglConfig);
+ mEglContext = createContext(mEgl, mEglDisplay, eglConfig);
- mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, mSurface, null);
+ mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, eglConfig, mSurface, null);
if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
int error = mEgl.eglGetError();
@@ -193,8 +189,6 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
throw new RuntimeException("eglMakeCurrent failed "
+ GLUtils.getEGLErrorString(mEgl.eglGetError()));
}
-
- mGL = mEglContext.getGL();
}
private void finishGL() {
@@ -202,7 +196,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
}
- private EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
+ private static EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
int[] attrib_list = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
return egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
}
@@ -226,7 +220,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
- EGL10.EGL_ALPHA_SIZE, 8,
+ EGL10.EGL_ALPHA_SIZE, 0,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE, 0,
EGL10.EGL_NONE
@@ -356,7 +350,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback {
private final int colorStride = COLOR_PLANES_PER_VERTEX * 4; // bytes per vertex
// Set color with red, green, blue and alpha (opacity) values
- float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f };
+ // float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f };
public Square() {
for (int i=0; i<vertexCount; i++) {