MonotonicFrameClock


Provides a time source for display frames and the ability to perform an action on the next frame. This may be used for matching timing with the refresh rate of a display or otherwise synchronizing work with a desired frame rate.

Summary

Public functions

suspend R
<R : Any?> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R)

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

Cmn

Public properties

open CoroutineContext.Key<*>
Cmn

Extension functions

suspend inline R
<R : Any?> MonotonicFrameClock.withFrameMillis(
    crossinline onFrame: (frameTimeMillis: Long) -> R
)

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in milliseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

Cmn

Inherited functions

From kotlin.coroutines.CoroutineContext
open operator CoroutineContext
Cmn
From kotlin.coroutines.CoroutineContext.Element
open R
<R : Any?> fold(initial: R, operation: (CoroutineContext.Element, R) -> R)
Cmn
open operator E?
Cmn
open CoroutineContext
Cmn

Public functions

withFrameNanos

suspend fun <R : Any?> withFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

frameTimeNanos should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value provided by withFrameNanos is implementation defined. Time values provided are strictly monotonically increasing; after a call to withFrameNanos completes it must not provide the same value again for a subsequent call.

Public properties

key

open val keyCoroutineContext.Key<*>

Extension functions

withFrameMillis

suspend inline fun <R : Any?> MonotonicFrameClock.withFrameMillis(
    crossinline onFrame: (frameTimeMillis: Long) -> R
): R

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in milliseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

frameTimeMillis should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value provided by MonotonicFrameClock.withFrameMillis is implementation defined. Time values provided are monotonically increasing; after a call to withFrameMillis completes it must not provide a smaller value for a subsequent call.