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

Commit 8116ab47 authored by Issei Suzuki's avatar Issei Suzuki Committed by Android (Google) Code Review
Browse files

Merge "Refactor TaskStackContainers#assignStackOrdering()"

parents f04abf9e 25a9e2b5
Loading
Loading
Loading
Loading
+68 −61
Original line number Diff line number Diff line
@@ -564,6 +564,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    // Last systemUiVisibility we dispatched to windows.
    private int mLastDispatchedSystemUiVisibility = 0;

    private final ArrayList<TaskStack> mTmpAlwaysOnTopStacks = new ArrayList<>();
    private final ArrayList<TaskStack> mTmpNormalStacks = new ArrayList<>();
    private final ArrayList<TaskStack> mTmpHomeStacks = new ArrayList<>();

    /** Corner radius that windows should have in order to match the display. */
    private final float mWindowCornerRadius;

@@ -4266,55 +4270,57 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }

        void assignStackOrdering(SurfaceControl.Transaction t) {

            final int HOME_STACK_STATE = 0;
            final int NORMAL_STACK_STATE = 1;
            final int ALWAYS_ON_TOP_STATE = 2;

            int layer = 0;
            int layerForAnimationLayer = 0;
            int layerForBoostedAnimationLayer = 0;
            int layerForHomeAnimationLayer = 0;

            for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
                for (int i = 0; i < mChildren.size(); i++) {
            if (getParent() == null) {
                return;
            }
            mTmpAlwaysOnTopStacks.clear();
            mTmpHomeStacks.clear();
            mTmpNormalStacks.clear();
            for (int i = 0; i < mChildren.size(); ++i) {
                final TaskStack s = mChildren.get(i);
                    if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
                        continue;
                    } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
                            || s.isAlwaysOnTop())) {
                        continue;
                    } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
                        continue;
                if (s.isAlwaysOnTop()) {
                    mTmpAlwaysOnTopStacks.add(s);
                } else if (s.isActivityTypeHome()) {
                    mTmpHomeStacks.add(s);
                } else {
                    mTmpNormalStacks.add(s);
                }
            }

            int layer = 0;
            // Place home stacks to the bottom.
            for (int i = 0; i < mTmpHomeStacks.size(); i++) {
                mTmpHomeStacks.get(i).assignLayer(t, layer++);
            }
            // The home animation layer is between the home stacks and the normal stacks.
            final int layerForHomeAnimationLayer = layer++;
            int layerForSplitScreenDividerAnchor = layer++;
            int layerForAnimationLayer = layer++;
            for (int i = 0; i < mTmpNormalStacks.size(); i++) {
                final TaskStack s = mTmpNormalStacks.get(i);
                s.assignLayer(t, layer++);
                    if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
                        t.setLayer(mSplitScreenDividerAnchor, layer++);
                if (s.inSplitScreenWindowingMode()) {
                    // The split screen divider anchor is located above the split screen window.
                    layerForSplitScreenDividerAnchor = layer++;
                }
                    if ((s.isTaskAnimating() || s.isAppAnimating())
                            && state != ALWAYS_ON_TOP_STATE) {
                        // Ensure the animation layer ends up above the
                        // highest animating stack and no higher.
                if (s.isTaskAnimating() || s.isAppAnimating()) {
                    // The animation layer is located above the highest animating stack and no
                    // higher.
                    layerForAnimationLayer = layer++;
                }
                    if (state != ALWAYS_ON_TOP_STATE) {
                        layerForBoostedAnimationLayer = layer++;
                    }
            }
                if (state == HOME_STACK_STATE) {
                    layerForHomeAnimationLayer = layer++;
            // The boosted animation layer is between the normal stacks and the always on top
            // stacks.
            final int layerForBoostedAnimationLayer = layer++;
            for (int i = 0; i < mTmpAlwaysOnTopStacks.size(); i++) {
                mTmpAlwaysOnTopStacks.get(i).assignLayer(t, layer++);
            }
            }
            if (mAppAnimationLayer != null) {

            t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
            t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
            }
            if (mBoostedAppAnimationLayer != null) {
            t.setLayer(mSplitScreenDividerAnchor, layerForSplitScreenDividerAnchor);
            t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
        }
            if (mHomeAppAnimationLayer != null) {
                t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
            }
        }

        @Override
        SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
@@ -4335,8 +4341,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        @Override
        void onParentChanged() {
            super.onParentChanged();
            if (getParent() != null) {
                super.onParentChanged(() -> {
                    mAppAnimationLayer = makeChildSurface(null)
                            .setName("animationLayer")
                            .build();
@@ -4354,8 +4360,9 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                            .show(mBoostedAppAnimationLayer)
                            .show(mHomeAppAnimationLayer)
                            .show(mSplitScreenDividerAnchor);
                scheduleAnimation();
                });
            } else {
                super.onParentChanged();
                mWmService.mTransactionFactory.get()
                        .remove(mAppAnimationLayer)
                        .remove(mBoostedAppAnimationLayer)
+16 −0
Original line number Diff line number Diff line
@@ -137,6 +137,14 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     */
    private boolean mCommittedReparentToAnimationLeash;

    /**
     * Callback which is triggered while changing the parent, after setting up the surface but
     * before asking the parent to assign child layers.
     */
    interface PreAssignChildLayersCallback {
        void onPreAssignChildLayers();
    }

    WindowContainer(WindowManagerService wms) {
        mWmService = wms;
        mPendingTransaction = wms.mTransactionFactory.get();
@@ -176,6 +184,10 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     */
    @Override
    void onParentChanged() {
        onParentChanged(null);
    }

    void onParentChanged(PreAssignChildLayersCallback callback) {
        super.onParentChanged();
        if (mParent == null) {
            return;
@@ -195,6 +207,10 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            reparentSurfaceControl(getPendingTransaction(), mParent.mSurfaceControl);
        }

        if (callback != null) {
            callback.onPreAssignChildLayers();
        }

        // Either way we need to ask the parent to assign us a Z-order.
        mParent.assignChildLayers();
        scheduleAnimation();