OSDN Git Service

Improve our EGL management when pausing / resuming.
authorJack Palevich <jackpal@google.com>
Wed, 24 Mar 2010 20:46:15 +0000 (13:46 -0700)
committerJack Palevich <jackpal@google.com>
Wed, 24 Mar 2010 20:48:27 +0000 (13:48 -0700)
We now release the EGL context when pausing. This
is required to reduce the chance of running out of
contexts on devices which support a limited number
of active EGL contexts.

Someday we may implement a global EGL context
manager that will allow us to let EGL contexts
persist until another activity needs an EGL
context. But for now, without such a manager,
we take the conservative approach.

Separately, we now terminate EGL when
pausing on Sapphire. This is a requirement of the
Sapphire OpenGL driver.

opengl/java/android/opengl/GLSurfaceView.java

index 2c43e59..e07b3f9 100644 (file)
@@ -1179,6 +1179,12 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
                                         Log.i("GLThread", "releasing EGL context because paused tid=" + getId());
                                     }
                                 }
+                                if (sGLThreadManager.shouldTerminateEGLWhenPausing()) {
+                                    mEglHelper.finish();
+                                    if (LOG_SURFACE) {
+                                        Log.i("GLThread", "terminating EGL because paused tid=" + getId());
+                                    }
+                                }
                             }
 
                             // Have we lost the surface view surface?
@@ -1549,6 +1555,13 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
         }
 
         public synchronized boolean shouldReleaseEGLContextWhenPausing() {
+            // Release the EGL context when pausing even if
+            // the hardware supports multiple EGL contexts.
+            // Otherwise the device could run out of EGL contexts.
+            return true;
+        }
+
+        public synchronized boolean shouldTerminateEGLWhenPausing() {
             checkGLESVersion();
             return !mMultipleGLESContextsAllowed;
         }