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

Commit 105a0553 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Automerger Merge Worker
Browse files

Merge "Set early-wakeup flag a frame earlier when bluring" into udc-dev am:...

Merge "Set early-wakeup flag a frame earlier when bluring" into udc-dev am: ec5ee66b am: 650848b5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22873596



Change-Id: I31d66a9446f33e9c0162015bf350a181a55d2523
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents bcaf9aea 650848b5
Loading
Loading
Loading
Loading
+33 −6
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActivityManager
import android.content.res.Resources
import android.content.res.Resources
import android.os.SystemProperties
import android.os.SystemProperties
import android.os.Trace
import android.os.Trace
import android.os.Trace.TRACE_TAG_APP
import android.util.IndentingPrintWriter
import android.util.IndentingPrintWriter
import android.util.MathUtils
import android.util.MathUtils
import android.view.CrossWindowBlurListeners
import android.view.CrossWindowBlurListeners
@@ -43,8 +44,8 @@ open class BlurUtils @Inject constructor(
) : Dumpable {
) : Dumpable {
    val minBlurRadius = resources.getDimensionPixelSize(R.dimen.min_window_blur_radius)
    val minBlurRadius = resources.getDimensionPixelSize(R.dimen.min_window_blur_radius)
    val maxBlurRadius = resources.getDimensionPixelSize(R.dimen.max_window_blur_radius)
    val maxBlurRadius = resources.getDimensionPixelSize(R.dimen.max_window_blur_radius)
    private val traceCookie = System.identityHashCode(this)
    private var lastAppliedBlur = 0
    private var lastAppliedBlur = 0
    private var earlyWakeupEnabled = false


    init {
    init {
        dumpManager.registerDumpable(javaClass.name, this)
        dumpManager.registerDumpable(javaClass.name, this)
@@ -71,6 +72,26 @@ open class BlurUtils @Inject constructor(
                0f /* maxStart */, 1f /* maxStop */, blur)
                0f /* maxStart */, 1f /* maxStop */, blur)
    }
    }


    /**
     * This method should be called before [applyBlur] so that, if needed, we can set the
     * early-wakeup flag in SurfaceFlinger.
     */
    fun prepareBlur(viewRootImpl: ViewRootImpl?, radius: Int) {
        if (viewRootImpl == null || !viewRootImpl.surfaceControl.isValid ||
            !supportsBlursOnWindows() || earlyWakeupEnabled
        ) {
            return
        }
        if (lastAppliedBlur == 0 && radius != 0) {
            Trace.asyncTraceForTrackBegin(TRACE_TAG_APP, TRACK_NAME, EARLY_WAKEUP_SLICE_NAME, 0)
            earlyWakeupEnabled = true
            createTransaction().use {
                it.setEarlyWakeupStart()
                it.apply()
            }
        }
    }

    /**
    /**
     * Applies background blurs to a {@link ViewRootImpl}.
     * Applies background blurs to a {@link ViewRootImpl}.
     *
     *
@@ -85,14 +106,20 @@ open class BlurUtils @Inject constructor(
        createTransaction().use {
        createTransaction().use {
            if (supportsBlursOnWindows()) {
            if (supportsBlursOnWindows()) {
                it.setBackgroundBlurRadius(viewRootImpl.surfaceControl, radius)
                it.setBackgroundBlurRadius(viewRootImpl.surfaceControl, radius)
                if (lastAppliedBlur == 0 && radius != 0) {
                if (!earlyWakeupEnabled && lastAppliedBlur == 0 && radius != 0) {
                    Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, TRACK_NAME,
                    Trace.asyncTraceForTrackBegin(
                            EARLY_WAKEUP_SLICE_NAME, traceCookie)
                        TRACE_TAG_APP,
                        TRACK_NAME,
                        EARLY_WAKEUP_SLICE_NAME,
                        0
                    )
                    it.setEarlyWakeupStart()
                    it.setEarlyWakeupStart()
                    earlyWakeupEnabled = true
                }
                }
                if (lastAppliedBlur != 0 && radius == 0) {
                if (earlyWakeupEnabled && lastAppliedBlur != 0 && radius == 0) {
                    it.setEarlyWakeupEnd()
                    it.setEarlyWakeupEnd()
                    Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, TRACK_NAME, traceCookie)
                    Trace.asyncTraceForTrackEnd(TRACE_TAG_APP, TRACK_NAME, 0)
                    earlyWakeupEnabled = false
                }
                }
                lastAppliedBlur = radius
                lastAppliedBlur = radius
            }
            }
+13 −6
Original line number Original line Diff line number Diff line
@@ -189,12 +189,7 @@ class NotificationShadeDepthController @Inject constructor(
            scheduleUpdate()
            scheduleUpdate()
        }
        }


    /**
    private fun computeBlurAndZoomOut(): Pair<Int, Float> {
     * Callback that updates the window blur value and is called only once per frame.
     */
    @VisibleForTesting
    val updateBlurCallback = Choreographer.FrameCallback {
        updateScheduled = false
        val animationRadius = MathUtils.constrain(shadeAnimation.radius,
        val animationRadius = MathUtils.constrain(shadeAnimation.radius,
                blurUtils.minBlurRadius.toFloat(), blurUtils.maxBlurRadius.toFloat())
                blurUtils.minBlurRadius.toFloat(), blurUtils.maxBlurRadius.toFloat())
        val expansionRadius = blurUtils.blurRadiusOfRatio(
        val expansionRadius = blurUtils.blurRadiusOfRatio(
@@ -232,6 +227,16 @@ class NotificationShadeDepthController @Inject constructor(
        // Brightness slider removes blur, but doesn't affect zooms
        // Brightness slider removes blur, but doesn't affect zooms
        blur = (blur * (1f - brightnessMirrorSpring.ratio)).toInt()
        blur = (blur * (1f - brightnessMirrorSpring.ratio)).toInt()


        return Pair(blur, zoomOut)
    }

    /**
     * Callback that updates the window blur value and is called only once per frame.
     */
    @VisibleForTesting
    val updateBlurCallback = Choreographer.FrameCallback {
        updateScheduled = false
        val (blur, zoomOut) = computeBlurAndZoomOut()
        val opaque = scrimsVisible && !blursDisabledForAppLaunch
        val opaque = scrimsVisible && !blursDisabledForAppLaunch
        Trace.traceCounter(Trace.TRACE_TAG_APP, "shade_blur_radius", blur)
        Trace.traceCounter(Trace.TRACE_TAG_APP, "shade_blur_radius", blur)
        blurUtils.applyBlur(root.viewRootImpl, blur, opaque)
        blurUtils.applyBlur(root.viewRootImpl, blur, opaque)
@@ -441,6 +446,8 @@ class NotificationShadeDepthController @Inject constructor(
            return
            return
        }
        }
        updateScheduled = true
        updateScheduled = true
        val (blur, _) = computeBlurAndZoomOut()
        blurUtils.prepareBlur(root.viewRootImpl, blur)
        choreographer.postFrameCallback(updateBlurCallback)
        choreographer.postFrameCallback(updateBlurCallback)
    }
    }


+2 −0
Original line number Original line Diff line number Diff line
@@ -356,6 +356,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
    @Test
    @Test
    fun ignoreShadeBlurUntilHidden_schedulesFrame() {
    fun ignoreShadeBlurUntilHidden_schedulesFrame() {
        notificationShadeDepthController.blursDisabledForAppLaunch = true
        notificationShadeDepthController.blursDisabledForAppLaunch = true
        verify(blurUtils).prepareBlur(any(), anyInt())
        verify(choreographer)
        verify(choreographer)
            .postFrameCallback(eq(notificationShadeDepthController.updateBlurCallback))
            .postFrameCallback(eq(notificationShadeDepthController.updateBlurCallback))
    }
    }
@@ -419,6 +420,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
        notificationShadeDepthController.updateBlurCallback.doFrame(0)
        notificationShadeDepthController.updateBlurCallback.doFrame(0)
        verify(notificationShadeWindowController).setBackgroundBlurRadius(eq(0))
        verify(notificationShadeWindowController).setBackgroundBlurRadius(eq(0))
        verify(wallpaperController).setNotificationShadeZoom(eq(1f))
        verify(wallpaperController).setNotificationShadeZoom(eq(1f))
        verify(blurUtils).prepareBlur(any(), eq(0))
        verify(blurUtils).applyBlur(eq(viewRootImpl), eq(0), eq(false))
        verify(blurUtils).applyBlur(eq(viewRootImpl), eq(0), eq(false))
    }
    }