summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chavi Weingarten <chaviw@google.com> 2022-12-01 17:02:54 +0000
committer Chavi Weingarten <chaviw@google.com> 2022-12-01 19:52:04 +0000
commitc96fbf2287c809f55caea29df87eaca699e3eede (patch)
tree8a5ed232b7f9ce0be33d03f386662f1550c9fe6a
parented77dad0ccbbd60955ca6879b3d862870fe8a8ab (diff)
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
-rw-r--r--core/java/android/view/ViewRootImpl.java44
1 files changed, 26 insertions, 18 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 0f970bf4f91c..09a9d46ba257 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<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() {