Skip to content

feat: Implement MonochromaticOverlayPresenter - #25710

Open
MartinZikmund wants to merge 6 commits into
unoplatform:masterfrom
MartinZikmund:ccr-1ee0936c-npq68q
Open

MartinZikmund wants to merge 6 commits into
unoplatform:masterfrom
MartinZikmund:ccr-1ee0936c-npq68q

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #14353

PR Type:

✨ Feature

What changed? 🚀

MonochromaticOverlayPresenter was a stub that logged a warning and drew nothing. To hide that, Uno overrode the DatePicker and TimePicker flyout templates with transparent presenters and a half-opaque highlight band, so the selected value never appeared in the highlight foreground color the way it does in WinUI.

  • Port of WinUI's presenter (MonochromaticOverlayPresenter.cpp/.h, winui3/release/2.5.1). It takes a CompositionVisualSurface of SourceElement covering the presenter's bounds. That surface goes through a ColorMatrixEffect which keeps the source's alpha and replaces its color with ReplacementColor; a transparent ReplacementColor leaves the source unchanged. The result is set as the presenter's child SpriteVisual. Updates are batched onto CompositionTarget.Rendering, as in WinUI.
  • CompositionEffectBrush: live sources are now redrawn. The brush drew its non-backdrop sources once and cached them per bounds and scale. A source that changes without raising a property change stayed frozen, for example a VisualSurface of a scrolling LoopingSelector. So the highlight didn't follow the column while it scrolled. Such a source (RequiresRepaintOnEveryFrame) now makes the brush repaint and rebuild its effect graph every frame, matching WinUI's live VisualSurface. SetSourceParameter also tracks the source and invalidates the cached graph when it changes.
  • ElementName / namescope workaround. Uno doesn't port WinUI's name registration on tree entry (CFrameworkElement::EnterImpl). So the template's SourceElement="{Binding ElementName=DayLoopingSelector}" resolved to null, because the selectors are created in code. DatePickerFlyoutPresenter now registers the names of its Day/Month/YearLoopingSelectors in the template namescope. The TimePicker binds to elements defined in its template, so it needs nothing.
  • Templates: the DatePicker and TimePicker flyout presenter overrides are removed from UnoFluentOverlay.xaml, so the verbatim WinUI templates apply again.
  • Samples (Pickers category):
    • MonochromaticOverlayPresenter_Showcase: a port of WinUI's MonochromaticOverlayPresenterPage.
    • MonochromaticOverlayPresenter_Playground: choose the source content (text, icons, shapes with alpha, a scrolling list), ReplacementColor (presets or a ColorPicker), the presenter's background and size, and move or animate the source.

Validation

Runtime tests ran on Skia Desktop (X11 under Xvfb), once with the Skia renderer and once with UNO_WEBGPU=1 (wgpu-native on Mesa lavapipe).

  • New Given_MonochromaticOverlayPresenter tests: recoloring, alpha preservation, source content moving while the presenter isn't invalidated, a ReplacementColor change, and a transparent ReplacementColor.
  • Given_DatePicker / Given_TimePicker.When_Flyout_Opened_Highlight_Shows_Selected_Value replace the old *_Workaround tests. Each opens the flyout, checks the band contains the replacement color, pans a LoopingSelector, and checks the band updated. The DatePicker test also checks that each overlay binds to its matching selector, again after the flyout is reopened.
  • Fails before / passes after: with the presenter port but without the CompositionEffectBrush change, When_Source_Content_Moves and both picker tests fail ("The highlight band did not update when the selector scrolled").
  • Regression set: 127 passed, 0 failed, on both Skia and WebGPU. It covers Given_DatePicker, Given_TimePicker, Given_MonochromaticOverlayPresenter, Given_EffectBrush_Parity, Given_CompositionVisualSurface, Given_AcrylicBrush, and Given_FrameworkElement_And_Leak, including the presenter's leak row.
  • Not run: the WASM head. It uses the same WebGpuDrawingFactory path as the desktop WebGPU run.

Notes

  • Inside each column the selected item's band is about 3.5% lighter. That's current WinUI 3 behavior: the LoopingSelectorItem Selected state sets ContentPresenter.Background to SubtleFillColorSecondary. WinUI's own LoopingSelector UIETree master records #09000000 there, and the overlay recolors it along with the text. The WinUI 2.6 template only changed Foreground, which is why older screenshots don't show it.
  • Existing WebGPU issue, not addressed here: content drawn through a CompositionVisualSurface loses edge antialiasing on WebGPU, with or without an effect, so curved edges in the overlay look aliased on that backend. Skia is unaffected.
  • Unrelated, not changed: EffectGraphParser maps the linear part of D2D's ColorMatrix transposed. It doesn't affect this effect, which only uses M44 and the offset row.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3

