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

Commit c3ed83e7 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Invoke draw if there are pending transactions in VRI" into main

parents 47cae7ca a31bc5c8
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -3858,9 +3858,7 @@ public final class ViewRootImpl implements ViewParent,
                mPendingTransitions.clear();
            }

            if (mActiveSurfaceSyncGroup != null) {
                mActiveSurfaceSyncGroup.markSyncReady();
            }
            handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction);
        } else if (cancelAndRedraw) {
            mLastPerformTraversalsSkipDrawReason = cancelDueToPreDrawListener
                ? "predraw_" + mAttachInfo.mTreeObserver.getLastDispatchOnPreDrawCanceledReason()
@@ -3874,8 +3872,8 @@ public final class ViewRootImpl implements ViewParent,
                }
                mPendingTransitions.clear();
            }
            if (!performDraw(mActiveSurfaceSyncGroup) && mActiveSurfaceSyncGroup != null) {
                mActiveSurfaceSyncGroup.markSyncReady();
            if (!performDraw(mActiveSurfaceSyncGroup)) {
                handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction);
            }
        }

@@ -3890,6 +3888,7 @@ public final class ViewRootImpl implements ViewParent,
            mReportNextDraw = false;
            mLastReportNextDrawReason = null;
            mActiveSurfaceSyncGroup = null;
            mHasPendingTransactions = false;
            mSyncBuffer = false;
            if (isInWMSRequestedSync()) {
                mWmsRequestSyncGroup.markSyncReady();
@@ -4688,7 +4687,8 @@ public final class ViewRootImpl implements ViewParent,
            return false;
        }

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

        mIsDrawing = true;
@@ -4718,8 +4718,15 @@ public final class ViewRootImpl implements ViewParent,
            mAttachInfo.mPendingAnimatingRenderNodes.clear();
        }

        if (mReportNextDraw) {
        final Transaction pendingTransaction;
        if (!usingAsyncReport && mHasPendingTransactions) {
            pendingTransaction = new Transaction();
            pendingTransaction.merge(mPendingTransaction);
        } else {
            pendingTransaction = null;
        }

        if (mReportNextDraw) {
            // if we're using multi-thread renderer, wait for the window frame draws
            if (mWindowDrawCountDown != null) {
                try {
@@ -4741,9 +4748,7 @@ public final class ViewRootImpl implements ViewParent,
            if (mSurfaceHolder != null && mSurface.isValid()) {
                usingAsyncReport = true;
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(() -> {
                    if (surfaceSyncGroup != null) {
                        surfaceSyncGroup.markSyncReady();
                    }
                    handleSyncRequestWhenNoAsyncDraw(surfaceSyncGroup, pendingTransaction);
                });

                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
@@ -4756,15 +4761,27 @@ public final class ViewRootImpl implements ViewParent,
            }
        }

        if (surfaceSyncGroup != null && !usingAsyncReport) {
            surfaceSyncGroup.markSyncReady();
        if (!usingAsyncReport) {
            handleSyncRequestWhenNoAsyncDraw(surfaceSyncGroup, pendingTransaction);
        }

        if (mPerformContentCapture) {
            performContentCaptureInitialReport();
        }
        return true;
    }

    private void handleSyncRequestWhenNoAsyncDraw(SurfaceSyncGroup surfaceSyncGroup,
            @Nullable Transaction pendingTransaction) {
        if (surfaceSyncGroup != null) {
            if (pendingTransaction != null) {
                surfaceSyncGroup.addTransaction(pendingTransaction);
            }
            surfaceSyncGroup.markSyncReady();
        } else if (pendingTransaction != null) {
            pendingTransaction.apply();
        }
    }
    /**
     * Checks (and caches) if content capture is enabled for this context.
     */
@@ -4850,8 +4867,8 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    private boolean draw(boolean fullRedrawNeeded,
            @Nullable SurfaceSyncGroup activeSyncGroup, boolean syncBuffer) {
    private boolean draw(boolean fullRedrawNeeded, @Nullable SurfaceSyncGroup activeSyncGroup,
            boolean syncBuffer) {
        Surface surface = mSurface;
        if (!surface.isValid()) {
            return false;
@@ -4995,12 +5012,11 @@ public final class ViewRootImpl implements ViewParent,
                        mAttachInfo.mThreadedRenderer.forceDrawNextFrame();
                    }
                } else if (mHasPendingTransactions) {
                    // Register a calback if there's no sync involved but there were calls to
                    // Register a callback if there's no sync involved but there were calls to
                    // applyTransactionOnDraw. If there is a sync involved, the sync callback will
                    // handle merging the pending transaction.
                    registerCallbackForPendingTransactions();
                }
                mHasPendingTransactions = false;

                mAttachInfo.mThreadedRenderer.draw(mView, mAttachInfo, this);
            } else {
@@ -8977,13 +8993,7 @@ public final class ViewRootImpl implements ViewParent,
            mAdded = false;
            AnimationHandler.removeRequestor(this);
        }
        if (mActiveSurfaceSyncGroup != null) {
            mActiveSurfaceSyncGroup.markSyncReady();
            mActiveSurfaceSyncGroup = null;
        }
        if (mHasPendingTransactions) {
            mPendingTransaction.apply();
        }
        handleSyncRequestWhenNoAsyncDraw(mActiveSurfaceSyncGroup, mPendingTransaction);
        WindowManagerGlobal.getInstance().doRemoveView(this);
    }

@@ -11502,9 +11512,7 @@ public final class ViewRootImpl implements ViewParent,
            Log.d(mTag, "registerCallbacksForSync syncBuffer=" + syncBuffer);
        }

        Transaction t = new Transaction();
        t.merge(mPendingTransaction);

        surfaceSyncGroup.addTransaction(mPendingTransaction);
        mAttachInfo.mThreadedRenderer.registerRtFrameCallback(new FrameDrawingCallback() {
            @Override
            public void onFrameDraw(long frame) {
@@ -11518,7 +11526,6 @@ public final class ViewRootImpl implements ViewParent,
                                    + frame + ".");
                }

                mergeWithNextTransaction(t, frame);
                // If the syncResults are SYNC_LOST_SURFACE_REWARD_IF_FOUND or
                // SYNC_CONTEXT_IS_STOPPED it means nothing will draw. There's no need to set up
                // any blast sync or commit callback, and the code should directly call