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

Commit 175679f0 authored by Chris Li's avatar Chris Li
Browse files

Cleanup animation layer

We no longer reparent animation leash to the animation layer.

This will also fix the activity animation leash layer when playing
transition with sibling TaskFragment.

Bug: 201623109
Bug: 196173550
Test: pass existing
Change-Id: I5cec41cfc6b25ff7696d2aba34408f0388365f86
parent 559ce89b
Loading
Loading
Loading
Loading
+3 −47
Original line number Diff line number Diff line
@@ -401,10 +401,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    private static final int STARTING_WINDOW_TYPE_SNAPSHOT = 1;
    private static final int STARTING_WINDOW_TYPE_SPLASH_SCREEN = 2;

    /**
     * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
     */
    @VisibleForTesting static final int Z_BOOST_BASE = 800570000;
    static final int INVALID_PID = -1;

    // How long we wait until giving up on the last activity to pause.  This
@@ -4255,20 +4251,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return callback.test(this) ? this : null;
    }

    @Override
    protected void setLayer(Transaction t, int layer) {
        if (!mSurfaceAnimator.hasLeash()) {
            t.setLayer(mSurfaceControl, layer);
        }
    }

    @Override
    protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
        if (!mSurfaceAnimator.hasLeash()) {
            t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
        }
    }

    void logStartActivity(int tag, Task task) {
        final Uri data = intent.getData();
        final String strData = data != null ? data.toSafeString() : null;
@@ -6797,12 +6779,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return candidate;
    }

    SurfaceControl getAppAnimationLayer() {
        return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
                : needsZBoost() ? ANIMATION_LAYER_BOOSTED
                        : ANIMATION_LAYER_STANDARD);
    }

    @Override
    boolean needsZBoost() {
        return mNeedsZBoost || super.needsZBoost();
@@ -6863,29 +6839,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                || mDisplayContent.isNextTransitionForward();
    }

    private int getAnimationLayer() {
        // The leash is parented to the animation layer. We need to preserve the z-order by using
        // the prefix order index, but we boost if necessary.
        int layer;
        if (!inPinnedWindowingMode()) {
            layer = getPrefixOrderIndex();
        } else {
            // Root pinned tasks have animations take place within themselves rather than an
            // animation layer so we need to preserve the order relative to the root task (e.g.
            // the order of our task/parent).
            layer = getParent().getPrefixOrderIndex();
        }

        if (mNeedsZBoost) {
            layer += Z_BOOST_BASE;
        }
        return layer;
    }

    @Override
    public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
        t.setLayer(leash, getAnimationLayer());
        getDisplayContent().assignRootTaskOrdering();
    void resetSurfacePositionForAnimationLeash(SurfaceControl.Transaction t) {
        // Noop as Activity may be offset for letterbox
    }

    @Override
@@ -6914,7 +6870,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

            // Crop to root task bounds.
            t.setLayer(leash, 0);
            t.setLayer(mAnimationBoundsLayer, getAnimationLayer());
            t.setLayer(mAnimationBoundsLayer, getLastLayer());

            // Reparent leash to animation bounds layer.
            t.reparent(leash, mAnimationBoundsLayer);
