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

Commit 8432b3f9 authored by Jack Palevich's avatar Jack Palevich
Browse files

Add support for preserving EGL contexts when pausing / resuming.

Hidden for now.

Change-Id: I350576c11960a1aa232da7aebc5c6ec60ff796b5
parent 9aba2324
Loading
Loading
Loading
Loading
+43 −7
Original line number Diff line number Diff line
@@ -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,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;
            }
@@ -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;
}