From 1ff9421785955a40549e85abb11a19413e3cdeb5 Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Thu, 1 May 2025 21:37:07 +0000 Subject: [PATCH] Performance improvements for Launcher blurs. - Ignore blur changes smaller than 1dp unless going to/from 0. - Don't apply depth animation during app launch from blurred All Apps. - Use DepthController directly rather than creating a new one for other app launch animaitons. Avoids extraneous memory and performance overhead. Bug: 411292920 Bug: 410973453 Bug: 408284263 Test: forrest perf tests Flag: com.android.launcher3.all_apps_blur Change-Id: Id5c8e71b19ebb8f1c1b82f8c5c76785e001017af --- .../launcher3/QuickstepTransitionManager.java | 52 ++++++++----------- .../quickstep/util/BaseDepthController.java | 48 ++++++++++++----- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java index d403b81faa..1a616d0837 100644 --- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java +++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java @@ -99,7 +99,6 @@ import android.provider.Settings; import android.util.Log; import android.util.Pair; import android.util.Size; -import android.view.CrossWindowBlurListeners; import android.view.IRemoteAnimationFinishedCallback; import android.view.RemoteAnimationAdapter; import android.view.RemoteAnimationDefinition; @@ -133,7 +132,6 @@ import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.shortcuts.DeepShortcutView; -import com.android.launcher3.statehandlers.DepthController; import com.android.launcher3.taskbar.LauncherTaskbarUIController; import com.android.launcher3.testing.shared.ResourceUtils; import com.android.launcher3.touch.PagedOrientationHandler; @@ -1138,16 +1136,25 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener } /** Returns animator that controls depth/blur of the background during app/widget opening. */ - private ObjectAnimator getBackgroundAnimator() { + private Animator getBackgroundAnimator() { + LauncherState launcherState = mLauncher.getStateManager().getState(); + boolean currentlyBlurringAllApps = Flags.allAppsBlur() && launcherState == ALL_APPS + && mLauncher.isBackgroundBlurEnabled(); + if (currentlyBlurringAllApps) { + // Don't additionally animate/blur the background for this launch (All Apps content + // already scales slightly to simulate depth). + return new AnimatorSet(); + } + // When launching an app from overview that doesn't map to a task, we still want to just // blur the wallpaper instead of the launcher surface as well - boolean allowBlurringLauncher = mLauncher.getStateManager().getState() != OVERVIEW - && BlurUtils.supportsBlursOnWindows(); + boolean allowBlurringLauncher = + launcherState != OVERVIEW && BlurUtils.supportsBlursOnWindows(); - LaunchDepthController depthController = new LaunchDepthController(mLauncher); - ObjectAnimator backgroundRadiusAnim = ObjectAnimator.ofFloat(depthController.stateDepth, - MULTI_PROPERTY_VALUE, BACKGROUND_APP.getDepth(mLauncher)) - .setDuration(APP_LAUNCH_DURATION); + ObjectAnimator backgroundRadiusAnim = ObjectAnimator.ofFloat( + mLauncher.getDepthController().stateDepth, MULTI_PROPERTY_VALUE, + BACKGROUND_APP.getDepth(mLauncher)) + .setDuration(APP_LAUNCH_DURATION); if (allowBlurringLauncher) { // Create a temporary effect layer, that lives on top of launcher, so we can apply @@ -1168,18 +1175,14 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener .setEffectLayer() .build(); - backgroundRadiusAnim.addListener(AnimatorListeners.forEndCallback(() -> - new SurfaceControl.Transaction().remove(dimLayer).apply())); + backgroundRadiusAnim.addListener(AnimatorListeners.forEndCallback(() -> { + // Use try-with-resources to ensure the transaction gets closed. + try (SurfaceControl.Transaction transaction = new SurfaceControl.Transaction()) { + transaction.remove(dimLayer).apply(); + } + })); } - backgroundRadiusAnim.addListener( - AnimatorListeners.forEndCallback(() -> { - // reset the depth to match the main depth controller's depth - depthController.stateDepth - .setValue(mLauncher.getDepthController().stateDepth.getValue()); - depthController.dispose(); - })); - return backgroundRadiusAnim; } @@ -2396,15 +2399,4 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener return Utilities.mapToRange(progress, start, end, 1, 0, ACCELERATE_1_5); } } - - private static class LaunchDepthController extends DepthController { - LaunchDepthController(QuickstepLauncher launcher) { - super(launcher); - setCrossWindowBlursEnabled( - CrossWindowBlurListeners.getInstance().isCrossWindowBlurEnabled()); - // Make sure that the starting value matches the current depth set by the main - // controller. - stateDepth.setValue(launcher.getDepthController().stateDepth.getValue()); - } - } } diff --git a/quickstep/src/com/android/quickstep/util/BaseDepthController.java b/quickstep/src/com/android/quickstep/util/BaseDepthController.java index e749959b31..5961588924 100644 --- a/quickstep/src/com/android/quickstep/util/BaseDepthController.java +++ b/quickstep/src/com/android/quickstep/util/BaseDepthController.java @@ -179,8 +179,21 @@ public class BaseDepthController { applyDepthAndBlur(null, /* applyImmediately */ false); } + /** + * Applies depth and blur to the launcher. + * + * @param transaction optional Surface to apply to the blur to. + * @param applyImmediately whether to apply the blur immediately or defer to the next frame. + */ protected void applyDepthAndBlur(SurfaceControl.Transaction transaction, boolean applyImmediately) { + try (transaction) { + applyDepthAndBlurInternal(transaction, applyImmediately); + } + } + + private void applyDepthAndBlurInternal(SurfaceControl.Transaction transaction, + boolean applyImmediately) { float depth = mDepth; IBinder windowToken = mLauncher.getRootView().getWindowToken(); if (windowToken != null) { @@ -218,15 +231,25 @@ public class BaseDepthController { } else { blurAmount = depth; } - mCurrentBlur = mBlursEnabled && !hasOpaqueBg ? (int) (blurAmount * mMaxBlurRadius) : 0; - SurfaceControl blurSurface = enableOverviewBackgroundWallpaperBlur() && mBlurSurface != null ? mBlurSurface : mBaseSurface; - if (transaction == null) { - transaction = createTransaction(); + + int previousBlur = mCurrentBlur; + int newBlur = mBlursEnabled && !hasOpaqueBg ? (int) (blurAmount * mMaxBlurRadius) : 0; + int delta = Math.abs(newBlur - previousBlur); + // Don't skip blur if a transaction is provided. + boolean skipSimilarBlur = transaction == null; + if (skipSimilarBlur && delta < Utilities.dpToPx(1) && newBlur != 0 && previousBlur != 0) { + Log.d(TAG, "Skipping small blur delta. newBlur: " + newBlur + " previousBlur: " + + previousBlur + " delta: " + delta + " surface: " + blurSurface); + return; } - final SurfaceControl.Transaction finalTransaction = transaction; + mCurrentBlur = newBlur; + Log.v(TAG, "Applying blur: " + mCurrentBlur + " to " + blurSurface); + + final SurfaceControl.Transaction finalTransaction = + transaction == null ? createTransaction() : transaction; try (finalTransaction) { finalTransaction.setBackgroundBlurRadius(blurSurface, mCurrentBlur) .setOpaque(blurSurface, isSurfaceOpaque); @@ -292,14 +315,13 @@ public class BaseDepthController { * Sets the lowest surface that should not be blurred. *

* Blur is applied to below {@link #mBaseSurfaceOverride}. When set to {@code null}, blur is - * applied - * to below {@link #mBaseSurface}. + * applied to below {@link #mBaseSurface}. *

*/ public void setBaseSurfaceOverride(@Nullable SurfaceControl baseSurfaceOverride) { if (mBaseSurfaceOverride != baseSurfaceOverride) { boolean applyImmediately = mBaseSurfaceOverride != null && baseSurfaceOverride == null; - this.mBaseSurfaceOverride = baseSurfaceOverride; + mBaseSurfaceOverride = baseSurfaceOverride; Log.d(TAG, "setBaseSurfaceOverride: applying blur behind leash " + baseSurfaceOverride); SurfaceControl.Transaction transaction = setupBlurSurface(); applyDepthAndBlur(transaction, applyImmediately); @@ -324,12 +346,10 @@ public class BaseDepthController { } transaction.setRelativeLayer(mBlurSurface, mBaseSurfaceOverride, -1); Log.d(TAG, "setupBlurSurface: relayering to leash " + mBaseSurfaceOverride); - } else { - if (mBlurSurface != null) { - Log.d(TAG, "setupBlurSurface: removing blur surface " + mBlurSurface); - transaction = createTransaction().remove(mBlurSurface); - mBlurSurface = null; - } + } else if (mBlurSurface != null) { + Log.d(TAG, "setupBlurSurface: removing blur surface " + mBlurSurface); + transaction = createTransaction().remove(mBlurSurface); + mBlurSurface = null; } return transaction; }