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

Commit 479a5f10 authored by Vania Desmonda's avatar Vania Desmonda
Browse files

Move setPipTransformations to PipSurfaceTransactionHelper

Fixes: 409956661
Test: atest PipDisplayTransferHandlerTest
Flag: EXEMPT minor refactoring
Change-Id: I3fe032d3e5dd8485b415e2dd57060fc223c1ff2f
parent c554a796
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -155,6 +155,30 @@ public class PipSurfaceTransactionHelper {
        return this;
    }


    /**
     * Sets PiP translational, scaling and rotational transformations on a given transaction.
     *
     * @param leash PiP leash to apply the transformations on
     * @param outTransaction transaction to set the matrix on
     * @param baseBounds base bounds from PipBoundsState
     * @param toBounds bounds to position the PiP to
     * @param degrees the angle to rotate the bounds to
     */
    public PipSurfaceTransactionHelper setPipTransformations(SurfaceControl leash,
            SurfaceControl.Transaction outTransaction, Rect baseBounds, Rect toBounds,
            float degrees) {
        final float scale = (float) toBounds.width() / baseBounds.width();

        mTmpTransform.setScale(scale, scale);
        mTmpTransform.postTranslate(toBounds.left, toBounds.top);
        mTmpTransform.postRotate(degrees, toBounds.centerX(), toBounds.centerY());

        round(outTransaction, leash, baseBounds, toBounds);
        outTransaction.setMatrix(leash, mTmpTransform, mTmpFloat9);
        return this;
    }

    /**
     * Interface to standardize {@link SurfaceControl.Transaction} generation across PiP.
     */
+8 −4
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class PipDisplayTransferHandler implements
    private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
            mSurfaceControlTransactionFactory;
    private final RootTaskDisplayAreaOrganizer mRootTaskDisplayAreaOrganizer;
    private final PipSurfaceTransactionHelper mPipSurfaceTransactionHelper;
    private PipSurfaceTransactionHelper mPipSurfaceTransactionHelper;
    private final DisplayController mDisplayController;
    private final PipTransitionState mPipTransitionState;
    private final PipScheduler mPipScheduler;
@@ -174,9 +174,8 @@ public class PipDisplayTransferHandler implements
            final Rect boundsOnCurrentDisplay =
                    MultiDisplayDragMoveBoundsCalculator.convertGlobalDpToLocalPxForRect(
                            globalDpPipBounds, displayLayout);

            mPipScheduler.setPipTransformations(mirror, transaction,
                    boundsOnCurrentDisplay, /* degrees= */ 0);
            mPipSurfaceTransactionHelper.setPipTransformations(mirror, transaction,
                    mPipBoundsState.getBounds(), boundsOnCurrentDisplay, /* degrees= */ 0);
            mRootTaskDisplayAreaOrganizer.reparentToDisplayArea(displayId, mirror, transaction);
            transaction.show(mirror);
        }
@@ -202,4 +201,9 @@ public class PipDisplayTransferHandler implements
            @NonNull PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {
        mSurfaceControlTransactionFactory = factory;
    }

    @VisibleForTesting
    void setSurfaceTransactionHelper(PipSurfaceTransactionHelper surfaceTransactionHelper) {
        mPipSurfaceTransactionHelper = surfaceTransactionHelper;
    }
}
+2 −26
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.hardware.display.DisplayTopology.pxToDp;

