From 1c28a44714cc856697048def44923f99b613d44e Mon Sep 17 00:00:00 2001 From: Luca Zuccarini Date: Tue, 26 Nov 2024 15:03:03 +0000 Subject: [PATCH] Revert "Revert "Use the Coreographer's frame time for a more rel..." Revert submission 30577378-revert-30509816-raf-timing-EAFMYZVSQM Reason for revert: this test on Cuttlefish seems to be very unstable in general. I tried to re-test on ABTD with these reverts patched in, but the test isn't being included in the suite, and I couldn't find information anywhere on whether it's supposed to be still running. Since these changes are fully flagged, I don't see how they could be the real culprit. Trying to submit again and monitoring the impact on the postsubmits. Reverted changes: /q/submissionid:30577378-revert-30509816-raf-timing-EAFMYZVSQM Change-Id: I4c1dc43858060716450bab20e3c56728235508c7 --- .../android/quickstep/AbsSwipeUpHandler.java | 25 ++++++++++++++++--- .../com/android/quickstep/TaskViewUtils.java | 5 ++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 21c4d8cffb..27790ce89e 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -80,6 +80,8 @@ import android.os.IBinder; import android.os.SystemClock; import android.util.Log; import android.util.Pair; +import android.util.TimeUtils; +import android.view.Choreographer; import android.view.MotionEvent; import android.view.RemoteAnimationTarget; import android.view.SurfaceControl; @@ -1728,13 +1730,30 @@ public abstract class AbsSwipeUpHandler< } private void handOffAnimation(PointF velocityPxPerMs) { - if (!TransitionAnimator.Companion.longLivedReturnAnimationsEnabled() - || mRecentsAnimationController == null) { + if (!TransitionAnimator.Companion.longLivedReturnAnimationsEnabled()) { + return; + } + + // This function is not guaranteed to be called inside a frame. We try to access the frame + // time immediately, but if we're not inside a frame we must post a callback to be run at + // the beginning of the next frame. + try { + handOffAnimationInternal(Choreographer.getInstance().getFrameTime(), velocityPxPerMs); + } catch (IllegalStateException e) { + Choreographer.getInstance().postFrameCallback( + frameTimeNanos -> handOffAnimationInternal( + frameTimeNanos / TimeUtils.NANOS_PER_MS, velocityPxPerMs)); + } + } + + private void handOffAnimationInternal(long timestamp, PointF velocityPxPerMs) { + if (mRecentsAnimationController == null) { return; } Pair targetsAndStates = - extractTargetsAndStates(mRemoteTargetHandles, velocityPxPerMs); + extractTargetsAndStates( + mRemoteTargetHandles, timestamp, velocityPxPerMs); mRecentsAnimationController.handOffAnimation( targetsAndStates.first, targetsAndStates.second); ActiveGestureProtoLogProxy.logHandOffAnimation(); diff --git a/quickstep/src/com/android/quickstep/TaskViewUtils.java b/quickstep/src/com/android/quickstep/TaskViewUtils.java index 783c87c8af..084cede033 100644 --- a/quickstep/src/com/android/quickstep/TaskViewUtils.java +++ b/quickstep/src/com/android/quickstep/TaskViewUtils.java @@ -795,14 +795,15 @@ public final class TaskViewUtils { * second applies to the target in the same index of the first. * * @param handles The handles wrapping each target. + * @param timestamp The start time of the current frame. * @param velocityPxPerMs The current velocity of the target animations. */ @NonNull public static Pair extractTargetsAndStates( - @NonNull RemoteTargetHandle[] handles, @NonNull PointF velocityPxPerMs) { + @NonNull RemoteTargetHandle[] handles, long timestamp, + @NonNull PointF velocityPxPerMs) { RemoteAnimationTarget[] targets = new RemoteAnimationTarget[handles.length]; WindowAnimationState[] animationStates = new WindowAnimationState[handles.length]; - long timestamp = System.currentTimeMillis(); for (int i = 0; i < handles.length; i++) { targets[i] = handles[i].getTransformParams().getTargetSet().apps[i];