Frame Buffer Access

DirectDrawSurface objects represent surface memory in the DirectDraw architecture. A DirectDrawSurface allows an application to directly gain access to this surface memory through the IDirectDrawSurface::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 IDirectDrawSurface::Lock with a NULL RECT, it is assumed that exclusive access to the entire piece of surface memory is being requested by the application. 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 with the IDirectDrawSurface::Unlock method.

Experience shows that there are several common problems you may encounter when rendering directly into a DirectDrawSurface. The following list describes some solutions to these problems:

·Never assume a constant display pitch. Always examine the pitch information returned by the IDirectDrawSurface::Lock method. This pitch may 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 being used.

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

·Be sure you 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. This module 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 happens to span memory banks.