import android.app.PictureInPictureParams;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.SystemProperties;
@@ -279,34 +278,11 @@ public class PipScheduler implements PipTransitionState.PipTransitionStateChange
        SurfaceControl leash = mPipTransitionState.getPinnedTaskLeash();
        final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();

        setPipTransformations(leash, tx, toBounds, degrees);
        mPipSurfaceTransactionHelper.setPipTransformations(leash, tx, mPipBoundsState.getBounds(),
                toBounds, degrees);
        tx.apply();
    }

    /**
     * Sets PiP translational, scaling and rotational transformations on a given transaction.
     *
     * @param leash PiP leash to apply the transformations on
     * @param outTransaction transaction to set the matrix on
     * @param toBounds bounds to position the PiP to
     * @param degrees the angle to rotate the bounds to
     */
    public void setPipTransformations(SurfaceControl leash,
            SurfaceControl.Transaction outTransaction, Rect toBounds, float degrees) {
        Matrix transformTensor = new Matrix();
        final float[] mMatrixTmp = new float[9];
        final float scale = (float) toBounds.width() / mPipBoundsState.getBounds().width();

        transformTensor.setScale(scale, scale);
        transformTensor.postTranslate(toBounds.left, toBounds.top);
        transformTensor.postRotate(degrees, toBounds.centerX(), toBounds.centerY());

        mPipSurfaceTransactionHelper.round(outTransaction, leash, mPipBoundsState.getBounds(),
                toBounds);

        outTransaction.setMatrix(leash, transformTensor, mMatrixTmp);
    }

    void startOverlayFadeoutAnimation(@NonNull SurfaceControl overlayLeash,
            boolean withStartDelay, @NonNull Runnable onAnimationEnd) {
        mOverlayFadeoutAnimator = mPipAlphaAnimatorSupplier.get(mContext, overlayLeash,
+25 −3
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
    private val mockTransaction = mock<SurfaceControl.Transaction>()
    private val mockLeash = mock<SurfaceControl>()
    private val mockFactory = mock<PipSurfaceTransactionHelper.SurfaceControlTransactionFactory>()
    private val mockSurfaceTransactionHelper = mock<PipSurfaceTransactionHelper>()

    private lateinit var testableResources: TestableResources
    private lateinit var resources: Resources
@@ -91,6 +92,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
    private lateinit var pipDisplayTransferHandler: PipDisplayTransferHandler

    private val displayIds = intArrayOf(ORIGIN_DISPLAY_ID, TARGET_DISPLAY_ID, SECONDARY_DISPLAY_ID)
    private val mockBounds = Rect()

    @JvmField
    @Rule
@@ -121,6 +123,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
        whenever(mockTransaction.remove(any())).thenReturn(mockTransaction)
        whenever(mockTransaction.show(any())).thenReturn(mockTransaction)
        whenever(mockFactory.transaction).thenReturn(mockTransaction)
        whenever(mockPipBoundsState.bounds).thenReturn(mockBounds)

        defaultTda =
            DisplayAreaInfo(mock<WindowContainerToken>(), ORIGIN_DISPLAY_ID, /* featureId = */ 0)
@@ -143,6 +146,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
                mockRootTaskDisplayAreaOrganizer, mockPipBoundsState, mockDisplayController
            )
        pipDisplayTransferHandler.setSurfaceControlTransactionFactory(mockFactory)
        pipDisplayTransferHandler.setSurfaceTransactionHelper(mockSurfaceTransactionHelper)
    }

    @Test
@@ -197,7 +201,13 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
            any()
        )
        assertThat(pipDisplayTransferHandler.mOnDragMirrorPerDisplayId.isEmpty()).isTrue()
        verify(mockPipScheduler, never()).setPipTransformations(any(), any(), any(), any())
        verify(mockSurfaceTransactionHelper, never()).setPipTransformations(
            any(),
            any(),
            any(),
            any(),
            any()
        )
        verify(mockTransaction, never()).show(any())
        verify(mockTransaction, times(1)).apply()
    }
@@ -217,7 +227,13 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
        )
        assertThat(pipDisplayTransferHandler.mOnDragMirrorPerDisplayId.size).isEqualTo(1)
        assertThat(pipDisplayTransferHandler.mOnDragMirrorPerDisplayId.containsKey(TARGET_DISPLAY_ID)).isTrue()
        verify(mockPipScheduler).setPipTransformations(any(), any(), any(), any())
        verify(mockSurfaceTransactionHelper).setPipTransformations(
            any(),
            any(),
            any(),
            any(),
            any()
        )
        verify(mockTransaction, times(1)).show(any())
        verify(mockTransaction, times(1)).apply()
    }
@@ -247,7 +263,13 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
            )
        ).isTrue()
        assertThat(pipDisplayTransferHandler.mOnDragMirrorPerDisplayId.containsKey(TARGET_DISPLAY_ID)).isTrue()
        verify(mockPipScheduler, times(2)).setPipTransformations(any(), any(), any(), any())
        verify(mockSurfaceTransactionHelper, times(2)).setPipTransformations(
            any(),
            any(),
            any(),
            any(),
            any()
        )
        verify(mockTransaction, times(2)).show(any())
        verify(mockTransaction, times(1)).apply()
    }