Use screen rotation animation only if the display has content

It is unnecessary to run animation which is invisible to user.
Especially when adding a new display which is empty initially.

Also make sure that the leash for fade rotation animation is valid.
(For the case if the animation was canceled by other places.)

Bug: 213562756
Test: Either use legacy transition or shell transition.
      Start ScreenRecord and check logcat that there is no
      "Screen frozen" or "Creating Transition".
Change-Id: I8e905e4161a8eb768eadda4b160af57b7148f81d
This commit is contained in:
Riddle Hsu
2022-01-11 16:40:06 +08:00
parent 9771f44dad
commit 47a37486f7
4 changed files with 15 additions and 4 deletions

View File

@@ -1425,7 +1425,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mWaitingForConfig = true;
if (mTransitionController.isShellTransitionsEnabled()) {
requestChangeTransitionIfNeeded(changes, null /* displayChange */);
} else {
} else if (mLastHasContent) {
mWmService.startFreezingDisplay(0 /* exitAnim */, 0 /* enterAnim */, this);
}
sendNewConfiguration();
@@ -3222,6 +3222,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
*/
void requestChangeTransitionIfNeeded(@ActivityInfo.Config int changes,
@Nullable TransitionRequestInfo.DisplayChange displayChange) {
if (!mLastHasContent) return;
final TransitionController controller = mTransitionController;
if (controller.isCollecting()) {
if (displayChange != null) {
@@ -5090,6 +5091,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
return mLastHasContent;
}
@VisibleForTesting
void setLastHasContent() {
mLastHasContent = true;
}
void registerPointerEventListener(@NonNull PointerEventListener listener) {
mPointerEventDispatcher.registerInputEventListener(listener);
}

View File

@@ -256,7 +256,7 @@ public class FadeRotationAnimationController extends FadeAnimationController {
false /* applyFixedTransformationHint */);
for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
final SurfaceControl leash = mTargetWindowTokens.valueAt(i);
if (leash != null) {
if (leash != null && leash.isValid()) {
rotator.applyTransform(t, leash);
}
}
@@ -265,7 +265,7 @@ public class FadeRotationAnimationController extends FadeAnimationController {
// Hide the windows immediately because a screenshot layer should cover the screen.
for (int i = mTargetWindowTokens.size() - 1; i >= 0; i--) {
final SurfaceControl leash = mTargetWindowTokens.valueAt(i);
if (leash != null) {
if (leash != null && leash.isValid()) {
t.setAlpha(leash, 0f);
}
}

View File

@@ -1718,6 +1718,7 @@ public class DisplayContentTests extends WindowTestsBase {
@Test
public void testShellTransitRotation() {
DisplayContent dc = createNewDisplay();
dc.setLastHasContent();
final TestTransitionPlayer testPlayer = registerTestTransitionPlayer();
final DisplayRotation dr = dc.getDisplayRotation();

View File

@@ -488,6 +488,7 @@ public class TransitionTests extends WindowTestsBase {
final TestTransitionPlayer player = registerTestTransitionPlayer();
mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
mDisplayContent.setLastHasContent();
mDisplayContent.requestChangeTransitionIfNeeded(1 /* any changes */,
null /* displayChange */);
final FadeRotationAnimationController fadeController =
@@ -536,6 +537,7 @@ public class TransitionTests extends WindowTestsBase {
null /* remoteTransition */, null /* displayChange */);
mDisplayContent.getDisplayRotation().setRotation(mDisplayContent.getRotation() + 1);
final int anyChanges = 1;
mDisplayContent.setLastHasContent();
mDisplayContent.requestChangeTransitionIfNeeded(anyChanges, null /* displayChange */);
transition.setKnownConfigChanges(mDisplayContent, anyChanges);
final FadeRotationAnimationController fadeController =
@@ -550,9 +552,11 @@ public class TransitionTests extends WindowTestsBase {
assertTrue(app.getTask().inTransition());
final SurfaceControl.Transaction startTransaction = mock(SurfaceControl.Transaction.class);
final SurfaceControl leash = statusBar.mToken.getAnimationLeash();
doReturn(true).when(leash).isValid();
player.onTransactionReady(startTransaction);
// The leash should be unrotated.
verify(startTransaction).setMatrix(eq(statusBar.mToken.getAnimationLeash()), any(), any());
verify(startTransaction).setMatrix(eq(leash), any(), any());
// The redrawn window will be faded in when the transition finishes. And because this test
// only use one non-activity window, the fade rotation controller should also be cleared.