Skip to content

Commit

Permalink
fix order
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Jan 14, 2024
1 parent ecbd352 commit 5d97e0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions paparazzi/src/main/java/app/cash/paparazzi/Paparazzi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,17 @@ class Paparazzi @JvmOverloads constructor(
timeNanos: Long,
block: () -> Unit
) {
val frameNanos = timeNanos + TIME_OFFSET_NANOS
// System_Delegate.nanoTime() is nanoTime - previousNanoTime + sChoreographerTime.
// Because of that setNanosTime needs to be called with 0 first so that the previous time will be 0 for the actual
// call. sChoreographerTime does not matter because doFrame which modifies it is not called by Paparazzi.
System_Delegate.setNanosTime(0L)
// Execute the block at the requested time.
System_Delegate.setNanosTime(timeNanos)
System_Delegate.setNanosTime(frameNanos)

// 1 is the only callbackType allowed by doCallbacks
Choreographer_Delegate.doCallbacks(Choreographer.getInstance(), 1, timeNanos)
executeHandlerCallbacks()
// 1 is the only callbackType allowed by doCallbacks
Choreographer_Delegate.doCallbacks(Choreographer.getInstance(), 1, frameNanos)

block()
}
Expand Down Expand Up @@ -609,6 +610,9 @@ class Paparazzi @JvmOverloads constructor(
}

companion object {
/** The choreographer doesn't like 0 as a frame time, so start an hour later. */
internal val TIME_OFFSET_NANOS = TimeUnit.HOURS.toNanos(1L)

internal lateinit var renderer: Renderer
internal val isInitialized get() = ::renderer.isInitialized

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,6 @@ class PaparazziTest {

private val time: Long
get() {
return TimeUnit.NANOSECONDS.toMillis(System_Delegate.nanoTime())
return TimeUnit.NANOSECONDS.toMillis(System_Delegate.nanoTime() - Paparazzi.TIME_OFFSET_NANOS)
}
}

0 comments on commit 5d97e0a

Please sign in to comment.