diff --git a/src/Avalonia.Base/Media/MediaContext.Compositor.cs b/src/Avalonia.Base/Media/MediaContext.Compositor.cs
index d9d3c915d4..6234f36a12 100644
--- a/src/Avalonia.Base/Media/MediaContext.Compositor.cs
+++ b/src/Avalonia.Base/Media/MediaContext.Compositor.cs
@@ -40,10 +40,10 @@ partial class MediaContext
_animationsAreWaitingForComposition = false;
// Check if we have uncommited changes
- if (_scheduleCommitOnLastCompositionBatchCompletion && _pendingCompositionBatches.Count > 0)
+ if (_scheduleCommitOnLastCompositionBatchCompletion)
{
- CommitCompositorsWithThrottling();
_scheduleCommitOnLastCompositionBatchCompletion = false;
+ CommitCompositorsWithThrottling();
}
// Check if there are active animations and schedule the next render
else if(_clock.HasSubscriptions)
@@ -52,16 +52,23 @@ partial class MediaContext
}
+ ///
+ /// Triggers a composition commit if any batches are waiting to be sent,
+ /// handles throttling
+ ///
+ /// true if there are pending commits in-flight and there will be a "all-done" callback later
private bool CommitCompositorsWithThrottling()
{
// Check if we are still waiting for previous composition batches
if (_pendingCompositionBatches.Count > 0)
{
_scheduleCommitOnLastCompositionBatchCompletion = true;
+ // Previous commit isn't handled yet
return true;
}
-
+
if (_requestedCommits.Count == 0)
+ // Nothing to do, and there are no pending commits
return false;
foreach (var c in _requestedCommits)
diff --git a/src/Avalonia.Base/Media/MediaContext.cs b/src/Avalonia.Base/Media/MediaContext.cs
index 023b2f728c..c261dd80b8 100644
--- a/src/Avalonia.Base/Media/MediaContext.cs
+++ b/src/Avalonia.Base/Media/MediaContext.cs
@@ -28,6 +28,14 @@ internal partial class MediaContext : ICompositorScheduler
private List? _invokeOnRenderCallbacks;
private readonly Stack> _invokeOnRenderCallbackListPool = new();
+ private DispatcherTimer _animationsTimer = new(DispatcherPriority.Render)
+ {
+ // Since this timer is used to drive animations that didn't contribute to the previous frame at all
+ // We can safely use 16ms interval until we fix our animation system to actually report the next expected
+ // frame
+ Interval = TimeSpan.FromMilliseconds(16)
+ };
+
private Dictionary