The biggest gain in performance in the DirectX 2 SDK comes from the DirectDraw services, a combination of four Component Object Model (COM) interfaces: IDirectDraw, IDirectDrawSurface, IDirectDrawPalette, and IDirectDrawClipper. For more information about the COM concepts required for programming applications using the DirectX 2 SDK, see The Component Object Model.
A DirectDraw object, created using the DirectDrawCreate function, represents the display adapter card. One of the object's methods, IDirectDraw::CreateSurface, creates the primary DirectDrawSurface object, which represents the display memory being viewed on the monitor. From the primary surface, off-screen surfaces can be created in a linked-list fashion.
In the most common case, one back buffer surface is created in addition to the primary surface and exchanges images with the primary surface. While the screen is busy displaying the lines of the image in the primary surface, the back buffer surface frame is being composed. This is done by transferring a series of off-screen bitmaps stored on other DirectDrawSurface objects in display RAM. The IDirectDrawSurface::Flip method is called to display the recently composed frame, which sets a register so the exchange occurs when the screen performs a vertical retrace. This operation is asynchronous, so the application can continue processing after calling IDirectDrawSurface::Flip. (After this method has been called, the back buffer is automatically write-blocked until the exchange occurs.) After the exchange occurs, this process continues: the application composes the next frame in the back buffer, calls IDirectDrawSurface::Flip, and so on.
DirectDraw improves performance over the Windows 3.1 GDI model. The Windows 3.1 GDI model had no direct access to bitmaps in display memory. Blits always occurred in system RAM and were then transferred to display memory, thereby slowing performance. With DirectDraw, all processing is done on the display adapter card whenever possible. DirectDraw also improves performance over the Microsoft Windows 95 and Windows NT GDI model, which uses the CreateDIBSection function to enable hardware processing.
The third type of DirectDraw object is DirectDrawPalette. Because the physical display palette is usually maintained in display hardware, an object represents and manipulates it. The IDirectDrawPalette interface implements palettes in hardware. These bypass Windows palettes and are therefore only available when a game has exclusive access to the display hardware. DirectDrawPalette objects are also created from DirectDraw objects.
The fourth type of DirectDraw object is DirectDrawClipper. DirectDraw manages clipped regions of display memory by using this object.
Transparent blitting is the technique by which a bitmap is transferred to a surface and a certain color, or range of colors, in the bitmap is defined as transparent. Transparent blits are achieved using color keying. Source color keying operates by defining which color or color range on the bitmap is transparent and therefore not copied during a transfer operation. Destination color keying operates by defining which color or color range on the surface will be covered by pixels of that color or color range in the source bitmap.
Finally, DirectDraw supports overlays in hardware and by software emulation. Overlays present an easier means of implementing sprites and managing multiple layers of animation. Any DirectDrawSurface object can be created as an overlay with all of the capabilities of any other surface, plus extra capabilities associated only with overlays. These capabilities require extra display memory, and if there are no overlays in display memory, the overlay surfaces can exist in system memory.
Color keying works in the same way for overlays as for transparent blits. The z-order of the overlay automatically handles the occlusion and transparency manipulations between overlays.