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

Commit 5ac3a8a8 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge "Coalesce layout traversal when resizing stacks"

parents 7c4b0829 c402520f
Loading
Loading
Loading
Loading
+69 −66
Original line number Diff line number Diff line
@@ -2991,7 +2991,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }

        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stackId);

        mWindowManager.deferSurfaceLayout();
        try {
            ActivityRecord r = stack.topRunningActivityLocked();

            mTmpBounds.clear();
@@ -3067,9 +3068,11 @@ public final class ActivityStackSupervisor implements DisplayListener {
                    resumeTopActivitiesLocked(stack, null, null);
                }
            }

        } finally {
            mWindowManager.continueSurfaceLayout();
            Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
        }
    }

    void resizeTaskLocked(TaskRecord task, Rect bounds, int resizeMode, boolean preserveWindow) {
        if (!task.mResizeable) {
+21 −1
Original line number Diff line number Diff line
@@ -4679,7 +4679,7 @@ public class WindowManagerService extends IWindowManager.Stub
                throw new IllegalArgumentException("resizeStack: stackId " + stackId
                        + " not found.");
            }
            if (stack.setBounds(bounds, configs, taskBounds)) {
            if (stack.setBounds(bounds, configs, taskBounds) && stack.isVisibleLocked()) {
                stack.resizeWindows();
                stack.getDisplayContent().layoutNeeded = true;
                mWindowPlacerLocked.performSurfacePlacement();
@@ -4732,6 +4732,26 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    /**
     * Starts deferring layout passes. Useful when doing multiple changes but to optimize
     * performance, only one layout pass should be done. This can be called multiple times, and
     * layouting will be resumed once the last caller has called {@link #continueSurfaceLayout}
     */
    public void deferSurfaceLayout() {
        synchronized (mWindowMap) {
            mWindowPlacerLocked.deferLayout();
        }
    }

    /**
     * Resumes layout passes after deferring them. See {@link #deferSurfaceLayout()}
     */
    public void continueSurfaceLayout() {
        synchronized (mWindowMap) {
            mWindowPlacerLocked.continueLayout();
        }
    }

    public void getTaskBounds(int taskId, Rect bounds) {
        synchronized (mWindowMap) {
            Task task = mTaskIdToTask.get(taskId);
+21 −0
Original line number Diff line number Diff line
@@ -112,13 +112,34 @@ class WindowSurfacePlacer {
    private int mPreferredModeId = 0;

    private boolean mTraversalScheduled;
    private int mDeferDepth = 0;

    public WindowSurfacePlacer(WindowManagerService service) {
        mService = service;
        mWallpaperControllerLocked = mService.mWallpaperControllerLocked;
    }

    /**
     * See {@link WindowManagerService#deferSurfaceLayout()}
     */
    void deferLayout() {
        mDeferDepth++;
    }

    /**
     * See {@link WindowManagerService#continueSurfaceLayout()}
     */
    void continueLayout() {
        mDeferDepth--;
        if (mDeferDepth <= 0) {
            performSurfacePlacement();
        }
    }

    final void performSurfacePlacement() {
        if (mDeferDepth > 0) {
            return;
        }
        int loopCount = 6;
        do {
            mTraversalScheduled = false;