Microsoft-ui-xaml: Proposal: Window Transparency support

Created on 21 May 2020  路  6Comments  路  Source: microsoft/microsoft-ui-xaml

It'd be nice to see support for window transparency which will allow us to draw our own desktop overlay. Currently we are able to do just that in WPF by declaring the following properties on a Window <Window WindowStyle="None" AllowsTransparency="True" Background="Transparent" /> however if we were to implement WindowsXAMLHost in a WPF application to host modern controls, it is currently not supported with the transparent regions showing through as black. We should just truly embrace support for Window transparency by adding support for it in WinUI for the desktop.

area-AppWindow duplicate feature proposal

Most helpful comment

While this might have been true in olden times when transparency was just overpainting, these days composition is out of process by a separate compositor, so I don't think capturing a windows content will reveal underlying windows if the compositor doesn't want to go out of its way to implement that. Also the legacy GDI transparency is still supported, just expensive and awkward to use with modern DirectX/Composition rendering because you have to loop GPU resources back to CPU through GDI every frame just to have desktop composition reupload to GPU.

[edit] on a side note regarding security, theres the option of marking a window to be excluded from composition readback via SetWindowDisplayAffinity so the compositor is already able to recognize content that should not be copied.

All 6 comments

Last I checked WPF doesn't use OS support for transparent windows, as far as I'm aware its a hack transferring every rendered frame through system memory into a GDI surface, using UpdateLayeredWindow. Very CPU intensive especially when animated or scrolling.

The docs say native OS support for transparent windows is "optional" (depending on the graphic driver) and may not be available, so I'm wondering if thats still true on Win10 and whether that influenced the decision to never make proper transparency available in any UI framework?

I'd love for WinUI to be the first UI framework with proper support of hardware transparency, including SwapChains controls & co. for rendering into them, assuming thats even possible on the OS level.

I seem to remember Microsoft considering transparent windows, a security concern. Apps capturing their window's content, and the contents of the windows below being visible.

While this might have been true in olden times when transparency was just overpainting, these days composition is out of process by a separate compositor, so I don't think capturing a windows content will reveal underlying windows if the compositor doesn't want to go out of its way to implement that. Also the legacy GDI transparency is still supported, just expensive and awkward to use with modern DirectX/Composition rendering because you have to loop GPU resources back to CPU through GDI every frame just to have desktop composition reupload to GPU.

[edit] on a side note regarding security, theres the option of marking a window to be excluded from composition readback via SetWindowDisplayAffinity so the compositor is already able to recognize content that should not be copied.

Using legacy GDI is not necessary. UWP uses DirectX and DirectComposition under the hood for complete rendering anyways, along with the DWM. That being said, certain features like background acrylic are possible because of DirectComposition. A brush returned from CreateHostBackdropBrush() is just part of the transparent swapchain that DirectComposition uses with a gaussian blur applied to it.

AllowTransparency is very much possible, it seems like the CompositionBackdropBrush should be preconfigured to exclude a gaussian blur by default, so creating a truly transparent window can be possible.

Using legacy GDI is not necessary. UWP uses DirectX and DirectComposition under the hood for complete rendering anyways, along with the DWM. That being said, certain features like background acrylic are possible because of DirectComposition. A brush returned from CreateHostBackdropBrush() is just part of the transparent swapchain that DirectComposition uses with a gaussian blur applied to it.

AllowTransparency is very much possible, it seems like the CompositionBackdropBrush should be preconfigured to exclude a gaussian blur by default, so creating a truly transparent window can be possible.

HostBackdrop is one of those features that is disabled in WinUI 3.0 right now, as the team tries to find a way to implement it once decoupled from the OS.

I believe this is a duplicate of https://github.com/microsoft/microsoft-ui-xaml/issues/1247. Feel free to add and comment there.

Was this page helpful?
0 / 5 - 0 ratings