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

Commit 66563b44 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Copy pip surface for the usages outside transition

The surfaces in transition should be released once the transition
is finished. If the transition handler needs to perform some
actions to the surface outside the transition, it needs to make
a copy and manage when to release.

For pip1, the accesses outside transition use the surface from
PipTaskOrganizer#getSurfaceControl (not the leash from transition),
so only pip menu needs a copy for the case that uses the surface
from menu's surfaceCreated.

For pip2, all accesses use PipTransitionState#getPinnedTaskLeash.
So make a copy when receiving ENTERING_PIP and release the surface
when receiving EXITED_PIP.

Bug: 429548260
Flag: com.android.window.flags.release_all_transition_surfaces
Test: atest PinnedStackTests
Change-Id: I4889d168b99f370dfc865a00efe351ba89a1ec99
parent 5d23bdf5
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1114,8 +1114,7 @@ public class PipTransition extends PipTransitionController {
                    destinationBounds, sourceHintRect);
        }
        if (!mPipOrganizer.shouldAttachMenuEarly()) {
            mTransitions.getMainExecutor().executeDelayed(
                    () -> mPipMenuController.attach(leash), 0);
            mPipMenuController.attach(leash);
        }

        if (taskInfo.pictureInPictureParams != null
+5 −2
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ public class PhonePipMenuController implements PipMenuController {
     */
    @Override
    public void attach(SurfaceControl leash) {
        mLeash = leash;
        mLeash = new SurfaceControl(leash, "PhonePipMenuController");
        attachPipMenuView();
    }

@@ -177,8 +177,11 @@ public class PhonePipMenuController implements PipMenuController {
    public void detach() {
        hideMenu();
        detachPipMenuView();
        if (mLeash != null) {
            mLeash.release();
            mLeash = null;
        }
    }

    void attachPipMenuView() {
        // In case detach was not called (e.g. PIP unexpectedly closed)
+5 −2
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
            throw new IllegalStateException("Delegate is not set.");
        }

        mLeash = leash;
        mLeash = new SurfaceControl(leash, "TvPipMenuController");
        attachPipMenu(/* showEduText */ true);
    }

@@ -294,8 +294,11 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis
    public void detach() {
        detachPipMenu();
        switchToMenuMode(MODE_NO_MENU);
        if (mLeash != null) {
            mLeash.release();
            mLeash = null;
        }
    }

    @Override
    public void setAppActions(List<RemoteAction> actions, RemoteAction closeAction) {
+1 −1
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ public class PhonePipMenuController implements PipMenuController,
                            @Override
                            public void surfaceCreated(SurfaceControl.Transaction t) {
                                final SurfaceControl sc = getSurfaceControl();
                                if (sc != null) {
                                if (sc != null && mLeash.isValid()) {
                                    t.reparent(sc, mLeash);
                                    // make menu on top of the surface
                                    t.setLayer(sc, Integer.MAX_VALUE);
+1 −6
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import static com.android.wm.shell.pip2.phone.PipTransition.ANIMATING_BOUNDS_CHA
import static com.android.wm.shell.pip2.phone.PipTransition.PIP_DESTINATION_BOUNDS;

import android.annotation.Nullable;
import android.app.TaskInfo;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -143,8 +142,7 @@ public class PipDisplayTransferHandler implements
                ProtoLog.v(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                        "%s Animating PiP display change to=%d", TAG, mTargetDisplayId);

                SurfaceControl pipLeash = mPipTransitionState.getPinnedTaskLeash();
                TaskInfo taskInfo = mPipTransitionState.getPipTaskInfo();
                final SurfaceControl pipLeash = mPipTransitionState.getPinnedTaskLeash();
                final int duration = extra.getInt(ANIMATING_BOUNDS_CHANGE_DURATION,
                        PipTransition.BOUNDS_CHANGE_JUMPCUT_DURATION);
                final Transaction startTx = extra.getParcelable(
@@ -169,9 +167,6 @@ public class PipDisplayTransferHandler implements
                mPipTransitionState.setState(PipTransitionState.EXITING_PIP);
                mPipTransitionState.setState(PipTransitionState.EXITED_PIP);

                mPipTransitionState.setPinnedTaskLeash(pipLeash);
                mPipTransitionState.setPipTaskInfo(taskInfo);

                final PipResizeAnimator animator = mPipResizeAnimatorSupplier.get(mContext,
                        mPipSurfaceTransactionHelper, pipLeash, startTx, finishTx,
                        mPipBoundsState.getBounds(), mPipBoundsState.getBounds(), pipBounds,
Loading