Browse Source

Added documentation.

pull/9441/head
DJGosnell 4 years ago
parent
commit
713d2cab35
  1. 30
      src/Skia/Avalonia.Skia/SKPaintCache.cs

30
src/Skia/Avalonia.Skia/SKPaintCache.cs

@ -1,13 +1,11 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using SkiaSharp;
namespace Avalonia.Skia
{
/// <summary>
/// Cache for SKPaints.
/// </summary>
internal static class SKPaintCache
{
private static ConcurrentBag<SKPaint> s_cachedPaints;
@ -17,6 +15,14 @@ namespace Avalonia.Skia
s_cachedPaints = new ConcurrentBag<SKPaint>();
}
/// <summary>
/// Gets a SKPaint for usage.
/// </summary>
/// <remarks>
/// If a SKPaint is in the cache, that existing SKPaint will be returned.
/// Otherwise a new SKPaint will be created.
/// </remarks>
/// <returns></returns>
public static SKPaint Get()
{
if (!s_cachedPaints.TryTake(out var paint))
@ -27,12 +33,24 @@ namespace Avalonia.Skia
return paint;
}
/// <summary>
/// Returns a SKPaint for reuse later.
/// </summary>
/// <remarks>
/// Do not use the paint further.
/// Do not return the same paint multiple times as that will break the cache.
/// Uses SKPaint.Reset() for reuse later.
/// </remarks>
/// <param name="paint"></param>
public static void Return(SKPaint paint)
{
paint.Reset();
s_cachedPaints.Add(paint);
}
/// <summary>
/// Clears and disposes all cached paints.
/// </summary>
public static void Clear()
{
while (s_cachedPaints.TryTake(out var paint))

Loading…
Cancel
Save