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

Commit 3cfc93c3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use immediate transactions to start/end early wakeup when surface...

Merge "Use immediate transactions to start/end early wakeup when surface control is not valid." into main
parents 60187a84 00fd2fe0
Loading
Loading
Loading
Loading
+31 −8
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.util.Log
import android.util.MathUtils
import android.view.CrossWindowBlurListeners
import android.view.CrossWindowBlurListeners.CROSS_WINDOW_BLUR_SUPPORTED
import android.view.SurfaceControl
import android.view.SyncRtSurfaceTransactionApplier
import android.view.ViewRootImpl
import androidx.annotation.VisibleForTesting
@@ -81,6 +82,9 @@ constructor(
        earlyWakeupInfo.trace = BlurUtils::class.java.getName()
    }

    @VisibleForTesting
    open fun createTransaction(): SurfaceControl.Transaction = SurfaceControl.Transaction()

    /** Translates a ratio from 0 to 1 to a blur radius in pixels. */
    fun blurRadiusOfRatio(ratio: Float): Float {
        if (ratio == 0f) {
@@ -190,22 +194,38 @@ constructor(

    @SuppressLint("MissingPermission")
    private fun earlyWakeupStart(
        builder: SyncRtSurfaceTransactionApplier.SurfaceParams.Builder,
        builder: SyncRtSurfaceTransactionApplier.SurfaceParams.Builder?,
        traceMethodName: String,
    ) {
        v("earlyWakeupStart from $traceMethodName")
        Trace.asyncTraceForTrackBegin(TRACE_TAG_APP, TRACK_NAME, traceMethodName, 0)
        if (builder != null) {
            builder.withEarlyWakeupStart(earlyWakeupInfo)
        } else {
            Log.w(
                TAG,
                "surfaceControl is not valid, using immediate transaction to set early wakeup",
            )
            createTransaction().use { it.setEarlyWakeupStart(earlyWakeupInfo).apply() }
        }
        earlyWakeupEnabled = true
    }

    @SuppressLint("MissingPermission")
    private fun earlyWakeupEnd(
        builder: SyncRtSurfaceTransactionApplier.SurfaceParams.Builder,
        builder: SyncRtSurfaceTransactionApplier.SurfaceParams.Builder?,
        loggingContext: String,
    ) {
        v("earlyWakeupEnd from $loggingContext")
        if (builder != null) {
            builder.withEarlyWakeupEnd(earlyWakeupInfo)
        } else {
            Log.w(
                TAG,
                "surfaceControl is not valid, using immediate transaction to reset early wakeup",
            )
            createTransaction().use { it.setEarlyWakeupEnd(earlyWakeupInfo).apply() }
        }
        Trace.asyncTraceForTrackEnd(TRACE_TAG_APP, TRACK_NAME, 0)
        earlyWakeupEnabled = false
    }
@@ -260,13 +280,16 @@ constructor(
        persistentEarlyWakeupRequired = persistentWakeup
        if (viewRootImpl == null || !supportsBlursOnWindows()) return

        updateTransactionApplier(viewRootImpl)
        val builder =
            if (!Flags.instantHideShade() || viewRootImpl.surfaceControl?.isValid == true) {
                updateTransactionApplier(viewRootImpl)
                SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(viewRootImpl.surfaceControl)
            } else {
                null
            }
        if (persistentEarlyWakeupRequired) {
            if (earlyWakeupEnabled) return
            earlyWakeupStart(builder, "setEarlyWakeup")
            transactionApplier.scheduleApply(builder.build())
        } else {
            if (!earlyWakeupEnabled) return
            if (lastAppliedBlur > 0) {
@@ -278,8 +301,8 @@ constructor(
                )
            }
            earlyWakeupEnd(builder, "resetEarlyWakeup")
            transactionApplier.scheduleApply(builder.build())
        }
        builder?.let { transactionApplier.scheduleApply(it.build()) }
    }

    companion object {