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

Commit 32fd84ac authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Lock free app animations (6/n): Move back-pressure to new animator

SurfaceFlinger was currently only back-pressuring the old
animation system. Move this to the new SurfaceAnimationRunner,
such that every animation frame is presented on screen.

Test: go/wm-smoke
Test: Insert 16ms sleep statement when applying transaction, make
sure animations are still smooth.
Bug:

Change-Id: I510d22c9c4359659e7a061a26b7adad9c265b734
parent 2e3c31d0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.os.SystemClock;
import android.util.ArrayMap;
import android.view.Choreographer;
import android.view.SurfaceControl;
@@ -195,6 +196,7 @@ class SurfaceAnimationRunner {
    }

    private void applyTransaction() {
        mFrameTransaction.setAnimationTransaction();
        mFrameTransaction.apply();
        mApplyScheduled = false;
    }
+0 −10
Original line number Diff line number Diff line
@@ -140,16 +140,6 @@ public class WindowAnimator {
            scheduleAnimation();
        }

        // Simulate back-pressure by opening and closing an empty animation transaction. This makes
        // sure that an animation frame is at least presented once on the screen. We do this outside
        // of the regular transaction such that we can avoid holding the window manager lock in case
        // we receive back-pressure from SurfaceFlinger. Since closing an animation transaction
        // without the window manager locks leads to ordering issues (as the transaction will be
        // processed only at the beginning of the next frame which may result in another transaction
        // that was executed later in WM side gets executed first on SF side), we don't update any
        // Surface properties here such that reordering doesn't cause issues.
        mService.executeEmptyAnimationTransaction();

        synchronized (mService.mWindowMap) {
            mCurrentTime = frameTimeNs / TimeUtils.NANOS_PER_MS;
            mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
+0 −29
Original line number Diff line number Diff line
@@ -852,35 +852,6 @@ public class WindowManagerService extends IWindowManager.Stub
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
        }
    }

    /**
     * Executes an empty animation transaction without holding the WM lock to simulate
     * back-pressure. See {@link WindowAnimator#animate} why this is needed.
     */
    void executeEmptyAnimationTransaction() {
        try {
            Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "openSurfaceTransaction");
            synchronized (mWindowMap) {
                if (mRoot.mSurfaceTraceEnabled) {
                    mRoot.mRemoteEventTrace.openSurfaceTransaction();
                }
                SurfaceControl.openTransaction();
                SurfaceControl.setAnimationTransaction();
                if (mRoot.mSurfaceTraceEnabled) {
                    mRoot.mRemoteEventTrace.closeSurfaceTransaction();
                }
            }
        } finally {
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
        }
        try {
            Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "closeSurfaceTransaction");
            SurfaceControl.closeTransaction();
        } finally {
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
        }
    }

    /** Listener to notify activity manager about app transitions. */
    final WindowManagerInternal.AppTransitionListener mActivityManagerAppTransitionNotifier
            = new WindowManagerInternal.AppTransitionListener() {