Frame-Buffer Access

DirectDrawSurface objects represent surface memory in the DirectDraw architecture. A DirectDrawSurface object allows an application to gain direct access to this surface memory by using the IDirectDrawSurface2::Lock method. An application calls this method, providing a RECT structure that specifies the rectangle on the surface it requires access to. If the application calls IDirectDrawSurface2::Lock with a NULL RECT structure, it is assumed that the application is requesting exclusive access to the entire piece of surface memory. This method fills in a DDSURFACEDESC structure with the information needed for the application to gain access to the surface memory. This information includes the pitch (or stride) and the pixel format of the surface, if different from the pixel format of the primary surface. When an application is finished with the surface memory, the surface memory can be made available again by using the IDirectDrawSurface2::Unlock method.

The following list describes some tips for avoiding the most common problems with rendering directly into a DirectDrawSurface object:

·Never assume a constant display pitch. Always examine the pitch information returned by the IDirectDrawSurface2::Lock method. This pitch can vary for a number of reasons, including the location of the surface memory, the type of display card, or even the version of the DirectDraw driver.

·Limit activity between the calls to the IDirectDrawSurface2::Lock and IDirectDrawSurface2::Unlock methods. The IDirectDrawSurface2::Lock method holds the WIN16 lock so that gaining access to surface memory can occur safely, and the IDirectDrawSurface2::GetDC method implicitly calls IDirectDrawSurface2::Lock. The WIN16 lock serializes access to GDI and USER, shutting down Windows for the duration between the IDirectDrawSurface2::Lock and IDirectDrawSurface2::Unlock operations, as well as between the IDirectDrawSurface2::GetDC and IDirectDrawSurface2::ReleaseDC operations.

·Copy aligned to display memory. Windows 95 uses a page fault handler, Vflatd.386, to implement a virtual flat-frame buffer for display cards with bank-switched memory. The handler allows these display devices to present a linear frame buffer to DirectDraw. Copying unaligned to display memory can cause the system to suspend operations if the copy spans memory banks.