Skip to content

Add a rect-only ancestor clip query instead of building an SKPath in GetGlobalBoundsWithOptionsΒ #24163

Open

Description

@Xiaoy312

What would you like to be added? πŸ’‘

UIElement.GetGlobalBoundsWithOptions(ignoreClipping: false, …) needs only the axis-aligned bounds of the effective ancestor clip, but the only way to obtain it today is Visual.GetTotalClipPath, which walks the ancestor chain building an SKPath (a native SKPath.Op(Intersect) per clipping ancestor) that the caller immediately reduces to clipPath.Bounds:

// src/Uno.UI/UI/Xaml/UIElement.mux.cs
var clipPath = _globalBoundsClipScratch ??= new SkiaSharp.SKPath();
Visual.GetTotalClipPath(clipPath, skipPostPaintingClipping);
var clip = clipPath.Bounds;

Proposal: add a rect-returning ancestor-clip query β€” intersecting Rect/SKRects up the ancestor chain β€” and have GetGlobalBoundsWithOptions (and therefore IsOffscreen) use it, falling back to the existing path walk only when an ancestor's clip is genuinely non-rectangular in global space (a rotating/skewing transform, or a non-rectangular Clip geometry).

ContainerVisual.GetPrePaintingClipping already carries the TODO for exactly this, with the rect-based code sketched out in comments beside it:

// src/Uno.UI.Composition/Composition/ContainerVisual.skia.cs:164
internal override bool GetPrePaintingClipping(SKPath dst) // TODO: Do not use SKPath here, bad for perf and prevents usage for IDirectManipulationHandler.IsInBoundsForResume

Why is this needed? πŸ€”

Cost on per-frame callers. The path is built with native Skia ops per clipping ancestor and then discarded for four floats. Two consumers walk it repeatedly:

  • TextSelectionGripperPresenter.Update (src/Uno.UI/UI/Xaml/Controls/Primitives/TextSelectionGripperPresenter.skia.cs) runs once per rendered frame for as long as touch text-selection grippers are up, and reads the host's clipped bounds to decide whether to cull them.
  • SystemFocusVisual (src/Uno.UI/UI/Xaml/Controls/FocusVisual/SystemFocusVisual.cs:124) does the same walk on its own scratch path.

Precision. Reducing the path to .Bounds discards rotation: a rotated clipping ancestor over-approximates its clip, so an element whose true visible area is empty can still report non-empty bounds. Culling built on this therefore under-culls rather than over-culls β€” safe, but imprecise, and it means "is this element visible" cannot be answered exactly today.

Unblocks the existing TODO. The comment above names IDirectManipulationHandler.IsInBoundsForResume as a caller that cannot use the current shape at all.

Renderer 🎨

  • Skia
  • Native

For which platforms πŸ“±πŸ’»πŸ–₯️

All Skia targets (Desktop Windows/macOS/X11, WebAssembly, Skia-on-Android/iOS).

Anything else we need to know? πŸ’¬

Framework-internal change: GetTotalClipPath, GetPrePaintingClipping and GetGlobalBoundsWithOptions are all internal, so no public API surface is affected and there is no WinUI-parity constraint on the shape of the new query.

Surfaced while reviewing #24132, which made GetGlobalBoundsWithOptions ancestor-clip-aware and put it on a per-frame path for the first time. That PR is unaffected by this β€” the bbox over-approximation only makes it cull less β€” so this is a follow-up, not a prerequisite.

Activity

  1. added
    kind/enhancement
    triage/untriaged
    on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementtriage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions