Skip to content

fix(win32): Make SystemBackdrop work and stop rewriting app backgrounds (6.8) - #24806

Merged
agneszitte merged 20 commits into
servicing/6.8from
dev/mazi/68-window-background
Oct 2, 2026
Merged

agneszitte merged 20 commits into
servicing/6.8from
dev/mazi/68-window-background

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24189

PR Type:

🐞 Bugfix

What changed? 🚀

Backport of #24190 to servicing/6.8. See that PR for the full analysis and the WinUI 3 pixel comparison. In short:

  • The framework stops rewriting the application's backgrounds. Setting a backdrop no longer walks the visual tree replacing every opaque SolidColorBrush Background with a transparent one (a Grid painted red read back as Transparent, and {ThemeResource} backgrounds stopped updating on theme change). As in MUX (CXamlIslandRoot::SetHasTransparentBackground), only the island root's background primitive is skipped, and Panel.Background keeps its theme brush.
  • The Win32 material tint follows the app's theme, not the desktop's. It follows the window content's ActualTheme (MUX SystemBackdrop_Partial.cpp) and moves with it when Window.Content is replaced or cleared.
  • The root background comes from one source. The construction-time seed and the theme-change path both use FrameworkTheming, so a high-contrast app no longer starts on plain white/black.
  • Heads that can't render a material paint the window background (ApplicationPageBackgroundThemeBrush under the content's theme) instead of going transparent over nothing, the equivalent of WinUI's MicaController.FallbackColor.
  • Edge cases: a backdrop set before the native window exists is replayed once it's initialized; on Win32 an unsupported backdrop type clears the DWM backdrop (DWMSBT_NONE); Window.ContentChanged is also raised for secondary-ALC content.

Differences from the master PR

  • Not backported: fix(win32): Show system backdrops on the default renderer and fix(win32): Keep Vulkan under a system backdrop. The second exactly reverts the first, and both target master's graphics-context negotiation, which 6.8 doesn't have (Win32 defaults to OpenGL here).
  • BorderHelper.UpdateBackground: there's no high-contrast UseBackgroundOverride branch, because that feature is master-only.
  • Theme-change path: CoreServices.NotifyThemeChange switched from the plain White/Black helper to FrameworkTheming.GetRootVisualBackground(), which master already used, so there's one source here too. The two are identical outside high contrast.
  • Per-flavor guard: the island root's background update is wrapped in #if UNO_HAS_BORDER_VISUAL, since 6.8 still builds Uno.UI for Reference and the native renderers.
  • Docs: 6.x has no 7.0 migration guide, so the behavior-change note is on the SystemBackdrop feature page instead.

Related

On macOS (Metal) and the other RetainedLayer heads, the ghosting reported in #24495 is a separate blend-mode bug in the damage-layer blit, fixed by #24546. Win32's OpenGL renderer has its own inline copy of that blit, which that PR doesn't yet cover.

Validation

  • Compile: a strict build (analyzers on) of Uno.UI.Runtime.Skia.Win32, Uno.UI.Runtime.Skia.MacOS and Uno.UI.UnitTests, which includes the Reference flavor. All pass.
  • Unit tests: Given_Window_SystemBackdrop passes 3/3, and Given_Window 1 passed, 1 skipped (pre-existing skip).
  • Runtime: not run locally on 6.8. The two runtime tests and the pixel measurements come from the master PR; CI runs the runtime tests here.

PR Checklist ✅

Behavior change

Content backgrounds are no longer made transparent when a SystemBackdrop is set. An app that relied on the framework doing this will now see its own opaque backgrounds hide the material. The fix is the one-line change WinUI has always required:

<Page Background="Transparent">

This is documented in doc/articles/features/system-backdrop.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XU3kKG9jHwupx4TefeXQAe

MartinZikmund and others added 20 commits September 29, 2026 11:41
Setting Window.SystemBackdrop walked the entire visual tree and replaced
the Background of every Panel, Border, ContentPresenter and Control that
had an opaque SolidColorBrush with a transparent one, re-walking on every
Loaded to catch newly navigated content.

