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

Commit ad6283e4 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Invoke onTrimMemory with an EGL context Bug #6369600"

parents 9919a4a1 19f86e83
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -3765,9 +3765,11 @@ public final class ActivityThread {

    final void handleTrimMemory(int level) {
        if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level);
        WindowManagerImpl.getDefault().trimMemory(level);
        ArrayList<ComponentCallbacks2> callbacks;

        final WindowManagerImpl windowManager = WindowManagerImpl.getDefault();
        windowManager.startTrimMemory(level);

        ArrayList<ComponentCallbacks2> callbacks;
        synchronized (mPackages) {
            callbacks = collectComponentCallbacksLocked(true, null);
        }
@@ -3776,7 +3778,8 @@ public final class ActivityThread {
        for (int i = 0; i < N; i++) {
            callbacks.get(i).onTrimMemory(level);
        }
        WindowManagerImpl.getDefault().terminateEgl();

        windowManager.endTrimMemory();        
    }

    private void setupGraphicsSupport(LoadedApk info) {
+31 −4
Original line number Diff line number Diff line
@@ -484,7 +484,28 @@ public abstract class HardwareRenderer {
     *              see {@link android.content.ComponentCallbacks}
     */
    static void trimMemory(int level) {
        Gl20Renderer.trimMemory(level);
        startTrimMemory(level);
        endTrimMemory();
    }

    /**
     * Starts the process of trimming memory. Usually this call will setup
     * hardware rendering context and reclaim memory.Extra cleanup might
     * be required by calling {@link #endTrimMemory()}.
     * 
     * @param level Hint about the amount of memory that should be trimmed,
     *              see {@link android.content.ComponentCallbacks}
     */
    static void startTrimMemory(int level) {
        Gl20Renderer.startTrimMemory(level);
    }

    /**
     * Finishes the process of trimming memory. This method will usually
     * cleanup special resources used by the memory trimming process.
     */
    static void endTrimMemory() {
        Gl20Renderer.endTrimMemory();
    }

    /**
@@ -1122,12 +1143,15 @@ public abstract class HardwareRenderer {
                        callbacks.onHardwarePostDraw(canvas);
                        canvas.restoreToCount(saveCount);
                        view.mRecreateDisplayList = false;

                        mFrameCount++;

                        if (mDebugDirtyRegions) {
                            if (mDebugPaint == null) {
                                mDebugPaint = new Paint();
                                mDebugPaint.setColor(0x7fff0000);
                            }

                            if (dirty != null && (mFrameCount & 1) == 0) {
                                canvas.drawRect(dirty, mDebugPaint);
                            }
@@ -1446,7 +1470,7 @@ public abstract class HardwareRenderer {
            return null;
        }

        static void trimMemory(int level) {
        static void startTrimMemory(int level) {
            if (sEgl == null || sEglConfig == null) return;

            Gl20RendererEglContext managedContext =
@@ -1463,9 +1487,12 @@ public abstract class HardwareRenderer {
            } else if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
                GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_MODERATE);
            }
        }

            sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    EGL_NO_CONTEXT);
        static void endTrimMemory() {
            if (sEgl != null && sEglDisplay != null) {
                sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
            }
        }

        private static void usePbufferSurface(EGLContext eglContext) {
+9 −4
Original line number Diff line number Diff line
@@ -429,8 +429,10 @@ public class WindowManagerImpl implements WindowManager {

    /**
     * @param level See {@link android.content.ComponentCallbacks}
     *
     * @hide
     */
    public void trimMemory(int level) {
    public void startTrimMemory(int level) {
        if (HardwareRenderer.isAvailable()) {
            // On low-end gfx devices we trim when memory is moderate;
            // on high-end devices we do this when low.
@@ -447,18 +449,21 @@ public class WindowManagerImpl implements WindowManager {
                    }
                }
                // Force a full memory flush
                HardwareRenderer.trimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE);
                mNeedsEglTerminate = true;
                HardwareRenderer.startTrimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE);
                return;
            }
            HardwareRenderer.trimMemory(level);

            HardwareRenderer.startTrimMemory(level);
        }
    }

    /**
     * @hide
     */
    public void terminateEgl() {
    public void endTrimMemory() {
        HardwareRenderer.endTrimMemory();

        if (mNeedsEglTerminate) {
            ManagedEGLContext.doTerminate();
            mNeedsEglTerminate = false;