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

Commit 8fb00be7 authored by Massimo Carli's avatar Massimo Carli
Browse files

[27/n] Handle surface visibility in moveAndCrop util

This is necessary because cropping with an empty Rect doesn't
hide the surface but it makes it occupy all the available space.

Flag: com.android.window.flags.app_compat_refactoring
Bug: 384473893
Test: atest WMShellUnitTests:LetterboxUtilsTest

Change-Id: Ie8e9b87b128a477085e60360727483c0ba17ccec
parent 3c74ec20
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ object LetterboxUtils {

    // Utility methods about Transaction usage in Letterbox.
    object Transactions {
        // Sets position and crops in one method.
        // Sets position and crops in one method. The surface is hidden if the crop Rect is empty.
        fun Transaction.moveAndCrop(
            surface: SurfaceControl,
            rect: Rect
@@ -103,6 +103,8 @@ object LetterboxUtils {
                    surface,
                    rect.width(),
                    rect.height()
                )
                ).apply {
                    setVisibility(surface, !rect.isEmpty)
                }
    }
}
+22 −1
Original line number Diff line number Diff line
@@ -115,11 +115,28 @@ class LetterboxUtilsTest : ShellTestCase() {
    }

    @Test
    fun `moveAndCrop invoked Move and then Crop`() {
    fun `moveAndCrop invoked Move and then Crop and Visible`() {
        runTestScenario { r ->
            r.invoke(Rect(1, 2, 51, 62))
            r.verifySetPosition(expectedX = 1f, expectedY = 2f)
            r.verifySetWindowCrop(expectedWidth = 50, expectedHeight = 60)
            r.verifySetVisibility(expectedVisibility = true)
        }
    }

    @Test
    fun `moveAndCrop hide surface if rect has an empty dimension`() {
        runTestScenario { r ->
            r.invoke(Rect(100, 0, 100, 100))
            r.verifySetVisibility(expectedVisibility = false)
        }
    }

    @Test
    fun `moveAndCrop hide surface if rect is empty`() {
        runTestScenario { r ->
            r.invoke(Rect(0, 0, 0, 0))
            r.verifySetVisibility(expectedVisibility = false)
        }
    }

@@ -219,6 +236,10 @@ class LetterboxUtilsTest : ShellTestCase() {
            verify(transaction).setWindowCrop(surface, expectedWidth, expectedHeight)
        }

        fun verifySetVisibility(expectedVisibility: Boolean) {
            verify(transaction).setVisibility(surface, expectedVisibility)
        }

        override fun buildController(): LetterboxController =
            firstLetterboxController.append(secondLetterboxController)
                .append(thirdLetterboxController)