Desktop Window Manager - Redirection

Redirection

For rendering techniques that are not DWM-aware, output must be redirected to the DWM buffers. With Windows, either GDI or DirectX can be used for rendering. To make these two work with DWM, redirection techniques for both are provided.

With GDI, which is the most used UI rendering technique in Microsoft Windows, each application window is notified when it or a part of it comes in view and it is the job of the application to render itself. Without DWM, the rendering rasterizes the UI in a buffer in video memory, from where it is rendered to the screen. Under DWM, a buffer equal to the size of the window is allocated in system memory. GDI calls are redirected to write their outputs to this buffer rather than the video memory. Another buffer is allocated in the video memory to represent the DirectX surface, which is used as the texture for the window meshes. The system memory buffer is converted to the DirectX surface separately, and kept in sync. This round-about route is required because GDI cannot output directly in DirectX pixel format. The surface is read by the compositor and is composited to the desktop in video memory. Writing the output of GDI to system memory is not hardware accelerated, nor is conversion to the DirectX surface. When a GDI window is minimized, invisible or visible on the same monitor as a full screen DirectX application, by limitation of GDI, the GDI bitmap buffer is no longer received by the application when requesting a device context during painting or updating (this can sometimes be seen when a GDI operation copying from one window to another outputs black or empty regions instead of the expected window content). Thus, DWM uses the last bitmap rendered to the buffer before the application was minimized.

For applications using DirectX to write to a 3D surface, the DirectX implementation in Windows Vista uses WDDM to share the surface with DWM. DWM then uses the surface directly and maps it on to the window meshes. For Windows presentation foundation (WPF) applications (which are DirectX applications), the compositor renders to such shared surfaces which are then composited into the final desktop. Applications can mix either rendering technique across multiple child windows, as long as both GDI and DirectX are not used to render the same window. In that case, the ordering between DirectX and GDI rendering cannot be guaranteed, and as such it cannot be guaranteed that the GDI bitmap from the system memory has been translated to the video memory surface. This means that the final composition may not contain the GDI-rendered elements. To prevent this, DWM is temporarily turned off, as long as an application which mixes GDI and DirectX in the same window is running.

Read more about this topic:  Desktop Window Manager