Browse Source

PR Feedback

pull/1715/head
Jeremy Koritzinsky 8 years ago
parent
commit
5fce271ff8
  1. 4
      src/Avalonia.Animation/IAnimation.cs
  2. 2
      src/Avalonia.Animation/IAnimator.cs
  3. 10
      src/Avalonia.Animation/IGlobalClock.cs
  4. 2
      src/Avalonia.Controls/Application.cs
  5. 9
      src/Avalonia.Controls/Platform/InternalPlatformThreadingInterface.cs
  6. 1
      src/Avalonia.Controls/TopLevel.cs
  7. 6
      src/Avalonia.Visuals/Animation/RenderLoopClock.cs
  8. 12
      src/Avalonia.Visuals/Rendering/DefaultRenderTimer.cs
  9. 2
      src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
  10. 15
      src/Avalonia.Visuals/Rendering/IRenderLoopTask.cs
  11. 4
      src/Avalonia.Visuals/Rendering/IRenderTimer.cs
  12. 4
      src/Avalonia.Visuals/Rendering/RenderLoop.cs
  13. 14
      tests/Avalonia.Visuals.UnitTests/Rendering/RenderLoopTests.cs

4
src/Avalonia.Animation/IAnimation.cs

@ -9,12 +9,12 @@ namespace Avalonia.Animation
public interface IAnimation
{
/// <summary>
/// Apply the animation to the specified control
/// Apply the animation to the specified control and run it when <paramref name="match" /> produces <c>true</c>.
/// </summary>
IDisposable Apply(Animatable control, IClock clock, IObservable<bool> match, Action onComplete = null);
/// <summary>
/// Run the animation to the specified control
/// Run the animation on the specified control.
/// </summary>
Task RunAsync(Animatable control, IClock clock);
}

2
src/Avalonia.Animation/IAnimator.cs

@ -16,6 +16,6 @@ namespace Avalonia.Animation
/// <summary>
/// Applies the current KeyFrame group to the specified control.
/// </summary>
IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> obsMatch, Action onComplete);
IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> match, Action onComplete);
}
}

10
src/Avalonia.Animation/IGlobalClock.cs

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Avalonia.Animation
{
public interface IGlobalClock : IClock
{
}
}

2
src/Avalonia.Controls/Application.cs

@ -340,7 +340,7 @@ namespace Avalonia
var clock = new RenderLoopClock();
AvaloniaLocator.CurrentMutable
.Bind<IClock>().ToConstant(clock)
.Bind<IGlobalClock>().ToConstant(clock)
.GetService<IRenderLoop>()?.Add(clock);
}
}

9
src/Avalonia.Controls/Platform/InternalPlatformThreadingInterface.cs

@ -14,7 +14,10 @@ namespace Avalonia.Controls.Platform
public InternalPlatformThreadingInterface()
{
TlsCurrentThreadIsLoopThread = true;
StartTimer(DispatcherPriority.Render, new TimeSpan(0, 0, 0, 0, 66), () => Tick?.Invoke(Environment.TickCount));
StartTimer(
DispatcherPriority.Render,
new TimeSpan(0, 0, 0, 0, 66),
() => Tick?.Invoke(TimeSpan.FromMilliseconds(Environment.TickCount)));
}
private readonly AutoResetEvent _signaled = new AutoResetEvent(false);
@ -105,7 +108,7 @@ namespace Avalonia.Controls.Platform
public bool CurrentThreadIsLoopThread => TlsCurrentThreadIsLoopThread;
public event Action<DispatcherPriority?> Signaled;
public event Action<long> Tick;
public event Action<TimeSpan> Tick;
}
}
}

1
src/Avalonia.Controls/TopLevel.cs

@ -96,7 +96,6 @@ namespace Avalonia.Controls
_applicationLifecycle = TryGetService<IApplicationLifecycle>(dependencyResolver);
_renderInterface = TryGetService<IPlatformRenderInterface>(dependencyResolver);
var renderLoop = TryGetService<IRenderTimer>(dependencyResolver);
Renderer = impl.CreateRenderer(this);
impl.SetInputRoot(this);

6
src/Avalonia.Visuals/Animation/RenderLoopClock.cs

