Unverified Commit 38781274 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

js CanvasRenderer: prevent scheduling another drawFrame if previous request is still pending (#421)

Co-authored-by: 's avatarOleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
parent ce81afca
......@@ -34,8 +34,15 @@ abstract class CanvasRenderer constructor(htmlCanvas: HTMLCanvasElement, val wid
abstract fun drawFrame(currentTimestamp: Double)
private var redrawScheduled = false
fun needRedraw() {
if (redrawScheduled) {
return
}
redrawScheduled = true
window.requestAnimationFrame { timestamp ->
redrawScheduled = false
GL.makeContextCurrent(contextPointer)
canvas.clear(-1)
drawFrame(timestamp)
......@@ -43,4 +50,4 @@ abstract class CanvasRenderer constructor(htmlCanvas: HTMLCanvasElement, val wid
context.flush()
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment