Skip to content

fix: Pause AnimatedVisualPlayer when hidden to release Skia render loop - #23190

Merged
MartinZikmund merged 9 commits into
masterfrom
dev/mazi/renderingstucklottie
May 7, 2026
Merged

MartinZikmund merged 9 commits into
masterfrom
dev/mazi/renderingstucklottie

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

Summary

  • On Skia, LottieVisualSource drives animation by subscribing to CompositionTarget.Rendering, which keeps the system render loop running at full FPS for as long as it's subscribed. Hiding the player or calling Stop() did not reliably release the subscription, so CPU stayed pinned and the framerate counter never settled.
  • AnimatedVisualPlayer now tracks effective visibility (loaded + Visibility==Visible) and pauses/resumes the source on visibility transitions, matching native WinUI's AnimationPlay::OnHiding/OnUnhiding.
  • Removed UpdateSourceOnChanged from the read-only IsPlaying / IsAnimatedVisualLoaded / Duration DPs (WinUI doesn't wire callbacks on these). This eliminates the reentrant Source.Update→Invalidate() chain that fired during Stop().

Fixes #23189.

Test plan

  • Build Uno.UI.Lottie.Skia.csproj and Uno.UI.RuntimeTests.Skia.csproj cleanly.
  • Build SamplesApp.Skia.Generic and run the new Given_AnimatedVisualPlayer runtime tests on Skia Desktop — all 4 pass:
    • When_Stop_Removes_Rendering_Subscription
    • When_Hidden_Pauses_And_Removes_Rendering_Subscription
    • When_Unhidden_Resumes_Playback
    • When_Stopped_While_Hidden_Stays_Stopped_When_Unhidden
  • Existing Given_ProgressRing runtime tests continue to pass (ProgressRing uses the same player + Lottie source via its template).
  • Smoke-test a Lottie sample (e.g. LottieEmbeddedJson) and confirm the framerate counter stabilizes after collapsing the player or calling Stop().

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 4, 2026 10:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 IsPlaying callback.
  • 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.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

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

…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]>
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/renderingstucklottie branch from 221128e to ed3ad9a Compare May 5, 2026 13:36
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label May 5, 2026
@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings May 5, 2026 14:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@unodevops

Copy link
Copy Markdown
Contributor

MartinZikmund and others added 3 commits May 5, 2026 18:12
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]>
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label May 5, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 210924 found UI Test snapshots differences: skia-linux-screenshots: 0, skia-windows-screenshots: 216, wasm: 0

Details
  • skia-linux-screenshots: 0 changed over 2338

  • skia-windows-screenshots: 216 changed over 2340

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ElevatedView_Levels.png-dark
    • ElevatedView_Levels.png
    • ElevatedView_Tester.png-dark
    • ElevatedView_Tester.png
    • ElevatedView_Corners.png-dark
    • ElevatedView_Corners.png
    • ElevatedView_Dimensions.png-dark
    • ElevatedView_Dimensions.png
    • CameraCaptureUISample.png-dark
    • CameraCaptureUISample.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • Haptics.VibrationDevice.png-dark
    • Haptics.VibrationDevice.png
    • Contacts_Pick.png-dark
    • Contacts_Pick.png
  • wasm: 0 changed over 1073

Copilot AI review requested due to automatic review settings May 5, 2026 21:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 211015 found UI Test snapshots differences: skia-linux-screenshots: 0, skia-windows-screenshots: 742, wasm: 0

Details
  • skia-linux-screenshots: 0 changed over 2338

  • skia-windows-screenshots: 742 changed over 2340

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppXamlDefinedResources.png
    • AutoSuggestBox_Keyboard.png
    • BitmapIcon_Monochromatic.png
    • Border_AntiAlias.png
    • Border_BorderThickness.png-dark
    • Border_CornerRadius_Toggle.png-dark
    • Border_CornerRadius_Toggle.png
    • Capture.png-dark
    • Capture.png
    • ClippingWithOpacity.png-dark
    • ClippingWithOpacity.png
    • DeferLoadStrategyWithTemplateBinding.png-dark
    • DeferLoadStrategyWithTemplateBinding.png
    • Display.DisplayRequest.png-dark
    • Display.DisplayRequest.png
    • ElevatedView_CornerRadius.png-dark
    • ElevatedView_CornerRadius.png
    • ElevatedView_Corners.png-dark
    • ElevatedView_Corners.png
    • FlipView_Background.png-dark
  • wasm: 0 changed over 1073

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund
MartinZikmund enabled auto-merge May 6, 2026 12:51
@unodevops

Copy link
Copy Markdown
Contributor

- 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]>
Copilot AI review requested due to automatic review settings May 6, 2026 13:15
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/renderingstucklottie branch from 86f4177 to 3eabaaa Compare May 6, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 211177 found UI Test snapshots differences: skia-linux-screenshots: 0, skia-windows-screenshots: 87, wasm: 0

Details
  • skia-linux-screenshots: 0 changed over 2338

  • skia-windows-screenshots: 87 changed over 2342

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Buttons.png-dark
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Image_Stretch_Alignment_Bigger.png-dark
    • Image_Stretch_Alignment_Bigger.png
    • Examples.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Gamepad_Enumeration.png-dark
  • wasm: 0 changed over 1073

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund
MartinZikmund merged commit af78129 into master May 7, 2026
68 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/renderingstucklottie branch May 7, 2026 04:50
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.

AnimatedVisualPlayer keeps rendering loop active when hidden or stopped (Skia)

6 participants