committed by
GitHub
50 changed files with 774 additions and 176 deletions
@ -0,0 +1,84 @@ |
|||||
|
#include "common.h" |
||||
|
|
||||
|
class PlatformRenderTimer : public ComSingleObject<IAvnPlatformRenderTimer, &IID_IAvnPlatformRenderTimer> |
||||
|
{ |
||||
|
private: |
||||
|
ComPtr<IAvnActionCallback> _callback; |
||||
|
CVDisplayLinkRef _displayLink; |
||||
|
|
||||
|
public: |
||||
|
FORWARD_IUNKNOWN() |
||||
|
virtual HRESULT RegisterTick ( |
||||
|
IAvnActionCallback* callback) override |
||||
|
{ |
||||
|
START_COM_CALL; |
||||
|
|
||||
|
@autoreleasepool |
||||
|
{ |
||||
|
if (_displayLink != nil) |
||||
|
{ |
||||
|
return E_UNEXPECTED; |
||||
|
} |
||||
|
|
||||
|
_callback = callback; |
||||
|
auto result = CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink); |
||||
|
if (result != 0) |
||||
|
{ |
||||
|
return E_FAIL; |
||||
|
} |
||||
|
|
||||
|
result = CVDisplayLinkSetOutputCallback(_displayLink, OnTick, this); |
||||
|
if (result != 0) |
||||
|
{ |
||||
|
return E_FAIL; |
||||
|
} |
||||
|
} |
||||
|
return S_OK; |
||||
|
} |
||||
|
|
||||
|
virtual void Start () override |
||||
|
{ |
||||
|
START_COM_CALL; |
||||
|
|
||||
|
@autoreleasepool |
||||
|
{ |
||||
|
if (CVDisplayLinkIsRunning(_displayLink) == false) { |
||||
|
CVDisplayLinkStart(_displayLink); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
virtual void Stop () override |
||||
|
{ |
||||
|
START_COM_CALL; |
||||
|
|
||||
|
@autoreleasepool |
||||
|
{ |
||||
|
if (CVDisplayLinkIsRunning(_displayLink) == true) { |
||||
|
CVDisplayLinkStop(_displayLink); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
virtual bool RunsInBackground () override |
||||
|
{ |
||||
|
START_COM_CALL; |
||||
|
|
||||
|
@autoreleasepool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
static CVReturn OnTick(CVDisplayLinkRef displayLink, const CVTimeStamp *inNow, const CVTimeStamp *inOutputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) |
||||
|
{ |
||||
|
PlatformRenderTimer *object = (PlatformRenderTimer *)displayLinkContext; |
||||
|
object->_callback->Run(); |
||||
|
return kCVReturnSuccess; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
extern IAvnPlatformRenderTimer* CreatePlatformRenderTimer() |
||||
|
{ |
||||
|
return new PlatformRenderTimer(); |
||||
|
} |
||||
@ -0,0 +1,100 @@ |
|||||
|
using System; |
||||
|
using System.Diagnostics.CodeAnalysis; |
||||
|
using Avalonia.Animation.Easings; |
||||
|
|
||||
|
namespace Avalonia.Animation |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Defines how a property should be animated using a transition.
|
||||
|
/// </summary>
|
||||
|
public abstract class TransitionBase : AvaloniaObject, ITransition |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Defines the <see cref="Duration"/> property.
|
||||
|
/// </summary>
|
||||
|
public static readonly DirectProperty<TransitionBase, TimeSpan> DurationProperty = |
||||
|
AvaloniaProperty.RegisterDirect<TransitionBase, TimeSpan>( |
||||
|
nameof(Duration), |
||||
|
o => o._duration, |
||||
|
(o, v) => o._duration = v); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Defines the <see cref="Delay"/> property.
|
||||
|
/// </summary>
|
||||
|
public static readonly DirectProperty<TransitionBase, TimeSpan> DelayProperty = |
||||
|
AvaloniaProperty.RegisterDirect<TransitionBase, TimeSpan>( |
||||
|
nameof(Delay), |
||||
|
o => o._delay, |
||||
|
(o, v) => o._delay = v); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Defines the <see cref="Easing"/> property.
|
||||
|
/// </summary>
|
||||
|
public static readonly DirectProperty<TransitionBase, Easing> EasingProperty = |
||||
|
AvaloniaProperty.RegisterDirect<TransitionBase, Easing>( |
||||
|
nameof(Easing), |
||||
|
o => o._easing, |
||||
|
(o, v) => o._easing = v); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Defines the <see cref="Property"/> property.
|
||||
|
/// </summary>
|
||||
|
public static readonly DirectProperty<TransitionBase, AvaloniaProperty?> PropertyProperty = |
||||
|
AvaloniaProperty.RegisterDirect<TransitionBase, AvaloniaProperty?>( |
||||
|
nameof(Property), |
||||
|
o => o._prop, |
||||
|
(o, v) => o._prop = v); |
||||
|
|
||||
|
private TimeSpan _duration; |
||||
|
private TimeSpan _delay = TimeSpan.Zero; |
||||
|
private Easing _easing = new LinearEasing(); |
||||
|
private AvaloniaProperty? _prop; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the duration of the transition.
|
||||
|
/// </summary>
|
||||
|
public TimeSpan Duration |
||||
|
{ |
||||
|
get { return _duration; } |
||||
|
set { SetAndRaise(DurationProperty, ref _duration, value); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets delay before starting the transition.
|
||||
|
/// </summary>
|
||||
|
public TimeSpan Delay |
||||
|
{ |
||||
|
get { return _delay; } |
||||
|
set { SetAndRaise(DelayProperty, ref _delay, value); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the easing class to be used.
|
||||
|
/// </summary>
|
||||
|
public Easing Easing |
||||
|
{ |
||||
|
get { return _easing; } |
||||
|
set { SetAndRaise(EasingProperty, ref _easing, value); } |
||||
|
} |
||||
|
|
||||
|
/// <inheritdocs/>
|
||||
|
[DisallowNull] |
||||
|
public AvaloniaProperty? Property |
||||
|
{ |
||||
|
get { return _prop; } |
||||
|
set { SetAndRaise(PropertyProperty, ref _prop, value); } |
||||
|
} |
||||
|
|
||||
|
AvaloniaProperty ITransition.Property |
||||
|
{ |
||||
|
get => Property ?? throw new InvalidOperationException("Transition has no property specified."); |
||||
|
set => Property = value; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdocs/>
|
||||
|
IDisposable ITransition.Apply(Animatable control, IClock clock, object? oldValue, object? newValue) |
||||
|
=> Apply(control, clock, oldValue, newValue); |
||||
|
|
||||
|
internal abstract IDisposable Apply(Animatable control, IClock clock, object? oldValue, object? newValue); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,58 @@ |
|||||
|
using System; |
||||
|
using System.Diagnostics; |
||||
|
using Avalonia.Native.Interop; |
||||
|
using Avalonia.Rendering; |
||||
|
#nullable enable |
||||
|
|
||||
|
namespace Avalonia.Native; |
||||
|
|
||||
|
internal sealed class AvaloniaNativeRenderTimer : NativeCallbackBase, IRenderTimer, IAvnActionCallback |
||||
|
{ |
||||
|
private readonly IAvnPlatformRenderTimer _platformRenderTimer; |
||||
|
private readonly Stopwatch _stopwatch; |
||||
|
private Action<TimeSpan>? _tick; |
||||
|
private int _subscriberCount; |
||||
|
private bool registered; |
||||
|
|
||||
|
public AvaloniaNativeRenderTimer(IAvnPlatformRenderTimer platformRenderTimer) |
||||
|
{ |
||||
|
_platformRenderTimer = platformRenderTimer; |
||||
|
_stopwatch = Stopwatch.StartNew(); |
||||
|
} |
||||
|
|
||||
|
public event Action<TimeSpan> Tick |
||||
|
{ |
||||
|
add |
||||
|
{ |
||||
|
_tick += value; |
||||
|
|
||||
|
if (!registered) |
||||
|
{ |
||||
|
registered = true; |
||||
|
_platformRenderTimer.RegisterTick(this); |
||||
|
} |
||||
|
|
||||
|
if (_subscriberCount++ == 0) |
||||
|
{ |
||||
|
_platformRenderTimer.Start(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
remove |
||||
|
{ |
||||
|
if (--_subscriberCount == 0) |
||||
|
{ |
||||
|
_platformRenderTimer.Stop(); |
||||
|
} |
||||
|
|
||||
|
_tick -= value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public bool RunsInBackground => _platformRenderTimer.RunsInBackground().FromComBool(); |
||||
|
|
||||
|
public void Run() |
||||
|
{ |
||||
|
_tick?.Invoke(_stopwatch.Elapsed); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue