PackageDescription: Epigent Vertical Retrace Windows


Epigent Vertical Retrace Windows

Last published: July 29, 2007 by 'runar'

Defines 2 Classes
Extends 2 Classes


Interface to a DLL which waits for the graphic card's "Vertical Retrace" to start. The DLL is part of SmoothAnimationDemo by Chet Haase, February 2006. The DLL can be found at http://today.java.net/pub/a/today/2006/02/23/smooth-moves-solutions.html

Currently, only Windows is supported.

Double buffering is a well-known technique to avoid flickering in graphic applications. This technique is used to make animation smoother or to avoid showing the intermediate drawing steps when rendering application windows. When using double buffering glitches in screen update can happen. This happen when copying of a frame buffer to the screen is not synchronized with the vertical retrace. For a very short time, the user will basically see two different frames at the same time:

"Imagine that the vertical retrace is in the middle of refreshing the screen, and it happens to be refreshing the pixels in the area where you are copying pixels to the screen. The effect will be that the pixels below and to the right of the refresh location will show up in their new location, but the pixels to the left and above that location will still be shown in their old location; this is because the refresh is only updating the pixels to the right and below on this refresh. (...) the tearing will be so obvious that this will add to any perception of a choppy animation." (From http://weblogs.java.net/blog/chet/archive/2006/02/make_your_anima.html)

The solution to the problem is to wait for the vertical retrace to reach the top or bottom of the screen. At that point, screen buffers in memory are copied to the screen. If the copying function is fast, the vertical retrace will not pass by the vertical position of the pixels being copied.

I have tested making smooth animations in Widgetry. There you need to modify Widget.DoubleBufferingWindowDisplayPolicy>>displayIn:withBackground: like this:

(...)
windowGraphicsContext clippingRectangle: aRectangle.
Epigent.VerticalRetrace new vbLockNative.
displayPixmap displayOn: windowGraphicsContext.
(...)