Merge "Reduce unnecessary operations in perpareSurface" into udc-dev

This commit is contained in:
Riddle Hsu
2023-04-06 06:10:04 +00:00
committed by Android (Google) Code Review
7 changed files with 61 additions and 46 deletions

View File

@@ -126,6 +126,9 @@ class Dimmer {
boolean isVisible;
SurfaceAnimator mSurfaceAnimator;
// TODO(b/64816140): Remove after confirming dimmer layer always matches its container.
final Rect mDimBounds = new Rect();
/**
* Determines whether the dim layer should animate before destroying.
*/
@@ -260,11 +263,16 @@ class Dimmer {
* {@link WindowContainer#prepareSurfaces}. After calling this, the container should
* chain {@link WindowContainer#prepareSurfaces} down to it's children to give them
* a chance to request dims to continue.
* @return Non-null dim bounds if the dimmer is showing.
*/
void resetDimStates() {
if (mDimState != null && !mDimState.mDontReset) {
Rect resetDimStates() {
if (mDimState == null) {
return null;
}
if (!mDimState.mDontReset) {
mDimState.mDimming = false;
}
return mDimState.mDimBounds;
}
void dontAnimateExit() {
@@ -275,13 +283,13 @@ class Dimmer {
/**
* Call after invoking {@link WindowContainer#prepareSurfaces} on children as
* described in {@link #resetDimStates}.
* described in {@link #resetDimStates}. The dim bounds returned by {@link #resetDimStates}
* should be set before calling this method.
*
* @param t A transaction in which to update the dims.
* @param bounds The bounds at which to dim.
* @return true if any Dims were updated.
*/
boolean updateDims(SurfaceControl.Transaction t, Rect bounds) {
boolean updateDims(SurfaceControl.Transaction t) {
if (mDimState == null) {
return false;
}
@@ -297,6 +305,7 @@ class Dimmer {
mDimState = null;
return false;
} else {
final Rect bounds = mDimState.mDimBounds;
// TODO: Once we use geometry from hierarchy this falls away.
t.setPosition(mDimState.mDimLayer, bounds.left, bounds.top);
t.setWindowCrop(mDimState.mDimLayer, bounds.width(), bounds.height());

View File

@@ -767,7 +767,6 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
*/
static class Dimmable extends DisplayArea<DisplayArea> {
private final Dimmer mDimmer = new Dimmer(this);
private final Rect mTmpDimBoundsRect = new Rect();
Dimmable(WindowManagerService wms, Type type, String name, int featureId) {
super(wms, type, name, featureId);
@@ -780,11 +779,13 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
@Override
void prepareSurfaces() {
mDimmer.resetDimStates();
final Rect dimBounds = mDimmer.resetDimStates();
super.prepareSurfaces();
// Bounds need to be relative, as the dim layer is a child.
getBounds(mTmpDimBoundsRect);
mTmpDimBoundsRect.offsetTo(0 /* newLeft */, 0 /* newTop */);
if (dimBounds != null) {
// Bounds need to be relative, as the dim layer is a child.
getBounds(dimBounds);
dimBounds.offsetTo(0 /* newLeft */, 0 /* newTop */);
}
// If SystemUI is dragging for recents, we want to reset the dim state so any dim layer
// on the display level fades out.
@@ -792,8 +793,10 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
mDimmer.resetDimStates();
}
if (mDimmer.updateDims(getSyncTransaction(), mTmpDimBoundsRect)) {
scheduleAnimation();
if (dimBounds != null) {
if (mDimmer.updateDims(getSyncTransaction())) {
scheduleAnimation();
}
}
}
}

View File

@@ -481,8 +481,6 @@ class Task extends TaskFragment {
// to layout without loading all the task snapshots
final PersistedTaskSnapshotData mLastTaskSnapshotData;
private final Rect mTmpDimBoundsRect = new Rect();
/** @see #setCanAffectSystemUiFlags */
private boolean mCanAffectSystemUiFlags = true;
@@ -3254,22 +3252,24 @@ class Task extends TaskFragment {
@Override
void prepareSurfaces() {
mDimmer.resetDimStates();
final Rect dimBounds = mDimmer.resetDimStates();
super.prepareSurfaces();
getDimBounds(mTmpDimBoundsRect);
// Bounds need to be relative, as the dim layer is a child.
if (inFreeformWindowingMode()) {
getBounds(mTmpRect);
mTmpDimBoundsRect.offsetTo(mTmpDimBoundsRect.left - mTmpRect.left,
mTmpDimBoundsRect.top - mTmpRect.top);
} else {
mTmpDimBoundsRect.offsetTo(0, 0);
if (dimBounds != null) {
getDimBounds(dimBounds);
// Bounds need to be relative, as the dim layer is a child.
if (inFreeformWindowingMode()) {
getBounds(mTmpRect);
dimBounds.offsetTo(dimBounds.left - mTmpRect.left, dimBounds.top - mTmpRect.top);
} else {
dimBounds.offsetTo(0, 0);
}
}
final SurfaceControl.Transaction t = getSyncTransaction();
if (mDimmer.updateDims(t, mTmpDimBoundsRect)) {
if (dimBounds != null && mDimmer.updateDims(t)) {
scheduleAnimation();
}

View File

@@ -2923,14 +2923,15 @@ class TaskFragment extends WindowContainer<WindowContainer> {
return;
}
mDimmer.resetDimStates();
final Rect dimBounds = mDimmer.resetDimStates();
super.prepareSurfaces();
// Bounds need to be relative, as the dim layer is a child.
final Rect dimBounds = getBounds();
dimBounds.offsetTo(0 /* newLeft */, 0 /* newTop */);
if (mDimmer.updateDims(getSyncTransaction(), dimBounds)) {
scheduleAnimation();
if (dimBounds != null) {
// Bounds need to be relative, as the dim layer is a child.
dimBounds.offsetTo(0 /* newLeft */, 0 /* newTop */);
if (mDimmer.updateDims(getSyncTransaction())) {
scheduleAnimation();
}
}
}

View File

@@ -5177,13 +5177,14 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
@Override
void prepareSurfaces() {
mIsDimming = false;
applyDims();
updateSurfacePositionNonOrganized();
// Send information to SurfaceFlinger about the priority of the current window.
updateFrameRateSelectionPriorityIfNeeded();
updateScaleIfNeeded();
mWinAnimator.prepareSurfaceLocked(getSyncTransaction());
if (mHasSurface) {
applyDims();
updateSurfacePositionNonOrganized();
// Send information to SurfaceFlinger about the priority of the current window.
updateFrameRateSelectionPriorityIfNeeded();
updateScaleIfNeeded();
mWinAnimator.prepareSurfaceLocked(getSyncTransaction());
}
super.prepareSurfaces();
}

View File

@@ -147,8 +147,8 @@ public class DimmerTests extends WindowTestsBase {
int width = 100;
int height = 300;
Rect bounds = new Rect(0, 0, width, height);
mDimmer.updateDims(mTransaction, bounds);
mDimmer.mDimState.mDimBounds.set(0, 0, width, height);
mDimmer.updateDims(mTransaction);
verify(mTransaction).setWindowCrop(getDimLayer(), width, height);
verify(mTransaction).show(getDimLayer());
@@ -194,7 +194,7 @@ public class DimmerTests extends WindowTestsBase {
SurfaceControl dimLayer = getDimLayer();
mDimmer.resetDimStates();
mDimmer.updateDims(mTransaction, new Rect());
mDimmer.updateDims(mTransaction);
verify(mSurfaceAnimatorStarter).startAnimation(any(SurfaceAnimator.class), any(
SurfaceControl.Transaction.class), any(AnimationAdapter.class), anyBoolean(),
eq(ANIMATION_TYPE_DIMMER));
@@ -212,29 +212,29 @@ public class DimmerTests extends WindowTestsBase {
mDimmer.resetDimStates();
mDimmer.dimAbove(mTransaction, child, alpha);
mDimmer.updateDims(mTransaction, new Rect());
mDimmer.updateDims(mTransaction);
verify(mTransaction).show(dimLayer);
verify(mTransaction, never()).remove(dimLayer);
}
@Test
public void testDimUpdateWhileDimming() {
Rect bounds = new Rect();
TestWindowContainer child = new TestWindowContainer(mWm);
mHost.addChild(child, 0);
final float alpha = 0.8f;
mDimmer.dimAbove(mTransaction, child, alpha);
final Rect bounds = mDimmer.mDimState.mDimBounds;
SurfaceControl dimLayer = getDimLayer();
bounds.set(0, 0, 10, 10);
mDimmer.updateDims(mTransaction, bounds);
mDimmer.updateDims(mTransaction);
verify(mTransaction).setWindowCrop(dimLayer, bounds.width(), bounds.height());
verify(mTransaction, times(1)).show(dimLayer);
verify(mTransaction).setPosition(dimLayer, 0, 0);
bounds.set(10, 10, 30, 30);
mDimmer.updateDims(mTransaction, bounds);
mDimmer.updateDims(mTransaction);
verify(mTransaction).setWindowCrop(dimLayer, bounds.width(), bounds.height());
verify(mTransaction).setPosition(dimLayer, 10, 10);
}
@@ -246,13 +246,13 @@ public class DimmerTests extends WindowTestsBase {
mDimmer.dimAbove(mTransaction, child, 1);
SurfaceControl dimLayer = getDimLayer();
mDimmer.updateDims(mTransaction, new Rect());
mDimmer.updateDims(mTransaction);
verify(mTransaction, times(1)).show(dimLayer);
reset(mSurfaceAnimatorStarter);
mDimmer.dontAnimateExit();
mDimmer.resetDimStates();
mDimmer.updateDims(mTransaction, new Rect());
mDimmer.updateDims(mTransaction);
verify(mSurfaceAnimatorStarter, never()).startAnimation(any(SurfaceAnimator.class), any(
SurfaceControl.Transaction.class), any(AnimationAdapter.class), anyBoolean(),
eq(ANIMATION_TYPE_DIMMER));

View File

@@ -691,6 +691,7 @@ public class WindowStateTests extends WindowTestsBase {
// Child window without scale (e.g. different app) should apply inverse scale of parent.
doReturn(1f).when(cmp).getCompatScale(anyString(), anyInt());
final WindowState child2 = createWindow(w, TYPE_APPLICATION_SUB_PANEL, "child2");
makeWindowVisible(w, child2);
clearInvocations(t);
child2.prepareSurfaces();
verify(t).setMatrix(child2.mSurfaceControl, w.mInvGlobalScale, 0, 0, w.mInvGlobalScale);