A CompositionEffectBrush rasterized its non-backdrop sources once and
reused them while bounds/scale stayed the same, so a source whose
content changes without a property change (a CompositionVisualSurface
of a scrolling visual) was frozen. Treat such sources as live: the brush
now repaints every frame and re-parses its graph, matching WinUI's live
VisualSurface. SetSourceParameter also tracks the source so that its
own changes invalidate the cached graph.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3
Port WinUI's MonochromaticOverlayPresenter: a VisualSurface of the
SourceElement, under the presenter's bounds, fed through a ColorMatrix
effect that keeps the alpha and replaces the color with
ReplacementColor, shown as the presenter's child visual.

The DatePicker and TimePicker flyouts now use the verbatim WinUI
templates again, so the value under the highlight band is drawn in the
highlight foreground color and follows the column while it scrolls.
DatePickerFlyoutPresenter registers the names of its code-created
LoopingSelectors in the template namescope, as WinUI does on Enter, so
the presenters' ElementName bindings resolve.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3
Port of WinUI's MonochromaticOverlayPresenterPage, plus a scrollable
list under a fixed highlight band with ReplacementColor and width
controls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3
Assert each MonochromaticOverlayPresenter in the DatePicker flyout
resolves its ElementName source to the matching code-created
LoopingSelector, also after the reused flyout presenter is reopened.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3
Interactive page to pick the source content (text, icons, shapes with
alpha, scrolling list), ReplacementColor (presets or a ColorPicker),
presenter background and size, and to move or animate the source to
see the overlay follow it live. The showcase is now the plain port of
WinUI's MonochromaticOverlayPresenterPage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3
@github-actions github-actions Bot added area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation labels Oct 26, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

The overlay's live source was rasterized into an offscreen texture at
the scale rounded up to a power of two (4x for a 2.625x display), then
resampled onto the device pixels, which blurred the recolored text.

A live source is redrawn every frame anyway, so when the effect graph
is a colour matrix over it, paint it straight through that matrix at
device resolution instead. On WebGPU the alpha-keeping colour matrix
was folded into direct draws only and never reached replayed
recordings (what a VisualSurface draws), so a replay under it now goes
through a layer that applies the matrix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 241385 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 2458 changed over 2490

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AndroidWindowInsets.png-dark
    • AndroidWindowInsets.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedIconPage.png
    • AppBarButtonTest.png-dark
    • AppBarButtonWithIconTest.png-dark
    • AppBarToggleButtonTest.png
    • ApplicationViewSizing.png
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowPresenters.png-dark
    • AppWindowPresenters.png
    • AuthenticationBroker_Cancel.png-dark
    • AuthenticationBroker_Cancel.png
    • AutomationProperties_Name.png
    • AutomationProperties_Relations.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • AutoSuggestBox_BitmapIcon.png-dark
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 241385 has failed on Uno.UI - CI.

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through MonochromaticOverlayPresenter.cpp/.h side by side with the new .mux.cs files, and the port is 1:1: InvalidateBrush coalesces onto CompositionTarget.Rendering, the effect factory is rebuilt only on a color change, the ColorMatrix branches and the VisualSurface offset/size match, and the class still derives from Grid as in the IDL. Dropping the picker overrides so the WinUI templates apply again is the right call. I have one perf question on the effect brush and two smaller notes inline.

{
foreach (var source in _sourceParameters.Values)
{
if (source is not CompositionBackdropBrush && source.RequiresRepaintOnEveryFrame)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequiresRepaintOnEveryFrame on a CompositionSurfaceBrush is true for any IPaintableSurface, which also covers CompositionSvgSurface and AlphaMaskSurface, not just CompositionVisualSurface. So an effect brush over an SVG or alpha-mask surface would count as live, and the graph would be re-parsed and damaged every frame even when nothing changed. Since the behavior you're matching is specifically the live VisualSurface (MonochromaticOverlayPresenter.cpp UpdateBrush), could this check CompositionSurfaceBrush { Surface: CompositionVisualSurface } instead?

// UNO: WinUI registers the name of an element created in code in its template namescope when it enters the tree
// (CFrameworkElement::EnterImpl). Do it here so the template's ElementName bindings to the selectors resolve
// (e.g. MonochromaticOverlayPresenter.SourceElement).
private void RegisterTemplateName(FrameworkElement element)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small correction: in WinUI, names are registered on tree entry in CDependencyObject::Enter (core/core/elements/depends.cpp, the RegisterName(pNamescopeOwner) calls), not in CFrameworkElement::EnterImpl. Since this works around a missing core feature, could you add a TODO with a tracking issue? Any other control that names code-created template parts will hit the same thing.


[TestMethod]
[GitHubWorkItem("https://github.com/unoplatform/uno/issues/14353")]
public async Task When_ReplacementColor_Changes()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice coverage. The other two invalidation paths from the WinUI ctor and OnPropertyChanged aren't covered yet: SizeChanged (resizing the presenter should resize the SpriteVisual and the surface's SourceSize) and swapping SourceElement. A short test for each would pin down the InvalidateBrush wiring.

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Skia] Support for MonochromaticOverlayPresenter

6 participants