Loading libs/WindowManager/Shell/src/com/android/wm/shell/animation/PhysicsAnimator.kt +4 −37 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.view.View import androidx.dynamicanimation.animation.DynamicAnimation import androidx.dynamicanimation.animation.FlingAnimation import androidx.dynamicanimation.animation.FloatPropertyCompat import androidx.dynamicanimation.animation.FrameCallbackScheduler import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce Loading Loading @@ -124,12 +123,6 @@ class PhysicsAnimator<T> private constructor (target: T) { /** FlingConfig to use by default for properties whose fling configs were not provided. */ private var defaultFling: FlingConfig = globalDefaultFling /** * FrameCallbackScheduler to use if it need custom FrameCallbackScheduler, if this is null, * it will use the default FrameCallbackScheduler in the DynamicAnimation. */ private var customScheduler: FrameCallbackScheduler? = null /** * Internal listeners that respond to DynamicAnimations updating and ending, and dispatch to * the listeners provided via [addUpdateListener] and [addEndListener]. This allows us to add Loading Loading @@ -454,14 +447,6 @@ class PhysicsAnimator<T> private constructor (target: T) { this.defaultFling = defaultFling } /** * Set the custom FrameCallbackScheduler for all aniatmion in this animator. Set this with null for * restoring to default FrameCallbackScheduler. */ fun setCustomScheduler(scheduler: FrameCallbackScheduler) { this.customScheduler = scheduler } /** Starts the animations! */ fun start() { startAction() Loading Loading @@ -511,12 +496,9 @@ class PhysicsAnimator<T> private constructor (target: T) { // springs) on this property before flinging. cancel(animatedProperty) // Apply the custom animation scheduler if it not null val flingAnim = getFlingAnimation(animatedProperty, target) flingAnim.scheduler = customScheduler ?: flingAnim.scheduler // Apply the configuration and start the animation. flingAnim.also { flingConfig.applyToAnimation(it) }.start() getFlingAnimation(animatedProperty, target) .also { flingConfig.applyToAnimation(it) }.start() } } Loading @@ -529,18 +511,6 @@ class PhysicsAnimator<T> private constructor (target: T) { // Apply the configuration and start the animation. val springAnim = getSpringAnimation(animatedProperty, target) // If customScheduler is exist and has not been set to the animation, // it should set here. if (customScheduler != null && springAnim.scheduler != customScheduler) { // Cancel the animation before set animation handler if (springAnim.isRunning) { cancel(animatedProperty) } // Apply the custom scheduler handler if it not null springAnim.scheduler = customScheduler ?: springAnim.scheduler } // Apply the configuration and start the animation. springConfig.applyToAnimation(springAnim) animationStartActions.add(springAnim::start) Loading Loading @@ -596,12 +566,9 @@ class PhysicsAnimator<T> private constructor (target: T) { } } // Apply the custom animation scheduler if it not null val springAnim = getSpringAnimation(animatedProperty, target) springAnim.scheduler = customScheduler ?: springAnim.scheduler // Apply the configuration and start the spring animation. springAnim.also { springConfig.applyToAnimation(it) }.start() getSpringAnimation(animatedProperty, target) .also { springConfig.applyToAnimation(it) }.start() } } }) Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +12 −18 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import android.annotation.NonNull; import android.app.TaskInfo; import android.content.Context; import android.graphics.Rect; import android.view.Choreographer; import android.view.Surface; import android.view.SurfaceControl; import android.window.TaskSnapshot; Loading Loading @@ -279,14 +278,15 @@ public class PipAnimationController { mEndValue = endValue; addListener(this); addUpdateListener(this); mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new; mSurfaceControlTransactionFactory = new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory(); mTransitionDirection = TRANSITION_DIRECTION_NONE; } @Override public void onAnimationStart(Animator animation) { mCurrentValue = mStartValue; onStartTransaction(mLeash, newSurfaceControlTransaction()); onStartTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction()); if (mPipAnimationCallback != null) { mPipAnimationCallback.onPipAnimationStart(mTaskInfo, this); } Loading @@ -294,14 +294,16 @@ public class PipAnimationController { @Override public void onAnimationUpdate(ValueAnimator animation) { applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(), applySurfaceControlTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction(), animation.getAnimatedFraction()); } @Override public void onAnimationEnd(Animator animation) { mCurrentValue = mEndValue; final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); onEndTransaction(mLeash, tx, mTransitionDirection); if (mPipAnimationCallback != null) { mPipAnimationCallback.onPipAnimationEnd(mTaskInfo, tx, this); Loading Loading @@ -348,7 +350,8 @@ public class PipAnimationController { } void setColorContentOverlay(Context context) { final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); if (mContentOverlay != null) { mContentOverlay.detach(tx); } Loading @@ -357,7 +360,8 @@ public class PipAnimationController { } void setSnapshotContentOverlay(TaskSnapshot snapshot, Rect sourceRectHint) { final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); if (mContentOverlay != null) { mContentOverlay.detach(tx); } Loading Loading @@ -406,7 +410,7 @@ public class PipAnimationController { void setDestinationBounds(Rect destinationBounds) { mDestinationBounds.set(destinationBounds); if (mAnimationType == ANIM_TYPE_ALPHA) { onStartTransaction(mLeash, newSurfaceControlTransaction()); onStartTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction()); } } Loading Loading @@ -441,16 +445,6 @@ public class PipAnimationController { mEndValue = endValue; } /** * @return {@link SurfaceControl.Transaction} instance with vsync-id. */ protected SurfaceControl.Transaction newSurfaceControlTransaction() { final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); tx.setFrameTimelineVsync(Choreographer.getSfInstance().getVsyncId()); return tx; } @VisibleForTesting public void setSurfaceControlTransactionFactory( PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) { Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.RectF; import android.view.Choreographer; import android.view.SurfaceControl; import com.android.wm.shell.R; Loading Loading @@ -234,4 +235,18 @@ public class PipSurfaceTransactionHelper { public interface SurfaceControlTransactionFactory { SurfaceControl.Transaction getTransaction(); } /** * Implementation of {@link SurfaceControlTransactionFactory} that returns * {@link SurfaceControl.Transaction} with VsyncId being set. */ public static class VsyncSurfaceControlTransactionFactory implements SurfaceControlTransactionFactory { @Override public SurfaceControl.Transaction getTransaction() { final SurfaceControl.Transaction tx = new SurfaceControl.Transaction(); tx.setFrameTimelineVsync(Choreographer.getInstance().getVsyncId()); return tx; } } } libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +2 −1 Original line number Diff line number Diff line Loading @@ -304,7 +304,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, mSurfaceTransactionHelper = surfaceTransactionHelper; mPipAnimationController = pipAnimationController; mPipUiEventLoggerLogger = pipUiEventLogger; mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new; mSurfaceControlTransactionFactory = new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory(); mSplitScreenOptional = splitScreenOptional; mTaskOrganizer = shellTaskOrganizer; mMainExecutor = mainExecutor; Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +0 −25 Original line number Diff line number Diff line Loading @@ -33,10 +33,6 @@ import android.content.Context; import android.graphics.PointF; import android.graphics.Rect; import android.os.Debug; import android.os.Looper; import android.view.Choreographer; import androidx.dynamicanimation.animation.FrameCallbackScheduler; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.R; Loading Loading @@ -89,25 +85,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** Coordinator instance for resolving conflicts with other floating content. */ private FloatingContentCoordinator mFloatingContentCoordinator; private ThreadLocal<FrameCallbackScheduler> mSfSchedulerThreadLocal = ThreadLocal.withInitial(() -> { final Looper initialLooper = Looper.myLooper(); final FrameCallbackScheduler scheduler = new FrameCallbackScheduler() { @Override public void postFrameCallback(@androidx.annotation.NonNull Runnable runnable) { // TODO(b/222697646): remove getSfInstance usage and use vsyncId for // transactions Choreographer.getSfInstance().postFrameCallback(t -> runnable.run()); } @Override public boolean isCurrentThread() { return Looper.myLooper() == initialLooper; } }; return scheduler; }); /** * PhysicsAnimator instance for animating {@link PipBoundsState#getMotionBoundsState()} * using physics animations. Loading Loading @@ -210,10 +187,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, } public void init() { // Note: Needs to get the shell main thread sf vsync animation handler mTemporaryBoundsPhysicsAnimator = PhysicsAnimator.getInstance( mPipBoundsState.getMotionBoundsState().getBoundsInMotion()); mTemporaryBoundsPhysicsAnimator.setCustomScheduler(mSfSchedulerThreadLocal.get()); } @NonNull Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/animation/PhysicsAnimator.kt +4 −37 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import android.view.View import androidx.dynamicanimation.animation.DynamicAnimation import androidx.dynamicanimation.animation.FlingAnimation import androidx.dynamicanimation.animation.FloatPropertyCompat import androidx.dynamicanimation.animation.FrameCallbackScheduler import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce Loading Loading @@ -124,12 +123,6 @@ class PhysicsAnimator<T> private constructor (target: T) { /** FlingConfig to use by default for properties whose fling configs were not provided. */ private var defaultFling: FlingConfig = globalDefaultFling /** * FrameCallbackScheduler to use if it need custom FrameCallbackScheduler, if this is null, * it will use the default FrameCallbackScheduler in the DynamicAnimation. */ private var customScheduler: FrameCallbackScheduler? = null /** * Internal listeners that respond to DynamicAnimations updating and ending, and dispatch to * the listeners provided via [addUpdateListener] and [addEndListener]. This allows us to add Loading Loading @@ -454,14 +447,6 @@ class PhysicsAnimator<T> private constructor (target: T) { this.defaultFling = defaultFling } /** * Set the custom FrameCallbackScheduler for all aniatmion in this animator. Set this with null for * restoring to default FrameCallbackScheduler. */ fun setCustomScheduler(scheduler: FrameCallbackScheduler) { this.customScheduler = scheduler } /** Starts the animations! */ fun start() { startAction() Loading Loading @@ -511,12 +496,9 @@ class PhysicsAnimator<T> private constructor (target: T) { // springs) on this property before flinging. cancel(animatedProperty) // Apply the custom animation scheduler if it not null val flingAnim = getFlingAnimation(animatedProperty, target) flingAnim.scheduler = customScheduler ?: flingAnim.scheduler // Apply the configuration and start the animation. flingAnim.also { flingConfig.applyToAnimation(it) }.start() getFlingAnimation(animatedProperty, target) .also { flingConfig.applyToAnimation(it) }.start() } } Loading @@ -529,18 +511,6 @@ class PhysicsAnimator<T> private constructor (target: T) { // Apply the configuration and start the animation. val springAnim = getSpringAnimation(animatedProperty, target) // If customScheduler is exist and has not been set to the animation, // it should set here. if (customScheduler != null && springAnim.scheduler != customScheduler) { // Cancel the animation before set animation handler if (springAnim.isRunning) { cancel(animatedProperty) } // Apply the custom scheduler handler if it not null springAnim.scheduler = customScheduler ?: springAnim.scheduler } // Apply the configuration and start the animation. springConfig.applyToAnimation(springAnim) animationStartActions.add(springAnim::start) Loading Loading @@ -596,12 +566,9 @@ class PhysicsAnimator<T> private constructor (target: T) { } } // Apply the custom animation scheduler if it not null val springAnim = getSpringAnimation(animatedProperty, target) springAnim.scheduler = customScheduler ?: springAnim.scheduler // Apply the configuration and start the spring animation. springAnim.also { springConfig.applyToAnimation(it) }.start() getSpringAnimation(animatedProperty, target) .also { springConfig.applyToAnimation(it) }.start() } } }) Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +12 −18 Original line number Diff line number Diff line Loading @@ -29,7 +29,6 @@ import android.annotation.NonNull; import android.app.TaskInfo; import android.content.Context; import android.graphics.Rect; import android.view.Choreographer; import android.view.Surface; import android.view.SurfaceControl; import android.window.TaskSnapshot; Loading Loading @@ -279,14 +278,15 @@ public class PipAnimationController { mEndValue = endValue; addListener(this); addUpdateListener(this); mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new; mSurfaceControlTransactionFactory = new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory(); mTransitionDirection = TRANSITION_DIRECTION_NONE; } @Override public void onAnimationStart(Animator animation) { mCurrentValue = mStartValue; onStartTransaction(mLeash, newSurfaceControlTransaction()); onStartTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction()); if (mPipAnimationCallback != null) { mPipAnimationCallback.onPipAnimationStart(mTaskInfo, this); } Loading @@ -294,14 +294,16 @@ public class PipAnimationController { @Override public void onAnimationUpdate(ValueAnimator animation) { applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(), applySurfaceControlTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction(), animation.getAnimatedFraction()); } @Override public void onAnimationEnd(Animator animation) { mCurrentValue = mEndValue; final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); onEndTransaction(mLeash, tx, mTransitionDirection); if (mPipAnimationCallback != null) { mPipAnimationCallback.onPipAnimationEnd(mTaskInfo, tx, this); Loading Loading @@ -348,7 +350,8 @@ public class PipAnimationController { } void setColorContentOverlay(Context context) { final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); if (mContentOverlay != null) { mContentOverlay.detach(tx); } Loading @@ -357,7 +360,8 @@ public class PipAnimationController { } void setSnapshotContentOverlay(TaskSnapshot snapshot, Rect sourceRectHint) { final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); if (mContentOverlay != null) { mContentOverlay.detach(tx); } Loading Loading @@ -406,7 +410,7 @@ public class PipAnimationController { void setDestinationBounds(Rect destinationBounds) { mDestinationBounds.set(destinationBounds); if (mAnimationType == ANIM_TYPE_ALPHA) { onStartTransaction(mLeash, newSurfaceControlTransaction()); onStartTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction()); } } Loading Loading @@ -441,16 +445,6 @@ public class PipAnimationController { mEndValue = endValue; } /** * @return {@link SurfaceControl.Transaction} instance with vsync-id. */ protected SurfaceControl.Transaction newSurfaceControlTransaction() { final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); tx.setFrameTimelineVsync(Choreographer.getSfInstance().getVsyncId()); return tx; } @VisibleForTesting public void setSurfaceControlTransactionFactory( PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) { Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipSurfaceTransactionHelper.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.RectF; import android.view.Choreographer; import android.view.SurfaceControl; import com.android.wm.shell.R; Loading Loading @@ -234,4 +235,18 @@ public class PipSurfaceTransactionHelper { public interface SurfaceControlTransactionFactory { SurfaceControl.Transaction getTransaction(); } /** * Implementation of {@link SurfaceControlTransactionFactory} that returns * {@link SurfaceControl.Transaction} with VsyncId being set. */ public static class VsyncSurfaceControlTransactionFactory implements SurfaceControlTransactionFactory { @Override public SurfaceControl.Transaction getTransaction() { final SurfaceControl.Transaction tx = new SurfaceControl.Transaction(); tx.setFrameTimelineVsync(Choreographer.getInstance().getVsyncId()); return tx; } } }
libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +2 −1 Original line number Diff line number Diff line Loading @@ -304,7 +304,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, mSurfaceTransactionHelper = surfaceTransactionHelper; mPipAnimationController = pipAnimationController; mPipUiEventLoggerLogger = pipUiEventLogger; mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new; mSurfaceControlTransactionFactory = new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory(); mSplitScreenOptional = splitScreenOptional; mTaskOrganizer = shellTaskOrganizer; mMainExecutor = mainExecutor; Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +0 −25 Original line number Diff line number Diff line Loading @@ -33,10 +33,6 @@ import android.content.Context; import android.graphics.PointF; import android.graphics.Rect; import android.os.Debug; import android.os.Looper; import android.view.Choreographer; import androidx.dynamicanimation.animation.FrameCallbackScheduler; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.R; Loading Loading @@ -89,25 +85,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** Coordinator instance for resolving conflicts with other floating content. */ private FloatingContentCoordinator mFloatingContentCoordinator; private ThreadLocal<FrameCallbackScheduler> mSfSchedulerThreadLocal = ThreadLocal.withInitial(() -> { final Looper initialLooper = Looper.myLooper(); final FrameCallbackScheduler scheduler = new FrameCallbackScheduler() { @Override public void postFrameCallback(@androidx.annotation.NonNull Runnable runnable) { // TODO(b/222697646): remove getSfInstance usage and use vsyncId for // transactions Choreographer.getSfInstance().postFrameCallback(t -> runnable.run()); } @Override public boolean isCurrentThread() { return Looper.myLooper() == initialLooper; } }; return scheduler; }); /** * PhysicsAnimator instance for animating {@link PipBoundsState#getMotionBoundsState()} * using physics animations. Loading Loading @@ -210,10 +187,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, } public void init() { // Note: Needs to get the shell main thread sf vsync animation handler mTemporaryBoundsPhysicsAnimator = PhysicsAnimator.getInstance( mPipBoundsState.getMotionBoundsState().getBoundsInMotion()); mTemporaryBoundsPhysicsAnimator.setCustomScheduler(mSfSchedulerThreadLocal.get()); } @NonNull Loading