Repository navigation
fix(win32): Make SystemBackdrop work and stop rewriting app backgrounds - #24190
Conversation
|
Claude finished @MartinZikmund's task in 6m 12s —— View job Review: fix(win32): Make SystemBackdrop work and stop rewriting app backgroundsVerdict: fix-first (two medium findings; low findings can follow in a subsequent commit) SummaryThe three root-cause fixes — swapping the renderer for Vulkan bypass, replacing the tree-walk with a single island-root flag, and driving DWM dark mode from content's Issues by severity
Cross-cutting notes
|
|
|
There was a problem hiding this comment.
Pull request overview
Fixes Skia Win32 SystemBackdrop rendering, preserves application backgrounds, synchronizes themes, and updates tests and documentation.
Changes:
- Switches backdrop windows from Vulkan to compatible renderers.
- Uses island-root transparency instead of rewriting app backgrounds.
- Adds theme synchronization and runtime coverage.
- Updates samples and migration documentation.
Unresolved moderate findings remain in backdrop lifecycle handling, shared renderer state, test cleanup, and unsupported backdrop handling.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Summary |
|---|---|
src/Uno.UI/UI/Xaml/Window/Window.cs |
Manages backdrop state and root transparency. |
src/Uno.UI/UI/Xaml/ThemingHelper.cs |
Supports themed background handling. |
src/Uno.UI/UI/Xaml/Internal/UnoRootElementLogic.cs |
Updates root-element behavior. |
src/Uno.UI/UI/Xaml/Internal/Islands/XamlIslandRoot.Core.cs |
Stores island transparency and initializes backgrounds. |
src/Uno.UI/UI/Xaml/Internal/CoreServices.cs |
Initializes themed root backgrounds. |
src/Uno.UI/UI/Xaml/BorderHelper.cs |
Suppresses only the island root background primitive. |
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Window.cs |
Adds backdrop regression coverage; cleanup requires changes. |
src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Window/Win32WindowWrapper.cs |
Handles renderer and DWM theme integration; lifecycle and shared-state issues remain. |
src/SamplesApp/SamplesApp.Samples/Microsoft/UI/Windowing/MicaBackdropTests.xaml.cs |
Updates backdrop sample behavior. |
src/SamplesApp/SamplesApp.Samples/Microsoft/UI/Windowing/MicaBackdropTests.xaml |
Updates sample UI for transparent content. |
doc/articles/migrating-to-uno-7.md |
Documents the breaking background behavior change. |
doc/articles/features/system-backdrop.md |
Corrects SystemBackdrop guidance. |
Suppressed comments (7)
src/SamplesApp/SamplesApp.Samples/Microsoft/UI/Windowing/MicaBackdropTests.xaml.cs:18
- The
SetBackdropmethod later in this file still says that the framework “transparentizes the visual tree.” That statement is now false and contradicts this updated sample guidance, so update or remove the stale comment to avoid directing future changes toward the deleted traversal.
"Setting a backdrop drops the window's own root background; app content keeps its own, so this page sets Background=\"Transparent\". " +
src/Uno.UI.Runtime.Skia.Win32/UI/Xaml/Window/Win32WindowWrapper.cs:975
- This can run on every active/inactive backdrop transition. With the default Vulkan renderer, the first attach creates OpenGL and assigns the HWND's pixel format; clearing the backdrop recreates Vulkan, and a later attach attempts to assign the pixel format again. Win32 pixel formats are immutable per HWND, so OpenGL creation then fails and the fallback silently downgrades the window to software. Reuse the existing pixel format when rebuilding OpenGL or retain a renderer/context that avoids reassigning it.
_renderer = CreateRenderer();
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Window.cs:240
- This test also leaves its red
Gridattached to the main window. SinceCleanupTestdoes not clear main-window content and the headless runner retains it, the loaded tree can leak into subsequent runtime tests; clearWindowHelper.WindowContentin the existingfinallyblock.
window.SystemBackdrop = previousBackdrop;
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Window.cs:178
- This new regression test directly covers issue #24189, but it has no
GitHubWorkItemlink. Add[GitHubWorkItem("https://github.com/unoplatform/uno/issues/24189")]so the test remains traceable to the behavior it guards.
[TestMethod]
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Window.cs:213
- The second new regression test also directly covers issue #24189 but lacks the issue annotation. Add the same
GitHubWorkItemattribute here (or use a narrowly scoped shared annotation) so both guards are discoverable from the issue.
[RunsOnUIThread]
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Window.cs:227
- The new test exercises setting a backdrop but only asserts the content brush. The reported Vulkan regression (a black client area) would still pass if renderer selection or DWM composition regressed; add a Skia Win32 render/pixel assertion, or another assertion that proves the non-Vulkan path is active.
window.SystemBackdrop = new MicaBackdrop();
await TestServices.WindowHelper.WaitForIdle();
src/Uno.UI/UI/Xaml/Window/Window.cs:437
- This new helper only updates the managed root flag, but it does not address the case where
SystemBackdropwas assigned beforeWindow.Initialize(): the setter then saw noNativeWrapper, so no DWM attribute was sent. Initialization later creates the Win32 wrapper and selects a non-Vulkan renderer from the stored property, but never replaysSetSystemBackdrop, leaving DWM atDWMSBT_NONEand the material absent. Reapply the pending native backdrop when the wrapper is created.
private void UpdateRootVisualBackgroundForBackdrop(Media.SystemBackdrop? backdrop)
{
if (RootElement is Uno.UI.Xaml.Islands.XamlIslandRoot islandRoot)
{
islandRoot.SetHasTransparentBackground(backdrop is not null && IsBackdropSupported(backdrop));
}
|
The build 230018 found UI Test snapshots differences: Details
|
|
|
b4c41db to
6c4e984
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
|
|
The build 231038 found UI Test snapshots differences: Details
|
|
|
6c4e984 to
bfb1f4f
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
|
|
The build 231185 found UI Test snapshots differences: Details
|
|
|
bfb1f4f to
18b1278
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
The build 231202 found UI Test snapshots differences: Details
|
|
|
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WHHcu5U9N25wvKGNFCrpJm
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WHHcu5U9N25wvKGNFCrpJm
41f25f9 to
5a4a5a6
Compare
🤖 Addressed PR comments up to this pointRebased onto latest
|
|
Claude finished @MartinZikmund's task in 1m 16s —— View job Review: fix(win32): Make SystemBackdrop work and stop rewriting app backgroundsVerdict: ship (no new findings — no code changes since the last review round)
What changed since the last review roundNothing. Current HEAD (
This Re-verified against AGENTS.md
Nothing further to flag from a code-review standpoint. |
|
The build 236166 found UI Test snapshots differences: Details
|
|
|
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XU3kKG9jHwupx4TefeXQAe
|
Claude finished @MartinZikmund's task in 46s —— View job Review: fix(win32): Make SystemBackdrop work and stop rewriting app backgroundsVerdict: ship (no new findings — trivial docs-only change)
What changed since the last review roundOne commit, Re-confirmed stateNo code changed in this delta, so all prior findings remain resolved as previously verified: content-lifecycle retargeting (including the secondary-ALC Nothing further to flag from a code-review standpoint. |
|
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24190/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24190/docs/index.html |
|
The build 236173 found UI Test snapshots differences: Details
|
On a hybrid-GPU laptop, Window.SystemBackdrop showed Mica or Acrylic only under the non-client frame; the client area stayed opaque black. Vulkan device selection always preferred the discrete GPU, and on such a machine the discrete GPU usually drives no display: its swapchain reaches the screen through a cross-adapter copy that drops the alpha DWM needs to show the material through the client area. The same app shows the material when Vulkan runs on the integrated GPU that scans the panel out (verified with VK_LOADER_DRIVERS_SELECT on stock binaries), and on a desktop whose discrete GPU drives the monitor directly, as measured in #24190. Prefer the physical device whose VkPhysicalDeviceIDProperties.deviceLUID matches the adapter driving the window's monitor (QueryDisplayConfig source path for MonitorFromWindow), falling back to the previous discrete-first order when no LUID matches or the platform doesn't report one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LP133TsLEXjMo7XFGmakoS
GitHub Issue: closes #24189
PR Type:
🐞 Bugfix
What changed? 🚀
Window.SystemBackdropwas broken several ways on Skia Win32. The table below was measured on a realwindow's client-area centre pixel (screen capture with an occlusion guard, Windows 11 26100, desktop
in dark theme), against a stock WinAppSDK 2.4.0 app doing the same thing.
#000000#231F1D#211F21#000000#F8F1F2#F5F1F7#000000#3A3A3A#2C2C2CGridpainted red#FF0000#FF0000#FFFFFF/#000000#FFFFFF/#0000001. The renderer is unchanged
An earlier revision downgraded Vulkan to OpenGL whenever a backdrop was attached, and rebuilt the
renderer when one was attached or removed on a live window. That was dropped in
fix(win32): Keep Vulkan under a system backdrop: measured on Windows 11 (RTX 4090, NVIDIA 610.88),Mica renders the same under Vulkan and OpenGL, whether the backdrop is attached before or after the
window is shown.
Win32WindowWrapperstill picks its renderer once, at construction, with no backdropcondition, so there is no renderer-switch path in this PR.
2. The framework rewrote the application's own backgrounds
Setting a backdrop walked the entire visual tree and replaced
Backgroundon everyPanel,Border,ContentPresenter, andControlholding an opaqueSolidColorBrush, re-walking on everyLoadedand keepingLoaded/Unloadedsubscriptions on every element it visited. It was observablefrom app code — a
Gridexplicitly painted red read back asTransparent— and because the brushwas written with
Localprecedence, any{ThemeResource}background it touched stopped re-resolvingon theme change.
MUX instead flips one flag on the island root (
CXamlIslandRoot::SetHasTransparentBackground, fromDesktopWindowImpl::SetXamlIslandRootBackground) and the render walk skips that one element'sbackground primitive (
BaseContentRenderer::PanelRenderContent).Panel.Backgroundkeeps its themebrush throughout; app content is never touched.
This ports the same flag onto
XamlIslandRoot, suppresses the background push inBorderHelper.UpdateBackground— Uno's equivalent of the MUX render walk — and deletes the traversaland its eight helpers. 166 lines removed.
3. The material's tint followed the desktop theme
DWMWA_USE_IMMERSIVE_DARK_MODEwas set fromGetSystemTheme(), so an app running light on a darkdesktop got a dark material. MUX drives
SystemBackdropConfiguration.ThemefromXamlRoot.Content.ActualTheme(SystemBackdrop_Partial.cpp). It now follows the content'sActualTheme, falling back toApplication.RequestedThemebefore content exists, and re-applies wheneither the content theme or the desktop theme changes.
4. Two formulas computed the same root background
Construction seeded the root from a high-contrast-blind
White/Blackhelper, while every themechange re-applied the high-contrast-aware
FrameworkTheming.GetHwndBackground(Theme.None). Ahigh-contrast app therefore started with plain white or black under its content and only converged at
the first theme notification. MUX has no such split —
CXamlIslandRoot::NotifyThemeChangedCoreiscalled from
InitializeCommon()and from everyCCoreServices::NotifyThemeChange. Both seed pointsnow use
FrameworkTheming, and the second formula is gone.5. The backdrop theme follows the window's content, including when it is replaced
MUX's
SystemBackdropusesXamlRoot.Content.ActualThemeas its theme source, and moves thatsubscription to the new content on
XamlRoot.Changed(SystemBackdrop_Partial.cpp,OnXamlRootChanged). Uno now does the same.Windowraises an internalContentChangedwhenContentis replaced or cleared, and two consumers use it:Contentdrops thesubscription instead of keeping the old element alive.
ApplicationPageBackgroundThemeBrushunder the content's theme instead of the application's, andrefreshes when that theme changes or the content is replaced.
6. Backdrop edge cases
Windowcreated beforeApplication.InitializationCompleted) is now replayed to the native window once it is initialized.Before, it never reached DWM.
DWMSBT_NONE) andshows the fallback, the same as macOS. Before, the previous material stayed under the frame while
the root painted opaque.
Not changed on purpose
The no-backdrop case was already correct and is untouched. WinUI paints the underlying window
background pure
#FFFFFF/#000000— notApplicationPageBackgroundThemeBrush(
#F3F3F3/#202020) — from a hardcoded brush onCXamlIslandRoot'sPanel.Background, and Unoalready did exactly that on the same element. Verified for
Grid,Page,Border,UserControl, atransparent
Grid, andContent = null.No framework-side fallback colour was added either: with transparency effects off, DWM itself falls
back to
#F3F3F3/#202020, precisely WinUI'sSolidBackgroundFillColorBase.Validation
renderer configuration, re-verified after rebasing onto
feature/breakingchanges.clear it afterwards.
Given_Window_SystemBackdropchecks the colour the root actually renders, not justits mode. It covers the fallback following the content's
RequestedThemeand a replacedWindow.Content.theming classes, 266 tests) gives 260 passed / 5 failed / 1 inconclusive. The same filter on the
unmodified baseline gives the identical result with the same five names — DPI layout-rounding
assertions (27 vs 27.2, 145 vs 144.8) and one GC-collection timing test. No regressions.
Given_ContentPresenter, which exercises the changed background path heavily, passes 270/270.Unrelated pre-existing issue found while running these, filed separately for visibility: on Skia
Win32 any test run that closes a secondary window or popup dies with an access violation in
SKSurface's finalizer before the results file is written. It reproduces identically on anunmodified baseline build, and it is why the new tests host their content on the main window.
PR Checklist ✅
Screenshots Compare Test Runresults.Breaking change
Content backgrounds are no longer made transparent when a
SystemBackdropis set.An app that relied on the framework doing this will now see its own opaque backgrounds hide the
material. The migration is the one-line change WinUI has always required — make the surface you want
the material to show through transparent yourself:
Documented in
doc/articles/migrating-to-uno-7.md(new "SystemBackdrop no longer rewrites yourcontent's backgrounds" section plus a migration-checklist entry), and
doc/articles/features/system-backdrop.mdhas been corrected — it previously claimed the SamplesApptest performed the traversal, when the framework was doing it.