DirectDraw

DirectDraw is implemented in both hardware and software. Applications using DirectDraw retrieve two sets of capabilities, one for hardware capabilities and one for software-emulation capabilities. Using these, an application can easily determine what DirectDraw is emulating and what functionality is provided in hardware. DirectDraw is the only client of the DirectDraw hardware-abstraction layer (HAL). Applications must write to DirectDraw; there is no mechanism for writing to the HAL more directly.

DirectDraw is implemented by the Ddraw dynamic-link library (DLL). This 32-bit DLL implements all of the common functionality required by DirectDraw. It performs all of the necessary thunking between Win32® and the 16-bit portions of the HAL, as well as complete parameter validation. It provides management for off-screen display memory, and performs all of the bookkeeping and semantic logic required for DirectDraw. It is responsible for presenting the Component Object Model (COM) interface to the application, hooking window handles to provide clip lists, and all other device-independent functionality.

DirectDraw is a combination of four COM interfaces: IDirectDraw2, IDirectDrawSurface2, IDirectDrawPalette, and IDirectDrawClipper. For information about COM concepts, see The Component Object Model.

The first two objects a DirectDraw application uses are DirectDraw and DirectDrawSurface. A DirectDraw object, created by using the DirectDrawCreate function, represents the display adapter card. After retrieving an IDirectDraw2 interface to the object, an application can call the IDirectDraw2::CreateSurface method to create 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 is created to exchange 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 composed. This composition is performed by transferring to the back buffer a series of off-screen bitmaps stored on other DirectDrawSurface objects in display memory. To display the recently composed frame, the application calls the IDirectDrawSurface2::Flip method. This method sets a register so that the exchange occurs when the screen performs a vertical retrace. This operation is asynchronous, so the application can continue processing after calling this method. (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 IDirectDrawSurface2::Flip, and so on.

DirectDraw improves performance over the Windows version 3.1 GDI model, which had no direct access to bitmaps in display memory. Blits, which always occurred in system memory, were subequently transferred to display memory, slowing performance. With DirectDraw, processing is done on the display adapter card whenever possible. DirectDraw also improves performance over the Windows 95 and Windows NT GDI model, which uses the CreateDIBSection function to enable hardware processing.

A third 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 available only when a game has exclusive access to the display hardware. DirectDrawPalette objects are also created from DirectDraw objects.

The final DirectDraw object is DirectDrawClipper. DirectDraw manages clipped regions of display memory by using this object.