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
This commit is contained in:
Chavi Weingarten
2022-12-01 17:02:54 +00:00
parent ed77dad0cc
commit c96fbf2287

View File

@@ -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 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() {