Loading opengl/java/android/opengl/GLSurfaceView.java +43 −7 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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()); Loading Loading @@ -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() { Loading @@ -1716,15 +1747,17 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback public synchronized void checkGLDriver(GL10 gl) { if (! mGLESDriverCheckComplete) { checkGLESVersion(); if (mGLESVersion < kGLES_20) { String renderer = gl.glGetString(GL10.GL_RENDERER); if (mGLESVersion < kGLES_20) { mMultipleGLESContextsAllowed = ! renderer.startsWith(kMSM7K_RENDERER_PREFIX); notifyAll(); } mLimitedGLESContexts = !mMultipleGLESContextsAllowed || renderer.startsWith(kADRENO); if (LOG_SURFACE) { Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = " + mMultipleGLESContextsAllowed); } notifyAll(); + mMultipleGLESContextsAllowed + " mLimitedGLESContexts = " + mLimitedGLESContexts); } mGLESDriverCheckComplete = true; } Loading @@ -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; } Loading @@ -1768,4 +1803,5 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback private GLWrapper mGLWrapper; private int mDebugFlags; private int mEGLContextClientVersion; private boolean mPreserveEGLContextOnPause; } Loading
opengl/java/android/opengl/GLSurfaceView.java +43 −7 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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()); Loading Loading @@ -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() { Loading @@ -1716,15 +1747,17 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback public synchronized void checkGLDriver(GL10 gl) { if (! mGLESDriverCheckComplete) { checkGLESVersion(); if (mGLESVersion < kGLES_20) { String renderer = gl.glGetString(GL10.GL_RENDERER); if (mGLESVersion < kGLES_20) { mMultipleGLESContextsAllowed = ! renderer.startsWith(kMSM7K_RENDERER_PREFIX); notifyAll(); } mLimitedGLESContexts = !mMultipleGLESContextsAllowed || renderer.startsWith(kADRENO); if (LOG_SURFACE) { Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = " + mMultipleGLESContextsAllowed); } notifyAll(); + mMultipleGLESContextsAllowed + " mLimitedGLESContexts = " + mLimitedGLESContexts); } mGLESDriverCheckComplete = true; } Loading @@ -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; } Loading @@ -1768,4 +1803,5 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback private GLWrapper mGLWrapper; private int mDebugFlags; private int mEGLContextClientVersion; private boolean mPreserveEGLContextOnPause; }