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

Commit c96fbf22 authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Make count for numSyncsInProgress static

numSyncsInProgress is used to keep track of how many syncs VRI has
started to ensure it can disable RT Animations and then enable at the
end of the sync. This needs to be global across the process because RT
Animations config is global to the process. This means if there are any
VRI's in a sync across the process, we need to keep RT Animations
disabled until the end of all of them.

Test: Sync works
Bug: 237804605
Change-Id: I6304061f564ceea9de08331d7ee48834ad3c828b
parent ed77dad0
Loading
Loading
Loading
Loading
+26 −18
Original line number Diff line number Diff line
@@ -853,7 +853,12 @@ public final class ViewRootImpl implements ViewParent,

    private SurfaceSyncGroup mSyncGroup;
    private SurfaceSyncGroup.TransactionReadyCallback mTransactionReadyCallback;
    private int mNumSyncsInProgress = 0;

    private static final Object sSyncProgressLock = new Object();
    // The count needs to be static since it's used to enable or disable RT animations which is
    // done at a global level per process. If any VRI syncs are in progress, we can't enable RT
    // animations until all are done.
    private static int sNumSyncsInProgress = 0;

    private HashSet<ScrollCaptureCallback> mRootScrollCaptureCallbacks;

@@ -11229,13 +11234,6 @@ public final class ViewRootImpl implements ViewParent,
        });
    }

    private final Executor mPostAtFrontExecutor = new Executor() {
        @Override
        public void execute(Runnable command) {
            mHandler.postAtFrontOfQueue(command);
        }
    };

    public final SurfaceSyncGroup.SyncTarget mSyncTarget = new SurfaceSyncGroup.SyncTarget() {
        @Override
        public void onAddedToSyncGroup(SurfaceSyncGroup parentSyncGroup,
@@ -11245,9 +11243,6 @@ public final class ViewRootImpl implements ViewParent,
                // Always sync the buffer if the sync request did not come from VRI.
                mSyncBuffer = true;
            }
            if (mAttachInfo.mThreadedRenderer != null) {
                HardwareRenderer.setRtAnimationsEnabled(false);
            }

            if (mTransactionReadyCallback != null) {
                Log.d(mTag, "Already set sync for the next draw.");
@@ -11261,16 +11256,29 @@ public final class ViewRootImpl implements ViewParent,
                scheduleTraversals();
            }
        }
    };

    private final Executor mSimpleExecutor = Runnable::run;

    private void updateSyncInProgressCount(SurfaceSyncGroup syncGroup) {
        if (mAttachInfo.mThreadedRenderer == null) {
            return;
        }

        synchronized (sSyncProgressLock) {
            if (sNumSyncsInProgress++ == 0) {
                HardwareRenderer.setRtAnimationsEnabled(false);
            }
        }

        private void updateSyncInProgressCount(SurfaceSyncGroup parentSyncGroup) {
            mNumSyncsInProgress++;
            parentSyncGroup.addSyncCompleteCallback(mPostAtFrontExecutor, () -> {
                if (--mNumSyncsInProgress == 0 && mAttachInfo.mThreadedRenderer != null) {
        syncGroup.addSyncCompleteCallback(mSimpleExecutor, () -> {
            synchronized (sSyncProgressLock) {
                if (--sNumSyncsInProgress == 0) {
                    HardwareRenderer.setRtAnimationsEnabled(true);
                }
            }
        });
    }
    };

    @Override
    public SurfaceSyncGroup.SyncTarget getSyncTarget() {