From 93850bd00d6521eb17094ca5f07d7b7c9b2fddd8 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 3 Nov 2021 13:51:34 +0100 Subject: [PATCH] Use TDA for background color instead of new color layer Bug: 205274345 Bug: 202856837 Bug: 203567491 Test: Run task animations and make sure background color shows Change-Id: I57fa88c6f45adca9e3301b39e868bd127644b76f --- .../android/server/wm/TaskDisplayArea.java | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index 7482f4ee0ae91..de89c6e86bf87 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -47,6 +47,7 @@ import android.annotation.Nullable; import android.app.ActivityOptions; import android.app.WindowConfiguration; import android.content.res.Configuration; +import android.graphics.Color; import android.os.UserHandle; import android.util.IntArray; import android.util.Slog; @@ -80,9 +81,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 @@ -355,6 +356,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) { @@ -874,11 +883,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") @@ -890,28 +894,18 @@ 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; - + void setBackgroundColor(@ColorInt int colorInt) { + mBackgroundColor = colorInt; + Color color = Color.valueOf(colorInt); mColorLayerCounter++; - getPendingTransaction() - .setColor(mColorBackgroundLayer, new float[]{r, g, b}) - .show(mColorBackgroundLayer); + .setColor(mSurfaceControl, new float[]{color.red(), color.green(), color.blue()}); scheduleAnimation(); } @@ -922,7 +916,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(); } } @@ -930,12 +924,16 @@ final class TaskDisplayArea extends DisplayArea { @Override void migrateToNewSurfaceControl(SurfaceControl.Transaction t) { super.migrateToNewSurfaceControl(t); - if (mColorBackgroundLayer == null) { + + if (mColorLayerCounter > 0) { + setBackgroundColor(mBackgroundColor); + } + + if (mSplitScreenDividerAnchor == null) { return; } // As TaskDisplayArea is getting a new surface, reparent and reorder the child surfaces. - t.reparent(mColorBackgroundLayer, mSurfaceControl); t.reparent(mSplitScreenDividerAnchor, mSurfaceControl); reassignLayer(t); scheduleAnimation();