summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Marzia Favaro <marziana@google.com> 2025-03-10 10:59:41 +0000
committer Marzia Favaro <marziana@google.com> 2025-03-10 14:47:26 +0000
commit89341c12f60b1253327748c2ef8fbc43e927eb1e (patch)
tree034ffad4a272a85d9bc832b6ed41b16923b168ea
parentb4a1b07e0c166da880f0ef48f78623604ca1f518 (diff)
Do not create dim layer until it gets a valid dimming request
If a window requests a dim of 0 and no blur, the dim surface gets created (because technically someone is requesting to dim) and then immediately destroyed (because alpha=0, blur=0 means that this layer should be destroyed as it's useless). We can postpone creating a new surface until the window requests a non 0 value. Bug: 401449608 Test: DimmerTests Flag: EXEMPT minor change Change-Id: I11c97ae6401e3151df4941a5ec6ad42bb94357ce
-rw-r--r--services/core/java/com/android/server/wm/Dimmer.java7
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DimmerTests.java29
2 files changed, 34 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/wm/Dimmer.java b/services/core/java/com/android/server/wm/Dimmer.java
index 25fdf89afad1..2798e843d6dd 100644
--- a/services/core/java/com/android/server/wm/Dimmer.java
+++ b/services/core/java/com/android/server/wm/Dimmer.java
@@ -211,14 +211,17 @@ class Dimmer {
* child should call setAppearance again to request the Dim to continue.
* If multiple containers call this method, only the changes relative to the topmost will be
* applied.
+ * The creation of the dim layer is delayed if the requested dim and blur are 0.
* @param dimmingContainer Container requesting the dim
* @param alpha Dim amount
* @param blurRadius Blur amount
*/
protected void adjustAppearance(@NonNull WindowState dimmingContainer,
float alpha, int blurRadius) {
- final DimState d = obtainDimState(dimmingContainer);
- d.prepareLookChange(alpha, blurRadius);
+ if (mDimState != null || (alpha != 0 || blurRadius != 0)) {
+ final DimState d = obtainDimState(dimmingContainer);
+ d.prepareLookChange(alpha, blurRadius);
+ }
}
/**
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 a30591ea7b15..9486bc522a9c 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DimmerTests.java
@@ -25,6 +25,7 @@ import static com.android.server.wm.utils.LastCallVerifier.lastCall;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -432,4 +433,32 @@ public class DimmerTests extends WindowTestsBase {
verify(mTransaction, never()).setAlpha(dimLayer, 0.5f);
verify(mTransaction).setAlpha(dimLayer, 0.9f);
}
+
+ /**
+ * A window requesting to dim to 0 and without blur would cause the dim to be created and
+ * destroyed continuously.
+ * Ensure the dim layer is not created until the window is requesting valid values.
+ */
+ @Test
+ public void testDimNotCreatedIfNoAlphaNoBlur() {
+ mDimmer.adjustAppearance(mChild1, 0.0f, 0);
+ mDimmer.adjustPosition(mChild1, mChild1);
+ assertNull(mDimmer.getDimLayer());
+ mDimmer.updateDims(mTransaction);
+ assertNull(mDimmer.getDimLayer());
+
+ mDimmer.adjustAppearance(mChild1, 0.9f, 0);
+ mDimmer.adjustPosition(mChild1, mChild1);
+ assertNotNull(mDimmer.getDimLayer());
+ }
+
+ /**
+ * If there is a blur, then the dim layer is created even though alpha is 0
+ */
+ @Test
+ public void testDimCreatedIfNoAlphaButHasBlur() {
+ mDimmer.adjustAppearance(mChild1, 0.0f, 10);
+ mDimmer.adjustPosition(mChild1, mChild1);
+ assertNotNull(mDimmer.getDimLayer());
+ }
}