From 975e9ab45ba91482ed0dd1159d4fa77d83bdb71c Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Mon, 20 Dec 2021 17:26:46 +0100 Subject: [PATCH 1/2] Use TDA for background color instead of new color layer Bug: 205274345 Bug: 202856837 Bug: 203567491 Bug: 209936970 Test: Run task animations and make sure background color shows Merged-In: I57fa88c6f45adca9e3301b39e868bd127644b76f Change-Id: I57fa88c6f45adca9e3301b39e868bd127644b76f (cherry picked from commit 93850bd00d6521eb17094ca5f07d7b7c9b2fddd8) --- .../android/server/wm/TaskDisplayArea.java | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index e0e2876992993..5e1eac8d62a86 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -41,14 +41,13 @@ import static com.android.server.wm.DisplayContent.alwaysCreateRootTask; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ROOT_TASK; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; -import static java.lang.Integer.MIN_VALUE; - import android.annotation.ColorInt; import android.annotation.Nullable; import android.app.ActivityOptions; import android.app.WindowConfiguration; import android.content.pm.ActivityInfo; import android.content.res.Configuration; +import android.graphics.Color; import android.os.UserHandle; import android.util.IntArray; import android.util.Slog; @@ -83,9 +82,9 @@ final class TaskDisplayArea extends DisplayArea { DisplayContent mDisplayContent; /** - * A color layer that serves as a solid color background to certain animations. + * Keeps track of the last set color layer so that it can be reset during surface migrations. */ - private SurfaceControl mColorBackgroundLayer; + private @ColorInt int mBackgroundColor = 0; /** * This counter is used to make sure we don't prematurely clear the background color in the @@ -358,6 +357,14 @@ final class TaskDisplayArea extends DisplayArea { } } + @Override + void setInitialSurfaceControlProperties(SurfaceControl.Builder b) { + // We want an effect layer instead of the default container layer so that we can set a + // background color on it for task animations. + b.setEffectLayer(); + super.setInitialSurfaceControlProperties(b); + } + @Override void addChild(WindowContainer child, int position) { if (child.asTaskDisplayArea() != null) { @@ -946,11 +953,6 @@ final class TaskDisplayArea extends DisplayArea { void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { if (getParent() != null) { super.onParentChanged(newParent, oldParent, () -> { - mColorBackgroundLayer = makeChildSurface(null) - .setColorLayer() - .setName("colorBackgroundLayer") - .setCallsite("TaskDisplayArea.onParentChanged") - .build(); mSplitScreenDividerAnchor = makeChildSurface(null) .setName("splitScreenDividerAnchor") .setCallsite("TaskDisplayArea.onParentChanged") @@ -962,32 +964,19 @@ final class TaskDisplayArea extends DisplayArea { } else { super.onParentChanged(newParent, oldParent); mWmService.mTransactionFactory.get() - .remove(mColorBackgroundLayer) .remove(mSplitScreenDividerAnchor) .apply(); - mColorBackgroundLayer = null; mSplitScreenDividerAnchor = null; } } - void setBackgroundColor(@ColorInt int color) { - if (mColorBackgroundLayer == null) { - return; - } - - float r = ((color >> 16) & 0xff) / 255.0f; - float g = ((color >> 8) & 0xff) / 255.0f; - float b = ((color >> 0) & 0xff) / 255.0f; - float a = ((color >> 24) & 0xff) / 255.0f; - + void setBackgroundColor(@ColorInt int colorInt) { + mBackgroundColor = colorInt; + Color color = Color.valueOf(colorInt); mColorLayerCounter++; - getPendingTransaction().setLayer(mColorBackgroundLayer, MIN_VALUE) - .setColor(mColorBackgroundLayer, new float[]{r, g, b}) - .setAlpha(mColorBackgroundLayer, a) - .setWindowCrop(mColorBackgroundLayer, getSurfaceWidth(), getSurfaceHeight()) - .setPosition(mColorBackgroundLayer, 0, 0) - .show(mColorBackgroundLayer); + getPendingTransaction() + .setColor(mSurfaceControl, new float[]{color.red(), color.green(), color.blue()}); scheduleAnimation(); } @@ -998,7 +987,7 @@ final class TaskDisplayArea extends DisplayArea { // Only clear the color layer if we have received the same amounts of clear as set // requests. if (mColorLayerCounter == 0) { - getPendingTransaction().hide(mColorBackgroundLayer); + getPendingTransaction().unsetColor(mSurfaceControl); scheduleAnimation(); } } @@ -1006,12 +995,12 @@ final class TaskDisplayArea extends DisplayArea { @Override void migrateToNewSurfaceControl(SurfaceControl.Transaction t) { super.migrateToNewSurfaceControl(t); - if (mColorBackgroundLayer == null) { - return; + + if (mColorLayerCounter > 0) { + setBackgroundColor(mBackgroundColor); } // As TaskDisplayArea is getting a new surface, reparent and reorder the child surfaces. - t.reparent(mColorBackgroundLayer, mSurfaceControl); t.reparent(mSplitScreenDividerAnchor, mSurfaceControl); reassignLayer(t); scheduleAnimation(); From da737e714968cce26708db3940e6de3505baef70 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 24 Nov 2021 19:57:52 +0100 Subject: [PATCH 2/2] Don't set background color if TDA doesn't have a valid surface This is something that sometimes occurs in tests since the detaching of the TDA in not necesseraily synchronized with animations Test: atest CtsWindowManagerDeviceTestCases:MultiDisplaySystemDecorationTests Bug: 207667555 Bug: 209936970 Merged-In: I9881453ba14cba4f219861ec4449f2baa8058b57 Change-Id: I9881453ba14cba4f219861ec4449f2baa8058b57 (cherry picked from commit e644ff610220c9f8196cfa982d735e678b121bdc) --- .../com/android/server/wm/TaskDisplayArea.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index 5e1eac8d62a86..db6d3ce69cc87 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -975,18 +975,23 @@ final class TaskDisplayArea extends DisplayArea { Color color = Color.valueOf(colorInt); mColorLayerCounter++; - getPendingTransaction() - .setColor(mSurfaceControl, new float[]{color.red(), color.green(), color.blue()}); - - scheduleAnimation(); + // Only apply the background color if the TDA is actually attached and has a valid surface + // to set the background color on. We still want to keep track of the background color state + // even if we are not showing it for when/if the TDA is reattached and gets a valid surface + if (mSurfaceControl != null) { + getPendingTransaction() + .setColor(mSurfaceControl, + new float[]{color.red(), color.green(), color.blue()}); + scheduleAnimation(); + } } void clearBackgroundColor() { mColorLayerCounter--; // Only clear the color layer if we have received the same amounts of clear as set - // requests. - if (mColorLayerCounter == 0) { + // requests and TDA has a non null surface control (i.e. is attached) + if (mColorLayerCounter == 0 && mSurfaceControl != null) { getPendingTransaction().unsetColor(mSurfaceControl); scheduleAnimation(); }