Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b54407f2 authored by Jack Palevich's avatar Jack Palevich Committed by Android (Google) Code Review
Browse files

Merge "Add support for preserving EGL contexts when pausing / resuming." into honeycomb

parents 529fc53d 8432b3f9
Loading
Loading
Loading
Loading
+43 −7
Original line number Original line Diff line number Diff line
@@ -271,6 +271,37 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        return mDebugFlags;
        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
     * Set the renderer associated with this view. Also starts the thread that
     * will call the renderer, which in turn causes the rendering to start.
     * 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());
                                    Log.i("GLThread", "releasing EGL surface because paused tid=" + getId());
                                }
                                }
                                stopEglSurfaceLocked();
                                stopEglSurfaceLocked();
                                if (sGLThreadManager.shouldReleaseEGLContextWhenPausing()) {
                                if (!mPreserveEGLContextOnPause || sGLThreadManager.shouldReleaseEGLContextWhenPausing()) {
                                    stopEglContextLocked();
                                    stopEglContextLocked();
                                    if (LOG_SURFACE) {
                                    if (LOG_SURFACE) {
                                        Log.i("GLThread", "releasing EGL context because paused tid=" + getId());
                                        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
            // Release the EGL context when pausing even if
            // the hardware supports multiple EGL contexts.
            // the hardware supports multiple EGL contexts.
            // Otherwise the device could run out of EGL contexts.
            // Otherwise the device could run out of EGL contexts.
            return true;
            return mLimitedGLESContexts;
        }
        }


        public synchronized boolean shouldTerminateEGLWhenPausing() {
        public synchronized boolean shouldTerminateEGLWhenPausing() {
@@ -1716,15 +1747,17 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        public synchronized void checkGLDriver(GL10 gl) {
        public synchronized void checkGLDriver(GL10 gl) {
            if (! mGLESDriverCheckComplete) {
            if (! mGLESDriverCheckComplete) {
                checkGLESVersion();
                checkGLESVersion();
                if (mGLESVersion < kGLES_20) {
                String renderer = gl.glGetString(GL10.GL_RENDERER);
                String renderer = gl.glGetString(GL10.GL_RENDERER);
                if (mGLESVersion < kGLES_20) {
                    mMultipleGLESContextsAllowed =
                    mMultipleGLESContextsAllowed =
                        ! renderer.startsWith(kMSM7K_RENDERER_PREFIX);
                        ! renderer.startsWith(kMSM7K_RENDERER_PREFIX);
                    notifyAll();
                }
                mLimitedGLESContexts = !mMultipleGLESContextsAllowed || renderer.startsWith(kADRENO);
                if (LOG_SURFACE) {
                if (LOG_SURFACE) {
                    Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = "
                    Log.w(TAG, "checkGLDriver renderer = \"" + renderer + "\" multipleContextsAllowed = "
                            + mMultipleGLESContextsAllowed);
                        + mMultipleGLESContextsAllowed
                    }
                        + " mLimitedGLESContexts = " + mLimitedGLESContexts);
                    notifyAll();
                }
                }
                mGLESDriverCheckComplete = true;
                mGLESDriverCheckComplete = true;
            }
            }
@@ -1750,9 +1783,11 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        private int mGLESVersion;
        private int mGLESVersion;
        private boolean mGLESDriverCheckComplete;
        private boolean mGLESDriverCheckComplete;
        private boolean mMultipleGLESContextsAllowed;
        private boolean mMultipleGLESContextsAllowed;
        private boolean mLimitedGLESContexts;
        private static final int kGLES_20 = 0x20000;
        private static final int kGLES_20 = 0x20000;
        private static final String kMSM7K_RENDERER_PREFIX =
        private static final String kMSM7K_RENDERER_PREFIX =
            "Q3Dimension MSM7500 ";
            "Q3Dimension MSM7500 ";
        private static final String kADRENO = "Adreno";
        private GLThread mEglOwner;
        private GLThread mEglOwner;
    }
    }


@@ -1768,4 +1803,5 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
    private GLWrapper mGLWrapper;
    private GLWrapper mGLWrapper;
    private int mDebugFlags;
    private int mDebugFlags;
    private int mEGLContextClientVersion;
    private int mEGLContextClientVersion;
    private boolean mPreserveEGLContextOnPause;
}
}