+0 −5
Original line number Diff line number Diff line
@@ -2972,11 +2972,6 @@ class Task extends TaskFragment {
        return super.makeAnimationLeash().setMetadata(METADATA_TASK_ID, mTaskId);
    }

    @Override
    void resetSurfacePositionForAnimationLeash(SurfaceControl.Transaction t) {
        super.resetSurfacePositionForAnimationLeash(t);
    }

    boolean shouldAnimate() {
        /**
         * Animations are handled by the TaskOrganizer implementation.
+7 −79
Original line number Diff line number Diff line
@@ -98,13 +98,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
     */
    private int mColorLayerCounter = 0;

    /**
     * A control placed at the appropriate level for transitions to occur.
     */
    private SurfaceControl mAppAnimationLayer;
    private SurfaceControl mBoostedAppAnimationLayer;
    private SurfaceControl mHomeAppAnimationLayer;

    /**
     * Given that the split-screen divider does not have an AppWindowToken, it
     * will have to live inside of a "NonAppWindowContainer". However, in visual Z order
@@ -132,7 +125,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
    private final ArrayList<WindowContainer> mTmpNormalChildren = new ArrayList<>();
    private final ArrayList<WindowContainer> mTmpHomeChildren = new ArrayList<>();
    private final IntArray mTmpNeedsZBoostIndexes = new IntArray();
    private int mTmpLayerForAnimationLayer;

    private ArrayList<Task> mTmpTasks = new ArrayList<>();

@@ -871,33 +863,13 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {

        int layer = 0;
        // Place root home tasks to the bottom.
        layer = adjustRootTaskLayer(t, mTmpHomeChildren, layer, false /* normalRootTasks */);
        // The home animation layer is between the root home tasks and the normal root tasks.
        final int layerForHomeAnimationLayer = layer++;
        mTmpLayerForAnimationLayer = layer++;
        layer = adjustRootTaskLayer(t, mTmpNormalChildren, layer, true /* normalRootTasks */);

        // The boosted animation layer is between the normal root tasks and the always on top
        // root tasks.
        final int layerForBoostedAnimationLayer = layer++;
        // Always on top tasks layer should higher than split divider layer so set it as start.
        layer = SPLIT_DIVIDER_LAYER + 1;
        adjustRootTaskLayer(t, mTmpAlwaysOnTopChildren, layer, false /* normalRootTasks */);
        layer = adjustRootTaskLayer(t, mTmpHomeChildren, layer);
        adjustRootTaskLayer(t, mTmpNormalChildren, layer);

        t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
        t.setLayer(mAppAnimationLayer, mTmpLayerForAnimationLayer);
        // Always on top tasks layer should higher than split divider layer so set it as start.
        t.setLayer(mSplitScreenDividerAnchor, SPLIT_DIVIDER_LAYER);
        t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
    }

    private int adjustNormalRootTaskLayer(WindowContainer child, int layer) {
        if ((child.asTask() != null && child.asTask().isAnimatingByRecents())
                || child.isAppTransitioning()) {
            // The animation layer is located above the highest animating root task and no
            // higher.
            mTmpLayerForAnimationLayer = layer++;
        }
        return layer;
        layer = SPLIT_DIVIDER_LAYER + 1;
        adjustRootTaskLayer(t, mTmpAlwaysOnTopChildren, layer);
    }

    /**
@@ -906,11 +878,10 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
     * normal rootTasks.
     *
     * @param startLayer   The beginning layer of this group of rootTasks.
     * @param normalRootTasks Set {@code true} if this group is neither home nor always on top.
     * @return The adjusted layer value.
     */
    private int adjustRootTaskLayer(SurfaceControl.Transaction t,
            ArrayList<WindowContainer> children, int startLayer, boolean normalRootTasks) {
            ArrayList<WindowContainer> children, int startLayer) {
        mTmpNeedsZBoostIndexes.clear();
        final int childCount = children.size();
        for (int i = 0; i < childCount; i++) {
@@ -923,9 +894,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {

            if (!childNeedsZBoost) {
                child.assignLayer(t, startLayer++);
                if (normalRootTasks) {
                    startLayer = adjustNormalRootTaskLayer(child, startLayer);
                }
            } else {
                mTmpNeedsZBoostIndexes.add(i);
            }
@@ -935,9 +903,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        for (int i = 0; i < zBoostSize; i++) {
            final WindowContainer child = children.get(mTmpNeedsZBoostIndexes.get(i));
            child.assignLayer(t, startLayer++);
            if (normalRootTasks) {
                startLayer = adjustNormalRootTaskLayer(child, startLayer);
            }
        }
        return startLayer;
    }
@@ -950,19 +915,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        return needsZBoost[0];
    }

    @Override
    SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
        switch (animationLayer) {
            case ANIMATION_LAYER_BOOSTED:
                return mBoostedAppAnimationLayer;
            case ANIMATION_LAYER_HOME:
                return mHomeAppAnimationLayer;
            case ANIMATION_LAYER_STANDARD:
            default:
                return mAppAnimationLayer;
        }
    }

    @Override
    RemoteAnimationTarget createRemoteAnimationTarget(
            RemoteAnimationController.RemoteAnimationRecord record) {
@@ -983,42 +935,21 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
                        .setName("colorBackgroundLayer")
                        .setCallsite("TaskDisplayArea.onParentChanged")
                        .build();
                mAppAnimationLayer = makeChildSurface(null)
                        .setName("animationLayer")
                        .setCallsite("TaskDisplayArea.onParentChanged")
                        .build();
                mBoostedAppAnimationLayer = makeChildSurface(null)
                        .setName("boostedAnimationLayer")
                        .setCallsite("TaskDisplayArea.onParentChanged")
                        .build();
                mHomeAppAnimationLayer = makeChildSurface(null)
                        .setName("homeAnimationLayer")
                        .setCallsite("TaskDisplayArea.onParentChanged")
                        .build();
                mSplitScreenDividerAnchor = makeChildSurface(null)
                        .setName("splitScreenDividerAnchor")
                        .setCallsite("TaskDisplayArea.onParentChanged")
                        .build();

                getSyncTransaction()
                        .show(mAppAnimationLayer)
                        .show(mBoostedAppAnimationLayer)
                        .show(mHomeAppAnimationLayer)
                        .show(mSplitScreenDividerAnchor);
            });
        } else {
            super.onParentChanged(newParent, oldParent);
            mWmService.mTransactionFactory.get()
                    .remove(mColorBackgroundLayer)
                    .remove(mAppAnimationLayer)
                    .remove(mBoostedAppAnimationLayer)
                    .remove(mHomeAppAnimationLayer)
                    .remove(mSplitScreenDividerAnchor)
                    .apply();
            mColorBackgroundLayer = null;
            mAppAnimationLayer = null;
            mBoostedAppAnimationLayer = null;
            mHomeAppAnimationLayer = null;
            mSplitScreenDividerAnchor = null;
        }
    }
