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

Commit c40d1edf authored by Evan Rosky's avatar Evan Rosky
Browse files

Move early-wake to transition start

Any binder to SF is actually pretty slow esp. on low-end
devices. Early-wake just needs to be set "before the animation",
so move it to transition-start and merge it with the global
transaction (which gets applied no-matter what in `animation`).
This actually bring it more in-line with legacy (where early-wake
is more likely to be set before the first frame) and it remove
the latency of making the blocking binder to set it in its own
transaction.

Bug: 258909157
Test: record trace when launching app (or run the benchmark
      in the bug) and check the "animating" track.
Change-Id: I31e0cf4ea0644c327a99c4dc62047e6e465c853c
parent 6ab7f5ee
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -209,6 +209,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {

    private boolean mIsSeamlessRotation = false;
    private IContainerFreezer mContainerFreezer = null;
    private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();

    Transition(@TransitionType int type, @TransitionFlags int flags,
            TransitionController controller, BLASTSyncEngine syncEngine) {
@@ -362,6 +363,10 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        return mState == STATE_COLLECTING || mState == STATE_STARTED;
    }

    boolean isStarted() {
        return mState == STATE_STARTED;
    }

    @VisibleForTesting
    void startCollecting(long timeoutMs) {
        startCollecting(timeoutMs, TransitionController.SYNC_METHOD);
@@ -395,6 +400,12 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        applyReady();

        mController.mTransitionTracer.logState(this);

        mController.updateAnimatingState(mTmpTransaction);
        // merge into the next-time the global transaction is applied. This is too-early to set
        // early-wake anyways, so we don't need to apply immediately (in fact applying right now
        // can preempt more-important work).
        SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
    }

    /**
@@ -895,6 +906,8 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
                    false /* forceRelayout */);
        }
        cleanUpInternal();
        mController.updateAnimatingState(mTmpTransaction);
        mTmpTransaction.apply();
    }

    void abort() {
@@ -1071,8 +1084,6 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
                        "Calling onTransitionReady: %s", info);
                mController.getTransitionPlayer().onTransitionReady(
                        mToken, info, transaction, mFinishTransaction);
                // Since we created root-leash but no longer reference it from core, release it now
                info.releaseAnimSurfaces();
                if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) {
                    Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, TRACE_NAME_PLAY_TRANSITION,
                            System.identityHashCode(this));
@@ -1089,6 +1100,9 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        mOverrideOptions = null;

        reportStartReasonsToLogger();

        // Since we created root-leash but no longer reference it from core, release it now
        info.releaseAnimSurfaces();
    }

    /**
+20 −9
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.IRemoteCallback;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.util.ArrayMap;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -117,7 +118,7 @@ class TransitionController {
     */
    boolean mBuildingFinishLayers = false;

    private final SurfaceControl.Transaction mWakeT = new SurfaceControl.Transaction();
    private boolean mAnimatingState = false;

    TransitionController(ActivityTaskManagerService atm,
            TaskSnapshotController taskSnapshotController,
@@ -623,20 +624,30 @@ class TransitionController {
        mTransitionTracer.logState(transition);
    }

    void updateAnimatingState(SurfaceControl.Transaction t) {
        final boolean animatingState = !mPlayingTransitions.isEmpty()
                    || (mCollectingTransition != null && mCollectingTransition.isStarted());
        if (animatingState && !mAnimatingState) {
            t.setEarlyWakeupStart();
            // Usually transitions put quite a load onto the system already (with all the things
            // happening in app), so pause task snapshot persisting to not increase the load.
            mAtm.mWindowManager.mSnapshotPersistQueue.setPaused(true);
            mAnimatingState = true;
            Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "transitAnim", 0);
        } else if (!animatingState && mAnimatingState) {
            t.setEarlyWakeupEnd();
            mAtm.mWindowManager.mSnapshotPersistQueue.setPaused(false);
            mAnimatingState = false;
            Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "transitAnim", 0);
        }
    }

    /** Updates the process state of animation player. */
    private void updateRunningRemoteAnimation(Transition transition, boolean isPlaying) {
        if (mTransitionPlayerProc == null) return;
        if (isPlaying) {
            mWakeT.setEarlyWakeupStart();
            mWakeT.apply();
            // Usually transitions put quite a load onto the system already (with all the things
            // happening in app), so pause task snapshot persisting to not increase the load.
            mAtm.mWindowManager.mSnapshotPersistQueue.setPaused(true);
            mTransitionPlayerProc.setRunningRemoteAnimation(true);
        } else if (mPlayingTransitions.isEmpty()) {
            mWakeT.setEarlyWakeupEnd();
            mWakeT.apply();
            mAtm.mWindowManager.mSnapshotPersistQueue.setPaused(false);
            mTransitionPlayerProc.setRunningRemoteAnimation(false);
            mRemotePlayer.clear();
            return;