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

Commit 2e09cb31 authored by chaviw's avatar chaviw
Browse files

Set mSyncBuffer to true when VRI did not initiate the sync request

VRI can initiate syncs, but they can also happen from other places when
using SurfaceSyncer. When VRI initiates the sync, sometimes the buffer
needs to be synced. Other times, we just want to know the buffer has
drawn, but don't actually need to sync the buffer.

When a sync is initiated from outside VRI, using SurfaceSyncer, we
always want to sync the buffer. This change ensures that if the sync was
started from an outside request, it will set mSyncBuffer to true.

An additional part to clarify the sync logic, renamed mLastSyncId to
mSyncId and renamed isInSync to isInLocalSync to clarify that the
mSyncId only represents VRI initiated syncs.

Test: Internet Dialog syncs buffer
Fixes: 229098223
Change-Id: I99e9e6341a487d59c33a33a61e442be7909518c2
parent e360c271
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -967,7 +967,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                final boolean redrawNeeded = sizeChanged || creating || hintChanged
                        || (mVisible && !mDrawFinished);
                boolean shouldSyncBuffer =
                        redrawNeeded && viewRoot.wasRelayoutRequested() && viewRoot.isInSync();
                        redrawNeeded && viewRoot.wasRelayoutRequested() && viewRoot.isInLocalSync();
                SyncBufferTransactionCallback syncBufferTransactionCallback = null;
                if (shouldSyncBuffer) {
                    syncBufferTransactionCallback = new SyncBufferTransactionCallback();
+24 −16
Original line number Diff line number Diff line
@@ -319,6 +319,8 @@ public final class ViewRootImpl implements ViewParent,
     */
    private static final int SCROLL_CAPTURE_REQUEST_TIMEOUT_MILLIS = 2500;

    private static final int UNSET_SYNC_ID = -1;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>();

@@ -815,7 +817,7 @@ public final class ViewRootImpl implements ViewParent,
    }

    private final SurfaceSyncer mSurfaceSyncer = new SurfaceSyncer();
    private int mLastSyncId = -1;
    private int mSyncId = UNSET_SYNC_ID;
    private SurfaceSyncer.SyncBufferCallback mSyncBufferCallback;
    private int mNumSyncsInProgress = 0;

@@ -3462,21 +3464,21 @@ public final class ViewRootImpl implements ViewParent,
            mReportNextDraw = false;
            mSyncBufferCallback = null;
            mSyncBuffer = false;
            if (mLastSyncId != -1) {
                mSurfaceSyncer.markSyncReady(mLastSyncId);
                mLastSyncId = -1;
            if (isInLocalSync()) {
                mSurfaceSyncer.markSyncReady(mSyncId);
                mSyncId = UNSET_SYNC_ID;
            }
        }
    }

    private void createSyncIfNeeded() {
        // Started a sync already or there's nothing needing to sync
        if (mLastSyncId != -1 || !mReportNextDraw) {
        if (isInLocalSync() || !mReportNextDraw) {
            return;
        }

        final int seqId = mSyncSeqId;
        mLastSyncId = mSurfaceSyncer.setupSync(transaction -> {
        mSyncId = mSurfaceSyncer.setupSync(transaction -> {
            // Callback will be invoked on executor thread so post to main thread.
            mHandler.postAtFrontOfQueue(() -> {
                mSurfaceChangedTransaction.merge(transaction);
@@ -3484,9 +3486,9 @@ public final class ViewRootImpl implements ViewParent,
            });
        });
        if (DEBUG_BLAST) {
            Log.d(mTag, "Setup new sync id=" + mLastSyncId);
            Log.d(mTag, "Setup new sync id=" + mSyncId);
        }
        mSurfaceSyncer.addToSync(mLastSyncId, mSyncTarget);
        mSurfaceSyncer.addToSync(mSyncId, mSyncTarget);
    }

    private void notifyContentCatpureEvents() {
@@ -4122,17 +4124,19 @@ public final class ViewRootImpl implements ViewParent,
        return mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled();
    }

    boolean addToSync(SurfaceSyncer.SyncTarget syncable) {
        if (mLastSyncId == -1) {
            return false;
    void addToSync(SurfaceSyncer.SyncTarget syncable) {
        if (!isInLocalSync()) {
            return;
        }
        mSurfaceSyncer.addToSync(mLastSyncId, syncable);
        return true;
        mSurfaceSyncer.addToSync(mSyncId, syncable);
    }


    public boolean isInSync() {
        return mLastSyncId != -1;
    /**
     * This VRI is currently in the middle of a sync request, but specifically one initiated from
     * within VRI.
     */
    public boolean isInLocalSync() {
        return mSyncId != UNSET_SYNC_ID;
    }

    private void addFrameCommitCallbackIfNeeded() {
@@ -10889,6 +10893,10 @@ public final class ViewRootImpl implements ViewParent,

    private void readyToSync(SurfaceSyncer.SyncBufferCallback syncBufferCallback) {
        mNumSyncsInProgress++;
        if (!isInLocalSync()) {
            // Always sync the buffer if the sync request did not come from VRI.
            mSyncBuffer = true;
        }
        if (mAttachInfo.mThreadedRenderer != null) {
            HardwareRenderer.setRtAnimationsEnabled(false);
        }