SyncFenceCompat


public final class SyncFenceCompat implements AutoCloseable


A synchronization primitive which signals when hardware units have completed work on a particular resource. They initially start in an unsignaled state and make a one-time transaction to either a signaled or error state.

SyncFenceCompat is a presentation fence used in combination with SurfaceControlCompat.Transaction.setBuffer. Note that depending on API level, this will utilize either android.hardware.SyncFence or a compatibility implementation.

Summary

Constants

static final long

An invalid signal time.

static final long

A pending signal time.

Public methods

final boolean
await(long timeoutNanos)

Waits for a SyncFenceCompat to signal for up to the timeout duration

final boolean

Waits forever for a SyncFenceImpl to signal

void

Close the SyncFenceImpl

static final @NonNull SyncFenceCompat

Creates a native synchronization fence from an EGLSync object.

final long

Returns the time that the fence signaled in the CLOCK_MONOTONIC time domain.

final boolean

Checks if the SyncFence object is valid.

Constants

SIGNAL_TIME_INVALID

public static final long SIGNAL_TIME_INVALID

An invalid signal time. Represents either the signal time for a SyncFence that isn't valid (that is, isValid is false), or if an error occurred while attempting to retrieve the signal time.

SIGNAL_TIME_PENDING

public static final long SIGNAL_TIME_PENDING

A pending signal time. This is equivalent to the max value of a long, representing an infinitely far point in the future.

Public methods

await

Added in 1.0.0
public final boolean await(long timeoutNanos)

Waits for a SyncFenceCompat to signal for up to the timeout duration

Parameters
long timeoutNanos

time in nanoseconds to wait for before timing out.

awaitForever

Added in 1.0.0
public final boolean awaitForever()

Waits forever for a SyncFenceImpl to signal

close

Added in 1.0.0
public void close()

Close the SyncFenceImpl

createNativeSyncFence

Added in 1.0.0
public static final @NonNull SyncFenceCompat createNativeSyncFence()

Creates a native synchronization fence from an EGLSync object.

Throws
kotlin.IllegalStateException

if EGL dependencies cannot be resolved

getSignalTimeNanos

Added in 1.0.0
@RequiresApi(value = 26)
public final long getSignalTimeNanos()

Returns the time that the fence signaled in the CLOCK_MONOTONIC time domain. This returns an instant, SyncFenceCompat.SIGNAL_TIME_INVALID if the SyncFence is invalid, and if the fence hasn't yet signaled, then SyncFenceCompat.SIGNAL_TIME_PENDING is returned.

isValid

Added in 1.0.0
public final boolean isValid()

Checks if the SyncFence object is valid.

Returns
boolean

true if it is valid, false otherwise