Skip to content

Commit a09c1a1

Browse files
committed
chore: Porting AnimatedVisualPlayer
1 parent bbeb2b9 commit a09c1a1

File tree

5 files changed

+1243
-19
lines changed

5 files changed

+1243
-19
lines changed

src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Automation.Peers/AnimatedVisualPlayerAutomationPeer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#pragma warning disable 114 // new keyword hiding
44
namespace Microsoft.UI.Xaml.Automation.Peers
55
{
6-
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
6+
#if false
77
[global::Uno.NotImplemented]
88
#endif
99
public partial class AnimatedVisualPlayerAutomationPeer : global::Microsoft.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer
1010
{
11-
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
11+
#if false
1212
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
1313
public AnimatedVisualPlayerAutomationPeer(global::Microsoft.UI.Xaml.Controls.AnimatedVisualPlayer owner) : base(owner)
1414
{

src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.Properties.cs

+33-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public PlayerAnimationOptimization AnimationOptimization
2626
nameof(AnimationOptimization),
2727
typeof(PlayerAnimationOptimization),
2828
typeof(AnimatedVisualPlayer),
29-
new FrameworkPropertyMetadata(PlayerAnimationOptimization.Latency));
29+
new FrameworkPropertyMetadata(
30+
PlayerAnimationOptimization.Latency,
31+
(sender, args) => ((AnimatedVisualPlayer)sender).OnAnimationOptimizationPropertyChanged(args));
3032

3133
/// <summary>
3234
/// Gets or sets a value that indicates whether an animated visual plays immediately when it is loaded.
@@ -45,12 +47,18 @@ public bool AutoPlay
4547
nameof(AutoPlay),
4648
typeof(bool),
4749
typeof(AnimatedVisualPlayer),
48-
new FrameworkPropertyMetadata(true));
50+
new FrameworkPropertyMetadata(
51+
true,
52+
(sender, args) => ((AnimatedVisualPlayer)sender).OnAutoPlayPropertyChanged(args)));
4953

5054
/// <summary>
5155
/// Gets optional diagnostics information about the last attempt to load an animated visual.
5256
/// </summary>
53-
public object Diagnostics => GetValue(DiagnosticsProperty);
57+
public object Diagnostics
58+
{
59+
get => GetValue(DiagnosticsProperty);
60+
private set => SetValue(DiagnosticsProperty, value);
61+
}
5462

5563
/// <summary>
5664
/// Identifies the Diagnostics dependency property.
@@ -65,7 +73,11 @@ public bool AutoPlay
6573
/// <summary>
6674
/// Gets the duration of the the currently loaded animated visual, or TimeSpan.Zero if no animated visual is loaded.
6775
/// </summary>
68-
public TimeSpan Duration => (TimeSpan)GetValue(DurationProperty);
76+
public TimeSpan Duration
77+
{
78+
get => (TimeSpan)GetValue(DurationProperty);
79+
private set => SetValue(DurationProperty, value);
80+
}
6981

7082
/// <summary>
7183
/// Identifies the Duration dependency property.
@@ -94,12 +106,18 @@ public DataTemplate FallbackContent
94106
nameof(FallbackContent),
95107
typeof(DataTemplate),
96108
typeof(AnimatedVisualPlayer),
97-
new FrameworkPropertyMetadata(null));
109+
new FrameworkPropertyMetadata(
110+
null,
111+
(sender, args) => ((AnimatedVisualPlayer)sender).OnFallbackContentPropertyChanged(args)));
98112

99113
/// <summary>
100114
/// Gets a value that indicates whether an animated visual is loaded.
101115
/// </summary>
102-
public bool IsAnimatedVisualLoaded => (bool)GetValue(IsAnimatedVisualLoadedProperty);
116+
public bool IsAnimatedVisualLoaded
117+
{
118+
get => (bool)GetValue(IsAnimatedVisualLoadedProperty);
119+
private set => SetValue(IsAnimatedVisualLoadedProperty, value);
120+
}
103121

104122
/// <summary>
105123
/// Identifies the IsAnimatedVisualLoaded dependency property.
@@ -139,7 +157,9 @@ public double PlaybackRate
139157
nameof(PlaybackRate),
140158
typeof(double),
141159
typeof(AnimatedVisualPlayer),
142-
new FrameworkPropertyMetadata(1.0));
160+
new FrameworkPropertyMetadata(
161+
1.0,
162+
(sender, args) => ((AnimatedVisualPlayer)sender).OnPlaybackRatePropertyChanged(args)));
143163

