using Blacklight.Core;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Glass.Blacklight
{
///
/// Holds the texture made for each font page, so fonts that name the same page share one.
///
public sealed class PageTextureCache
{
private readonly Dictionary<(Assembly Assembly, string Resource), Texture> textures =
new Dictionary<(Assembly Assembly, string Resource), Texture>();
///
/// Gets how many different pages have a texture.
///
public int Count => textures.Count;
///
/// Returns the texture for the page of , making it with
/// the first time it's asked for.
///
public Texture GetOrCreate(Assembly assembly, string resource, Func create)
{
if (assembly == null)
{
throw new ArgumentNullException(nameof(assembly));
}
if (resource == null)
{
throw new ArgumentNullException(nameof(resource));
}
if (create == null)
{
throw new ArgumentNullException(nameof(create));
}
if (!textures.TryGetValue((assembly, resource), out Texture returnMe))
{
returnMe = create();
textures.Add((assembly, resource), returnMe);
}
return returnMe;
}
}
}