Skip to content

Commit

Permalink
chore: Porting AnimatedVisualPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jan 23, 2025
1 parent bbeb2b9 commit a09c1a1
Show file tree
Hide file tree
Showing 5 changed files with 1,243 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Microsoft.UI.Xaml.Automation.Peers
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class AnimatedVisualPlayerAutomationPeer : global::Microsoft.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer
{
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public AnimatedVisualPlayerAutomationPeer(global::Microsoft.UI.Xaml.Controls.AnimatedVisualPlayer owner) : base(owner)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public PlayerAnimationOptimization AnimationOptimization
nameof(AnimationOptimization),
typeof(PlayerAnimationOptimization),
typeof(AnimatedVisualPlayer),
new FrameworkPropertyMetadata(PlayerAnimationOptimization.Latency));
new FrameworkPropertyMetadata(
PlayerAnimationOptimization.Latency,
(sender, args) => ((AnimatedVisualPlayer)sender).OnAnimationOptimizationPropertyChanged(args));

/// <summary>
/// Gets or sets a value that indicates whether an animated visual plays immediately when it is loaded.
Expand All @@ -45,12 +47,18 @@ public bool AutoPlay
nameof(AutoPlay),
typeof(bool),
typeof(AnimatedVisualPlayer),
new FrameworkPropertyMetadata(true));
new FrameworkPropertyMetadata(
true,
(sender, args) => ((AnimatedVisualPlayer)sender).OnAutoPlayPropertyChanged(args)));

/// <summary>
/// Gets optional diagnostics information about the last attempt to load an animated visual.
/// </summary>
public object Diagnostics => GetValue(DiagnosticsProperty);
public object Diagnostics
{
get => GetValue(DiagnosticsProperty);
private set => SetValue(DiagnosticsProperty, value);
}

/// <summary>
/// Identifies the Diagnostics dependency property.
Expand All @@ -65,7 +73,11 @@ public bool AutoPlay
/// <summary>
/// Gets the duration of the the currently loaded animated visual, or TimeSpan.Zero if no animated visual is loaded.
/// </summary>
public TimeSpan Duration => (TimeSpan)GetValue(DurationProperty);
public TimeSpan Duration
{
get => (TimeSpan)GetValue(DurationProperty);
private set => SetValue(DurationProperty, value);
}

/// <summary>
/// Identifies the Duration dependency property.
Expand Down Expand Up @@ -94,12 +106,18 @@ public DataTemplate FallbackContent
nameof(FallbackContent),
typeof(DataTemplate),
typeof(AnimatedVisualPlayer),
new FrameworkPropertyMetadata(null));
new FrameworkPropertyMetadata(
null,
(sender, args) => ((AnimatedVisualPlayer)sender).OnFallbackContentPropertyChanged(args)));

/// <summary>
/// Gets a value that indicates whether an animated visual is loaded.
/// </summary>
public bool IsAnimatedVisualLoaded => (bool)GetValue(IsAnimatedVisualLoadedProperty);
public bool IsAnimatedVisualLoaded
{
get => (bool)GetValue(IsAnimatedVisualLoadedProperty);
private set => SetValue(IsAnimatedVisualLoadedProperty, value);
}

/// <summary>
/// Identifies the IsAnimatedVisualLoaded dependency property.
Expand Down Expand Up @@ -139,7 +157,9 @@ public double PlaybackRate
nameof(PlaybackRate),
typeof(double),
typeof(AnimatedVisualPlayer),
new FrameworkPropertyMetadata(1.0));
new FrameworkPropertyMetadata(
1.0,
(sender, args) => ((AnimatedVisualPlayer)sender).OnPlaybackRatePropertyChanged(args)));

