From 5109c0dadfe9247e3ebec0912f392d7c45f338f2 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Sun, 6 Mar 2022 11:40:39 -0800 Subject: [PATCH] Async BLAST Sync [2/N]: Introduce seqId We introduce a seqId and use it to replace the RELAYOUT_RES_BLAST_SYNC flag. The server code block that produces RELAYOUT_RES_BLAST_SYNC is guarded by mNextRelayoutUseSync, and sets it to false when executed. This block is the only place that sets it to false. We replace every place where it is set to true, with incrementing a seqId stored on the integer. We change this block to not check mNextRelayoutUseSync but instead check if the seqId has changed since we reached the block. This is evidentally equivalent conditions and in these cases we send the client the seqId. In the else block where we wouldn't have sent RELAYOUT_RES_BLAST_SYNC we send -1. On the client side, we replace the USE_BLAST_SYNC conditional with a check if the SeqId we received has increased. It's clear that this will never execute in cases where the seqId is -1. Likewise its clear that if the seqId has increased, it will execute. Since the seqId increases in all cases where the server would have returned RELAYOUT_RES_BLAST_SYNC this change is a noop by itself. Bug: 161810301 Bug: 175861051 Bug: 175861127 Bug: 200285149 Change-Id: Ib2e45cae7709519251e4bfcc2b8adc689c590a00 --- core/java/android/view/ViewRootImpl.java | 7 +++++-- core/java/android/view/WindowManagerGlobal.java | 8 -------- .../com/android/server/wm/WindowManagerService.java | 10 ++++++---- .../core/java/com/android/server/wm/WindowState.java | 7 ++++--- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index b72725ad2c32d..adcb42df56a8b 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -845,7 +845,8 @@ public final class ViewRootImpl implements ViewParent, * integer back over relayout. */ private Bundle mRelayoutBundle = new Bundle(); - private int mSyncSeqId; + private int mSyncSeqId = 0; + private int mLastSyncSeqId = 0; private String mTag = TAG; @@ -2918,7 +2919,8 @@ public final class ViewRootImpl implements ViewParent, final boolean dockedResizing = (relayoutResult & RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; final boolean dragResizing = freeformResizing || dockedResizing; - if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC) != 0) { + if (mSyncSeqId > mLastSyncSeqId) { + mLastSyncSeqId = mSyncSeqId; if (DEBUG_BLAST) { Log.d(mTag, "Relayout called with blastSync"); } @@ -8086,6 +8088,7 @@ public final class ViewRootImpl implements ViewParent, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets, mTempControls, mRelayoutBundle); + mSyncSeqId = mRelayoutBundle.getInt("seqid"); final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index b0da877bfddd9..55c9f0f961517 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -96,14 +96,6 @@ public final class WindowManagerGlobal { */ public static final int RELAYOUT_RES_CONSUME_ALWAYS_SYSTEM_BARS = 1 << 5; - /** - * This flag indicates the client should not directly submit it's next frame, - * but instead should pass it in the postDrawTransaction of - * {@link WindowManagerService#finishDrawing}. This is used by the WM - * BLASTSyncEngine to synchronize rendering of multiple windows. - */ - public static final int RELAYOUT_RES_BLAST_SYNC = 1 << 6; - /** * Flag for relayout: the client will be later giving * internal insets; as a result, the window will not impact other window diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index c50888b5a1724..53b5ac0e8630e 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -89,7 +89,6 @@ import static android.view.WindowManager.REMOVE_CONTENT_MODE_UNDEFINED; import static android.view.WindowManager.TRANSIT_NONE; import static android.view.WindowManager.TRANSIT_RELAUNCH; import static android.view.WindowManagerGlobal.ADD_OKAY; -import static android.view.WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC; import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID; import static android.view.WindowManagerPolicyConstants.TYPE_LAYER_MULTIPLIER; @@ -2508,11 +2507,14 @@ public class WindowManagerService extends IWindowManager.Stub win.mInRelayout = false; if (mUseBLASTSync && win.useBLASTSync() && viewVisibility != View.GONE - && win.mNextRelayoutUseSync) { + && (win.mSyncSeqId > win.mLastSeqIdSentToRelayout)) { win.prepareDrawHandlers(); win.markRedrawForSyncReported(); - win.mNextRelayoutUseSync = false; - result |= RELAYOUT_RES_BLAST_SYNC; + + win.mLastSeqIdSentToRelayout = win.mSyncSeqId; + outSyncIdBundle.putInt("seqid", win.mSyncSeqId); + } else { + outSyncIdBundle.putInt("seqid", -1); } if (configChanged) { diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 60e196c584653..270593e152dee 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -369,7 +369,8 @@ class WindowState extends WindowContainer implements WindowManagerP private boolean mDragResizingChangeReported = true; private int mResizeMode; private boolean mRedrawForSyncReported; - boolean mNextRelayoutUseSync; + int mSyncSeqId = 0; + int mLastSeqIdSentToRelayout = 0; /** * {@code true} when the client was still drawing for sync when the sync-set was finished or @@ -5923,7 +5924,7 @@ class WindowState extends WindowContainer implements WindowManagerP // to draw even if the children draw first or don't need to sync, so we start // in WAITING state rather than READY. mSyncState = SYNC_STATE_WAITING_FOR_DRAW; - mNextRelayoutUseSync = true; + mSyncSeqId++; requestRedrawForSync(); return true; } @@ -6066,7 +6067,7 @@ class WindowState extends WindowContainer implements WindowManagerP */ void applyWithNextDraw(Consumer consumer) { mPendingDrawHandlers.add(consumer); - mNextRelayoutUseSync = true; + mSyncSeqId++; requestRedrawForSync(); mWmService.mH.sendNewMessageDelayed(WINDOW_STATE_BLAST_SYNC_TIMEOUT, this,