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

Commit 18b7e5cd authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Improve cutout related performance

The cutout is now provided as a derived state from insets so it doesn't trigger recompositions every time insets change (but only when the actual cutout changes).
Also it is now read later in several cases, only when needed.

Bug: 417960167
Flag: com.android.systemui.shade_window_goes_around
Flag: com.android.systemui.scene_container
Test: Verify the shade header flicker when moving the window between displays is not there anymore
Change-Id: I0c5157c035901127c1339c49bc3131fc1f2d4ab1
parent bd62aa65
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.platform.LocalContext
@@ -52,7 +53,11 @@ fun ScreenDecorProvider(windowInsets: () -> WindowInsets?, content: @Composable
    val screenCornerRadiusPx =
        remember(context.display.uniqueId) { ScreenDecorationsUtils.getWindowCornerRadius(context) }
    val screenCornerRadiusDp = with(LocalDensity.current) { screenCornerRadiusPx.toDp() }
    val cutout = remember(windowInsets, context) { { windowInsets().toCutout(context) } }
    val cutout =
        remember(windowInsets, context) {
            val cutoutState = derivedStateOf { windowInsets().toCutout(context) }
            ({ cutoutState.value })
        }

    CompositionLocalProvider(
        LocalScreenCornerRadius provides screenCornerRadiusDp,
+6 −3
Original line number Diff line number Diff line
@@ -66,8 +66,7 @@ constructor(
    @Composable
    fun StatusBar(modifier: Modifier = Modifier) {
        val context = LocalContext.current
        val viewDisplayCutout =
            LocalDisplayCutout.current().viewDisplayCutoutKeyguardStatusBarView
        val displayCutout = LocalDisplayCutout.current

        @SuppressLint("InflateParams")
        val view =
@@ -114,7 +113,11 @@ constructor(
            },
            modifier =
                modifier.fillMaxWidth().height { Utils.getStatusBarHeaderHeightKeyguard(context) },
            update = { viewController.setDisplayCutout(viewDisplayCutout) },
            update = {
                viewController.setDisplayCutout(
                    displayCutout().viewDisplayCutoutKeyguardStatusBarView
                )
            },
        )
    }

+2 −1
Original line number Diff line number Diff line
@@ -598,7 +598,7 @@ private fun BatteryIconLegacy(
    val inverseColor =
        Utils.getColorAttrDefaultColor(themedContext, android.R.attr.textColorPrimaryInverse)

    val cutoutLocation = LocalDisplayCutout.current().location
    val cutout = LocalDisplayCutout.current

    AndroidView(
        factory = { context ->
@@ -618,6 +618,7 @@ private fun BatteryIconLegacy(
            batteryIcon
        },
        update = { batteryIcon ->
            val cutoutLocation = cutout().location
            batteryIcon.setPercentShowMode(
                if (useExpandedFormat || cutoutLocation != CutoutLocation.CENTER) {
                    BatteryMeterView.MODE_ESTIMATE
+3 −2
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ private fun ContentScope.SingleShade(
    shadeSession: SaveableSession,
    usingCollapsedLandscapeMedia: Boolean,
) {
    val cutoutLocation = LocalDisplayCutout.current().location
    val cutout = LocalDisplayCutout.current
    val cutoutInsets = WindowInsets.Companion.displayCutout
    mediaHost.expansion = if (usingCollapsedLandscapeMedia && isLandscape()) COLLAPSED else EXPANDED

@@ -285,7 +285,8 @@ private fun ContentScope.SingleShade(
    val shadeHorizontalPadding =
        dimensionResource(id = R.dimen.notification_panel_margin_horizontal)
    val shadeMeasurePolicy =
        remember(mediaInRow) {
        remember(mediaInRow, cutout, cutoutInsets) {
            val cutoutLocation = cutout().location
            SingleShadeMeasurePolicy(
                isMediaInRow = mediaInRow,
                mediaOffset = { mediaOffset.roundToPx() },