From b7620ab4f2723019658814c926e422efc8f46d62 Mon Sep 17 00:00:00 2001 From: Nick Chameyev Date: Fri, 1 Apr 2022 16:48:22 +0100 Subject: [PATCH] Use async callback for unfold overlay synchronization Replaces synchronous applying of unfold black overlay transactions with async versions of apply method. To wait for applying of the second transaction it uses the new addTransactionCommittedListener API in SurfaceControl.Transaction. This also fixes a problem that sometimes the overlay is not shown when unfolding. Bug: 227595670 Test: unfold multiple times and check that the scrim is visible Change-Id: Iaa6a8246e592f0bd0d67df755c73be2b3912d157 --- .../UnfoldLightRevealOverlayAnimation.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt index cbdf87ea0fcc7..8f2a432d0ba1b 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt @@ -155,21 +155,22 @@ constructor( newRoot.relayout(params) { transaction -> val vsyncId = Choreographer.getSfInstance().vsyncId - backgroundExecutor.execute { - // Apply the transaction that contains the first frame of the overlay - // synchronously and apply another empty transaction with - // 'vsyncId + 1' to make sure that it is actually displayed on - // the screen. The second transaction is necessary to remove the screen blocker - // (turn on the brightness) only when the content is actually visible as it - // might be presented only in the next frame. - // See b/197538198 - transaction.setFrameTimelineVsync(vsyncId).apply(/* sync */ true) + // Apply the transaction that contains the first frame of the overlay and apply + // another empty transaction with 'vsyncId + 1' to make sure that it is actually + // displayed on the screen. The second transaction is necessary to remove the screen + // blocker (turn on the brightness) only when the content is actually visible as it + // might be presented only in the next frame. + // See b/197538198 + transaction + .setFrameTimelineVsync(vsyncId) + .apply() - transaction.setFrameTimelineVsync(vsyncId + 1).apply(/* sync */ true) - - Trace.endAsyncSection("UnfoldLightRevealOverlayAnimation#relayout", 0) - callback.run() - } + transaction.setFrameTimelineVsync(vsyncId + 1) + .addTransactionCommittedListener(backgroundExecutor) { + Trace.endAsyncSection("UnfoldLightRevealOverlayAnimation#relayout", 0) + callback.run() + } + .apply() } }