144164
/// <summary>
145165
/// Gets or sets the provider of the animated visual for the player.
@@ -158,7 +178,9 @@ public IAnimatedVisualSource Source
158178
nameof(Source),
159179
typeof(IAnimatedVisualSource),
160180
typeof(AnimatedVisualPlayer),
161-
new FrameworkPropertyMetadata(null));
181+
new FrameworkPropertyMetadata(
182+
null,
183+
(sender, args) => ((AnimatedVisualPlayer)sender).OnSourcePropertyChanged(args)));
162184

163185
/// <summary>
164186
/// Gets or sets a value that describes how an animated visual should be stretched to fill the destination rectangle.
@@ -177,5 +199,7 @@ public Stretch Stretch
177199
nameof(Stretch),
178200
typeof(Stretch),
179201
typeof(AnimatedVisualPlayer),
180-
new FrameworkPropertyMetadata(Stretch.Uniform));
202+
new FrameworkPropertyMetadata(
203+
Stretch.Uniform,
204+
(sender, args) => ((AnimatedVisualPlayer)sender).OnStretchPropertyChanged(args)));
181205
}

src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ namespace Microsoft/* UWP don't rename */.UI.Xaml.Controls;
99
/// <summary>
1010
/// An element that displays and controls an IAnimatedVisual.
1111
/// </summary>
12-
public partial class AnimatedVisualPlayer
12+
public partial class AnimatedVisualPlayer : FrameworkElement
1313
{
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.Numerics;
53
using System.Threading.Tasks;
4+
using Microsoft.UI.Composition;
5+
using Uno.Disposables;
66

77
namespace Microsoft/* UWP don't rename */.UI.Xaml.Controls;
88

99
partial class AnimatedVisualPlayer
1010
{
11+
internal partial class AnimationPlay : TaskCompletionSource
12+
{
13+
private AnimatedVisualPlayer m_owner;
14+
private readonly float m_fromProgress;
15+
private readonly float m_toProgress;
16+
private readonly bool m_looped;
17+
private TimeSpan m_playDuration;
18+
19+
private AnimationController m_controller;
20+
private bool m_isPaused;
21+
private bool m_isPausedBecauseHidden;
22+
private long m_batchCompletedToken;
23+
CompositionScopedBatch m_batch;
24+
}
25+
26+
//
27+
// Initialized by the constructor.
28+
//
29+
// A Visual used for clipping and for parenting of m_animatedVisualRoot.
30+
private SpriteVisual m_rootVisual;
31+
// The property set that contains the Progress property that will be used to
32+
// set the progress of the animated visual.
33+
private CompositionPropertySet m_progressPropertySet;
34+
// Revokers for events that we are subscribed to.
35+
private SerialDisposable m_suspendingRevoker = new();
36+
private SerialDisposable m_resumingRevoker = new();
37+
private SerialDisposable m_xamlRootChangedRevoker = new();
38+
private SerialDisposable m_loadedRevoker = new();
39+
private SerialDisposable m_unloadedRevoker = new();
40+
41+
//
42+
// Player mutable state state.
43+
//
44+
private IAnimatedVisual m_animatedVisual;
45+
// The native size of the current animated visual. Only valid if m_animatedVisual is not nullptr.
46+
private Vector2 m_animatedVisualSize;
47+
private Visual m_animatedVisualRoot;
48+
private int m_playAsyncVersion;
49+
private double m_currentPlayFromProgress;
50+
// The play that will be stopped when Stop() is called.
51+
private AnimationPlay m_nowPlaying;
52+
private SerialDisposable m_dynamicAnimatedVisualInvalidatedRevoker;
53+
54+
// Set true if an animated visual has failed to load and set false the next time an animated
55+
// visual loads with non-null content. When this is true the fallback content (if any) will
56+
// be displayed.
57+
private bool m_isFallenBack;
58+
59+
// Set true when FrameworkElement::Unloaded is fired, then set false when FrameworkElement::Loaded is fired.
60+
// This is used to differentiate the first Loaded event (when the element has never been
61+
// unloaded) from later Loaded events.
62+
private bool m_isUnloaded;
63+
64+
private bool m_isAnimationsCreated;
65+
private uint m_createAnimationsCounter = 0;
66+
67+
private bool m_isHostVisible;
1168
}

0 commit comments

Comments
 (0)