@ -5,7 +5,7 @@ using Avalonia.Rendering;
namespace Avalonia.Animation
{
public class RenderLoopClock : ClockBase, IRenderLoopTask
public class RenderLoopClock : ClockBase, IRenderLoopTask, IGlobalClock
{
protected override void Stop()
{
@ -18,9 +18,9 @@ namespace Avalonia.Animation
{
}
void IRenderLoopTask.Update(long tickCount)
void IRenderLoopTask.Update(TimeSpan time)
{
Pulse(TimeSpan.FromMilliseconds(tickCount));
Pulse(time);
}
}
}

12
src/Avalonia.Visuals/Rendering/DefaultRenderTimer.cs

@ -19,7 +19,7 @@ namespace Avalonia.Rendering
{
private IRuntimePlatform _runtime;
private int _subscriberCount;
private Action<long> _tick;
private Action<TimeSpan> _tick;
private IDisposable _subscription;
/// <summary>
@ -39,7 +39,7 @@ namespace Avalonia.Rendering
public int FramesPerSecond { get; }
/// <inheritdoc/>
public event Action<long> Tick
public event Action<TimeSpan> Tick
{
add
{
@ -78,14 +78,16 @@ namespace Avalonia.Rendering
/// This can be overridden by platform implementations to use a specialized timer
/// implementation.
/// </remarks>
protected virtual IDisposable StartCore(Action<long> tick)
protected virtual IDisposable StartCore(Action<TimeSpan> tick)
{
if (_runtime == null)
{
_runtime = AvaloniaLocator.Current.GetService<IRuntimePlatform>();
}
return _runtime.StartSystemTimer(TimeSpan.FromSeconds(1.0 / FramesPerSecond), () => tick(Environment.TickCount));
return _runtime.StartSystemTimer(
TimeSpan.FromSeconds(1.0 / FramesPerSecond),
() => tick(TimeSpan.FromMilliseconds(Environment.TickCount)));
}
/// <summary>
@ -97,7 +99,7 @@ namespace Avalonia.Rendering
_subscription = null;
}
private void InternalTick(long tickCount)
private void InternalTick(TimeSpan tickCount)
{
_tick(tickCount);
}

2
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs

@ -166,7 +166,7 @@ namespace Avalonia.Rendering
bool IRenderLoopTask.NeedsUpdate => _dirty == null || _dirty.Count > 0;
void IRenderLoopTask.Update(long tickCount) => UpdateScene();
void IRenderLoopTask.Update(TimeSpan time) => UpdateScene();
void IRenderLoopTask.Render()
{

15
src/Avalonia.Visuals/Rendering/IRenderLoopTask.cs

@ -6,20 +6,7 @@ namespace Avalonia.Rendering
public interface IRenderLoopTask
{
bool NeedsUpdate { get; }
void Update(long tickCount);
void Update(TimeSpan time);
void Render();
}
public class MockRenderLoopTask : IRenderLoopTask
{
public bool NeedsUpdate => true;
public void Render()
{
}
public void Update(long tickCount)
{
}
}
}

4
src/Avalonia.Visuals/Rendering/IRenderTimer.cs

@ -15,6 +15,6 @@ namespace Avalonia.Rendering
/// This event can be raised on any thread; it is the responsibility of the subscriber to
/// switch execution to the right thread.
/// </remarks>
event Action<long> Tick;
event Action<TimeSpan> Tick;
}
}
}

4
src/Avalonia.Visuals/Rendering/RenderLoop.cs

@ -84,7 +84,7 @@ namespace Avalonia.Rendering
}
}
private async void TimerTick(long tickCount)
private async void TimerTick(TimeSpan time)
{
if (Interlocked.CompareExchange(ref inTick, 1, 0) == 0)
{
@ -96,7 +96,7 @@ namespace Avalonia.Rendering
{
foreach (var i in _items)
{
i.Update(tickCount);
i.Update(time);
}
}, DispatcherPriority.Render).ConfigureAwait(false);
}

14
tests/Avalonia.Visuals.UnitTests/Rendering/RenderLoopTests.cs

@ -35,14 +35,14 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var renderTask = new Mock<IRenderLoopTask>();
renderTask.Setup(t => t.NeedsUpdate).Returns(true);
renderTask.Setup(t => t.Update(It.IsAny<long>()))
renderTask.Setup(t => t.Update(It.IsAny<TimeSpan>()))
.Callback((long _) => Assert.True(inDispatcher));
loop.Add(renderTask.Object);
timer.Raise(t => t.Tick += null, 0L);
renderTask.Verify(t => t.Update(It.IsAny<long>()), Times.Once());
renderTask.Verify(t => t.Update(It.IsAny<TimeSpan>()), Times.Once());
}
[Fact]
@ -62,7 +62,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
loop.Add(renderTask.Object);
timer.Raise(t => t.Tick += null, 0L);
renderTask.Verify(t => t.Update(It.IsAny<long>()), Times.Never());
renderTask.Verify(t => t.Update(It.IsAny<TimeSpan>()), Times.Never());
}
[Fact]
@ -92,7 +92,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
loop.Add(renderTask.Object);
timer.Raise(t => t.Tick += null, 0L);
renderTask.Verify(t => t.Update(It.IsAny<long>()), Times.Once());
renderTask.Verify(t => t.Update(It.IsAny<TimeSpan>()), Times.Once());
}
[Fact]
@ -110,10 +110,10 @@ namespace Avalonia.Visuals.UnitTests.Rendering
renderTask.Setup(t => t.NeedsUpdate).Returns(true);
loop.Add(renderTask.Object);
var tickCount = 12345L;
timer.Raise(t => t.Tick += null, tickCount);
var time = new TimeSpan(123456789L);
timer.Raise(t => t.Tick += null, time);
renderTask.Verify(t => t.Update(tickCount), Times.Once());
renderTask.Verify(t => t.Update(time), Times.Once());
}
}
}

Loading…
Cancel
Save