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

Commit 70125e47 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove CounterRotator surface in finishTransaction"

parents 7b0de5c8 c00c3d93
Loading
Loading
Loading
Loading
+7 −4
Original line number Original line Diff line number Diff line
@@ -155,7 +155,8 @@ public class PipTransition extends PipTransitionController {


            switch (type) {
            switch (type) {
                case TRANSIT_EXIT_PIP:
                case TRANSIT_EXIT_PIP:
                    startExitAnimation(info, startTransaction, finishCallback, exitPipChange);
                    startExitAnimation(info, startTransaction, finishTransaction, finishCallback,
                            exitPipChange);
                    break;
                    break;
                case TRANSIT_EXIT_PIP_TO_SPLIT:
                case TRANSIT_EXIT_PIP_TO_SPLIT:
                    startExitToSplitAnimation(info, startTransaction, finishTransaction,
                    startExitToSplitAnimation(info, startTransaction, finishTransaction,
@@ -283,6 +284,7 @@ public class PipTransition extends PipTransitionController {


    private void startExitAnimation(@NonNull TransitionInfo info,
    private void startExitAnimation(@NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction,
            @NonNull Transitions.TransitionFinishCallback finishCallback,
            @NonNull Transitions.TransitionFinishCallback finishCallback,
            @NonNull TransitionInfo.Change pipChange) {
            @NonNull TransitionInfo.Change pipChange) {
        TransitionInfo.Change displayRotationChange = null;
        TransitionInfo.Change displayRotationChange = null;
@@ -298,8 +300,8 @@ public class PipTransition extends PipTransitionController {


        if (displayRotationChange != null) {
        if (displayRotationChange != null) {
            // Exiting PIP to fullscreen with orientation change.
            // Exiting PIP to fullscreen with orientation change.
            startExpandAndRotationAnimation(info, startTransaction, finishCallback,
            startExpandAndRotationAnimation(info, startTransaction, finishTransaction,
                    displayRotationChange, pipChange);
                    finishCallback, displayRotationChange, pipChange);
            return;
            return;
        }
        }


@@ -322,6 +324,7 @@ public class PipTransition extends PipTransitionController {


    private void startExpandAndRotationAnimation(@NonNull TransitionInfo info,
    private void startExpandAndRotationAnimation(@NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction finishTransaction,
            @NonNull Transitions.TransitionFinishCallback finishCallback,
            @NonNull Transitions.TransitionFinishCallback finishCallback,
            @NonNull TransitionInfo.Change displayRotationChange,
            @NonNull TransitionInfo.Change displayRotationChange,
            @NonNull TransitionInfo.Change pipChange) {
            @NonNull TransitionInfo.Change pipChange) {
@@ -335,7 +338,6 @@ public class PipTransition extends PipTransitionController {
        rotator.handleClosingChanges(info, startTransaction, rotateDelta, displayW, displayH);
        rotator.handleClosingChanges(info, startTransaction, rotateDelta, displayW, displayH);


        mFinishCallback = (wct, wctCB) -> {
        mFinishCallback = (wct, wctCB) -> {
            rotator.cleanUp();
            mPipOrganizer.onExitPipFinished(pipChange.getTaskInfo());
            mPipOrganizer.onExitPipFinished(pipChange.getTaskInfo());
            finishCallback.onTransitionFinished(wct, wctCB);
            finishCallback.onTransitionFinished(wct, wctCB);
        };
        };
@@ -366,6 +368,7 @@ public class PipTransition extends PipTransitionController {
                endBounds, startBounds, new Rect(), degree, x, y, true /* isExpanding */,
                endBounds, startBounds, new Rect(), degree, x, y, true /* isExpanding */,
                pipRotateDelta == ROTATION_270 /* clockwise */);
                pipRotateDelta == ROTATION_270 /* clockwise */);
        startTransaction.apply();
        startTransaction.apply();
        rotator.cleanUp(finishTransaction);


        // Expand and rotate the pip window to fullscreen.
        // Expand and rotate the pip window to fullscreen.
        final PipAnimationController.PipTransitionAnimator animator =
        final PipAnimationController.PipTransitionAnimator animator =
+8 −5
Original line number Original line Diff line number Diff line
@@ -35,13 +35,11 @@ import java.util.List;
 */
 */
public class CounterRotatorHelper {
public class CounterRotatorHelper {
    private final ArrayMap<WindowContainerToken, CounterRotator> mRotatorMap = new ArrayMap<>();
    private final ArrayMap<WindowContainerToken, CounterRotator> mRotatorMap = new ArrayMap<>();
    private SurfaceControl mRootLeash;


    /** Puts the surface controls of closing changes to counter-rotated surfaces. */
    /** Puts the surface controls of closing changes to counter-rotated surfaces. */
    public void handleClosingChanges(@NonNull TransitionInfo info,
    public void handleClosingChanges(@NonNull TransitionInfo info,
            @NonNull SurfaceControl.Transaction startTransaction,
            @NonNull SurfaceControl.Transaction startTransaction,
            int rotateDelta, int displayW, int displayH) {
            int rotateDelta, int displayW, int displayH) {
        mRootLeash = info.getRootLeash();
        final List<TransitionInfo.Change> changes = info.getChanges();
        final List<TransitionInfo.Change> changes = info.getChanges();
        final int numChanges = changes.size();
        final int numChanges = changes.size();
        for (int i = numChanges - 1; i >= 0; --i) {
        for (int i = numChanges - 1; i >= 0; --i) {
@@ -71,10 +69,15 @@ public class CounterRotatorHelper {
        }
        }
    }
    }


    /** Restores to the original state, i.e. reparent back to transition root. */
    /**
    public void cleanUp() {
     * Removes the counter rotation surface in the finish transaction. No need to reparent the
     * children as the finish transaction should have already taken care of that.
     *
     * This can only be called after startTransaction for {@link #handleClosingChanges} is applied.
     */
    public void cleanUp(@NonNull SurfaceControl.Transaction finishTransaction) {
        for (int i = mRotatorMap.size() - 1; i >= 0; --i) {
        for (int i = mRotatorMap.size() - 1; i >= 0; --i) {
            mRotatorMap.valueAt(i).cleanUp(mRootLeash);
            mRotatorMap.valueAt(i).cleanUp(finishTransaction);
        }
        }
        mRotatorMap.clear();
        mRotatorMap.clear();
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -282,7 +282,6 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
        final Runnable onAnimFinish = () -> {
        final Runnable onAnimFinish = () -> {
            if (!animations.isEmpty()) return;
            if (!animations.isEmpty()) return;


            rotator.cleanUp();
            if (mRotationAnimation != null) {
            if (mRotationAnimation != null) {
                mRotationAnimation.kill();
                mRotationAnimation.kill();
                mRotationAnimation = null;
                mRotationAnimation = null;
@@ -382,6 +381,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
        }
        }


        startTransaction.apply();
        startTransaction.apply();
        rotator.cleanUp(finishTransaction);
        TransitionMetrics.getInstance().reportAnimationStart(transition);
        TransitionMetrics.getInstance().reportAnimationStart(transition);
        // run finish now in-case there are no animations
        // run finish now in-case there are no animations
        onAnimFinish.run();
        onAnimFinish.run();
+6 −15
Original line number Original line Diff line number Diff line
@@ -18,14 +18,11 @@ package com.android.wm.shell.util;


import android.view.SurfaceControl;
import android.view.SurfaceControl;


import java.util.ArrayList;

/**
/**
 * Utility class that takes care of counter-rotating surfaces during a transition animation.
 * Utility class that takes care of counter-rotating surfaces during a transition animation.
 */
 */
public class CounterRotator {
public class CounterRotator {
    SurfaceControl mSurface = null;
    private SurfaceControl mSurface = null;
    ArrayList<SurfaceControl> mRotateChildren = null;


    /** Gets the surface with the counter-rotation. */
    /** Gets the surface with the counter-rotation. */
    public SurfaceControl getSurface() {
    public SurfaceControl getSurface() {
@@ -41,7 +38,6 @@ public class CounterRotator {
    public void setup(SurfaceControl.Transaction t, SurfaceControl parent, int rotateDelta,
    public void setup(SurfaceControl.Transaction t, SurfaceControl parent, int rotateDelta,
            float displayW, float displayH) {
            float displayW, float displayH) {
        if (rotateDelta == 0) return;
        if (rotateDelta == 0) return;
        mRotateChildren = new ArrayList<>();
        // We want to counter-rotate, so subtract from 4
        // We want to counter-rotate, so subtract from 4
        rotateDelta = 4 - (rotateDelta + 4) % 4;
        rotateDelta = 4 - (rotateDelta + 4) % 4;
        mSurface = new SurfaceControl.Builder()
        mSurface = new SurfaceControl.Builder()
@@ -64,24 +60,19 @@ public class CounterRotator {
    }
    }


    /**
    /**
     * Add a surface that needs to be counter-rotate.
     * Adds a surface that needs to be counter-rotate.
     */
     */
    public void addChild(SurfaceControl.Transaction t, SurfaceControl child) {
    public void addChild(SurfaceControl.Transaction t, SurfaceControl child) {
        if (mSurface == null) return;
        if (mSurface == null) return;
        t.reparent(child, mSurface);
        t.reparent(child, mSurface);
        mRotateChildren.add(child);
    }
    }


    /**
    /**
     * Clean-up. This undoes any reparenting and effectively stops the counter-rotation.
     * Clean-up. Since finishTransaction should reset all change leashes, we only need to remove the
     * counter rotation surface.
     */
     */
    public void cleanUp(SurfaceControl rootLeash) {
    public void cleanUp(SurfaceControl.Transaction finishTransaction) {
        if (mSurface == null) return;
        if (mSurface == null) return;
        SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        finishTransaction.remove(mSurface);
        for (int i = mRotateChildren.size() - 1; i >= 0; --i) {
            t.reparent(mRotateChildren.get(i), rootLeash);
        }
        t.remove(mSurface);
        t.apply();
    }
    }
}
}
+5 −3
Original line number Original line Diff line number Diff line
@@ -205,8 +205,10 @@ public class RemoteAnimationAdapterCompat {
                    @Override
                    @Override
                    @SuppressLint("NewApi")
                    @SuppressLint("NewApi")
                    public void run() {
                    public void run() {
                        counterLauncher.cleanUp(info.getRootLeash());
                        final SurfaceControl.Transaction finishTransaction =
                        counterWallpaper.cleanUp(info.getRootLeash());
                                new SurfaceControl.Transaction();
                        counterLauncher.cleanUp(finishTransaction);
                        counterWallpaper.cleanUp(finishTransaction);
                        // Release surface references now. This is apparently to free GPU memory
                        // Release surface references now. This is apparently to free GPU memory
                        // while doing quick operations (eg. during CTS).
                        // while doing quick operations (eg. during CTS).
                        for (int i = info.getChanges().size() - 1; i >= 0; --i) {
                        for (int i = info.getChanges().size() - 1; i >= 0; --i) {
@@ -216,7 +218,7 @@ public class RemoteAnimationAdapterCompat {
                            leashMap.valueAt(i).release();
                            leashMap.valueAt(i).release();
                        }
                        }
                        try {
                        try {
                            finishCallback.onTransitionFinished(null /* wct */, null /* sct */);
                            finishCallback.onTransitionFinished(null /* wct */, finishTransaction);
                        } catch (RemoteException e) {
                        } catch (RemoteException e) {
                            Log.e("ActivityOptionsCompat", "Failed to call app controlled animation"
                            Log.e("ActivityOptionsCompat", "Failed to call app controlled animation"
                                    + " finished callback", e);
                                    + " finished callback", e);