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

Commit d5968a9a authored by Hongwei Wang's avatar Hongwei Wang Committed by Automerger Merge Worker
Browse files

Merge "Deprecate getSfInstance usage in PiP component" into tm-dev am: b68626be

parents e7d5962a b68626be
Loading
Loading
Loading
Loading
+6 −42
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.wm.shell.animation
import android.util.ArrayMap
import android.util.Log
import android.view.View
import androidx.dynamicanimation.animation.AnimationHandler
import androidx.dynamicanimation.animation.DynamicAnimation
import androidx.dynamicanimation.animation.FlingAnimation
import androidx.dynamicanimation.animation.FloatPropertyCompat
@@ -123,12 +122,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

    /**
     * AnimationHandler to use if it need custom AnimationHandler, if this is null, it will use
     * the default AnimationHandler in the DynamicAnimation.
     */
    private var customAnimationHandler: AnimationHandler? = 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
@@ -453,14 +446,6 @@ class PhysicsAnimator<T> private constructor (target: T) {
        this.defaultFling = defaultFling
    }

    /**
     * Set the custom AnimationHandler for all aniatmion in this animator. Set this with null for
     * restoring to default AnimationHandler.
     */
    fun setCustomAnimationHandler(handler: AnimationHandler) {
        this.customAnimationHandler = handler
    }

    /** Starts the animations! */
    fun start() {
        startAction()
@@ -510,13 +495,10 @@ class PhysicsAnimator<T> private constructor (target: T) {
                    // springs) on this property before flinging.
                    cancel(animatedProperty)

                    // Apply the custom animation handler if it not null
                    val flingAnim = getFlingAnimation(animatedProperty, target)
                    flingAnim.animationHandler =
                            customAnimationHandler ?: flingAnim.animationHandler

                    // Apply the configuration and start the animation.
                    flingAnim.also { flingConfig.applyToAnimation(it) }.start()
                    getFlingAnimation(animatedProperty, target)
                        .also { flingConfig.applyToAnimation(it) }
                        .start()
                }
            }

@@ -528,21 +510,6 @@ class PhysicsAnimator<T> private constructor (target: T) {
                if (flingConfig == null) {
                    // Apply the configuration and start the animation.
                    val springAnim = getSpringAnimation(animatedProperty, target)

                    // If customAnimationHander is exist and has not been set to the animation,
                    // it should set here.
                    if (customAnimationHandler != null &&
                            springAnim.animationHandler != customAnimationHandler) {
                        // Cancel the animation before set animation handler
                        if (springAnim.isRunning) {
                            cancel(animatedProperty)
                        }
                        // Apply the custom animation handler if it not null
                        springAnim.animationHandler =
                                customAnimationHandler ?: springAnim.animationHandler
                    }

                    // Apply the configuration and start the animation.
                    springConfig.applyToAnimation(springAnim)
                    animationStartActions.add(springAnim::start)
                } else {
@@ -597,13 +564,10 @@ class PhysicsAnimator<T> private constructor (target: T) {
                                    }
                                }

                                // Apply the custom animation handler if it not null
                                val springAnim = getSpringAnimation(animatedProperty, target)
                                springAnim.animationHandler =
                                        customAnimationHandler ?: springAnim.animationHandler

                                // Apply the configuration and start the spring animation.
                                springAnim.also { springConfig.applyToAnimation(it) }.start()
                                getSpringAnimation(animatedProperty, target)
                                    .also { springConfig.applyToAnimation(it) }
                                    .start()
                            }
                        }
                    })
+10 −17
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.Choreographer;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceSession;
@@ -273,14 +272,15 @@ public class PipAnimationController {
            mStartingAngle = startingAngle;
            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);
            }
@@ -288,14 +288,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);
@@ -342,7 +344,8 @@ public class PipAnimationController {
        }

        PipTransitionAnimator<T> setUseContentOverlay(Context context) {
            final SurfaceControl.Transaction tx = newSurfaceControlTransaction();
            final SurfaceControl.Transaction tx =
                    mSurfaceControlTransactionFactory.getTransaction();
            if (mContentOverlay != null) {
                // remove existing content overlay if there is any.
                tx.remove(mContentOverlay);
@@ -417,7 +420,7 @@ public class PipAnimationController {
        void setDestinationBounds(Rect destinationBounds) {
            mDestinationBounds.set(destinationBounds);
            if (mAnimationType == ANIM_TYPE_ALPHA) {
                onStartTransaction(mLeash, newSurfaceControlTransaction());
                onStartTransaction(mLeash, mSurfaceControlTransactionFactory.getTransaction());
            }
        }

@@ -447,16 +450,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;
@@ -213,4 +214,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
@@ -280,7 +280,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;
+2 −3
Original line number Diff line number Diff line
@@ -146,11 +146,10 @@ public class PipInputConsumer {
                    "%s: Failed to create input consumer, %s", TAG, e);
        }
        mMainExecutor.execute(() -> {
            // Choreographer.getSfInstance() must be called on the thread that the input event
            // Choreographer.getInstance() must be called on the thread that the input event
            // receiver should be receiving events
            // TODO(b/222697646): remove getSfInstance usage and use vsyncId for transactions
            mInputEventReceiver = new InputEventReceiver(inputChannel,
                Looper.myLooper(), Choreographer.getSfInstance());
                Looper.myLooper(), Choreographer.getInstance());
            if (mRegistrationListener != null) {
                mRegistrationListener.onRegistrationChanged(true /* isRegistered */);
            }
Loading