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

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

Merge "Refactor SurfaceSyncer to use SurfaceSyncGroups instead of syncId"

parents 95fab76b ea372b7f
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@ package android.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.UiThread;
import android.graphics.Region;
import android.hardware.HardwareBuffer;
import android.window.SurfaceSyncGroup;

/**
 * Provides an interface to the root-Surface of a View Hierarchy or Window. This
@@ -138,4 +138,12 @@ public interface AttachedSurfaceControl {
     */
    default void setTouchableRegion(@Nullable Region r) {
    }

    /**
     * Returns a SyncTarget that can be used to sync {@link AttachedSurfaceControl} in a
     * {@link SurfaceSyncGroup}
     *
     * @hide
     */
    SurfaceSyncGroup.SyncTarget getSyncTarget();
}
+14 −14
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ import android.util.Log;
import android.view.SurfaceControl.Transaction;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.IAccessibilityEmbeddedConnection;
import android.window.SurfaceSyncer;
import android.window.SurfaceSyncGroup;

import com.android.internal.view.SurfaceCallbackHelper;

@@ -210,8 +210,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall

    private int mSurfaceFlags = SurfaceControl.HIDDEN;

    private final SurfaceSyncer mSurfaceSyncer = new SurfaceSyncer();
    private final ArraySet<Integer> mSyncIds = new ArraySet<>();
    private final ArraySet<SurfaceSyncGroup> mSyncGroups = new ArraySet<>();

    /**
     * Transaction that should be used from the render thread. This transaction is only thread safe
@@ -1077,20 +1076,21 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    }

    private void handleSyncNoBuffer(SurfaceHolder.Callback[] callbacks) {
        final int syncId = mSurfaceSyncer.setupSync(this::onDrawFinished);
        final SurfaceSyncGroup syncGroup = new SurfaceSyncGroup();
        synchronized (mSyncGroups) {
            mSyncGroups.add(syncGroup);
        }

        mSurfaceSyncer.addToSync(syncId, syncBufferCallback -> redrawNeededAsync(callbacks,
        syncGroup.addToSync(syncBufferCallback -> redrawNeededAsync(callbacks,
                () -> {
                    syncBufferCallback.onBufferReady(null);
                    synchronized (mSyncIds) {
                        mSyncIds.remove(syncId);
                    onDrawFinished();
                    synchronized (mSyncGroups) {
                        mSyncGroups.remove(syncGroup);
                    }
                }));

        mSurfaceSyncer.markSyncReady(syncId);
        synchronized (mSyncIds) {
            mSyncIds.add(syncId);
        }
        syncGroup.markSyncReady();
    }

    private void redrawNeededAsync(SurfaceHolder.Callback[] callbacks,
@@ -1106,9 +1106,9 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    public void surfaceSyncStarted() {
        ViewRootImpl viewRoot = getViewRootImpl();
        if (viewRoot != null) {
            synchronized (mSyncIds) {
                for (int syncId : mSyncIds) {
                    viewRoot.mergeSync(syncId, mSurfaceSyncer);
            synchronized (mSyncGroups) {
                for (SurfaceSyncGroup syncGroup : mSyncGroups) {
                    viewRoot.mergeSync(syncGroup);
                }
            }
        }
+26 −20
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ import android.window.ClientWindowFrames;
import android.window.CompatOnBackInvokedCallback;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.SurfaceSyncer;
import android.window.SurfaceSyncGroup;
import android.window.WindowOnBackInvokedDispatcher;

import com.android.internal.R;
@@ -829,9 +829,8 @@ public final class ViewRootImpl implements ViewParent,
        return mHandwritingInitiator;
    }

    private final SurfaceSyncer mSurfaceSyncer = new SurfaceSyncer();
    private int mSyncId = UNSET_SYNC_ID;
    private SurfaceSyncer.SyncBufferCallback mSyncBufferCallback;
    private SurfaceSyncGroup mSyncGroup;
    private SurfaceSyncGroup.SyncBufferCallback mSyncBufferCallback;
    private int mNumSyncsInProgress = 0;

    private HashSet<ScrollCaptureCallback> mRootScrollCaptureCallbacks;
@@ -3594,8 +3593,8 @@ public final class ViewRootImpl implements ViewParent,
            mSyncBufferCallback = null;
            mSyncBuffer = false;
            if (isInLocalSync()) {
                mSurfaceSyncer.markSyncReady(mSyncId);
                mSyncId = UNSET_SYNC_ID;
                mSyncGroup.markSyncReady();
                mSyncGroup = null;
            }
        }
    }
@@ -3607,17 +3606,19 @@ public final class ViewRootImpl implements ViewParent,
        }

        final int seqId = mSyncSeqId;
        mSyncId = mSurfaceSyncer.setupSync(transaction -> {
        mSyncGroup = new SurfaceSyncGroup(transaction -> {
            // Callback will be invoked on executor thread so post to main thread.
            mHandler.postAtFrontOfQueue(() -> {
                if (transaction != null) {
                    mSurfaceChangedTransaction.merge(transaction);
                }
                reportDrawFinished(seqId);
            });
        });
        if (DEBUG_BLAST) {
            Log.d(mTag, "Setup new sync id=" + mSyncId);
            Log.d(mTag, "Setup new sync id=" + mSyncGroup);
        }
        mSurfaceSyncer.addToSync(mSyncId, mSyncTarget);
        mSyncGroup.addToSync(mSyncTarget);
        notifySurfaceSyncStarted();
    }

@@ -4255,11 +4256,11 @@ public final class ViewRootImpl implements ViewParent,
        return mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled();
    }

    void addToSync(SurfaceSyncer.SyncTarget syncable) {
    void addToSync(SurfaceSyncGroup.SyncTarget syncable) {
        if (!isInLocalSync()) {
            return;
        }
        mSurfaceSyncer.addToSync(mSyncId, syncable);
        mSyncGroup.addToSync(syncable);
    }

    /**
@@ -4267,7 +4268,7 @@ public final class ViewRootImpl implements ViewParent,
     * within VRI.
     */
    public boolean isInLocalSync() {
        return mSyncId != UNSET_SYNC_ID;
        return mSyncGroup != null;
    }

    private void addFrameCommitCallbackIfNeeded() {
@@ -4392,7 +4393,7 @@ public final class ViewRootImpl implements ViewParent,
            }

            if (mSurfaceHolder != null && mSurface.isValid()) {
                final SurfaceSyncer.SyncBufferCallback syncBufferCallback = mSyncBufferCallback;
                final SurfaceSyncGroup.SyncBufferCallback syncBufferCallback = mSyncBufferCallback;
                SurfaceCallbackHelper sch = new SurfaceCallbackHelper(() ->
                        mHandler.post(() -> syncBufferCallback.onBufferReady(null)));
                mSyncBufferCallback = null;
@@ -10929,7 +10930,7 @@ public final class ViewRootImpl implements ViewParent,
    }

    private void registerCallbacksForSync(boolean syncBuffer,
            final SurfaceSyncer.SyncBufferCallback syncBufferCallback) {
            final SurfaceSyncGroup.SyncBufferCallback syncBufferCallback) {
        if (!isHardwareEnabled()) {
            return;
        }
@@ -11002,9 +11003,9 @@ public final class ViewRootImpl implements ViewParent,
        });
    }

    public final SurfaceSyncer.SyncTarget mSyncTarget = new SurfaceSyncer.SyncTarget() {
    public final SurfaceSyncGroup.SyncTarget mSyncTarget = new SurfaceSyncGroup.SyncTarget() {
        @Override
        public void onReadyToSync(SurfaceSyncer.SyncBufferCallback syncBufferCallback) {
        public void onReadyToSync(SurfaceSyncGroup.SyncBufferCallback syncBufferCallback) {
            readyToSync(syncBufferCallback);
        }

@@ -11018,7 +11019,12 @@ public final class ViewRootImpl implements ViewParent,
        }
    };

    private void readyToSync(SurfaceSyncer.SyncBufferCallback syncBufferCallback) {
    @Override
    public SurfaceSyncGroup.SyncTarget getSyncTarget() {
        return mSyncTarget;
    }

    private void readyToSync(SurfaceSyncGroup.SyncBufferCallback syncBufferCallback) {
        mNumSyncsInProgress++;
        if (!isInLocalSync()) {
            // Always sync the buffer if the sync request did not come from VRI.
@@ -11041,10 +11047,10 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    void mergeSync(int syncId, SurfaceSyncer otherSyncer) {
    void mergeSync(SurfaceSyncGroup otherSyncGroup) {
        if (!isInLocalSync()) {
            return;
        }
        mSurfaceSyncer.merge(mSyncId, syncId, otherSyncer);
        mSyncGroup.merge(otherSyncGroup);
    }
}
Loading