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

Commit 1d0c7089 authored by Romain Guy's avatar Romain Guy
Browse files

Destroy the EGL surface when the ViewRootImpl surface is invalid

Bug #5109839

Change-Id: Icebde9abf43b852397a73ffef519004993b46901
parent d3facf34
Loading
Loading
Loading
Loading
+23 −21
Original line number Diff line number Diff line
@@ -635,17 +635,9 @@ public abstract class HardwareRenderer {
            destroySurface();

            // Create an EGL surface we can render into.
            mEglSurface = sEgl.eglCreateWindowSurface(sEglDisplay, sEglConfig, holder, null);

            if (mEglSurface == null || mEglSurface == EGL_NO_SURFACE) {
                int error = sEgl.eglGetError();
                if (error == EGL_BAD_NATIVE_WINDOW) {
                    Log.e(LOG_TAG, "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
            if (!createSurface(holder)) {
                return null;
            }
                throw new RuntimeException("createWindowSurface failed "
                        + getEGLErrorString(error));
            }

            /*
             * Before we can issue GL commands, we need to make sure
@@ -716,21 +708,31 @@ public abstract class HardwareRenderer {

            if (mEglSurface != null && mEglSurface != EGL_NO_SURFACE) {
                sEgl.eglDestroySurface(sEglDisplay, mEglSurface);
                mEglSurface = null;
                setEnabled(false);
            }

            if (holder.getSurface().isValid()) {
                if (!createSurface(holder)) {
                    return;
                }
                setEnabled(true);                
            }
        }

        private boolean createSurface(SurfaceHolder holder) {
            mEglSurface = sEgl.eglCreateWindowSurface(sEglDisplay, sEglConfig, holder, null);

            if (mEglSurface == null || mEglSurface == EGL_NO_SURFACE) {
                int error = sEgl.eglGetError();
                if (error == EGL_BAD_NATIVE_WINDOW) {
                    Log.e(LOG_TAG, "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
                        return;
                    return false;
                }
                throw new RuntimeException("createWindowSurface failed "
                        + getEGLErrorString(error));
            }
            }
            return true;
        }

        @Override
+6 −1
Original line number Diff line number Diff line
@@ -1253,6 +1253,11 @@ public final class ViewRootImpl extends Handler implements ViewParent,
                        mScroller.abortAnimation();
                    }
                    disposeResizeBuffer();
                    // Our surface is gone
                    if (mAttachInfo.mHardwareRenderer != null &&
                            mAttachInfo.mHardwareRenderer.isEnabled()) {
                        mAttachInfo.mHardwareRenderer.destroy(true);
                    }
                } else if (surfaceGenerationId != mSurface.getGenerationId() &&
                        mSurfaceHolder == null && mAttachInfo.mHardwareRenderer != null) {
                    fullRedrawNeeded = true;