Repository navigation
feat(scroll): Drive scroll motion from a uniform frame clock - #23987
MartinZikmund wants to merge 8 commits into
Conversation
|
Claude finished @MartinZikmund's task in 10m 50s —— View job Code ReviewPR #23987 — feat(scroll): Drive scroll motion from a uniform frame clock
Overall verdictfix-first — 1 medium issue with a targeted fix, 1 low-severity efficiency issue, and 2 pre-existing items worth cleaning up while the file is open. Issues found: 2 (inline) + 2 pre-existing (not in diff)Medium —
Low — In a Pre-existing issues (not in this diff, worth noting)
What's working well
|
|
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. |
There was a problem hiding this comment.
Pull request overview
Implements a Skia-specific “single frame timestamp” discipline for scroll-related motion, routing wheel/touch inertia through a uniform frame clock so scroll position is evaluated once per frame (pre-layout / pre-record) instead of being driven by event arrival timing.
Changes:
- Add a Skia
FrameClockand aCompositionTarget.FrameStartingpre-layout hook to provide a single per-frame timestamp to motion drivers. - Rework ScrollViewer wheel + touch inertia to be time-parameterized (decay/fling simulations, unquantized deltas, fractional wheel detents).
- Add runtime tests plus a manual benchmark sample and a design spec documenting the rationale and constraints.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/Media/CompositionTarget.Rendering.skia.cs | Moves frame-record accounting under the publish gate to avoid false dropped-frame reporting. |
| src/Uno.UI/UI/Xaml/Media/CompositionTarget.FrameClock.skia.cs | Introduces FrameStarting event + per-target frame clock integration for Skia. |
| src/Uno.UI/UI/Xaml/Internal/InputManager.Pointers.Managed.cs | Sends fractional wheel “detents” (double) to trackers to avoid precision touchpad dead-zone. |
| src/Uno.UI/UI/Xaml/Internal/DirectManipulation.cs | Enables unquantized deltas for direct manipulation (scrolling) gesture recognizer. |
| src/Uno.UI/UI/Xaml/Internal/CoreServices.cs | Raises FrameStarting pre-layout (Skia) to tick motion drivers before recording. |
| src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollFlingSimulation.cs | Adds closed-form fling simulation (Android/iOS parity) for touch inertia. |
| src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollDecaySimulation.cs | Adds exponential decay simulation for wheel motion with impulse accumulation. |
| src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.Managed.cs | Wires wheel decay + touch fling to FrameStarting, adds velocity fitting, and updates animation frame handling. |
| src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.cs | Switches wheel path to feed the accumulating decay via AddWheelImpulse. |
| src/Uno.UI/UI/Input/WinRT/ScrollVelocityTracker.cs | Adds least-squares velocity estimation over recent samples for stable inertia launch velocity. |
| src/Uno.UI/UI/Input/WinRT/GestureRecognizer.Manipulation.InertiaProcessor.cs | Uses FrameStarting (Skia) to tick inertia pre-record instead of CompositionTarget.Rendering. |
| src/Uno.UI/UI/Input/WinRT/GestureRecognizer.Manipulation.cs | Ensures manipulation deltas can be committed even when below thresholds for scrolling. |
| src/Uno.UI/UI/Input/WinRT/GestureRecognizer.cs | Adds ReportsUnquantizedDeltas init flag to control delta threshold behavior for scroll. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ScrollViewer.cs | Updates/adds scroll behavior tests for wheel monotonicity, fling proportionality, and unquantized slow-drag. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Composition/Given_Compositor.cs | Adds frame clock behavior tests (jitter smoothing, drift, drops, reanchor, monotonicity). |
| src/Uno.UI.Composition/Composition/InteractionTracker/InteractionTrackerState.cs | Updates wheel delta API to accept double ticks. |
| src/Uno.UI.Composition/Composition/InteractionTracker/InteractionTrackerInteractingState.cs | Signature update for wheel delta (double). |
| src/Uno.UI.Composition/Composition/InteractionTracker/InteractionTrackerInertiaState.cs | Uses double wheel delta and casts to float vectors for inertia handling. |
| src/Uno.UI.Composition/Composition/InteractionTracker/InteractionTrackerIdleState.cs | Uses double wheel delta and adjusts velocity computation accordingly. |
| src/Uno.UI.Composition/Composition/InteractionTracker/InteractionTrackerCustomAnimationState.cs | Signature update for wheel delta (double). |
| src/Uno.UI.Composition/Composition/InteractionTracker/InteractionTracker.cs | Documents and implements fractional wheel detents end-to-end (double). |
| src/Uno.UI.Composition/Composition/FrameClock.skia.cs | New frame clock implementation based on median tick intervals and monotone correction. |
| src/Uno.UI.Composition/Composition/Compositor.skia.cs | Counts “frame drivers” as animating work so WaitForIdle(...waitForCompositionAnimations:true) covers them. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollSmoothnessBenchmark.xaml.cs | Adds a manual benchmark to report per-frame offset-delta jitter statistics while scrolling. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollSmoothnessBenchmark.xaml | UI for the scroll smoothness benchmark sample. |
| specs/scroll-smoothness/spec.md | Adds design spec capturing goals, invariants, research references, and staged plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
80cfa2b to
68659d3
Compare
5ffffb6 to
77c3d3f
Compare
8f48b38 to
021913b
Compare
|
Claude finished @MartinZikmund's task in 5m 36s —— View job Code ReviewPR #23987 — feat(scroll): Drive scroll motion from a uniform frame clock
Overall verdict: fix-first2 medium issues, 2 low issues, 1 nit. The medium issues follow the same pattern (cached-target vs. re-fetched target) and have the same fix; the low issues are each bounded to a specific scenario with a known workaround. Issues by severityMedium (2)
Low (2)
Nit (1)
Pre-existing (not in diff, worth cleaning up)
What's working well
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23987/wasm-skia-net9/index.html |
|
The build 229251 found UI Test snapshots differences: Details
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-23987/docs/index.html |
021913b to
cee1b78
Compare
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-23987/docs/index.html |
|
The build 232300 found UI Test snapshots differences: Details
|
|
|
SnapshotAndReset reset the region in a finally, so a throw between the builder's Detach and the reset left the region claiming rects it no longer held and those pixels stale. The dispatcher logs and swallows what escapes the render callback, so the app keeps rendering into that hole. Re-open the region on its accumulated bounds instead, and drop contributions once disposed: a render callback enqueued before the owning target unregistered can still reach the region afterwards, where writing to the freed native paths would be an access violation. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
Motion driven from CompositionTarget.Rendering is evaluated from a dispatcher continuation after the frame is recorded, so it writes into the following frame - a structural frame of latency - and against a raw clock that wobbles by milliseconds around the presented cadence. A driver whose position is a function of time turns that wobble into v-dt of position error, which at scroll speeds is a visible fraction of a frame step. Add CompositionTarget.FrameStarting, raised once per presented frame from the tick that precedes it (before layout and before the record), carrying a timestamp recovered from the median tick interval so every driver in the frame evaluates against the grid the frames are actually shown on. Drivers are counted so Compositor.IsAnimating covers them, dropped when their target unregisters (an unregistered target never presents again, so the frame that would bring the next tick never comes), and ticked for XAML islands as well as windows. MainFrameDriverTarget falls back to the primary XamlRoot so an island host, which has no Window at all, still resolves one. The macOS host now unregisters its XamlRoot on close, which is what releases the closed target's frame drivers and pending render jobs. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
Both inertia handlers ran on a System.Threading.Timer, which wrote composition state from a thread-pool thread and sampled at its own fixed 17ms rate regardless of the display's - so on a 120Hz panel most frames had nothing new to show. Advance them from the frame clock instead. Wheel detents are now fractional: a precision touchpad reports deltas finer than one 120-unit notch, and the integer division floored every one of them to zero. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
Win32 truncated pointer positions to whole logical pixels - and at 150% or 200% that threw away precision the digitizer actually reported - so a slow drag advanced in steps no matter what the layers above it did. Touch and pen carry a HIMETRIC position that is ~26x finer than the logical pixel grid; use it, and keep the whole-pixel screen-to-client translation separate so the sub-pixel part survives it. Mouse stays on ptPixelLocation, which Win32 reports in integer screen pixels anyway. X11 truncated the XInput2 sub-pixel position to feed XTranslateCoordinates, which only takes whole pixels. Translate the floor and re-add the fraction. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
Scrolling was quantized at three points and none of them belonged on the scroll path: the manipulation delta threshold held content still until 2px had accumulated and then jumped by the whole amount, the wheel restarted a fixed-duration ease per detent so each notch re-injected a large first step on an arbitrary frame, and touch inertia ran a constant-deceleration parabola whose distance grew with the square of a launch velocity estimated from the last two samples. Replace all three: - ScrollVelocityTracker fits a quadratic over the recent gesture, so one short sample interval no longer sends the content thousands of pixels. Parameters match Flutter's VelocityTracker, which Avalonia also mirrors. - ScrollFlingSimulation is the platform's own curve, closed-form in absolute time: Android's OverScroller spline (reproducing getSplineFlingDistance exactly, with 96 DIPs per inch substituted for Android's 160 dp) and iOS's UIScrollView exponential drag. - ScrollDecaySimulation gives the wheel exponential decay, which is memoryless, so a detent is an impulse added to the running velocity and composes exactly with whatever motion is already in flight. All three are evaluated against the frame clock, so a late or early frame produces the correct position rather than accumulating error. Pressing on coasting content stops it: the resume path completes the manipulation without reporting it, and the manipulation that replaces it only reports Started once the finger has travelled the 10px start threshold, so the fling needs an explicit notification to stop under a finger held still. A fling that runs out, is unloaded, or is pre-empted by a programmatic scroll now also ends the manipulation the coast was holding, which otherwise kept a frame driver alive and swallowed presses. A presenter that never claimed the inertia no longer publishes a final offset for a scroll it did not perform. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
- Anchor the wheel decay on its first frame-clock tick instead of a raw clock read, so the frame the notch arrives on is not dropped to a negative elapsed time. Mirrors what StartFling already did. - Gate each fling axis on its own curve, so a settled axis stops the driver instead of coasting on the other axis's duration. - Use the UIScrollView curve for a WASM app hosted by an iOS or iPadOS browser, resolved once via DeviceTargetHelper.BrowserHost rather than per fling. - Guard the FrameStarting accessors against a null handler, which also removes the condition the analyzer read as constant. - Cover the DamageRegion disposed guard with a runtime test. - Fall back to a themed-or-gray brush in the benchmark sample rather than indexing a resource key that a head may not define. - Doc and import tidy-ups. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
Stop() unsubscribes from CompositionTarget.Rendering, whose accessor asserts UI-thread access, so running it from the finalizer thread throws - and a throw from a finalizer terminates the process. It could never have done anything useful either: while a handler is subscribed the event roots the timer, so the instance only becomes collectable once Stop() has already run. InertiaProcessor.Dispose() is what ends the timer deterministically. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV
1cee004 to
8dc7d8d
Compare
|
Claude finished @MartinZikmund's task in 2m 57s —— View job Code Review — PR #23987
Overall verdict: ship (pending CI)This synchronize event did not introduce any code changes relative to what was already reviewed and resolved in the prior round (
Additional independent checks for this pass, beyond re-confirming prior findings:
Cross-cutting note (not a code defect)Recent CI runs show highly volatile |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23987/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-23987/docs/index.html |
|
The build 232885 found UI Test snapshots differences: Details
|
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvages the FrameClock tests from #23987 and adds two that fail on the post-present Rendering raise: a Rendering write must be recorded by the same tick, and FrameStarting and Rendering must share one frame time. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvages the FrameClock tests from #23987 and adds two that fail on the post-present Rendering raise: a Rendering write must be recorded by the same tick, and FrameStarting and Rendering must share one frame time. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvages the frame interval test from #23987 and adds two that fail on the post-present Rendering raise: a Rendering write must be recorded by the same tick, and FrameStarting and Rendering must share one frame time. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvages the frame interval test from unoplatform#23987 and adds two that fail on the post-present Rendering raise: a Rendering write must be recorded by the same tick, and FrameStarting and Rendering must share one frame time. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from #23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
Salvaged from unoplatform#23987. Only the fling distance, unload and notch-in-a-row tests fail on the previous motion model; the rest guard behaviour the rework has to keep (a press stops a coast and is swallowed, a wheel notch mid-fling never steps back, an interrupted fling publishes a final offset). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016WqaiNE2QBeUszQFongehx
GitHub Issue: closes #23985
PR Type
✨ Feature
TL;DR
Scroll motion was produced by six independent sources, none of which agreed on a clock, and two input paths quantized motion before it ever reached the visual. This PR gives every scroll motion one timestamp per frame and makes each one a closed-form function of time, then replaces the ad-hoc curves with the ones the host platform actually uses.
The problem, in one picture
Motion used to be evaluated after the frame it belonged to had already been recorded, from a clock nobody had aligned to the display:
sequenceDiagram autonumber participant OS as Native vsync participant UI as UI thread tick participant Rec as Record (SKPicture) participant Scr as Screen rect rgb(255, 235, 235) Note over OS,Scr: BEFORE — driver runs after the record OS->>UI: frame callback UI->>Rec: record picture (offset N) Rec->>Scr: present offset N Scr-->>UI: dispatcher continuation UI->>UI: CompositionTarget.Rendering fires<br/>driver reads Stopwatch, writes offset N+1 endTwo things go wrong there. The write lands one frame late, structurally — every fling was a frame behind the finger. And the driver times itself off a raw clock read taken whenever the dispatcher happened to get there, which wobbles by milliseconds around a cadence that is otherwise exact.
For anything whose position is a function of time, that wobble becomes position error:
And it gets worse as refresh rate rises: the error stays
v·Δtwhile the frame step halves.What this PR establishes
I1 — One frame, one timestamp
sequenceDiagram autonumber participant OS as Native vsync participant UI as UI thread tick participant Rec as Record (SKPicture) participant Scr as Screen rect rgb(235, 250, 235) Note over OS,Scr: AFTER — driver runs before layout, before the record OS->>UI: frame callback → ArmFrameDriverTick() UI->>UI: RaiseFrameStarting(t) → every driver evaluates at t UI->>UI: UpdateLayout() — cleans what the drivers dirtied UI->>Rec: record picture (offset N) Rec->>Scr: present offset N endtis not a clock read. A newFrameClockrecovers a phase-locked grid from the median tick interval:It lives on the
CompositionTarget, not the process-wideCompositor: several record loops sharing one clock push near-zero intervals into its window and collapse the estimated period.I2 — Motion is a function of time, not of event arrival
flowchart TD W["Wheel detent"] -->|impulse added to running velocity| D["ScrollDecaySimulation<br/><i>x(t) = x₀ + v/λ · (1 − e^−λt)</i>"] F["Finger lift"] --> VT["ScrollVelocityTracker<br/><i>least-squares quadratic fit</i>"] VT -->|launch velocity| FL["ScrollFlingSimulation<br/><i>platform curve, closed form</i>"] D --> FC(["FrameStarting(t)"]) FL --> FC FC --> S["Set(offset) → AnchorPoint"]Every one is closed-form in absolute time, so a late or early frame produces the correct position instead of accumulating error — which matters exactly where the frame rate changes mid-motion, as it does on Android browsers when the finger lifts.
The three simulations
ScrollDecaySimulation— exponential decay,λ = 8/sScrollFlingSimulation—OverScrollersplinegetSplineFlingDistanceexactly. Note this is not Flutter'sClampingScrollSimulation, which overshoots Android by ~21%; the extraDECELERATION_RATE · INFLEXIONfactor is what makes the distance match.PhysicalCoefficientuses 96 DIPs/inch, not Flutter's 160 dp/inch — using Flutter's value directly would make every fling travel 1.667× too far.ScrollFlingSimulation—UIScrollViewdragx(t) = x₀ + v₀ · (0.135^t − 1) / ln 0.135, matchingdecelerationRate.normal(0.998/ms). Applied on iOS/macOS/Mac Catalyst and to a WASM app hosted by an iOS or iPadOS browser — the user's other apps decelerate on that curve, so ours has to.Launch velocity comes from a least-squares quadratic fit over the recent gesture (Flutter's
VelocityTrackerparameters, which Avalonia also mirrors) rather than a first-vs-last difference. Inertia distance grows with the square of launch velocity, so a two-point estimate that catches one short interval sends the content thousands of pixels.De-quantizing the input
Three separate places rounded motion away before it reached any of the above:
flowchart LR HW["Digitizer<br/>sub-pixel"] --> P1["Win32: (int)(px / scale)<br/>❌ whole logical px"] P1 --> P2["Manipulation delta gate<br/>❌ ≥ 2 logical px"] P2 --> P3["Wheel: int ÷ 120<br/>❌ floors touchpads to 0"] P3 --> OUT["ScrollViewer"]ptHimetricLocation(HIMETRIC, ~26× finer), keeping the whole-pixel screen→client translation separate so the sub-pixel part survives it. Mouse stays onptPixelLocation, which Win32 reports in integer screen pixels anyway.XTranslateCoordinates, which only takes whole pixels. Now translates the floor and re-adds the fraction.ManipulationDeltaevents; on the scroll path it acted as a motion quantizer — content did not move until 2 px accumulated, then jumped by the whole amount, so a slow drag advanced every other frame. Now opt-in per recognizer (ReportsUnquantizedDeltas), set only for direct manipulation, so app-level recognizers keep their event volume unchanged. Inertia already bypassed it for the same reason.Also in here
System.Threading.Timer— it was writing composition state from a thread-pool thread, and sampling at a fixed 17 ms regardless of the display, so most frames on a 120 Hz panel had nothing new to show.Drawacquiring the gate in between read a fresh picture against a stale generation and logged a dropped frame that never happened.DamageRegionkeeps its damage when a snapshot throws, and drops contributions once disposed — a render callback enqueued before the owning target unregistered can still reach it, where writing to the freed native paths would be an access violation.XamlRooton close, which is what releases a closed target's frame drivers and pending render jobs.Reviewing this
Suggested order — each layer stands alone:
FrameClock.skia.cs+Given_Compositor— the grid, and the eight tests that pin its behaviour (jitter, drift, dropped frames, idle re-anchor, monotonicity, hitches).CompositionTarget.FrameClock.skia.cs+Given_CompositionTarget— driver lifetime and cadence.ScrollFlingSimulation/ScrollDecaySimulation/ScrollVelocityTracker— pure functions, unit-testable, no UI.ScrollContentPresenter.Managed.cs— the wiring, and the gesture lifecycle around it.Explicitly not adopted, each a silent parity deviation or a regression: pointer resampling as the headline fix (Flutter ships it off, and it costs ~38 ms of latency); pointer prediction/extrapolation (absent from dxaml, causes overshoot); a
CubicBezieron default programmatic scroll (WinUI supplies no easing function).Design rationale and the full research trail are in
specs/scroll-smoothness/spec.md.PR Checklist ✅
Given_Compositor(frame clock),Given_CompositionTarget(driver cadence and lifetime),Given_ScrollViewer(scroll motion, fling distance, press-to-stop, final-offset publication),Given_Visual_Damage(disposed-region guard), plus aScrollSmoothnessBenchmarksample for manual frame-pacing comparison.specs/scroll-smoothness/spec.mdcarries the design. No public API surface changed.Screenshots Compare Test Runresults.Validation
Compile —
Uno.UI-Skia-only.slnf,Uno.UI.UnitTests.csproj,SamplesApp(net10.0-desktop): 0 errors.Runtime (tests) — Skia Desktop,
Given_ScrollViewer+Given_Visual_Damage: 75/75 green. Each added test was verified red first, including:When_PressAndHold_During_Fling_Then_It_StopsWhen_Frame_Driver_Writes_Then_Ticked_Once_Per_FrameWhen_Frame_Driver_Writes_Nothing_Then_Still_Ticked_Every_FrameWhen_Window_Closed_Then_Frame_Drivers_DroppedCompositor.IsAnimatingto clearWhen_Region_Is_Disposed_Then_Contributions_Are_DroppedRuntime (pacing — the actual point) — per-frame counter on both heads, wheel decay driven synthetically:
Only the ratios are meaningful — the benchmark sample subscribes
CompositionTarget.Rendering, which holds presents at the refresh rate whether or not anything moves.Because this changes feel rather than API, the
ScrollSmoothnessBenchmarksample remains the reviewer-facing check: it reports frame pacing directly, which a pass/fail test cannot capture.🤖 Generated with Claude Code
https://claude.ai/code/session_01BotfVqadqduoPktL3wFznV