Turn ImFontLocked into a class

As `ImFontLocked` utilizes a reference counter, changed it to a class so that at worst case we still got the destructor to decrease the reference count.
This commit is contained in:
Soreepeong 2024-01-23 23:39:25 +09:00
parent df89472d4c
commit 68dc16803c
5 changed files with 75 additions and 34 deletions

View file

@ -557,7 +557,9 @@ internal sealed partial class FontAtlasFactory
foreach (var fontHandle in substance.RelevantHandles)
{
substance.DataRoot.AddRef();
var locked = new IFontHandle.ImFontLocked(substance.GetFontPtr(fontHandle), substance.DataRoot);
var locked = IFontHandle.ImFontLocked.Rent(
substance.GetFontPtr(fontHandle),
substance.DataRoot);
fontsAndLocks.Add((fontHandle, garbage.Add(locked)));
}
}

View file

@ -182,7 +182,7 @@ internal abstract class FontHandle : IFontHandle
// Transfer the ownership of reference.
errorMessage = null;
return new(fontPtr, substance.DataRoot);
return IFontHandle.ImFontLocked.Rent(fontPtr, substance.DataRoot);
}
}

View file

@ -28,7 +28,7 @@ internal sealed class SimplePushedFont : IDisposable
/// </summary>
/// <param name="stack">The <see cref="IFontHandle"/>-private stack.</param>
/// <param name="fontPtr">The font pointer being pushed.</param>
/// <returns><c>this</c>.</returns>
/// <returns>The rented instance of <see cref="SimplePushedFont"/>.</returns>
public static SimplePushedFont Rent(List<IDisposable> stack, ImFontPtr fontPtr)
{
var rented = Pool.Get();