Share via


Create Clipping Regions (Compact 7)

3/12/2014

When you create scenes that show simultaneous output from multiple applications, consider creating clipping regions. A clipping region draws a boundary around a region and tells Window Compositor not to perform alpha blending within the region. Clipping regions improve graphics performance by reducing the display area that must be updated each time the system refreshes the display.

For example, you can create a clipping region for a progress bar that occupies the bottom 10 percent of the display in a music player application window (with a static image that occupies the other 90 percent of the display), as shown in the following figure. If you create a clipping region for the progress bar, the entire display does not need to be updated each time the UI for the progress bar is updated.

Figure 1: Static Image Clipping Region

Static Image Clipping Region

Example

The following sample code shows how to create a clipping region.

RECT rcWindow = { 0 };
HRGN hrgnWindow = NULL;
RECT rcStaticImage = { 0 };
HRGN hrgnStaticImage = NULL;
 
// Get the full window area
GetWindowRect( hwnd, &rcWindow );
// Create a full window area region
hrgnWindow = CreateRectRgnIndirect( &rcWindow );

// Define the static image area rectangle
rcStaticImage.left = rcWindow.left;
rcStaticImage.top = rcWindow.top;
rcStaticImage.right = rcWindow.right;
rcStaticImage.bottom = rcWindow.bottom * .9;
// Create the static image clipping region.
hrgnStaticImage = CreateRectRgn( rcStaticImage.left, 
                                 rcStaticImage.top, 
                                 rcStaticImage.right,
                                 rcStaticImage.bottom);
// Create a new window region which excludes the static image area
CombineRgn( hrgnWindow, hrgnWindow, hrgnStaticImage, RGN_DIFF );
// Permit drawing to the progress bar area only
SetWindowRgn( hwnd , hrgnWindow, TRUE );

// After setting the window region, delete the static image
// region but not the window region since GWES now owns it.
if ( NULL != hrgnStaticImage )
{
    DeleteObject( hrgnStaticImage );
}

See Also

Concepts

Tune Graphics Performance with Window Compositor