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

Commit 4caa4ed1 authored by Romain Guy's avatar Romain Guy
Browse files

Only destroy the GL Canvas when necessary.

Change-Id: I6caf4873b02dc4a6d7c8c91925d2447b3b0e0593
parent f6fcac7c
Loading
Loading
Loading
Loading
+14 −24
Original line number Diff line number Diff line
@@ -53,8 +53,10 @@ public abstract class HardwareRenderer {

    /**
     * Destroys the hardware rendering context.
     * 
     * @param full If true, destroys all associated resources.
     */
    abstract void destroy();
    abstract void destroy(boolean full);

    /**
     * Initializes the hardware renderer for the specified surface.
@@ -187,7 +189,7 @@ public abstract class HardwareRenderer {
        }

        /**
         * Checks for OpenGL errors. If an error has occured, {@link #destroy()}
         * Checks for OpenGL errors. If an error has occured, {@link #destroy(boolean)}
         * is invoked and the requested flag is turned off. The error code is
         * also logged as a warning.
         */
@@ -197,7 +199,7 @@ public abstract class HardwareRenderer {
                if (error != EGL10.EGL_SUCCESS) {
                    // something bad has happened revert to
                    // normal rendering.
                    destroy();
                    destroy(true);
                    if (error != EGL11.EGL_CONTEXT_LOST) {
                        // we'll try again if it was context lost
                        setRequested(false);
@@ -217,13 +219,12 @@ public abstract class HardwareRenderer {
                if (mGl != null) {
                    int err = sEgl.eglGetError();
                    if (err != EGL10.EGL_SUCCESS) {
                        destroy();
                        destroy(true);
                        setRequested(false);
                    } else {
                        if (mCanvas != null) {
                            destroyCanvas();
                        }
                        if (mCanvas == null) {
                            mCanvas = createCanvas();
                        }
                        if (mCanvas != null) {
                            setEnabled(true);
                        } else {
@@ -237,11 +238,6 @@ public abstract class HardwareRenderer {
            return false;
        }

        private void destroyCanvas() {
            mCanvas.destroy();
            mCanvas = null;
        }

        abstract GLES20Canvas createCanvas();

        void initializeEgl() {
@@ -341,16 +337,16 @@ public abstract class HardwareRenderer {
        }
        
        @Override
        void destroy() {
        void destroy(boolean full) {
            if (full && mCanvas != null) {
                mCanvas.destroy();
                mCanvas = null;
            }
            
            if (!isEnabled() || mDestroyed) return;

            mDestroyed = true;

            checkCurrent();
            // Destroy the Canvas first in case it needs to use a GL context
            // to perform its cleanup.
            destroyCanvas();

            sEgl.eglMakeCurrent(sEglDisplay, EGL10.EGL_NO_SURFACE,
                    EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
            sEgl.eglDestroySurface(sEglDisplay, mEglSurface);
@@ -358,12 +354,6 @@ public abstract class HardwareRenderer {
            mEglSurface = null;
            mGl = null;

            // mEgl.eglDestroyContext(mEglDisplay, mEglContext);
            // mEglContext = null;            
            // mEgl.eglTerminate(mEglDisplay);
            // mEgl = null;
            // mEglDisplay = null;

            setEnabled(false);
        }

+11 −11
Original line number Diff line number Diff line
@@ -469,7 +469,9 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
            if (attrs != null &&
                    (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0) {
                final boolean translucent = attrs.format != PixelFormat.OPAQUE;
                destroyHardwareRenderer();
                if (mHwRenderer != null) {
                    mHwRenderer.destroy(true);
                }                
                mHwRenderer = HardwareRenderer.createGlRenderer(2, translucent);
            }
        }
@@ -678,7 +680,9 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
            attachInfo.mWindowVisibility = viewVisibility;
            host.dispatchWindowVisibilityChanged(viewVisibility);
            if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) {
                destroyHardwareRenderer();
                if (mHwRenderer != null) {
                    mHwRenderer.destroy(false);
                }                
            }
            if (viewVisibility == View.GONE) {
                // After making a window gone, we will count it as being
@@ -1597,8 +1601,10 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
        mAttachInfo.mRootView = null;
        mAttachInfo.mSurface = null;

        destroyHardwareRenderer();
        if (mHwRenderer != null) {
            mHwRenderer.destroy(true);
            mHwRenderer = null;
        }

        mSurface.release();

@@ -1624,12 +1630,6 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
        }
    }

    private void destroyHardwareRenderer() {
        if (mHwRenderer != null) {
            mHwRenderer.destroy();
        }
    }

    void updateConfiguration(Configuration config, boolean force) {
        if (DEBUG_CONFIGURATION) Log.v(TAG,
                "Applying new config to window "