Merge changes I9881453b,I57fa88c6

* changes:
  Don't set background color if TDA doesn't have a valid surface
  Use TDA for background color instead of new color layer
This commit is contained in:
Pablo Gamito
2022-02-18 01:46:40 +00:00
committed by Gerrit Code Review

View File

@@ -42,13 +42,12 @@ import static com.android.server.wm.Task.TASK_VISIBILITY_VISIBLE;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ROOT_TASK; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ROOT_TASK;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static java.lang.Integer.MIN_VALUE;
import android.annotation.ColorInt; import android.annotation.ColorInt;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.WindowConfiguration; import android.app.WindowConfiguration;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.IntArray; import android.util.IntArray;
import android.util.Slog; import android.util.Slog;
@@ -83,9 +82,9 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
DisplayContent mDisplayContent; 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 * This counter is used to make sure we don't prematurely clear the background color in the
@@ -366,6 +365,14 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
} }
} }
@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 @Override
void addChild(WindowContainer child, int position) { void addChild(WindowContainer child, int position) {
if (child.asTaskDisplayArea() != null) { if (child.asTaskDisplayArea() != null) {
@@ -980,11 +987,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) {
if (getParent() != null) { if (getParent() != null) {
super.onParentChanged(newParent, oldParent, () -> { super.onParentChanged(newParent, oldParent, () -> {
mColorBackgroundLayer = makeChildSurface(null)
.setColorLayer()
.setName("colorBackgroundLayer")
.setCallsite("TaskDisplayArea.onParentChanged")
.build();
mAppAnimationLayer = makeChildSurface(null) mAppAnimationLayer = makeChildSurface(null)
.setName("animationLayer") .setName("animationLayer")
.setCallsite("TaskDisplayArea.onParentChanged") .setCallsite("TaskDisplayArea.onParentChanged")
@@ -1011,13 +1013,11 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
} else { } else {
super.onParentChanged(newParent, oldParent); super.onParentChanged(newParent, oldParent);
mWmService.mTransactionFactory.get() mWmService.mTransactionFactory.get()
.remove(mColorBackgroundLayer)
.remove(mAppAnimationLayer) .remove(mAppAnimationLayer)
.remove(mBoostedAppAnimationLayer) .remove(mBoostedAppAnimationLayer)
.remove(mHomeAppAnimationLayer) .remove(mHomeAppAnimationLayer)
.remove(mSplitScreenDividerAnchor) .remove(mSplitScreenDividerAnchor)
.apply(); .apply();
mColorBackgroundLayer = null;
mAppAnimationLayer = null; mAppAnimationLayer = null;
mBoostedAppAnimationLayer = null; mBoostedAppAnimationLayer = null;
mHomeAppAnimationLayer = null; mHomeAppAnimationLayer = null;
@@ -1025,35 +1025,29 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
} }
} }
void setBackgroundColor(@ColorInt int color) { void setBackgroundColor(@ColorInt int colorInt) {
if (mColorBackgroundLayer == null) { mBackgroundColor = colorInt;
return; Color color = Color.valueOf(colorInt);
}
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;
mColorLayerCounter++; mColorLayerCounter++;
getPendingTransaction().setLayer(mColorBackgroundLayer, MIN_VALUE) // Only apply the background color if the TDA is actually attached and has a valid surface
.setColor(mColorBackgroundLayer, new float[]{r, g, b}) // to set the background color on. We still want to keep track of the background color state
.setAlpha(mColorBackgroundLayer, a) // even if we are not showing it for when/if the TDA is reattached and gets a valid surface
.setWindowCrop(mColorBackgroundLayer, getSurfaceWidth(), getSurfaceHeight()) if (mSurfaceControl != null) {
.setPosition(mColorBackgroundLayer, 0, 0) getPendingTransaction()
.show(mColorBackgroundLayer); .setColor(mSurfaceControl,
new float[]{color.red(), color.green(), color.blue()});
scheduleAnimation(); scheduleAnimation();
}
} }
void clearBackgroundColor() { void clearBackgroundColor() {
mColorLayerCounter--; mColorLayerCounter--;
// Only clear the color layer if we have received the same amounts of clear as set // Only clear the color layer if we have received the same amounts of clear as set
// requests. // requests and TDA has a non null surface control (i.e. is attached)
if (mColorLayerCounter == 0) { if (mColorLayerCounter == 0 && mSurfaceControl != null) {
getPendingTransaction().hide(mColorBackgroundLayer); getPendingTransaction().unsetColor(mSurfaceControl);
scheduleAnimation(); scheduleAnimation();
} }
} }
@@ -1061,12 +1055,16 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
@Override @Override
void migrateToNewSurfaceControl(SurfaceControl.Transaction t) { void migrateToNewSurfaceControl(SurfaceControl.Transaction t) {
super.migrateToNewSurfaceControl(t); super.migrateToNewSurfaceControl(t);
if (mColorLayerCounter > 0) {
setBackgroundColor(mBackgroundColor);
}
if (mAppAnimationLayer == null) { if (mAppAnimationLayer == null) {
return; return;
} }
// As TaskDisplayArea is getting a new surface, reparent and reorder the child surfaces. // As TaskDisplayArea is getting a new surface, reparent and reorder the child surfaces.
t.reparent(mColorBackgroundLayer, mSurfaceControl);
t.reparent(mAppAnimationLayer, mSurfaceControl); t.reparent(mAppAnimationLayer, mSurfaceControl);
t.reparent(mBoostedAppAnimationLayer, mSurfaceControl); t.reparent(mBoostedAppAnimationLayer, mSurfaceControl);
t.reparent(mHomeAppAnimationLayer, mSurfaceControl); t.reparent(mHomeAppAnimationLayer, mSurfaceControl);