am 3ee50921: am b54407f2: Merge "Add support for preserving EGL contexts when pausing / resuming." into honeycomb

* commit '3ee50921957a00a91a951707aeff83208d293f2f':
  Add support for preserving EGL contexts when pausing / resuming.
This commit is contained in:
Jack Palevich
2011-01-18 21:50:06 -08:00
committed by Android Git Automerger

View File

@@ -271,6 +271,37 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
return mDebugFlags;
}
/**
* @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.
@@ -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;
}