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

Commit 444af169 authored by Massimo Carli's avatar Massimo Carli
Browse files

[70/n] Improved Strategy for Translucent activities

Always use a single letterbox surface when rounded corners are
enabled unless the activity is translucent.

For translucent activities we always use multiple surfaces
without rounded corners

Flag: EXEMPT Refactoring
Bug: 377875146
Test: atest WMShellUnitTests:LetterboxControllerStrategyTest

Change-Id: Ib779b15eb99eae0e46dccc50b7fab50ca0f8fca2
parent 3f18e6fb
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -38,20 +38,18 @@ class LetterboxControllerStrategy @Inject constructor(
    private var currentMode: LetterboxMode = SINGLE_SURFACE

    fun configureLetterboxMode(event: LetterboxLifecycleEvent) {
        // TODO(b/377875146): Define criteria for switching between [LetterboxMode]s.
        // At the moment, we use the presence of rounded corners to understand if to use a single
        // surface or multiple surfaces for the letterbox areas. This rule will change when
        // considering transparent activities which won't have rounded corners leading to the
        // [MULTIPLE_SURFACES] option.
        // The chosen strategy will depend on performance considerations,
        // including surface memory usage and the impact of the rounded corners solution.
        // In case of Bubble we always use a single surface as simple optimisation for no
        // transparent activities.
        currentMode =
            if (event.isBubble || letterboxConfiguration.isLetterboxActivityCornersRounded()) {
                SINGLE_SURFACE
            } else {
                MULTIPLE_SURFACES
        // Decides whether to use a single surface or multiple surfaces for the letterbox.
        // The primary trade-off is memory usage versus rendering performance.
        //
        // A single surface is used for letterboxes with rounded corners on opaque activities
        // and always for Bubble. In all other cases, such as for letterboxes with straight corners
        // or for those with rounded corners on a translucent activity, we use multiple surfaces to
        // ensure better performance.
        currentMode = when {
            event.isBubble -> SINGLE_SURFACE
            event.isTranslucent -> MULTIPLE_SURFACES
            letterboxConfiguration.isLetterboxActivityCornersRounded() -> SINGLE_SURFACE
            else -> MULTIPLE_SURFACES
        }
    }

+20 −2
Original line number Diff line number Diff line
@@ -40,14 +40,31 @@ import org.junit.runner.RunWith
class LetterboxControllerStrategyTest : ShellTestCase() {

    @Test
    fun `LetterboxMode is SINGLE_SURFACE with rounded corners`() {
    fun `LetterboxMode is SINGLE_SURFACE with rounded corners and Not Translucent`() {
        runTestScenario { r ->
            r.configureRoundedCornerRadius(true)
            r.configureLetterboxMode()
            r.configureLetterboxMode(
                r.SIMPLE_TEST_EVENT.copy(
                    isTranslucent = false
                )
            )
            r.checkLetterboxModeIsSingle()
        }
    }

    @Test
    fun `LetterboxMode is MULTI_SURFACE with rounded corners but Translucent`() {
        runTestScenario { r ->
            r.configureRoundedCornerRadius(true)
            r.configureLetterboxMode(
                r.SIMPLE_TEST_EVENT.copy(
                    isTranslucent = true
                )
            )
            r.checkLetterboxModeIsMultiple()
        }
    }

    @Test
    fun `LetterboxMode is SINGLE_SURFACE with Bubble Events`() {
        runTestScenario { r ->
@@ -83,6 +100,7 @@ class LetterboxControllerStrategyTest : ShellTestCase() {
        companion object {
            @JvmStatic
            private val ROUNDED_CORNERS_TRUE = 10

            @JvmStatic
            private val ROUNDED_CORNERS_FALSE = 0
        }