summaryrefslogtreecommitdiffstats
path: root/opengl/java/android/opengl/GLSurfaceView.java
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2010-03-15 15:09:30 -0700
committerJack Palevich <jackpal@google.com>2010-03-15 16:30:47 -0700
commit04b17ab7b4a17a28f541f746c3d55046c5b87596 (patch)
tree3658ec6ee67336e7be5e98de5e76fb4365d7fcd4 /opengl/java/android/opengl/GLSurfaceView.java
parent7d740861415523feb239d94d805fa985835663c0 (diff)
downloadframeworks_base-04b17ab7b4a17a28f541f746c3d55046c5b87596.zip
frameworks_base-04b17ab7b4a17a28f541f746c3d55046c5b87596.tar.gz
frameworks_base-04b17ab7b4a17a28f541f746c3d55046c5b87596.tar.bz2
Improve eglSwapBuffers error handling.
We now distinguish EGL_CONTEXT_LOST errors from other kinds of errors. We return "true" if the swap completes successfully, "false" if the swap fails due to EGL_CONTEXT_LOST, and throw a RuntimeException if the swap fails due to any other cause. If eglSwapBuffers succeeds, we now avoid calling eglGetError at all, which means we avoid clearing any EGL errors that might already have been pending before eglSwapBuffers is called.
Diffstat (limited to 'opengl/java/android/opengl/GLSurfaceView.java')
-rw-r--r--opengl/java/android/opengl/GLSurfaceView.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java
index 882cbc5..3f029a6 100644
--- a/opengl/java/android/opengl/GLSurfaceView.java
+++ b/opengl/java/android/opengl/GLSurfaceView.java
@@ -977,15 +977,22 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* @return false if the context has been lost.
*/
public boolean swap() {
- mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
+ if (! mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
- /*
- * Always check for EGL_CONTEXT_LOST, which means the context
- * and all associated data were lost (For instance because
- * the device went to sleep). We need to sleep until we
- * get a new surface.
- */
- return mEgl.eglGetError() != EGL11.EGL_CONTEXT_LOST;
+ /*
+ * Check for EGL_CONTEXT_LOST, which means the context
+ * and all associated data were lost (For instance because
+ * the device went to sleep). We need to sleep until we
+ * get a new surface.
+ */
+ int error = mEgl.eglGetError();
+ if (error == EGL11.EGL_CONTEXT_LOST) {
+ return false;
+ } else {
+ throwEglException("eglSwapBuffers", error);
+ }
+ }
+ return true;
}
public void destroySurface() {
@@ -1010,7 +1017,11 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
}
private void throwEglException(String function) {
- throw new RuntimeException(function + " failed: " + mEgl.eglGetError());
+ throwEglException(function, mEgl.eglGetError());
+ }
+
+ private void throwEglException(String function, int error) {
+ throw new RuntimeException(function + " failed: " + error);
}
EGL10 mEgl;