That is not what WinUI does, and it is observable from app code: a Grid
explicitly painted red read back as Transparent afterwards. It also wrote
those brushes with Local precedence, so any {ThemeResource} background it
touched stopped re-resolving on a theme change, and it kept a Loaded and
Unloaded subscription on every FrameworkElement it had ever visited.

WinUI instead flips a single flag on the island root
(CXamlIslandRoot::SetHasTransparentBackground, from
DesktopWindowImpl::SetXamlIslandRootBackground) and the render walk skips
that one element's background primitive
(BaseContentRenderer::PanelRenderContent). The Panel.Background property
keeps its theme brush throughout; app content is never touched.

Ports the same flag onto XamlIslandRoot, suppressing the background push
in BorderHelper.UpdateBackground - Uno's equivalent of the MUX render
walk - and deletes the traversal and its eight helpers.

BREAKING CHANGE: Content backgrounds are no longer made transparent when
a SystemBackdrop is set. An app that relied on the framework doing this
must make its own page or root panel transparent for the material to show
through, which is what WinUI has always required.

Verified on Skia Win32, client-area centre pixel:

  Mica + background-less Grid   material visible, island root's
                                Background still #FF000000
  Mica + Grid painted red       #FF0000 (WinUI: #FF0000; was: material)
  no backdrop, light / dark     #FFFFFF / #000000, unchanged

Still to do when this lands on feature/breakingchanges: add the migration
entry to doc/articles/migrating-to-uno-7.md, which does not exist on this
branch's base.
DWMWA_USE_IMMERSIVE_DARK_MODE was set from the desktop theme, so an app
running light on a dark desktop got a dark Mica or Acrylic material. MUX
drives SystemBackdropConfiguration.Theme from XamlRoot.Content.ActualTheme
(SystemBackdrop_Partial.cpp), so WinUI shows a light material there.

DWM exposes one per-window flag for both the material tint and the caption
colour, so this follows the content's ActualTheme, falling back to
Application.RequestedTheme when there is no content yet, and re-applies
when the content or the desktop theme changes.

Light app on a dark desktop, client-area centre pixel:

  Mica     before #221F20    after #F8F1F2    WinUI #F5F1F7
  Acrylic  before dark       after light      WinUI light

