Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a24c542 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "[Re-land] Deprecate getSfInstance usage in PiP component" into tm-qpr-dev

parents 910d0090 9fe333a0
Loading
Loading
Loading
Loading
+4 −37
Original line number Diff line number Diff line
@@ -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()
                            }
                        }
                    })
+12 −18
Original line number Diff line number Diff line
@@ -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) {
+15 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -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;
+0 −25
Original line number Diff line number Diff line
@@ -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
Loading