From 7e1bb6e4a4bb5ec06ea2290645e918d155276b62 Mon Sep 17 00:00:00 2001 From: Galia Peycheva Date: Thu, 12 Nov 2020 13:45:32 +0100 Subject: [PATCH] Move background blur to Dim layer The way background blur is expected to work is the same as the dim layer - it should be cropped to the task/displayArea bounds and dim layers shouldn't stack on top of each other. This CL makes the background blur benefit from that and sets it on the dim surface control. Bug: 171679369 Test: m && flash Test: atest DimmerTests Change-Id: If64cc585a8a74ab5f3dc0757e25556fd89b5eaec --- .../java/com/android/server/wm/Dimmer.java | 19 +++++++++------- .../com/android/server/wm/WindowState.java | 11 ++++++---- .../server/wm/WindowStateAnimator.java | 1 - .../server/wm/WindowSurfaceController.java | 22 ------------------- .../com/android/server/wm/DimmerTests.java | 2 +- .../android/server/wm/StubTransaction.java | 5 +++++ 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/services/core/java/com/android/server/wm/Dimmer.java b/services/core/java/com/android/server/wm/Dimmer.java index 07729d17d7b2e..029056ac26fbe 100644 --- a/services/core/java/com/android/server/wm/Dimmer.java +++ b/services/core/java/com/android/server/wm/Dimmer.java @@ -204,7 +204,7 @@ class Dimmer { } private void dim(SurfaceControl.Transaction t, WindowContainer container, int relativeLayer, - float alpha) { + float alpha, int blurRadius) { final DimState d = getDimState(container); if (d == null) { @@ -220,6 +220,7 @@ class Dimmer { t.setLayer(d.mDimLayer, Integer.MAX_VALUE); } t.setAlpha(d.mDimLayer, alpha); + t.setBackgroundBlurRadius(d.mDimLayer, blurRadius); d.mDimming = true; } @@ -247,7 +248,7 @@ class Dimmer { * @param alpha The alpha at which to Dim. */ void dimAbove(SurfaceControl.Transaction t, float alpha) { - dim(t, null, 1, alpha); + dim(t, null, 1, alpha, 0); } /** @@ -260,19 +261,21 @@ class Dimmer { * @param alpha The alpha at which to Dim. */ void dimAbove(SurfaceControl.Transaction t, WindowContainer container, float alpha) { - dim(t, container, 1, alpha); + dim(t, container, 1, alpha, 0); } /** * Like {@link #dimAbove} but places the dim below the given container. * - * @param t A transaction in which to apply the Dim. - * @param container The container which to dim below. Should be a child of our host. - * @param alpha The alpha at which to Dim. + * @param t A transaction in which to apply the Dim. + * @param container The container which to dim below. Should be a child of our host. + * @param alpha The alpha at which to Dim. + * @param blurRadius The amount of blur added to the Dim. */ - void dimBelow(SurfaceControl.Transaction t, WindowContainer container, float alpha) { - dim(t, container, -1, alpha); + void dimBelow(SurfaceControl.Transaction t, WindowContainer container, float alpha, + int blurRadius) { + dim(t, container, -1, alpha, blurRadius); } /** diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 32b84a8d0a2c1..e0542fc612a7c 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -5228,14 +5228,17 @@ class WindowState extends WindowContainer implements WindowManagerP if (!mAnimatingExit && mAppDied) { mIsDimming = true; getDimmer().dimAbove(getSyncTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW); - } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) { - // Only show a dim behind when the following is satisfied: - // 1. The window has the flag FLAG_DIM_BEHIND + } else if (((mAttrs.flags & FLAG_DIM_BEHIND) != 0 || mAttrs.backgroundBlurRadius != 0) + && isVisibleNow() && !mHidden) { + // Only show the Dimmer when the following is satisfied: + // 1. The window has the flag FLAG_DIM_BEHIND or background blur is requested // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting. // 3. The WS is considered visible according to the isVisible() method // 4. The WS is not hidden. mIsDimming = true; - getDimmer().dimBelow(getSyncTransaction(), this, mAttrs.dimAmount); + final float dimAmount = (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? mAttrs.dimAmount : 0; + getDimmer().dimBelow( + getSyncTransaction(), this, mAttrs.dimAmount, mAttrs.backgroundBlurRadius); } } diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index 068d0dfd0602d..ab6a4120b0308 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -795,7 +795,6 @@ class WindowStateAnimator { if (displayed) { w.mToken.hasVisible = true; - mSurfaceController.setBackgroundBlurRadius(w.mAttrs.backgroundBlurRadius); } } diff --git a/services/core/java/com/android/server/wm/WindowSurfaceController.java b/services/core/java/com/android/server/wm/WindowSurfaceController.java index 788f004076713..f59eba93643ac 100644 --- a/services/core/java/com/android/server/wm/WindowSurfaceController.java +++ b/services/core/java/com/android/server/wm/WindowSurfaceController.java @@ -64,8 +64,6 @@ class WindowSurfaceController { private float mLastDsdy = 0; private float mLastDtdy = 1; - private int mLastBackgroundBlurRadius = 0; - private float mSurfaceAlpha = 0; private int mSurfaceLayer = 0; @@ -242,26 +240,6 @@ class WindowSurfaceController { } } - void setBackgroundBlurRadius(int radius) { - ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE backgroundBlur=%o: %s", radius, title); - - if (mSurfaceControl == null || radius == mLastBackgroundBlurRadius) { - return; - } - mLastBackgroundBlurRadius = radius; - - if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setBackgroundBlurRadius"); - mService.openSurfaceTransaction(); - try { - getGlobalTransaction().setBackgroundBlurRadius(mSurfaceControl, radius); - } finally { - mService.closeSurfaceTransaction("setBackgroundBlurRadius"); - if (SHOW_LIGHT_TRANSACTIONS) { - Slog.i(TAG, "<<< CLOSE TRANSACTION setBackgroundBlurRadius"); - } - } - } - void setSecure(boolean isSecure) { ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isSecure=%b: %s", isSecure, title); diff --git a/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java b/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java index f7beb74688d62..3beb7f2049dfa 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java @@ -199,7 +199,7 @@ public class DimmerTests extends WindowTestsBase { mHost.addChild(child, 0); final float alpha = 0.8f; - mDimmer.dimBelow(mTransaction, child, alpha); + mDimmer.dimBelow(mTransaction, child, alpha, 0); SurfaceControl dimLayer = getDimLayer(); assertNotNull("Dimmer should have created a surface", dimLayer); diff --git a/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java b/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java index ecbfac8b091b8..eff691938b249 100644 --- a/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java +++ b/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java @@ -135,6 +135,11 @@ public class StubTransaction extends SurfaceControl.Transaction { return this; } + @Override + public SurfaceControl.Transaction setBackgroundBlurRadius(SurfaceControl sc, int radius) { + return this; + } + @Override public SurfaceControl.Transaction setLayerStack(SurfaceControl sc, int layerStack) { return this;