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

Commit 5a672421 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Automerger Merge Worker
Browse files

Merge "Register frame callbacks for sync right before draw" into udc-qpr-dev...

Merge "Register frame callbacks for sync right before draw" into udc-qpr-dev am: 92c44a50 am: fe7497a6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23773376



Change-Id: Ib243e64d1d36c624c581085f582dbed5cb82bee5
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 3ef59228 fe7497a6
Loading
Loading
Loading
Loading
+33 −25
Original line number Original line Diff line number Diff line
@@ -3824,7 +3824,7 @@ public final class ViewRootImpl implements ViewParent,
                }
                }
                mPendingTransitions.clear();
                mPendingTransitions.clear();
            }
            }
            if (!performDraw() && mActiveSurfaceSyncGroup != null) {
            if (!performDraw(mActiveSurfaceSyncGroup) && mActiveSurfaceSyncGroup != null) {
                mActiveSurfaceSyncGroup.markSyncReady();
                mActiveSurfaceSyncGroup.markSyncReady();
            }
            }
        }
        }
@@ -4590,6 +4590,10 @@ public final class ViewRootImpl implements ViewParent,
        });
        });
    }
    }


    /**
     * These callbacks check if the draw failed for any reason and apply
     * those transactions directly so they don't get stuck forever.
     */
    private void registerCallbackForPendingTransactions() {
    private void registerCallbackForPendingTransactions() {
        Transaction t = new Transaction();
        Transaction t = new Transaction();
        t.merge(mPendingTransaction);
        t.merge(mPendingTransaction);
@@ -4618,7 +4622,7 @@ public final class ViewRootImpl implements ViewParent,
        });
        });
    }
    }


    private boolean performDraw() {
    private boolean performDraw(@Nullable SurfaceSyncGroup surfaceSyncGroup) {
        mLastPerformDrawSkippedReason = null;
        mLastPerformDrawSkippedReason = null;
        if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) {
        if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) {
            mLastPerformDrawSkippedReason = "screen_off";
            mLastPerformDrawSkippedReason = "screen_off";
@@ -4628,7 +4632,7 @@ public final class ViewRootImpl implements ViewParent,
            return false;
            return false;
        }
        }


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


        mIsDrawing = true;
        mIsDrawing = true;
@@ -4636,22 +4640,12 @@ public final class ViewRootImpl implements ViewParent,


        addFrameCommitCallbackIfNeeded();
        addFrameCommitCallbackIfNeeded();


        boolean usingAsyncReport = isHardwareEnabled() && mActiveSurfaceSyncGroup != null;
        boolean usingAsyncReport;
        if (usingAsyncReport) {
            registerCallbacksForSync(mSyncBuffer, mActiveSurfaceSyncGroup);
        } else if (mHasPendingTransactions) {
            // These callbacks are only needed if there's no sync involved and there were calls to
            // applyTransactionOnDraw. These callbacks check if the draw failed for any reason and
            // apply those transactions directly so they don't get stuck forever.
            registerCallbackForPendingTransactions();
        }
        mHasPendingTransactions = false;


        try {
        try {
            boolean canUseAsync = draw(fullRedrawNeeded, usingAsyncReport && mSyncBuffer);
            usingAsyncReport = draw(fullRedrawNeeded, surfaceSyncGroup, mSyncBuffer);
            if (usingAsyncReport && !canUseAsync) {
            if (mAttachInfo.mThreadedRenderer != null && !usingAsyncReport) {
                mAttachInfo.mThreadedRenderer.setFrameCallback(null);
                mAttachInfo.mThreadedRenderer.setFrameCallback(null);
                usingAsyncReport = false;
            }
            }
        } finally {
        } finally {
            mIsDrawing = false;
            mIsDrawing = false;
@@ -4689,10 +4683,12 @@ public final class ViewRootImpl implements ViewParent,
            }
            }


            if (mSurfaceHolder != null && mSurface.isValid()) {
            if (mSurfaceHolder != null && mSurface.isValid()) {
                final SurfaceSyncGroup surfaceSyncGroup = mActiveSurfaceSyncGroup;
                usingAsyncReport = true;
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(() ->
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(() -> {
                        mHandler.post(() -> surfaceSyncGroup.markSyncReady()));
                    if (surfaceSyncGroup != null) {
                mActiveSurfaceSyncGroup = null;
                        surfaceSyncGroup.markSyncReady();
                    }
                });


                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
                SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();


@@ -4703,8 +4699,9 @@ public final class ViewRootImpl implements ViewParent,
                }
                }
            }
            }
        }
        }
        if (mActiveSurfaceSyncGroup != null && !usingAsyncReport) {

            mActiveSurfaceSyncGroup.markSyncReady();
        if (surfaceSyncGroup != null && !usingAsyncReport) {
            surfaceSyncGroup.markSyncReady();
        }
        }
        if (mPerformContentCapture) {
        if (mPerformContentCapture) {
            performContentCaptureInitialReport();
            performContentCaptureInitialReport();
@@ -4797,7 +4794,8 @@ public final class ViewRootImpl implements ViewParent,
        }
        }
    }
    }


    private boolean draw(boolean fullRedrawNeeded, boolean forceDraw) {
    private boolean draw(boolean fullRedrawNeeded,
            @Nullable SurfaceSyncGroup activeSyncGroup, boolean syncBuffer) {
        Surface surface = mSurface;
        Surface surface = mSurface;
        if (!surface.isValid()) {
        if (!surface.isValid()) {
            return false;
            return false;
@@ -4935,9 +4933,19 @@ public final class ViewRootImpl implements ViewParent,
                    mAttachInfo.mThreadedRenderer.setTargetHdrSdrRatio(mRenderHdrSdrRatio);
                    mAttachInfo.mThreadedRenderer.setTargetHdrSdrRatio(mRenderHdrSdrRatio);
                }
                }


                if (forceDraw) {
                if (activeSyncGroup != null) {
                    registerCallbacksForSync(syncBuffer, activeSyncGroup);
                    if (syncBuffer) {
                        mAttachInfo.mThreadedRenderer.forceDrawNextFrame();
                        mAttachInfo.mThreadedRenderer.forceDrawNextFrame();
                    }
                    }
                } else if (mHasPendingTransactions) {
                    // Register a calback 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);
                mAttachInfo.mThreadedRenderer.draw(mView, mAttachInfo, this);
            } else {
            } else {
                // If we get here with a disabled & requested hardware renderer, something went
                // If we get here with a disabled & requested hardware renderer, something went