From 95ad68a9c32d950d44833dc0e9141ae980d6c2fd Mon Sep 17 00:00:00 2001 From: Jacqueline Bronger Date: Wed, 22 Feb 2023 10:58:53 +0100 Subject: [PATCH] Fade the TV PiP menu surfaces during enter/exit. With the bounds entry animation the surfaces appeared before/after the bounds animation, however with the change to the alpha entry animation we want the menu surfaces to fade in/out together with the PiP. This change works with both the shell transitions enabled and disabled. Bug: 271098548 Bug: 228071323 Test: manual - do once with shell transitions enabled and disabled: start a PiP -> PiP menu surfaces should fade in gradually with PiP content, close PiP via close button -> menu surfaces should fade out Change-Id: I51fcfe006a672e9c2a094f6657d1552a273c84cf --- .../wm/shell/pip/PipAnimationController.java | 13 ++++++++----- .../android/wm/shell/pip/PipMenuController.java | 11 +++++++++-- .../android/wm/shell/pip/PipTaskOrganizer.java | 15 ++++++++++----- .../com/android/wm/shell/pip/PipTransition.java | 4 +++- .../shell/pip/phone/PhonePipMenuController.java | 5 +++-- .../wm/shell/pip/tv/TvPipMenuController.java | 16 ++++++++++++---- .../wm/shell/pip/tv/TvPipTaskOrganizer.java | 7 +++++++ 7 files changed, 52 insertions(+), 19 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java index 4c53f607a5f83..92830924a17c3 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java @@ -250,7 +250,7 @@ public class PipAnimationController { * @return true if handled by the handler, false otherwise. */ public boolean handlePipTransaction(SurfaceControl leash, SurfaceControl.Transaction tx, - Rect destinationBounds) { + Rect destinationBounds, float alpha) { return false; } } @@ -351,9 +351,10 @@ public class PipAnimationController { } boolean handlePipTransaction(SurfaceControl leash, SurfaceControl.Transaction tx, - Rect destinationBounds) { + Rect destinationBounds, float alpha) { if (mPipTransactionHandler != null) { - return mPipTransactionHandler.handlePipTransaction(leash, tx, destinationBounds); + return mPipTransactionHandler.handlePipTransaction( + leash, tx, destinationBounds, alpha); } return false; } @@ -498,7 +499,9 @@ public class PipAnimationController { getSurfaceTransactionHelper().alpha(tx, leash, alpha) .round(tx, leash, shouldApplyCornerRadius()) .shadow(tx, leash, shouldApplyShadowRadius()); - tx.apply(); + if (!handlePipTransaction(leash, tx, destinationBounds, alpha)) { + tx.apply(); + } } @Override @@ -613,7 +616,7 @@ public class PipAnimationController { .shadow(tx, leash, shouldApplyShadowRadius()); } } - if (!handlePipTransaction(leash, tx, bounds)) { + if (!handlePipTransaction(leash, tx, bounds, /* alpha= */ 1f)) { tx.apply(); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMenuController.java index 000624499f792..0775f5279e316 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipMenuController.java @@ -44,6 +44,13 @@ public interface PipMenuController { String MENU_WINDOW_TITLE = "PipMenuView"; + /** + * Used with + * {@link PipMenuController#movePipMenu(SurfaceControl, SurfaceControl.Transaction, Rect, + * float)} to indicate that we don't want to affect the alpha value of the menu surfaces. + */ + float ALPHA_NO_CHANGE = -1f; + /** * Called when * {@link PipTaskOrganizer#onTaskAppeared(RunningTaskInfo, SurfaceControl)} @@ -85,8 +92,8 @@ public interface PipMenuController { * need to synchronize the movements on the same frame as PiP. */ default void movePipMenu(@Nullable SurfaceControl pipLeash, - @Nullable SurfaceControl.Transaction t, - Rect destinationBounds) {} + @Nullable SurfaceControl.Transaction t, Rect destinationBounds, float alpha) { + } /** * Update the PiP menu with the given bounds for re-layout purposes. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index d2001ecc7ca6f..01678dc8d7bb4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -238,7 +238,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, }, null); } - private boolean shouldSyncPipTransactionWithMenu() { + protected boolean shouldSyncPipTransactionWithMenu() { return mPipMenuController.isMenuVisible(); } @@ -266,9 +266,9 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, new PipAnimationController.PipTransactionHandler() { @Override public boolean handlePipTransaction(SurfaceControl leash, - SurfaceControl.Transaction tx, Rect destinationBounds) { + SurfaceControl.Transaction tx, Rect destinationBounds, float alpha) { if (shouldSyncPipTransactionWithMenu()) { - mPipMenuController.movePipMenu(leash, tx, destinationBounds); + mPipMenuController.movePipMenu(leash, tx, destinationBounds, alpha); return true; } return false; @@ -372,6 +372,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, return mPipTransitionController; } + PipAnimationController.PipTransactionHandler getPipTransactionHandler() { + return mPipTransactionHandler; + } + public Rect getCurrentOrAnimatingBounds() { PipAnimationController.PipTransitionAnimator animator = mPipAnimationController.getCurrentAnimator(); @@ -1375,7 +1379,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, .scale(tx, mLeash, startBounds, toBounds, degrees) .round(tx, mLeash, startBounds, toBounds); if (shouldSyncPipTransactionWithMenu()) { - mPipMenuController.movePipMenu(mLeash, tx, toBounds); + mPipMenuController.movePipMenu(mLeash, tx, toBounds, PipMenuController.ALPHA_NO_CHANGE); } else { tx.apply(); } @@ -1541,7 +1545,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, if (!isInPip()) { return; } - mPipMenuController.movePipMenu(null, null, destinationBounds); + mPipMenuController.movePipMenu(null, null, destinationBounds, + PipMenuController.ALPHA_NO_CHANGE); mPipMenuController.updateMenuBounds(destinationBounds); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index 4a76a502462c2..2e717e5f6bc1c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -838,6 +838,7 @@ public class PipTransition extends PipTransitionController { + mOneShotAnimationType); } animator.setTransitionDirection(TRANSITION_DIRECTION_TO_PIP) + .setPipTransactionHandler(mPipOrganizer.getPipTransactionHandler()) .setPipAnimationCallback(mPipAnimationCallback) .setDuration(mEnterExitAnimationDuration); if (rotationDelta != Surface.ROTATION_0 && mInFixedRotation) { @@ -964,7 +965,8 @@ public class PipTransition extends PipTransitionController { } private void finishResizeForMenu(Rect destinationBounds) { - mPipMenuController.movePipMenu(null, null, destinationBounds); + mPipMenuController.movePipMenu(null, null, destinationBounds, + PipMenuController.ALPHA_NO_CHANGE); mPipMenuController.updateMenuBounds(destinationBounds); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java index 94e593b106a5c..e7a1395f541cf 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java @@ -298,7 +298,8 @@ public class PhonePipMenuController implements PipMenuController { } // Sync the menu bounds before showing it in case it is out of sync. - movePipMenu(null /* pipLeash */, null /* transaction */, stackBounds); + movePipMenu(null /* pipLeash */, null /* transaction */, stackBounds, + PipMenuController.ALPHA_NO_CHANGE); updateMenuBounds(stackBounds); mPipMenuView.showMenu(menuState, stackBounds, allowMenuTimeout, willResizeMenu, withDelay, @@ -311,7 +312,7 @@ public class PhonePipMenuController implements PipMenuController { @Override public void movePipMenu(@Nullable SurfaceControl pipLeash, @Nullable SurfaceControl.Transaction t, - Rect destinationBounds) { + Rect destinationBounds, float alpha) { if (destinationBounds.isEmpty()) { return; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java index b18e21c03c630..b2a189b45d6c5 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java @@ -30,6 +30,7 @@ import android.os.Handler; import android.view.SurfaceControl; import android.view.View; import android.view.ViewRootImpl; +import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.window.SurfaceSyncGroup; @@ -202,8 +203,10 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis } private void addPipMenuViewToSystemWindows(View v, String title) { - mSystemWindows.addView(v, getPipMenuLayoutParams(mContext, title, 0 /* width */, - 0 /* height */), 0 /* displayId */, SHELL_ROOT_LAYER_PIP); + final WindowManager.LayoutParams layoutParams = + getPipMenuLayoutParams(mContext, title, 0 /* width */, 0 /* height */); + layoutParams.alpha = 0f; + mSystemWindows.addView(v, layoutParams, 0 /* displayId */, SHELL_ROOT_LAYER_PIP); } void onPipTransitionFinished(boolean enterTransition) { @@ -309,9 +312,9 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis @Override public void movePipMenu(SurfaceControl pipLeash, SurfaceControl.Transaction pipTx, - Rect pipBounds) { + Rect pipBounds, float alpha) { ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, - "%s: movePipMenu: %s", TAG, pipBounds.toShortString()); + "%s: movePipMenu: %s, alpha %s", TAG, pipBounds.toShortString(), alpha); if (pipBounds.isEmpty()) { if (pipTx == null) { @@ -333,6 +336,11 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis pipTx.setPosition(frontSurface, menuDestBounds.left, menuDestBounds.top); pipTx.setPosition(backSurface, menuDestBounds.left, menuDestBounds.top); + if (alpha != ALPHA_NO_CHANGE) { + pipTx.setAlpha(frontSurface, alpha); + pipTx.setAlpha(backSurface, alpha); + } + // Synchronize drawing the content in the front and back surfaces together with the pip // transaction and the position change for the front and back surfaces final SurfaceSyncGroup syncGroup = new SurfaceSyncGroup("TvPip"); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java index 0940490e99441..4819f665d6d3c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipTaskOrganizer.java @@ -98,4 +98,11 @@ public class TvPipTaskOrganizer extends PipTaskOrganizer { protected boolean shouldAlwaysFadeIn() { return true; } + + @Override + protected boolean shouldSyncPipTransactionWithMenu() { + // We always have a menu visible and want to sync the pip transaction with the menu, even + // when the menu alpha is 0 (e.g. when a fade-in animation starts). + return true; + } }