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

Commit 689b27f0 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

[PiP2]Take stashing into account on display change

Whether we are rotating the display while in PiP or
folding/unfolding a device, we should conserve the stash
state as well.

To do this properly first calculate the snap fraction taking
stash state into account. Then, use that snap fraction with
stash offsets and insets to calculate the proper final bounds.

Bug: 381171053
Flag: com.android.wm.shell.enable_pip2
Test: manually stash PiP then fold/unfold or rotate
Change-Id: Ic885e6c4990f7139d9aca3bb6322e133ff60fedd
parent ce48679b
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipDisplayLayoutState;
import com.android.wm.shell.common.pip.PipKeepClearAlgorithmInterface;
import com.android.wm.shell.common.pip.PipMediaController;
import com.android.wm.shell.common.pip.PipSnapAlgorithm;
import com.android.wm.shell.common.pip.PipUiEventLogger;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.pip.Pip;
@@ -429,7 +430,12 @@ public class PipController implements ConfigurationChangeListener,
        if (displayId != mPipDisplayLayoutState.getDisplayId()) {
            return;
        }
        final float snapFraction = mPipBoundsAlgorithm.getSnapFraction(mPipBoundsState.getBounds());

        final PipSnapAlgorithm snapAlgorithm = mPipBoundsAlgorithm.getSnapAlgorithm();
        final float snapFraction = snapAlgorithm.getSnapFraction(
                mPipBoundsState.getBounds(),
                mPipBoundsAlgorithm.getMovementBounds(mPipBoundsState.getBounds()),
                mPipBoundsState.getStashedState());

        // Update the display layout caches even if we are not in PiP.
        setDisplayLayout(mDisplayController.getDisplayLayout(displayId));
@@ -463,13 +469,16 @@ public class PipController implements ConfigurationChangeListener,
            Rect toBounds = new Rect(0, 0,
                    (int) Math.ceil(mPipBoundsState.getMaxSize().x * boundsScale),
                    (int) Math.ceil(mPipBoundsState.getMaxSize().y * boundsScale));
            // Update the caches to reflect the new display layout in the movement bounds;
            // temporarily update bounds to be at the top left for the movement bounds calculation.
            mPipBoundsState.setBounds(toBounds);
            mPipTouchHandler.updateMovementBounds();

            // The policy is to keep PiP snap fraction invariant.
            mPipBoundsAlgorithm.applySnapFraction(toBounds, snapFraction);
            snapAlgorithm.applySnapFraction(toBounds,
                    mPipBoundsAlgorithm.getMovementBounds(toBounds), snapFraction,
                    mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
                    mPipDisplayLayoutState.getDisplayBounds(),
                    mPipDisplayLayoutState.getDisplayLayout().stableInsets());

            mPipBoundsState.setBounds(toBounds);
            mPipTouchHandler.updateMovementBounds();
            mPipTouchHandler.setUserResizeBounds(toBounds);
        }
        if (mPipTransitionState.getPipTaskToken() == null) {