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

Commit a16f2f28 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Reduce layer assignment and placement for intermediate state

There may be no need to request traversal for all hierarchy changes.
Such as even if there is a z-order change, but if the client has
not drawn yet, the displayed content may not show visible changes
by the traversal because there is nothing to show or the transaction needs to be synchronized.

So instead of requesting to update surface/focus on intermediate
changes, let the existing signals: "relayout, add/remove window,
destroy surface, lifecycle callback, window container transaction,
significant changes detected in deferWindowLayout~continueWindowLayout"
trigger the update. In other words, focus more on dealing with
changes that are actually visible.

For example, this can reduce the number of passed for layoutAndAssignWindowLayers by 3 times and surface placement by 1 time
for startActivityInner.

Some tests depended on the setup in WindowTestsBase.ActivityBuilder
to dispatch pending organizer events. Since this change no longer
triggers traversal to dispatch them in the builder, refine the tests
to send the events by themselves.

Bug: 159103089
Test: CtsWindowManagerDeviceTestCases
Change-Id: Ib9c008994dbbc4d6e1dd1ca3e37b9aa0ccaba997
parent f558dd2d
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -3978,23 +3978,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
    }

    // TODO: This should probably be called any time a visual change is made to the hierarchy like
    // moving containers or resizing them. Need to investigate the best way to have it automatically
    // happen so we don't run into issues with programmers forgetting to do it.
    void layoutAndAssignWindowLayersIfNeeded() {
        mWmService.mWindowsChanged = true;
        setLayoutNeeded();

        if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                false /*updateInputWindows*/)) {
            assignWindowLayers(false /* setLayoutNeeded */);
        }

        mInputMonitor.setUpdateInputWindowsNeededLw();
        mWmService.mWindowPlacerLocked.performSurfacePlacement();
        mInputMonitor.updateInputWindowsLw(false /*force*/);
    }

    /** Returns true if a leaked surface was destroyed */
    boolean destroyLeakedSurfaces() {
        // Used to indicate that a surface was leaked.
+0 −10
Original line number Diff line number Diff line
@@ -5874,9 +5874,6 @@ class Task extends TaskFragment {
        }

        positionChildAt(POSITION_TOP, child, true /* includingParents */);

        final DisplayContent displayContent = getDisplayContent();
        displayContent.layoutAndAssignWindowLayersIfNeeded();
    }

    void positionChildAtBottom(Task child) {
@@ -5897,7 +5894,6 @@ class Task extends TaskFragment {
        }

        positionChildAt(POSITION_BOTTOM, child, includingParents);
        getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
    }

    @Override
@@ -5911,12 +5907,6 @@ class Task extends TaskFragment {
            // Non-root task position changed.
            mRootWindowContainer.invalidateTaskLayers();
        }

        final boolean isTop = getTopChild() == child;
        if (isTop) {
            final DisplayContent displayContent = getDisplayContent();
            displayContent.layoutAndAssignWindowLayersIfNeeded();
        }
    }

    void reparent(TaskDisplayArea newParent, boolean onTop) {
+0 −2
Original line number Diff line number Diff line
@@ -405,8 +405,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {

        child.updateTaskMovement(moveToTop, targetPosition);

        mDisplayContent.layoutAndAssignWindowLayersIfNeeded();

        // The insert position may be adjusted to non-top when there is always-on-top root task.
        // Since the original position is preferred to be top, the root task should have higher
        // priority when we are looking for top focusable root task. The condition {@code
+0 −1
Original line number Diff line number Diff line
@@ -566,7 +566,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            onDisplayChanged(dc);
            prevDc.setLayoutNeeded();
        }
        getDisplayContent().layoutAndAssignWindowLayersIfNeeded();

        // Send onParentChanged notification here is we disabled sending it in setParent for
        // reparenting case.
+2 −3
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_START_SHORTCUT;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_WINDOW_ORGANIZER;
import static com.android.server.wm.ActivityTaskManagerService.LAYOUT_REASON_CONFIG_CHANGED;
import static com.android.server.wm.ActivityTaskManagerService.enforceTaskPermission;
import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.Task.FLAG_FORCE_HIDDEN_FOR_PINNED_TASK;
@@ -622,8 +621,8 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                }
            }

            if ((effects & TRANSACT_EFFECTS_CLIENT_CONFIG) != 0) {
                mService.addWindowLayoutReasons(LAYOUT_REASON_CONFIG_CHANGED);
            if (effects != 0) {
                mService.mWindowManager.mWindowPlacerLocked.requestTraversal();
            }
        } finally {
            mService.mTaskSupervisor.setDeferRootVisibilityUpdate(false /* deferUpdate */);
Loading