Repository navigation
fix: Pause AnimatedVisualPlayer when hidden to release Skia render loop - #23190
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates AnimatedVisualPlayer on Skia so hidden players pause their Lottie source and release the CompositionTarget.Rendering subscription, with accompanying Skia runtime tests. It fits into Uno's animation/rendering stack by reducing unnecessary frame-loop activity for Lottie-backed controls such as ProgressRing.
Changes:
- Added visibility-driven pause/resume state handling in
AnimatedVisualPlayer. - Removed source-update callbacks from read-only player state dependency properties and added an
IsPlayingcallback. - Added Skia runtime tests and the Lottie project reference needed to compile them.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Uno.UI/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.cs |
Adds hidden/visible playback state tracking and adjusts DP callbacks. |
src/Uno.UI.RuntimeTests/Uno.UI.RuntimeTests.Skia.csproj |
Adds the Skia Lottie project reference required by the new tests. |
src/Uno.UI.RuntimeTests/Tests/Microsoft_UI_Xaml_Controls/Given_AnimatedVisualPlayer.cs |
Adds Skia runtime tests for stop/hide/unhide rendering-subscription behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
|
|
…op (fixes #23189) On Skia, LottieVisualSource subscribes to CompositionTarget.Rendering to drive animation. Any subscriber keeps the system render loop running at full FPS, so hiding the player or calling Stop() did not actually quiet the loop and CPU load stayed high. - Track effective visibility on AnimatedVisualPlayer and pause/resume the source when Visibility transitions to Collapsed/Visible, mirroring native WinUI's AnimationPlay::OnHiding/OnUnhiding. - Catch the async-AutoPlay-into-hidden-tree case via a new OnIsPlayingChanged callback that pauses immediately when IsPlaying flips true while not visible. - Stop/Pause/Play/Resume reset _wasPlayingWhenHidden so an explicit Stop while hidden is not auto-reversed by a later visibility transition. - Remove UpdateSourceOnChanged from IsPlaying, IsAnimatedVisualLoaded, and Duration DPs (they are set internally by the source and shouldn't trigger reentrant Source.Update calls — matches the WinUI registration). - Add Given_AnimatedVisualPlayer runtime tests verifying CompositionTarget. Rendering subscribers via reflection across Stop / Hide / Unhide / Stop-while-hidden flows. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
221128e to
ed3ad9a
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
Lottie samples depend on the toolkit's CommunityToolkit.WinUI.Lottie which is not wired up in the WinAppSDK head, but they are valid on Skia / WASM. Move the Lottie folder exclusion into the existing UseWinUI=true group. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The visibility-based pause/resume in ed3ad9a only handled the player's own Visibility, not ancestor collapse, so it was incomplete. The proper fix is to drive the Lottie clock from the player's own paint callback (next commit) so the compositor's render walk implicitly handles all visibility cases (self, ancestor, host, unloaded). Keep the unrelated registration cleanup: IsPlaying, IsAnimatedVisualLoaded, and Duration are read-only DPs and should not have UpdateSourceOnChanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ring (fixes #23189) LottieVisualSource subscribed to CompositionTarget.Rendering on Skia to drive its frame clock. That subscription forced the global Skia render loop to run at full FPS even when the player was collapsed, in a hidden ancestor, on an invisible host, or unloaded. Replace it with a self-pumping clock: Render() advances an accumulated time (clamped per-frame so a long gap is treated as a paused boundary), then Invalidate()s its own SKCanvasElement to schedule the next paint. The compositor's tree walk skips visuals in collapsed/hidden subtrees, so the pump dies naturally when there is nothing to draw — no ancestor chain watching needed, matching how the Windows compositor implicitly ticks composition animations only on visible visuals. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
|
The build 210924 found UI Test snapshots differences: Details
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
|
The build 211015 found UI Test snapshots differences: Details
|
|
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
- Sample: call UpdateEffectiveVisibilityText() from InTreeToggle handlers - Sample: preserve spaces around inline Run elements via xml:space - Lottie.Skottie: add SkiaRenderCount counter for runtime test assertions - Tests: assert paints stop when player or ancestor is collapsed Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
86f4177 to
3eabaaa
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23190/wasm-skia-net9/index.html |
|
The build 211177 found UI Test snapshots differences: Details
|
|
|
Summary
LottieVisualSourcedrives animation by subscribing toCompositionTarget.Rendering, which keeps the system render loop running at full FPS for as long as it's subscribed. Hiding the player or callingStop()did not reliably release the subscription, so CPU stayed pinned and the framerate counter never settled.AnimatedVisualPlayernow tracks effective visibility (loaded +Visibility==Visible) and pauses/resumes the source on visibility transitions, matching native WinUI'sAnimationPlay::OnHiding/OnUnhiding.UpdateSourceOnChangedfrom the read-onlyIsPlaying/IsAnimatedVisualLoaded/DurationDPs (WinUI doesn't wire callbacks on these). This eliminates the reentrantSource.Update→Invalidate()chain that fired duringStop().Fixes #23189.
Test plan
Uno.UI.Lottie.Skia.csprojandUno.UI.RuntimeTests.Skia.csprojcleanly.SamplesApp.Skia.Genericand run the newGiven_AnimatedVisualPlayerruntime tests on Skia Desktop — all 4 pass:When_Stop_Removes_Rendering_SubscriptionWhen_Hidden_Pauses_And_Removes_Rendering_SubscriptionWhen_Unhidden_Resumes_PlaybackWhen_Stopped_While_Hidden_Stays_Stopped_When_UnhiddenGiven_ProgressRingruntime tests continue to pass (ProgressRing uses the same player + Lottie source via its template).LottieEmbeddedJson) and confirm the framerate counter stabilizes after collapsing the player or callingStop().🤖 Generated with Claude Code