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

Commit 1bd888ba authored by Jack Palevich's avatar Jack Palevich
Browse files

Fix GLSurfaceView to sync surfaceDestroyed with GL rendering thread

Until now we had a race condition where the GL rendering thread could
continue rendering a frame after we have returned from the
SurfaceHolder.Callback.surfaceDestroyed notification.
parent a953ed4b
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -826,7 +826,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
            return mEgl.eglGetError() != EGL11.EGL_CONTEXT_LOST;
        }

        public void finish() {
        public void destroySurface() {
            if (mEglSurface != null) {
                mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
                        EGL10.EGL_NO_SURFACE,
@@ -834,6 +834,9 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
                mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
                mEglSurface = null;
            }
        }

        public void finish() {
            if (mEglContext != null) {
                mEgl.eglDestroyContext(mEglDisplay, mEglContext);
                mEglContext = null;
@@ -919,10 +922,18 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
                        r.run();
                    }
                    if (mPaused) {
                        mEglHelper.destroySurface();
                        mEglHelper.finish();
                        needStart = true;
                    }
                    while (needToWait()) {
                        if (!mHasSurface) {
                            if (!mWaitingForSurface) {
                                mEglHelper.destroySurface();
                                mWaitingForSurface = true;
                                notify();
                            }
                        }
                        wait();
                    }
                    if (mDone) {
@@ -933,6 +944,11 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
                    h = mHeight;
                    mSizeChanged = false;
                    mRequestRender = false;
                    if (mHasSurface && mWaitingForSurface) {
                        changed = true;
                        mWaitingForSurface = false;
                        mRequestRender = true; // Forces a redraw for RENDERMODE_RENDER_WHEN_DIRTY
                    }
                }
                if (needStart) {
                    mEglHelper.start();
@@ -966,6 +982,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
            /*
             * clean-up everything...
             */
            mEglHelper.destroySurface();
            mEglHelper.finish();
        }

@@ -1021,6 +1038,13 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
            synchronized(this) {
                mHasSurface = false;
                notify();
                while(!mWaitingForSurface) {
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
        }

@@ -1083,6 +1107,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        private boolean mDone;
        private boolean mPaused;
        private boolean mHasSurface;
        private boolean mWaitingForSurface;
        private int mWidth;
        private int mHeight;
        private int mRenderMode;