Dark-on-dark is unchanged (#231F1D, WinUI #211F21), and windows without a
backdrop keep #FFFFFF / #000000.

Side effect worth knowing: the caption follows suit, because it is the same
DWM flag. A light-themed app now gets a light caption, which is what WinUI
shows. A dark-themed app gets a dark caption, where WinUI shows a light one
- WinUI never opts a window into DWM dark mode at all, so its caption is
light regardless of theme, and apps override it by hand.
The root element's background was computed twice by two different rules.
UnoRootElementLogic seeded it at construction from
ThemingHelper.GetRootVisualBackground(), plain White/Black off
Application.RequestedTheme with no high-contrast handling, while
CoreServices.NotifyThemeChange re-applied it on every theme change from
FrameworkTheming.GetHwndBackground(Theme.None), which returns
GetSystemColor(COLOR_WINDOW) under high contrast.

A high-contrast app therefore started with plain white or black under its
content and only converged on the correct colour at the first theme
notification. MUX has no such split: CXamlIslandRoot::NotifyThemeChangedCore
is called from InitializeCommon() and from every CCoreServices::
NotifyThemeChange, so both values come from one function by construction.

Seeds the island root inside InitializeRoot and the CoreWindow content root
in InitCoreWindowContentRoot, both from FrameworkTheming - the same source
the theme-change path already uses - and drops the second formula.

Both seed points hold a CoreServices instance already, so this adds no
singleton access during CoreServices construction.

Unchanged on Skia Win32: #FFFFFF light, #000000 dark, with and without a
backdrop, for Grid, Page, Border, UserControl and null content.
Adds two runtime tests for the WinUI contract that the island-root flag
implements:

- setting HasTransparentBackground suppresses only the rendering, leaving
  Panel.Background holding its theme brush, so a later theme change still
  resolves against it;
- setting and clearing Window.SystemBackdrop leaves app content's own
  Background untouched, guarding the removed tree walk from coming back.

Also drops a stale 'Verify that center of window is red' comment in
VerifyWindowBackgroundAsync, which asserts a brush rather than a pixel.
WaitForLoaded requires a non-zero ActualWidth/ActualHeight, so the empty
Border and Grid never satisfied it. Gives both an explicit size, and hosts
them on the main window rather than a secondary one - Given_Window's
secondary-window tests currently tear down the render thread hard enough to
take the whole process with them on Skia Win32, which loses the results
file.
The island root dropped its opaque background whenever MicaController.IsSupported()
agreed, but that answers for the operating system, not for the head. Headless, X11,
FrameBuffer, Android, iOS and WASM all inherit a no-op SetSystemBackdrop, so on
Windows 11 they passed the OS check, went transparent, and rendered no material
behind the root.

Ask the native window instead, via INativeWindowWrapper.IsSystemBackdropSupported.
Heads that cannot render a material keep the themed root background, which is Uno's
equivalent of the solid FallbackColor MUX's MicaController paints when the material
is unavailable.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DbdjkceVUCdxeEEZkK1haR
Fails against the previous OS-version check on Windows 11: the unit-test host's
window wrapper renders no material, yet MicaController.IsSupported() reported
support and the island root went transparent over nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DbdjkceVUCdxeEEZkK1haR
An unsupported backdrop left the island root painting the root visual's colour, which
is flat black or white - the legacy UWP value, normally invisible because app content
covers it. A window that asked for a material and got that instead looks unfinished.

Paint ApplicationPageBackgroundThemeBrush in that state. Under the Fluent styles it
resolves to SolidBackgroundFillColorBase (#202020 dark, #F3F3F3 light) - the colours
WinUI 3 shows - and to the system window colour under high contrast.

This is Uno's analogue of MicaController.FallbackColor, which is what MUX paints when
the material cannot be rendered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DbdjkceVUCdxeEEZkK1haR
MUX's SystemBackdrop takes its theme from XamlRoot.Content.ActualTheme and
moves that subscription to the new content on XamlRoot.Changed. Uno only
re-read it on system-theme or backdrop changes, so replacing or clearing
Window.Content left the DWM caption/tint on the old element (and kept it
alive), and the unsupported-head fallback resolved against the app theme.

Window now raises an internal ContentChanged; the Win32 frame theme and the
island root's fallback brush both retarget on it and on ActualThemeChanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
A Window constructed before Application.InitializationCompleted gets its
native wrapper later, in Initialize(). A SystemBackdrop assigned in between
hit a null NativeWrapper and never reached the native window, while the
root had already switched to its backdrop background.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
A backdrop type Win32 cannot render makes the root paint its opaque
fallback, but SetSystemBackdrop returned early and left the previous
Mica/Acrylic under the frame. Clear it with DWMSBT_NONE and recompute the
frame extension, as the macOS head already does.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
The fallback test resolved the expected brush but never compared it with
anything. Compare it with what the root's BorderVisual actually renders
(BackgroundBrush getter made internal for that), and cover the fallback
following the content's RequestedTheme and a replaced Window.Content.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
Clear the main window content in finally so the headless runner does not
carry it into later tests, and link both tests to #24189.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019C454B8usXZRfvcjWT1BB4
The 7.0 migration guide carries this note on master; 6.x has no such
guide, so it lives on the SystemBackdrop feature page instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XU3kKG9jHwupx4TefeXQAe
6.x still builds Uno.UI for Reference and the native renderers, which have
no BorderVisual and so no UpdateBackground extension.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XU3kKG9jHwupx4TefeXQAe
@github-actions github-actions Bot added platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 7m 14s —— View job


Review complete

Verdict: ship — no blocking or non-blocking code defects found. No inline comments posted (none survived verification with sufficient confidence to warrant one).

Scope covered: full diff vs base commit 91e6b404 (servicing/6.8 tip) — Window.cs's backdrop rewrite (visual-tree-rewrite removal → XamlIslandRoot/BackdropBackgroundMode-based approach), BorderHelper.skia.cs's render-time brush selection, the new INativeWindowWrapper.IsSystemBackdropSupported member and its Win32/macOS overrides, the Win32 content-theme tracking (UpdateFrameTheme/ContentChanged), the CoreServices/ThemingHelper/XamlIslandRoot.Core.cs root-background seeding consolidation, the #if UNO_HAS_BORDER_VISUAL per-flavor guard, and all new unit/runtime tests and docs.

What held up under scrutiny:

  • The removed visual-tree-walking/transparency-rewrite code (_savedBackdropBackgrounds, ApplyTransparentBackgroundsForBackdrop, OnBackdropElementLoaded/Unloaded) is cleanly and completely removed — no dangling references anywhere in the tree.
  • BackdropBackgroundMode (None/Transparent/Fallback) is only special-cased for XamlIslandRoot inside BorderHelper.UpdateBackground() — ordinary Panel/Border/Control background rendering is untouched, so this is a minimal, targeted change despite touching a shared helper.
  • Theme-change (Panel.Background DP → OnBackgroundChanged → UpdateBackground()) correctly re-derives the rendered brush from the current BackdropBackgroundMode rather than fighting it — verified the wiring end-to-end.
  • IsSystemBackdropSupported is correctly scoped: only Win32 and macOS override SetSystemBackdrop, and both now consistently override the new capability check; other heads inherit the safe false default (matches the stated intent — a head with no native window must never report support).
  • macOS's IsSystemBackdropSupported has no OS-version gate, but that matches its own pre-existing, equally-ungated SetSystemBackdrop — not a regression this PR introduces.
  • Win32's _frameThemeSource/Window._backdropThemeSource subscriptions are symmetric (unsubscribe-old/subscribe-new on every content change, unsubscribed on WM_DESTROY) — no leak pattern reintroduced.
  • Removal of System.Collections.Generic using in Window.cs is correct (no more Stack<>/HashSet<> usage).
  • Tests: the new unit tests (Given_Window_SystemBackdrop) and runtime tests (Given_Window, Given_AlcContentHost) concretely exercise the new invariants (root keeps its Background value while only the rendered primitive changes; content backgrounds are left alone; fallback follows content theme/replacement; ContentChanged fires exactly once for secondary-ALC content). No skipped/ignored tests introduced.
  • Docs (system-backdrop.md) clearly call out the behavior change with a migration snippet, and the sample page/description were updated to match the new model.

One cross-cutting, non-code consideration for the release owner (not a defect): this is an intentional, documented, user-visible behavior change (apps with an opaque Page.Background will now visibly hide the backdrop material they previously saw, even if they never intended to rely on the old transparency-rewrite) landing in a servicing branch under a fix commit. That's consistent with fixing a real, user-facing bug (the old behavior silently mutated app-owned Background values and broke {ThemeResource} updates), but it's larger in scope and impact than a typical patch-level fix. Worth confirming this gets release-note visibility beyond the in-doc callout, independent of code correctness.

Compile/runtime validation not independently re-run here — relying on the PR's own stated validation (strict build of Win32/MacOS/UnitTests flavors, Given_Window_SystemBackdrop 3/3 passing) plus this code-review-by-inspection pass.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 236200 did not find any UI Test snapshots differences.

@mergify

mergify Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@agneszitte
agneszitte merged commit 630ab44 into servicing/6.8 Oct 2, 2026
45 of 46 checks passed
@agneszitte
agneszitte deleted the dev/mazi/68-window-background branch October 2, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/documentation platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants