diff options
author | Jack Palevich <jackpal@google.com> | 2011-01-14 11:45:17 -0800 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2011-01-14 11:45:17 -0800 |
commit | 8432b3f98a22d5cdfcc0183d134770597e44d412 (patch) | |
tree | cdf97b000439df11704863aa4ffbd7d79473fd8c /opengl | |
parent | 9aba2324ac8d7216732b42346bfcaf0be71eb22e (diff) | |
download | frameworks_base-8432b3f98a22d5cdfcc0183d134770597e44d412.zip frameworks_base-8432b3f98a22d5cdfcc0183d134770597e44d412.tar.gz frameworks_base-8432b3f98a22d5cdfcc0183d134770597e44d412.tar.bz2 |
Add support for preserving EGL contexts when pausing / resuming.
Hidden for now.
Change-Id: I350576c11960a1aa232da7aebc5c6ec60ff796b5
Diffstat (limited to 'opengl')
-rw-r--r-- | opengl/java/android/opengl/GLSurfaceView.java | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java index 8f2f974..4099c4c 100644 --- a/opengl/java/android/opengl/GLSurfaceView.java +++ b/opengl/java/android/opengl/GLSurfaceView.java @@ -272,6 +272,37 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback } /** + * @hide + * Control whether the EGL context is preserved when the GLSurfaceView is paused and + * resumed. + * <p> + * If set to true, then the EGL context may be preserved when the GLSurfaceView is paused. + * Whether the EGL context is actually preserved or not depends upon whether the + * Android device that the program is running on can support an arbitrary number of EGL + * contexts or not. Devices that can only support a limited number of EGL contexts must + * release the EGL context in order to allow multiple applications to share the GPU. + * <p> + * If set to false, the EGL context will be released when the GLSurfaceView is paused, + * and recreated when the GLSurfaceView is resumed. + * <p> + * + * The default is false. + * + * @param preserveOnPause preserve the EGL context when paused + */ + public void setPreserveEGLContextOnPause(boolean preserveOnPause) { + mPreserveEGLContextOnPause = preserveOnPause; + } + + /** + * @hide + * @return true if the EGL context will be preserved when paused + */ + public boolean getPreserveEGLContextOnPause() { + return mPreserveEGLContextOnPause; + } + + /** * Set the renderer associated with this view. Also starts the thread that * will call the renderer, which in turn causes the rendering to start. * <p>This method should be called once and only once in the life-cycle of @@ -1240,7 +1271,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback Log.i("GLThread", "releasing EGL surface because paused tid=" + getId()); } stopEglSurfaceLocked(); - if (sGLThreadManager.shouldReleaseEGLContextWhenPausing()) { + if (!mPreserveEGLContextOnPause || sGLThreadManager.shouldReleaseEGLContextWhenPausing()) { stopEglContextLocked(); if (LOG_SURFACE) { Log.i("GLThread", "releasing EGL context because paused tid=" + getId()); @@ -1705,7 +1736,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback // 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; + return mLimitedGLESContexts; } public synchronized boolean shouldTerminateEGLWhenPausing() { @@ -1716,16 +1747,18 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback public synchronized void checkGLDriver(GL10 gl) { if (! mGLESDriverCheckComplete) { checkGLESVersion(); + String renderer = gl.glGetString(GL10.GL_RENDERER); if (mGLESVersion < kGLES_20) { - String renderer = gl.glGetString(GL10.GL_RENDERER); mMultipleGLESContextsAllowed = ! renderer.startsWith(kMSM7K_RENDERER_PREFIX); - if (LOG_SURFACE) { - Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = " - + mMultipleGLESContextsAllowed); - } notifyAll(); } + mLimitedGLESContexts = !mMultipleGLESContextsAllowed || renderer.startsWith(kADRENO); + if (LOG_SURFACE) { + Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = " + + mMultipleGLESContextsAllowed + + " mLimitedGLESContexts = " + mLimitedGLESContexts); + } mGLESDriverCheckComplete = true; } } @@ -1750,9 +1783,11 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback private int mGLESVersion; private boolean mGLESDriverCheckComplete; private boolean mMultipleGLESContextsAllowed; + private boolean mLimitedGLESContexts; private static final int kGLES_20 = 0x20000; private static final String kMSM7K_RENDERER_PREFIX = "Q3Dimension MSM7500 "; + private static final String kADRENO = "Adreno"; private GLThread mEglOwner; } @@ -1768,4 +1803,5 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback private GLWrapper mGLWrapper; private int mDebugFlags; private int mEGLContextClientVersion; + private boolean mPreserveEGLContextOnPause; } |