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

Commit ec8d0fee authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Remove scheduleTraversal when applyTransactionOnDraw is called

When a caller invokes applyTransactionOnDraw, it means they want to sync
the transaction with the next frame change. This doesn't mean we need to
schedule the frame change at this time. It doesn't make sense for the
caller to attempt to sync a transaction without making any attempt to
draw a frame.

Also this cleans up code where there's nothing new to draw in
performTraversal, but there was pendingTransaction. The draw code will
return false and the code later on will ensure it applies the
transaction.

Add logs and traces to VRI

Test: AttachedSurfaceControlSyncTest
Test: AttachedSurfaceControlTest
Bug: 302404882
Bug: 302690479
Change-Id: I5add18c672060de924b4efd7e36f442f1ad796cf
parent c3ed83e7
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -3858,7 +3858,8 @@ public final class ViewRootImpl implements ViewParent,
                mPendingTransitions.clear();
            }

            handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction);
            handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction,
                    "view not visible");
        } else if (cancelAndRedraw) {
            mLastPerformTraversalsSkipDrawReason = cancelDueToPreDrawListener
                ? "predraw_" + mAttachInfo.mTreeObserver.getLastDispatchOnPreDrawCanceledReason()
@@ -3873,7 +3874,8 @@ public final class ViewRootImpl implements ViewParent,
                mPendingTransitions.clear();
            }
            if (!performDraw(mActiveSurfaceSyncGroup)) {
                handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction);
                handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction,
                        mLastPerformDrawSkippedReason);
            }
        }

@@ -4665,6 +4667,10 @@ public final class ViewRootImpl implements ViewParent,

                return didProduceBuffer -> {
                    if (!didProduceBuffer) {
                        Trace.instant(Trace.TRACE_TAG_VIEW,
                                "Transaction not synced due to no frame drawn-" + mTag);
                        Log.d(mTag, "Pending transaction will not be applied in sync with a draw "
                                + "because there was nothing new to draw");
                        mBlastBufferQueue.applyPendingTransactions(frame);
                    }
                };
@@ -4687,8 +4693,7 @@ public final class ViewRootImpl implements ViewParent,
            return false;
        }

        final boolean fullRedrawNeeded =
                mFullRedrawNeeded || surfaceSyncGroup != null || mHasPendingTransactions;
        final boolean fullRedrawNeeded = mFullRedrawNeeded || surfaceSyncGroup != null;
        mFullRedrawNeeded = false;

        mIsDrawing = true;
@@ -4748,7 +4753,8 @@ public final class ViewRootImpl implements ViewParent,
            if (mSurfaceHolder != null && mSurface.isValid()) {
                usingAsyncReport = true;
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(() -> {
                    handleSyncRequestWhenNoAsyncDraw(surfaceSyncGroup, pendingTransaction);
                    handleSyncRequestWhenNoAsyncDraw(surfaceSyncGroup, pendingTransaction,
                            "SurfaceHolder");
                });

                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
@@ -4762,7 +4768,8 @@ public final class ViewRootImpl implements ViewParent,
        }

        if (!usingAsyncReport) {
            handleSyncRequestWhenNoAsyncDraw(surfaceSyncGroup, pendingTransaction);
            handleSyncRequestWhenNoAsyncDraw(surfaceSyncGroup, pendingTransaction,
                    "no async report");
        }

        if (mPerformContentCapture) {
@@ -4772,13 +4779,19 @@ public final class ViewRootImpl implements ViewParent,
    }

    private void handleSyncRequestWhenNoAsyncDraw(SurfaceSyncGroup surfaceSyncGroup,
            @Nullable Transaction pendingTransaction) {
            @Nullable Transaction pendingTransaction, String logReason) {
        if (surfaceSyncGroup != null) {
            if (pendingTransaction != null) {
                surfaceSyncGroup.addTransaction(pendingTransaction);
            }
            surfaceSyncGroup.markSyncReady();
        } else if (pendingTransaction != null) {
            Trace.instant(Trace.TRACE_TAG_VIEW,
                    "Transaction not synced due to " + logReason + "-" + mTag);
            if (DEBUG_BLAST) {
                Log.d(mTag, "Pending transaction will not be applied in sync with a draw due to "
                        + logReason);
            }
            pendingTransaction.apply();
        }
    }
@@ -8993,7 +9006,8 @@ public final class ViewRootImpl implements ViewParent,
            mAdded = false;
            AnimationHandler.removeRequestor(this);
        }
        handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction);
        handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction,
                "shutting down VRI");
        WindowManagerGlobal.getInstance().doRemoveView(this);
    }

@@ -11362,15 +11376,15 @@ public final class ViewRootImpl implements ViewParent,
    @Override
    public boolean applyTransactionOnDraw(@NonNull SurfaceControl.Transaction t) {
        if (mRemoved || !isHardwareEnabled()) {
            Trace.instant(Trace.TRACE_TAG_VIEW, "applyTransactionOnDraw applyImmediately-" + mTag);
            Log.d(mTag, "applyTransactionOnDraw: Applying transaction immediately");
            t.apply();
        } else {
            Trace.instant(Trace.TRACE_TAG_VIEW, "applyTransactionOnDraw-" + mTag);
            // Copy and clear the passed in transaction for thread safety. The new transaction is
            // accessed on the render thread.
            mPendingTransaction.merge(t);
            mHasPendingTransactions = true;
            // Schedule the traversal to ensure there's an attempt to draw a frame and apply the
            // pending transactions. This is also where the registerFrameCallback will be scheduled.
            scheduleTraversals();
        }
        return true;
    }