From aa295ddb062d8c74a06e4e878914e5027f9a3f2d Mon Sep 17 00:00:00 2001 From: Chavi Weingarten Date: Tue, 3 Jan 2023 21:46:38 +0000 Subject: [PATCH] Clear mSyncGroups when VRI does a performTraversal When VRI is ready to start drawing, we need to sync any SV syncs that have started, but not completed yet. However, it's possible a second VRI can start drawing before the SV completes which would include those original SV syncs in the second VRI frame. This isn't the expected behavior since each SV sync is intended for a single VRI frame. Therefore, clear the saved SV syncGroups once VRI is expected to start drawing. Test: async SV with resize due to insets no longer ANRs. Bug: 263340543 Change-Id: Ib37505cd494ced68a7d9db291fe42d786d900a8a --- core/java/android/view/SurfaceView.java | 7 ++++--- core/java/android/view/ViewRootImpl.java | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index e38376d7d4a12..c64a2e8e4a4f6 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -1122,14 +1122,15 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall * @hide */ @Override - public void surfaceSyncStarted() { + public void vriDrawStarted(boolean isWmSync) { ViewRootImpl viewRoot = getViewRootImpl(); - if (viewRoot != null) { - synchronized (mSyncGroups) { + synchronized (mSyncGroups) { + if (isWmSync && viewRoot != null) { for (SurfaceSyncGroup syncGroup : mSyncGroups) { viewRoot.addToSync(syncGroup); } } + mSyncGroups.clear(); } } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index c0f4731aeaf42..3d1a1dde9c8f0 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2115,7 +2115,7 @@ public final class ViewRootImpl implements ViewParent, void surfaceCreated(Transaction t); void surfaceReplaced(Transaction t); void surfaceDestroyed(); - default void surfaceSyncStarted() {}; + default void vriDrawStarted(boolean isWmSync) {}; } private final ArrayList mSurfaceChangedCallbacks = new ArrayList<>(); @@ -2150,9 +2150,9 @@ public final class ViewRootImpl implements ViewParent, } } - private void notifySurfaceSyncStarted() { + private void notifyDrawStarted(boolean isWmSync) { for (int i = 0; i < mSurfaceChangedCallbacks.size(); i++) { - mSurfaceChangedCallbacks.get(i).surfaceSyncStarted(); + mSurfaceChangedCallbacks.get(i).vriDrawStarted(isWmSync); } } @@ -3664,6 +3664,7 @@ public final class ViewRootImpl implements ViewParent, } createSyncIfNeeded(); + notifyDrawStarted(isInWMSRequestedSync()); mDrewOnceForSync = true; } @@ -3737,7 +3738,6 @@ public final class ViewRootImpl implements ViewParent, mWmsRequestSyncGroup.addToSync(this); Trace.traceEnd(Trace.TRACE_TAG_VIEW); - notifySurfaceSyncStarted(); } private void notifyContentCatpureEvents() {