/// <summary>
/// Gets or sets the provider of the animated visual for the player.
Expand All @@ -158,7 +178,9 @@ public IAnimatedVisualSource Source
nameof(Source),
typeof(IAnimatedVisualSource),
typeof(AnimatedVisualPlayer),
new FrameworkPropertyMetadata(null));
new FrameworkPropertyMetadata(
null,
(sender, args) => ((AnimatedVisualPlayer)sender).OnSourcePropertyChanged(args)));

/// <summary>
/// Gets or sets a value that describes how an animated visual should be stretched to fill the destination rectangle.
Expand All @@ -177,5 +199,7 @@ public Stretch Stretch
nameof(Stretch),
typeof(Stretch),
typeof(AnimatedVisualPlayer),
new FrameworkPropertyMetadata(Stretch.Uniform));
new FrameworkPropertyMetadata(
Stretch.Uniform,
(sender, args) => ((AnimatedVisualPlayer)sender).OnStretchPropertyChanged(args)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace Microsoft/* UWP don't rename */.UI.Xaml.Controls;
/// <summary>
/// An element that displays and controls an IAnimatedVisual.
/// </summary>
public partial class AnimatedVisualPlayer
public partial class AnimatedVisualPlayer : FrameworkElement
{
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using Microsoft.UI.Composition;
using Uno.Disposables;

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

partial class AnimatedVisualPlayer
{
internal partial class AnimationPlay : TaskCompletionSource
{
private AnimatedVisualPlayer m_owner;
private readonly float m_fromProgress;
private readonly float m_toProgress;
private readonly bool m_looped;
private TimeSpan m_playDuration;

private AnimationController m_controller;
private bool m_isPaused;
private bool m_isPausedBecauseHidden;
private long m_batchCompletedToken;
CompositionScopedBatch m_batch;
}

//
// Initialized by the constructor.
//
// A Visual used for clipping and for parenting of m_animatedVisualRoot.
private SpriteVisual m_rootVisual;
// The property set that contains the Progress property that will be used to
// set the progress of the animated visual.
private CompositionPropertySet m_progressPropertySet;
// Revokers for events that we are subscribed to.
private SerialDisposable m_suspendingRevoker = new();

Check warning on line 35 in src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.h.mux.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.h.mux.cs#L35

Make 'm_suspendingRevoker' 'readonly'.
private SerialDisposable m_resumingRevoker = new();
private SerialDisposable m_xamlRootChangedRevoker = new();

Check warning on line 37 in src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.h.mux.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.h.mux.cs#L37

Make 'm_xamlRootChangedRevoker' 'readonly'.
private SerialDisposable m_loadedRevoker = new();
private SerialDisposable m_unloadedRevoker = new();

Check warning on line 39 in src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.h.mux.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/Microsoft/UI/Xaml/Controls/AnimatedVisualPlayer/AnimatedVisualPlayer.h.mux.cs#L39

Make 'm_unloadedRevoker' 'readonly'.

//
// Player mutable state state.
//
private IAnimatedVisual m_animatedVisual;
// The native size of the current animated visual. Only valid if m_animatedVisual is not nullptr.
private Vector2 m_animatedVisualSize;
private Visual m_animatedVisualRoot;
private int m_playAsyncVersion;
private double m_currentPlayFromProgress;
// The play that will be stopped when Stop() is called.
private AnimationPlay m_nowPlaying;
private SerialDisposable m_dynamicAnimatedVisualInvalidatedRevoker;

// Set true if an animated visual has failed to load and set false the next time an animated
// visual loads with non-null content. When this is true the fallback content (if any) will
// be displayed.
private bool m_isFallenBack;

// Set true when FrameworkElement::Unloaded is fired, then set false when FrameworkElement::Loaded is fired.
// This is used to differentiate the first Loaded event (when the element has never been
// unloaded) from later Loaded events.
private bool m_isUnloaded;

private bool m_isAnimationsCreated;
private uint m_createAnimationsCounter = 0;

private bool m_isHostVisible;
}
Loading

0 comments on commit a09c1a1

Please sign in to comment.