using System.Collections.Generic;
namespace Spectre.Console.Rendering
{
///
/// Represents the render pipeline.
///
public sealed class RenderPipeline
{
private readonly List _hooks;
private readonly object _lock;
///
/// Initializes a new instance of the class.
///
public RenderPipeline()
{
_hooks = new List();
_lock = new object();
}
///
/// Attaches a new render hook onto the pipeline.
///
/// The render hook to attach.
public void Attach(IRenderHook hook)
{
lock (_lock)
{
_hooks.Add(hook);
}
}
///
/// Detaches a render hook from the pipeline.
///
/// The render hook to detach.
public void Detach(IRenderHook hook)
{
lock (_lock)
{
_hooks.Remove(hook);
}
}
///
/// Processes the specified renderables.
///
/// The render context.
/// The renderables to process.
/// The processed renderables.
public IEnumerable Process(RenderContext context, IEnumerable renderables)
{
lock (_lock)
{
var current = renderables;
for (var index = _hooks.Count - 1; index >= 0; index--)
{
current = _hooks[index].Process(context, current);
}
return current;
}
}
}
}