Owen Taylor has written a new blog post about avoiding jitter in composited frame display. Owen -- along with help from Kristian Høgsberg -- made improvements to the algorithm for compositor frame timing as used by GNOME's Mutter compositing window manager and also Wayland's Weston.
The basic algorithm up to this point was when receiving damage, a redraw should be scheduled immediately. If a redraw is scheduled and the system is still waiting for the previous swap to complete, a redraw should be done when the swap completes. This algorithm though doesn't work out ideally when showing content that runs at a fixed frame-rate that is less than the display's frame-rate, such as displaying video content at 24/30 FPS on a 60Hz display.
In the end the modified algorithm he came up with includes introducing a concept of "urgent" frames that can be marked by the application. Now when receiving damage, if it's part of an urgent frame, a redraw will be scheduled immediately. If it's not urgent, schedule a redraw for 2ms after the next VBlank. If a redraw is scheduled for time T and they're still waiting for the previous swap to complete at time T, redraw immediately when the swap completes. "I’m pretty happy with how this algorithm works out in testing, and it may be as good as we can get for X. The main downside I know of is that it only individually solves the two problems – handling clients that need all the rendering resources of the system and handling clients that want minimum jitter for displayed frames, it doesn’t solve the combination. The client that is rendering full-out at 24fps is also vulnerable to jitter from other clients drawing, just like the client that is choosing to run at 24fps. There are mitigation strategies – for example, not triggering a redraw when client that is obscured changes, but I don’t have a full answer. Unredirecting full-screen games definitely is a good idea."
Other possible approaches being evaluated for avoiding jitter in composited frame display include triple buffering with the compositor (though this could lead to wasted resources) or allowing applications to submit frames with their intended time frames. The later approach, however, wouldn't be good for X but could work nicely in a Wayland world.
Read the blog post at FishSoup.net