-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
7 changed files
with
71 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.legado.app.utils | ||
|
||
import android.view.Choreographer | ||
|
||
class SyncedRenderer(val doFrame: (frameTime: Double) -> Unit) { | ||
|
||
private var callback: (Long) -> Unit = {} | ||
|
||
fun start() { | ||
var currTime = System.nanoTime() / 1000000.0 | ||
callback = { | ||
val currTimeMs = it / 1000000.0 | ||
val frameTime = currTimeMs - currTime | ||
currTime = currTimeMs | ||
doFrame(frameTime) | ||
Choreographer.getInstance().postFrameCallback(callback) | ||
} | ||
Choreographer.getInstance().postFrameCallback(callback) | ||
} | ||
|
||
fun stop() { | ||
Choreographer.getInstance().removeFrameCallback(callback) | ||
callback = {} | ||
} | ||
} |