|
|
@ -9,7 +9,6 @@ import androidx.compose.runtime.* |
|
|
|
import androidx.compose.runtime.snapshots.ObserverHandle |
|
|
|
import androidx.compose.runtime.snapshots.ObserverHandle |
|
|
|
import androidx.compose.runtime.snapshots.Snapshot |
|
|
|
import androidx.compose.runtime.snapshots.Snapshot |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.datetime.Clock |
|
|
|
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.resume |
|
|
|
import kotlin.coroutines.resume |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
@ -76,11 +75,14 @@ private object GlobalSnapshotManager { |
|
|
|
private class MonotonicClockImpl : MonotonicFrameClock { |
|
|
|
private class MonotonicClockImpl : MonotonicFrameClock { |
|
|
|
|
|
|
|
|
|
|
|
private val NANOS_PER_MILLI = 1_000_000 |
|
|
|
private val NANOS_PER_MILLI = 1_000_000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var i = 0L |
|
|
|
|
|
|
|
|
|
|
|
override suspend fun <R> withFrameNanos( |
|
|
|
override suspend fun <R> withFrameNanos( |
|
|
|
onFrame: (Long) -> R |
|
|
|
onFrame: (Long) -> R |
|
|
|
): R = suspendCoroutine { continuation -> |
|
|
|
): R = suspendCoroutine { continuation -> |
|
|
|
val now = Clock.System.now() |
|
|
|
val now = ++i |
|
|
|
val currentNanos = now.toEpochMilliseconds() * NANOS_PER_MILLI + now.nanosecondsOfSecond |
|
|
|
val currentNanos = now * NANOS_PER_MILLI |
|
|
|
val result = onFrame(currentNanos) |
|
|
|
val result = onFrame(currentNanos) |
|
|
|
continuation.resume(result) |
|
|
|
continuation.resume(result) |
|
|
|
} |
|
|
|
} |
|
|
|