diff options
3 files changed, 48 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BlurUtils.kt b/packages/SystemUI/src/com/android/systemui/statusbar/BlurUtils.kt index 07b686948d7f..b6970aef6cad 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BlurUtils.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BlurUtils.kt @@ -20,6 +20,7 @@ import android.app.ActivityManager import android.content.res.Resources import android.os.SystemProperties import android.os.Trace +import android.os.Trace.TRACE_TAG_APP import android.util.IndentingPrintWriter import android.util.MathUtils import android.view.CrossWindowBlurListeners @@ -43,8 +44,8 @@ open class BlurUtils @Inject constructor( ) : Dumpable { val minBlurRadius = resources.getDimensionPixelSize(R.dimen.min_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 earlyWakeupEnabled = false init { dumpManager.registerDumpable(javaClass.name, this) @@ -72,6 +73,26 @@ open class BlurUtils @Inject constructor( } /** + * 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}. * * @param viewRootImpl The window root. @@ -85,14 +106,20 @@ open class BlurUtils @Inject constructor( createTransaction().use { if (supportsBlursOnWindows()) { it.setBackgroundBlurRadius(viewRootImpl.surfaceControl, radius) - if (lastAppliedBlur == 0 && radius != 0) { - Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, TRACK_NAME, - EARLY_WAKEUP_SLICE_NAME, traceCookie) + if (!earlyWakeupEnabled && lastAppliedBlur == 0 && radius != 0) { + Trace.asyncTraceForTrackBegin( + TRACE_TAG_APP, + TRACK_NAME, + EARLY_WAKEUP_SLICE_NAME, + 0 + ) it.setEarlyWakeupStart() + earlyWakeupEnabled = true } - if (lastAppliedBlur != 0 && radius == 0) { + if (earlyWakeupEnabled && lastAppliedBlur != 0 && radius == 0) { it.setEarlyWakeupEnd() - Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, TRACK_NAME, traceCookie) + Trace.asyncTraceForTrackEnd(TRACE_TAG_APP, TRACK_NAME, 0) + earlyWakeupEnabled = false } lastAppliedBlur = radius } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt index 8dc78426da7d..a3bd247668fe 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt @@ -189,12 +189,7 @@ class NotificationShadeDepthController @Inject constructor( scheduleUpdate() } - /** - * Callback that updates the window blur value and is called only once per frame. - */ - @VisibleForTesting - val updateBlurCallback = Choreographer.FrameCallback { - updateScheduled = false + private fun computeBlurAndZoomOut(): Pair<Int, Float> { val animationRadius = MathUtils.constrain(shadeAnimation.radius, blurUtils.minBlurRadius.toFloat(), blurUtils.maxBlurRadius.toFloat()) val expansionRadius = blurUtils.blurRadiusOfRatio( @@ -232,6 +227,16 @@ class NotificationShadeDepthController @Inject constructor( // Brightness slider removes blur, but doesn't affect zooms 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 Trace.traceCounter(Trace.TRACE_TAG_APP, "shade_blur_radius", blur) blurUtils.applyBlur(root.viewRootImpl, blur, opaque) @@ -441,6 +446,8 @@ class NotificationShadeDepthController @Inject constructor( return } updateScheduled = true + val (blur, _) = computeBlurAndZoomOut() + blurUtils.prepareBlur(root.viewRootImpl, blur) choreographer.postFrameCallback(updateBlurCallback) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt index beaf3009125b..c49f179c925e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt @@ -356,6 +356,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { @Test fun ignoreShadeBlurUntilHidden_schedulesFrame() { notificationShadeDepthController.blursDisabledForAppLaunch = true + verify(blurUtils).prepareBlur(any(), anyInt()) verify(choreographer) .postFrameCallback(eq(notificationShadeDepthController.updateBlurCallback)) } @@ -419,6 +420,7 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() { notificationShadeDepthController.updateBlurCallback.doFrame(0) verify(notificationShadeWindowController).setBackgroundBlurRadius(eq(0)) verify(wallpaperController).setNotificationShadeZoom(eq(1f)) + verify(blurUtils).prepareBlur(any(), eq(0)) verify(blurUtils).applyBlur(eq(viewRootImpl), eq(0), eq(false)) } |