From fb8ccaa1bcd4d0cedd9876079407e85b7f1d1132 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Wed, 6 May 2020 12:18:05 -0700 Subject: BLASTBufferQueue: Fix two conditions leading to freeze. If we ask the BLASTBufferQueue to redirect a buffer in to a transaction but then lose the buffer the app will of course eventually ANR as it is stuck on EGLSwapBuffers. Here we fix two cases where this could have happened: 1. Currently if we are blast syncing and report draw is true we send the buffer to the WM. This is from an earlier version of the code and is not correct. The WM now explicitly notifies us if it wants to receive the buffer, and so we avoid sending it if it hasn't asked. 2. We should pause the renderer in addition to fencing it otherwise a render thread animation frame could sneak in. We are right on the verge of kicking off a new frame so this shouldn't have much impact besides ensuring overlapping frames don't confuse our transaction logic. Bug: 155300507 Test: Existing tests pass. Change-Id: I816d806da6c09ae12734de8909c0e61af433f93f --- core/java/android/view/ViewRootImpl.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'core/java/android/view/ViewRootImpl.java') diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 42f11c162473..e10fcfbcca8d 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -704,6 +704,11 @@ public final class ViewRootImpl implements ViewParent, // draw returns. private SurfaceControl.Transaction mRtBLASTSyncTransaction = new SurfaceControl.Transaction(); + // Keeps track of whether the WM requested us to use BLAST Sync when calling relayout. + // We use this to make sure we don't send the WM transactions from an internal BLAST sync + // (e.g. SurfaceView) + private boolean mSendNextFrameToWm = false; + private HashSet mRootScrollCaptureCallbacks; private String mTag = TAG; @@ -3053,6 +3058,7 @@ public final class ViewRootImpl implements ViewParent, if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC) != 0) { reportNextDraw(); setUseBLASTSyncTransaction(); + mSendNextFrameToWm = true; } boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; @@ -3762,7 +3768,7 @@ public final class ViewRootImpl implements ViewParent, if (needFrameCompleteCallback) { final Handler handler = mAttachInfo.mHandler; mAttachInfo.mThreadedRenderer.setFrameCompleteCallback((long frameNr) -> { - finishBLASTSync(!reportNextDraw); + finishBLASTSync(!mSendNextFrameToWm); handler.postAtFrontOfQueue(() -> { if (reportNextDraw) { // TODO: Use the frame number @@ -3784,7 +3790,7 @@ public final class ViewRootImpl implements ViewParent, // so if we are BLAST syncing we make sure the previous draw has // totally finished. if (mAttachInfo.mThreadedRenderer != null) { - mAttachInfo.mThreadedRenderer.fence(); + mAttachInfo.mThreadedRenderer.pause(); } mNextReportConsumeBLAST = true; @@ -9752,6 +9758,7 @@ public final class ViewRootImpl implements ViewParent, } private void finishBLASTSync(boolean apply) { + mSendNextFrameToWm = false; if (mNextReportConsumeBLAST) { mNextReportConsumeBLAST = false; -- cgit v1.2.3