@@ -1059,15 +990,12 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
    @Override
    void migrateToNewSurfaceControl(SurfaceControl.Transaction t) {
        super.migrateToNewSurfaceControl(t);
        if (mAppAnimationLayer == null) {
        if (mColorBackgroundLayer == null) {
            return;
        }

        // As TaskDisplayArea is getting a new surface, reparent and reorder the child surfaces.
        t.reparent(mColorBackgroundLayer, mSurfaceControl);
        t.reparent(mAppAnimationLayer, mSurfaceControl);
        t.reparent(mBoostedAppAnimationLayer, mSurfaceControl);
        t.reparent(mHomeAppAnimationLayer, mSurfaceControl);
        t.reparent(mSplitScreenDividerAnchor, mSurfaceControl);
        reassignLayer(t);
        scheduleAnimation();
+0 −32
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.WindowConfiguration;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
@@ -127,26 +126,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<

    private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowContainer" : TAG_WM;

    /** Animation layer that happens above all animating {@link Task}s. */
    static final int ANIMATION_LAYER_STANDARD = 0;

    /** Animation layer that happens above all {@link Task}s. */
    static final int ANIMATION_LAYER_BOOSTED = 1;

    /**
     * Animation layer that is reserved for {@link WindowConfiguration#ACTIVITY_TYPE_HOME}
     * activities and all activities that are being controlled by the recents animation. This
     * layer is generally below all {@link Task}s.
     */
    static final int ANIMATION_LAYER_HOME = 2;

    @IntDef(prefix = { "ANIMATION_LAYER_" }, value = {
            ANIMATION_LAYER_STANDARD,
            ANIMATION_LAYER_BOOSTED,
            ANIMATION_LAYER_HOME,
    })
    @interface AnimationLayer {}

    static final int POSITION_TOP = Integer.MAX_VALUE;
    static final int POSITION_BOTTOM = Integer.MIN_VALUE;

@@ -2668,17 +2647,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        return getParentSurfaceControl();
    }

    /**
     * @return The layer on which all app animations are happening.
     */
    SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
        final WindowContainer parent = getParent();
        if (parent != null) {
            return parent.getAppAnimationLayer(animationLayer);
        }
        return null;
    }

    // TODO: Remove this and use #getBounds() instead once we set an app transition animation
    // on TaskStack.
    Rect getAnimationBounds(int appRootTaskClipMode) {
+8 −2
Original line number Diff line number Diff line
@@ -75,13 +75,19 @@ public class AppWindowTokenAnimationTests extends WindowTestsBase {

    @Test
    public void clipAfterAnim_boundsLayerZBoosted() {
        final Task task = mActivity.getTask();
        final ActivityRecord topActivity = createActivityRecord(task);
        task.assignChildLayers(mTransaction);

        assertThat(topActivity.getLastLayer()).isGreaterThan(mActivity.getLastLayer());

        mActivity.mNeedsAnimationBoundsLayer = true;
        mActivity.mNeedsZBoost = true;

        mActivity.mSurfaceAnimator.startAnimation(mTransaction, mSpec, true /* hidden */,
                ANIMATION_TYPE_APP_TRANSITION);

        verify(mTransaction).setLayer(eq(mActivity.mAnimationBoundsLayer),
                intThat(layer -> layer >= ActivityRecord.Z_BOOST_BASE));
                intThat(layer -> layer > topActivity.getLastLayer()));
    }

    @Test