Alpha Blending in Window Compositor (Compact 7)
3/12/2014
Window Compositor uses alpha blending to create a user experience in which overlapping windows appear partially transparent and content on the covered window is still visible. Alpha blending combines the graphical output from multiple applications to create this transparency effect. Window Compositor performs alpha blending by combining the color values for pixels in the overlapping and overlapped windows with a specified alpha value that determines the degree of transparency between the overlapping and overlapped windows.
The Alpha Blending Process
The process by which Window Compositor performs alpha blending is as follows:
- When Window Compositor starts, GWES creates one virtual display surface for Window Compositor to use as a canvas to perform window composition, which is the process of combining the visual outputs of the multiple applications onto a single output display. This virtual display surface is called the compositor back surface.
- As each application window is created, Window Compositor creates a virtual display surface for the window. This display surface is the window’s back surface.
- When the application calls GWES to draw the window, GWES updates the window’s back surface instead of the primary surface. Because this back surface is exclusive to the application window, GWES does not do any clipping, which leaves the window’s back surface as a complete representation of its output.
- Window Compositor combines all of the application back surfaces into its own back surface and then updates the primary surface with the resulting combination. To achieve opacity, use Window Compositor APIs to set opacity values either for an entire back surface or for individual pixels in the back surface.
The following figure shows the alpha blending of two windows (1 and 2), each with its own back surface, using the compositor back surface (3).
Methods for Alpha Blending
The Window Compositor APIs use several methods to configure the degree of opacity for application windows. A window can be configured to have a single global opacity value for the entire window, or it can be configured so that opacity can be set for individual pixels. The following table describes the Window Compositor methods for configuring the degree of opacity.
Compositor method | Description |
---|---|
Defines the ability of the back surface of an application to set a per-pixel opacity value, or alpha value. To configure the back surface for a 24-bit-per-pixel (bpp) color value and an 8-bit alpha value, call this method with the WCF_ALPHATRANSPARENCY and WCF_TRUECOLOR flags set in the dwFlags parameter. Then the hexadecimal value for each pixel is defined as the following: 0xaarrggbb In this hexadecimal value:
To set the alpha value for each pixel, do the following:
|
|
Sets an opacity value that Window Compositor uses for the entire window when it composes its back surface. |
|
Retrieves the window composition flags. |
|
Retrieves the window opacity value. |
If you use XAML to create Microsoft Silverlight for Windows Embedded device applications, you cannot use XAML attributes to set the opacity levels. Instead, you must call the IXRVisualHost::GetContainerHWND method to obtain the window handle and then pass this handle to the SetWindowCompositionFlags or SetWindowOpacity function.