|
|
|
@ -5,14 +5,13 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Linq; |
|
|
|
using Perspex.Media; |
|
|
|
using Perspex.Platform; |
|
|
|
|
|
|
|
namespace Perspex.Rendering |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Base class for standard renderers.
|
|
|
|
/// Extension methods for rendering.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// This class provides implements the platform-independent parts of <see cref="IRenderTarget"/>.
|
|
|
|
@ -21,11 +20,20 @@ namespace Perspex.Rendering |
|
|
|
[SuppressMessage("ReSharper", "ForCanBeConvertedToForeach")] |
|
|
|
public static class RendererMixin |
|
|
|
{ |
|
|
|
static int s_frameNum; |
|
|
|
static int s_fps; |
|
|
|
static int s_currentFrames; |
|
|
|
static TimeSpan s_lastMeasure; |
|
|
|
static readonly Stopwatch s_stopwatch = Stopwatch.StartNew(); |
|
|
|
private static int s_frameNum; |
|
|
|
private static int s_fps; |
|
|
|
private static int s_currentFrames; |
|
|
|
private static TimeSpan s_lastMeasure; |
|
|
|
private static readonly Stopwatch s_stopwatch = Stopwatch.StartNew(); |
|
|
|
private static readonly Stack<List<IVisual>> s_listPool = new Stack<List<IVisual>>(); |
|
|
|
private static readonly ZIndexComparer s_visualComparer = new ZIndexComparer(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value which determines whether an FPS counted will be drawn on each
|
|
|
|
/// rendered frame.
|
|
|
|
/// </summary>
|
|
|
|
public static bool DrawFpsCounter { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Renders the specified visual.
|
|
|
|
/// </summary>
|
|
|
|
@ -62,13 +70,10 @@ namespace Perspex.Rendering |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static bool DrawFpsCounter { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Renders the specified visual.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="visual">The visual to render.</param>
|
|
|
|
///
|
|
|
|
/// <param name="context">The drawing context.</param>
|
|
|
|
public static void Render(this DrawingContext context, IVisual visual) |
|
|
|
{ |
|
|
|
@ -103,29 +108,24 @@ namespace Perspex.Rendering |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static readonly Stack<List<IVisual>> ListPool = new Stack<List<IVisual>>(); |
|
|
|
static readonly ZIndexComparer VisualComparer = new ZIndexComparer(); |
|
|
|
class ZIndexComparer : IComparer<IVisual> |
|
|
|
{ |
|
|
|
public int Compare(IVisual x, IVisual y) => x.ZIndex.CompareTo(y.ZIndex); |
|
|
|
} |
|
|
|
|
|
|
|
static void ReturnListToPool(List<IVisual> lst) |
|
|
|
{ |
|
|
|
lst.Clear(); |
|
|
|
ListPool.Push(lst); |
|
|
|
s_listPool.Push(lst); |
|
|
|
} |
|
|
|
|
|
|
|
static List<IVisual> GetSortedVisualList(IReadOnlyList<IVisual> source) |
|
|
|
{ |
|
|
|
var lst = ListPool.Count == 0 ? new List<IVisual>() : ListPool.Pop(); |
|
|
|
var lst = s_listPool.Count == 0 ? new List<IVisual>() : s_listPool.Pop(); |
|
|
|
for (var c = 0; c < source.Count; c++) |
|
|
|
lst.Add(source[c]); |
|
|
|
lst.Sort(VisualComparer); |
|
|
|
lst.Sort(s_visualComparer); |
|
|
|
return lst; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ZIndexComparer : IComparer<IVisual> |
|
|
|
{ |
|
|
|
public int Compare(IVisual x, IVisual y) => x.ZIndex.CompareTo(y.ZIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |