[Development] Custom QAnimationDriver

Gunnar Sletta gunnar.sletta at jolla.com
Fri Apr 11 20:23:10 CEST 2014


On 10 Apr 2014, at 13:29, Тимур Артиков <t.artikov at gmail.com> wrote:

> Hi,
> I'm trying to use Qt Quick for generation image sequence for video broadcasting.
> To do that I need to update Qt Quick scene animations with frame rate of the output video.
> I tried to create class derived from QAnimationDriver and overload the QAnimationDriver::advance method
> which calls QUnifiedTimer::updateAnimationTimers to control current time of animations.
> The problem is that QUnifiedTimer::updateAnimationTimers method is called from other places 
> avoiding my AnimationDriver (for example when a new animation is started).
> As result, animations are updated with incorrect time.

You shouldn't need to implement an animation driver. 

Animations will by default be advanced by currentTime at the time the animation is ticked. That means that if you have a vsynced graphics stack with blocking swap, the animations will automatically be ticked in sync with your video output. 

However.. 

If your driver implements a buffering scheme that blocks somewhere else or has multiple buffers, you might end up getting the "advance" call at non-even intervals which will result in jerky animations. (Mac OS X, for instance has does it like this). To remedy this problem you need to increment each frame with the vsync delta. You get this by either reporting BufferQueueingOpenGL from your platform plugin or by setting QSG_FIXED_ANIMATION_STEPS=yes in the environment of the application. (On Mac you have BufferQueueingOpenGL, for instance).

With fixed animations you have two remaining issues. First is that fixed steps mean that animations that run for a long time might drift time-wise from the clock time. In practice this is rarely a real problem and it is easy to work around. The second issue is that if your application is running slow, the application still ticks at vsync per slow frame so the animations slow down. On a desktop machine this happens so rarely that it isn't a problem in practice. 

An animation driver is required if you have very varying performance, often switching between steady 60fps (or 50 or 29 or whatever your app has) and 1fps and 30fps. Then you want the fixed steps for when things are good and time-based ticking for when things are bad. This is a problem that a platform typically needs to deal with. An single application should be able to run at steady framerate and thus rely on only the fixed steps.

cheers,
Gunnar


> 
> Here is a link to my test code: 
> https://dl.dropboxusercontent.com/u/25159021/animation_driver_test.zip
> There is the Qt Quick scene with a button and some animated objects. 
> Moving the mouse cursor over the button leads to jerking of animations.
> 
> 
> Thanks in advance, Timur
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list