Platform SDK: DirectX

Flipping Surfaces

Any surface in DirectDraw can be constructed as a flipping surface. A flipping surface is any piece of memory that can be swapped between a front buffer and a back buffer. (This construct is commonly referred to as a flipping chain). Often, the front buffer is the primary surface, but it doesn't have to be.

[C++]

Typically, when you use the IDirectDrawSurface7::Flip method to request a surface flip operation, the pointers to surface memory for the primary surface and back buffers are swapped. Flipping is performed by switching pointers that the display device uses for referencing memory, not by copying surface memory. (The exception to this is when DirectDraw is emulating the flip, in which case it simply copies the surfaces. DirectDraw emulates flip operations if a back buffer cannot fit into display memory or if the hardware doesn't support DirectDraw.) When a flipping chain contains a primary surface and more than one back buffer, the pointers are switched in a circular pattern, as shown in the following illustration.

[Visual Basic]

Typically, when you use the DirectDrawSurface7.Flip method to request a surface flip operation, the surface memory for the primary surface and back buffers are swapped. Flipping is performed by switching surfaces that the display device uses for referencing memory, not by copying surface memory. (The exception to this is when DirectDraw is emulating the flip, in which case it simply copies the surfaces. DirectDraw emulates flip operations if a back buffer cannot fit into display memory or if the hardware doesn't support DirectDraw.) When a flipping chain contains a primary surface and more than one back buffer, the surfaces are switched in a circular pattern, as shown in the following illustration.

Other surfaces that are attached to a DirectDraw object, but not part of the flipping chain, are unaffected when the Flip method is called.

[C++]

Remember, DirectDraw flips surfaces by swapping surface memory pointers within DirectDrawSurface objects, not by swapping the objects themselves. This means that, to blit to the back buffer in any type of flipping scheme, you always use the same DirectDrawSurface object — the one that was the back buffer when you created the flipping chain. Conversely, you always perform a flip operation by calling the front surface's Flip method.

When working with visible surfaces, such as a primary surface flipping chain or a visible overlay surface flipping chain, the Flip method is asynchronous unless you include the DDFLIP_WAIT flag. On these visible surfaces, the Flip method can return before the actual flip operation occurs in the hardware (because the hardware doesn't flip until the next vertical refresh occurs). While the actual flip operation is pending, the back buffer behind the currently visible surface can't be locked or blitted by calling the IDirectDrawSurface7::Lock, IDirectDrawSurface7::Blt, IDirectDrawSurface7::BltFast, or IDirectDrawSurface7::GetDC methods. If you attempt to call these methods while a flip operation is pending, they will fail and return DDERR_WASSTILLDRAWING. However, if you are using a triple buffered scheme, the rearmost buffer is still available.

[Visual Basic]

Remember, DirectDraw flips surfaces by swapping surface memory within DirectDrawSurface objects, not by swapping the objects themselves. This means that, to blit to the back buffer in any type of flipping scheme, you always use the same DirectDrawSurface object — the one that was the back buffer when you created the flipping chain. Conversely, you always perform a flip operation by calling the front surface's Flip method.

When working with visible surfaces, such as a primary surface flipping chain or a visible overlay surface flipping chain, the Flip method is asynchronous unless you include the DDFLIP_WAIT flag. On these visible surfaces, the Flip method can return before the actual flip operation occurs in the hardware (because the hardware doesn't flip until the next vertical refresh occurs). While the actual flip operation is pending, the back buffer behind the currently visible surface can't be locked or blitted by calling the DirectDrawSurface7.Lock, DirectDrawSurface7.Blt, DirectDrawSurface7.BltColorFill, DirectDrawSurface7.BltFast, DirectDrawSurface7.BltFx, DirectDrawSurface7.BltToDC or DirectDrawSurface7.GetDC methods. If you attempt to call these methods while a flip operation is pending, they will fail and raise the DDERR_WASSTILLDRAWING error. However, if you are using a triple buffered scheme, the rearmost buffer is still available.