From c96fbf2287c809f55caea29df87eaca699e3eede Mon Sep 17 00:00:00 2001 From: Chavi Weingarten Date: Thu, 1 Dec 2022 17:02:54 +0000 Subject: [PATCH] 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 --- core/java/android/view/ViewRootImpl.java | 44 ++++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 0f970bf4f91cd..09a9d46ba2570 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -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 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 void updateSyncInProgressCount(SurfaceSyncGroup parentSyncGroup) { - mNumSyncsInProgress++; - parentSyncGroup.addSyncCompleteCallback(mPostAtFrontExecutor, () -> { - if (--mNumSyncsInProgress == 0 && mAttachInfo.mThreadedRenderer != null) { + private final Executor mSimpleExecutor = Runnable::run; + + private void updateSyncInProgressCount(SurfaceSyncGroup syncGroup) { + if (mAttachInfo.mThreadedRenderer == null) { + return; + } + + synchronized (sSyncProgressLock) { + if (sNumSyncsInProgress++ == 0) { + HardwareRenderer.setRtAnimationsEnabled(false); + } + } + + syncGroup.addSyncCompleteCallback(mSimpleExecutor, () -> { + synchronized (sSyncProgressLock) { + if (--sNumSyncsInProgress == 0) { HardwareRenderer.setRtAnimationsEnabled(true); } - }); - } - }; + } + }); + } @Override public SurfaceSyncGroup.SyncTarget getSyncTarget() {