Repository navigation
feat: Implement MonochromaticOverlayPresenter - #25710
MartinZikmund wants to merge 6 commits into
Conversation
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
|
🤖 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
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
|
|
The build 241385 found UI Test snapshots differences: Details
|
|
|
morning4coffe-dev
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
|
Tick the box to add this pull request to the merge queue (same as
|
GitHub Issue: closes #14353
PR Type:
✨ Feature
What changed? 🚀
MonochromaticOverlayPresenterwas 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.MonochromaticOverlayPresenter.cpp/.h,winui3/release/2.5.1). It takes aCompositionVisualSurfaceofSourceElementcovering the presenter's bounds. That surface goes through aColorMatrixEffectwhich keeps the source's alpha and replaces its color withReplacementColor; a transparentReplacementColorleaves the source unchanged. The result is set as the presenter's childSpriteVisual. Updates are batched ontoCompositionTarget.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 scrollingLoopingSelector. 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.SetSourceParameteralso tracks the source and invalidates the cached graph when it changes.CFrameworkElement::EnterImpl). So the template'sSourceElement="{Binding ElementName=DayLoopingSelector}"resolved to null, because the selectors are created in code.DatePickerFlyoutPresenternow registers the names of itsDay/Month/YearLoopingSelectors in the template namescope. The TimePicker binds to elements defined in its template, so it needs nothing.UnoFluentOverlay.xaml, so the verbatim WinUI templates apply again.MonochromaticOverlayPresenter_Showcase: a port of WinUI'sMonochromaticOverlayPresenterPage.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).Given_MonochromaticOverlayPresentertests: recoloring, alpha preservation, source content moving while the presenter isn't invalidated, aReplacementColorchange, and a transparentReplacementColor.Given_DatePicker/Given_TimePicker.When_Flyout_Opened_Highlight_Shows_Selected_Valuereplace the old*_Workaroundtests. Each opens the flyout, checks the band contains the replacement color, pans aLoopingSelector, and checks the band updated. The DatePicker test also checks that each overlay binds to its matching selector, again after the flyout is reopened.CompositionEffectBrushchange,When_Source_Content_Movesand both picker tests fail ("The highlight band did not update when the selector scrolled").Given_DatePicker,Given_TimePicker,Given_MonochromaticOverlayPresenter,Given_EffectBrush_Parity,Given_CompositionVisualSurface,Given_AcrylicBrush, andGiven_FrameworkElement_And_Leak, including the presenter's leak row.WebGpuDrawingFactorypath as the desktop WebGPU run.Notes
LoopingSelectorItemSelectedstate setsContentPresenter.BackgroundtoSubtleFillColorSecondary. WinUI's own LoopingSelector UIETree master records#09000000there, 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.CompositionVisualSurfaceloses edge antialiasing on WebGPU, with or without an effect, so curved edges in the overlay look aliased on that backend. Skia is unaffected.EffectGraphParsermaps the linear part of D2D'sColorMatrixtransposed. It doesn't affect this effect, which only usesM44and the offset row.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fzb83MAdF8qKHKproF3Bn3