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

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

Change-Id: If55dc13bacf739d94970a3aa16baf7f4d850e1b0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Peter Kalauskas
2023-04-27 17:28:17 +00:00
committed by Automerger Merge Worker
3 changed files with 48 additions and 12 deletions

View File

@@ -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)
@@ -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}.
*
@@ -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
}

View File

@@ -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)
}

View File

@@ -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))
}