Loading packages/SystemUI/src/com/android/systemui/statusbar/BlurUtils.kt +33 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading @@ -71,6 +72,26 @@ open class BlurUtils @Inject constructor( 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}. * Loading @@ -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 } Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt +13 −6 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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) Loading Loading @@ -441,6 +446,8 @@ class NotificationShadeDepthController @Inject constructor( return } updateScheduled = true val (blur, _) = computeBlurAndZoomOut() blurUtils.prepareBlur(root.viewRootImpl, blur) choreographer.postFrameCallback(updateBlurCallback) } Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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)) } Loading Loading @@ -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)) } Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/BlurUtils.kt +33 −6 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading @@ -71,6 +72,26 @@ open class BlurUtils @Inject constructor( 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}. * Loading @@ -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 } Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt +13 −6 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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) Loading Loading @@ -441,6 +446,8 @@ class NotificationShadeDepthController @Inject constructor( return } updateScheduled = true val (blur, _) = computeBlurAndZoomOut() blurUtils.prepareBlur(root.viewRootImpl, blur) choreographer.postFrameCallback(updateBlurCallback) } Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationShadeDepthControllerTest.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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)) } Loading Loading @@ -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)) } Loading