Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f1324ff authored by Robert Carr's avatar Robert Carr Committed by Rob Carr
Browse files

ViewRootImpl: Resilience for applyOnNextDraw

If HWUI doesn't go on to produce a buffer (for example because
there were no changes) we need to ensure we flush the pending
transactions, otherwise our transaction can end up stuck in
BLASTBufferQueue no mans land until another draw eventually occurs.

Bug: 196926363
Bug: 217973491
Test: SurfaceViewSurfacePackageValidatorTest#testSurfacePackageNoFlicker
Change-Id: Ic830c75ed2c3d68cde7455e21a29e286a3bd3690
parent d26814a0
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -583,6 +583,12 @@ public final class ViewRootImpl implements ViewParent,
    boolean mForceNextWindowRelayout;
    CountDownLatch mWindowDrawCountDown;

    // Whether we have used applyTransactionOnDraw to schedule an RT
    // frame callback consuming a passed in transaction. In this case
    // we also need to schedule a commit callback so we can observe
    // if the draw was skipped, and the BBQ pending transactions.
    boolean mHasPendingTransactions;

    boolean mIsDrawing;
    int mLastSystemUiVisibility;
    int mClientWindowLayoutFlags;
@@ -4184,6 +4190,9 @@ public final class ViewRootImpl implements ViewParent,
                        mRtLastAttemptedDrawFrameNum);
                tmpTransaction.merge(pendingTransactions);
            }
            if (!useBlastSync && !reportNextDraw) {
                tmpTransaction.apply();
            }

            // Post at front of queue so the buffer can be processed immediately and allow RT
            // to continue processing new buffers. If RT tries to process buffers before the sync
@@ -4214,7 +4223,7 @@ public final class ViewRootImpl implements ViewParent,
        final boolean hasBlurUpdates = mBlurRegionAggregator.hasUpdates();
        final boolean needsCallbackForBlur = hasBlurUpdates || mBlurRegionAggregator.hasRegions();

        if (!useBlastSync && !needsCallbackForBlur && !reportNextDraw) {
        if (!useBlastSync && !needsCallbackForBlur && !reportNextDraw && !mHasPendingTransactions) {
            return null;
        }

@@ -4226,11 +4235,14 @@ public final class ViewRootImpl implements ViewParent,
                    + " nextDrawUseBlastSync=" + useBlastSync
                    + " reportNextDraw=" + reportNextDraw
                    + " hasBlurUpdates=" + hasBlurUpdates
                    + " hasBlastSyncConsumer=" + (blastSyncConsumer != null));
                    + " hasBlastSyncConsumer=" + (blastSyncConsumer != null)
                    + " mHasPendingTransactions=" + mHasPendingTransactions);
        }

        final BackgroundBlurDrawable.BlurRegion[] blurRegionsForFrame =
                needsCallbackForBlur ?  mBlurRegionAggregator.getBlurRegionsCopyForRT() : null;
        final boolean hasPendingTransactions = mHasPendingTransactions;
        mHasPendingTransactions = false;

        // The callback will run on the render thread.
        return new FrameDrawingCallback() {
@@ -4257,7 +4269,7 @@ public final class ViewRootImpl implements ViewParent,
                    return null;
                }

                if (!useBlastSync && !reportNextDraw) {
                if (!useBlastSync && !reportNextDraw && !hasPendingTransactions) {
                    return null;
                }

@@ -10700,7 +10712,10 @@ public final class ViewRootImpl implements ViewParent,
        if (mRemoved || !isHardwareEnabled()) {
            t.apply();
        } else {
            registerRtFrameCallback(frame -> mergeWithNextTransaction(t, frame));
            mHasPendingTransactions = true;
            registerRtFrameCallback(frame -> {
                mergeWithNextTransaction(t, frame);
            });
        }
        return true;
    }