AKA: Canvas requestPaint () is too slow; requestAnimationFrame () too fast
I am trying to create a QML canvas that replicates as quickly as possible - once per update in the main UI rendering loop - to create an FPS timer.
I originally wrote this simple test:
import QtQuick 2.7 import QtQuick.Window 2.2 Window { visible:true; width:100; height:100 Canvas { anchors.fill:parent onPaint: console.log(+new Date) } }
I get a callback only once. So I added requestPaint() :
onPaint: { console.log(+new Date) requestPaint() }
No change: I get only one callback. Same thing if I use markDirty() . Same thing if I actually draw something on the canvas every callback.
So, I went to requestAnimationFrame() :
import QtQuick 2.7 import QtQuick.Window 2.2 Window { visible:true; width:100; height:100 Canvas { anchors.fill:parent Component.onCompleted: crank() function crank(){ console.log(+new Date) requestAnimationFrame(crank) } } }
Now I get callbacks, but too many. On average, I get 77 callbacks per millisecond, several times more than 127 callbacks per millisecond. So many callbacks that nothing is displayed in the application, not even initially. Even if I remove console.log() to prove that I am not attached to i / o).
How can I get my canvas to recolor once per frame so that I can accurately measure FPS? Anyone why requestPaint() actually doesn't work? And why does requestAnimationFrame() seem useless?
source share