Merge "[Re-land] Deprecate getSfInstance usage in PiP component" into tm-qpr-dev am: 4a24c54245
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18930752 Change-Id: If2d23fe55e50189cdf9f75bde2ef095353e64ee8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
@@ -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
|
||||
|
||||
@@ -170,7 +170,7 @@ public class PipSurfaceTransactionHelper {
|
||||
/** @return {@link SurfaceControl.Transaction} instance with vsync-id */
|
||||
public static SurfaceControl.Transaction newSurfaceControlTransaction() {
|
||||
final SurfaceControl.Transaction tx = new SurfaceControl.Transaction();
|
||||
tx.setFrameTimelineVsync(Choreographer.getSfInstance().getVsyncId());
|
||||
tx.setFrameTimelineVsync(Choreographer.getInstance().getVsyncId());
|
||||
return tx;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user