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

Commit 2ff6a824 authored by Jack Palevich's avatar Jack Palevich
Browse files

Allow a GLSurfaceView to be reattached to a window.

This approach is more backwards-compatible than the previous attempt.

The onDetachedFromWindow case is unchanged from the "classic"
GLSurfaceView behavior, except that we don't throw a NPE if the
renderer has never been set.

Change-Id: Ia8103a73366ddb13be44f16b789c929e75ddc792
parent 9440083b
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -155,6 +155,8 @@ import android.view.SurfaceView;
 *
 */
public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
    private final static String TAG = "GLSurfaceView";
    private final static boolean LOG_ATTACH_DETACH = false;
    private final static boolean LOG_THREADS = false;
    private final static boolean LOG_PAUSE_RESUME = false;
    private final static boolean LOG_SURFACE = false;
@@ -306,6 +308,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        if (mEGLWindowSurfaceFactory == null) {
            mEGLWindowSurfaceFactory = new DefaultWindowSurfaceFactory();
        }
        mRenderer = renderer;
        mGLThread = new GLThread(renderer);
        mGLThread.start();
    }
@@ -522,6 +525,23 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
        mGLThread.queueEvent(r);
    }

    /**
     * This method is used as part of the View class and is not normally
     * called or subclassed by clients of GLSurfaceView.
     */
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (LOG_ATTACH_DETACH) {
            Log.d(TAG, "onAttachedToWindow reattach =" + mDetached);
        }
        if (mDetached && (mRenderer != null)) {
            mGLThread = new GLThread(mRenderer);
            mGLThread.start();
        }
        mDetached = false;
    }

    /**
     * This method is used as part of the View class and is not normally
     * called or subclassed by clients of GLSurfaceView.
@@ -529,6 +549,13 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
     */
    @Override
    protected void onDetachedFromWindow() {
        if (LOG_ATTACH_DETACH) {
            Log.d(TAG, "onDetachedFromWindow");
        }
        if (mGLThread != null) {
            mGLThread.requestExitAndWait();
        }
        mDetached = true;
        super.onDetachedFromWindow();
    }

@@ -1726,6 +1753,8 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
    private boolean mSizeChanged = true;

    private GLThread mGLThread;
    private Renderer mRenderer;
    private boolean mDetached;
    private EGLConfigChooser mEGLConfigChooser;
    private EGLContextFactory mEGLContextFactory;
    private EGLWindowSurfaceFactory mEGLWindowSurfaceFactory;