Wednesday, October 13, 2010

How Windows 7/Vista Manage Flicker Free Drawing?

Tip – How Windows 7/Vista Manage Flicker Free Drawing?

Details – The prior version of Windows (Windows XP and 2000 doesn’t support native double buffering for drawing operations. This may cause flickering in the applications it’s drawing intensive.
In one of the previous tips we already have seen how to enable Double buffering. WS_EX_COMSPOSITED style can be used for avoiding flickering of Windows in Windows 2000 and XP. But most of the developers are using MemDC based methods for drawing. The content need to be drawn in to a bitmap and directly Blt to screen using BitBly operation, which is extremely fast and avoid flickering caused by frequent drawing operations.

Basic Details
In Windows 7, the Desktop Window Manager (DWM) manages all the Windows running in the system. DWM uses GPU available in the system. When Windows Aero is enabled, the entire desktop area is a Direct3D surface. All drawing operations are made by applications are sent directly to the offline buffer for rendering. DWM will swap this buffer to screen whenever required. Thus by default all Window operations are done through double buffering. This architecture is quite different in prior versions of Windows, where all the drawing operations are redirected to the main screen(buffer).
Even DWM handles buffered drawing, we can’t completely make sure drawings are flicker free. Microsoft has introduced buffered drawing APIs since Windows Vista. This shall be covered as an another tip. Please check this blog post, if you want to know more about double buffering and double buffering helpers in Windows Vista .
More DWM
To explain a bit more detailed, the Window itself being mapped as texture on the screen, the transitions on minimize maximize are handling using GPU shaders. The shaders are small programs which can control the coordinates and pixels being displayed. Since the desktop itself a 3D surface, DWM has access to all the Windows displayed on the screen. This it can effortlessly implement the new features like, aero peak, flip 3D etc. The double buffering is also provided by DWM during Window movement, repainting etc. for flicker free drawing.
The DWM double buffering methods are sometimes not compatible with real-time graphics applications and games. In this case, DWM will not do window compositing so the application can gain the desired performance and no overheads of DWM implemented double buffering. DWM also employs efficient rendering techniques called culling to avoid displaying the Windows which are not visible in the screen (minimized, small windows hidden behind other windows etc).

Posted by - Sarath C

No comments:

Post a Comment