mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Remove PostPromotion event
`PostPromotion` is removed, as `IFontHandle.ImFontChanged` now does the job. It also removes the possibility that resources may get disposed while post promotion callback is in progress. * `IFontHandle.ImFontChanged` is now called with a locked instance of the font. * `IFontHandle.ImFontLocked`: Added `NewRef` to increase reference count.
This commit is contained in:
parent
fb8beb9370
commit
871deca6e9
17 changed files with 138 additions and 269 deletions
|
|
@ -69,7 +69,7 @@ namespace Dalamud.CorePlugin
|
|||
this.Interface.UiBuilder.Draw += this.OnDraw;
|
||||
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
|
||||
this.Interface.UiBuilder.OpenMainUi += this.OnOpenMainUi;
|
||||
this.Interface.UiBuilder.DefaultFontHandle.ImFontChanged += fc =>
|
||||
this.Interface.UiBuilder.DefaultFontHandle.ImFontChanged += (fc, _) =>
|
||||
{
|
||||
Log.Information($"CorePlugin : DefaultFontHandle.ImFontChanged called {fc}");
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public sealed class GameFontHandle : IFontHandle
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event Action<IFontHandle> ImFontChanged
|
||||
public event IFontHandle.ImFontChangedDelegate ImFontChanged
|
||||
{
|
||||
add => this.fontHandle.ImFontChanged += value;
|
||||
remove => this.fontHandle.ImFontChanged -= value;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ internal class InterfaceManager : IDisposable, IServiceType
|
|||
private Hook<ResizeBuffersDelegate>? resizeBuffersHook;
|
||||
|
||||
private IFontAtlas? dalamudAtlas;
|
||||
private IFontHandle.ImFontLocked defaultFontResourceLock;
|
||||
|
||||
// can't access imgui IO before first present call
|
||||
private bool lastWantCapture = false;
|
||||
|
|
@ -717,8 +718,7 @@ internal class InterfaceManager : IDisposable, IServiceType
|
|||
tk => tk.AddDalamudAssetFont(
|
||||
DalamudAsset.InconsolataRegular,
|
||||
new() { SizePx = DefaultFontSizePx })));
|
||||
this.dalamudAtlas.BuildStepChange += e => e
|
||||
.OnPostBuild(
|
||||
this.dalamudAtlas.BuildStepChange += e => e.OnPostBuild(
|
||||
tk =>
|
||||
{
|
||||
// Fill missing glyphs in MonoFont from DefaultFont.
|
||||
|
|
@ -726,23 +726,27 @@ internal class InterfaceManager : IDisposable, IServiceType
|
|||
tk.GetFont(this.DefaultFontHandle),
|
||||
tk.GetFont(this.MonoFontHandle),
|
||||
missingOnly: true);
|
||||
})
|
||||
.OnPostPromotion(
|
||||
tk =>
|
||||
});
|
||||
this.DefaultFontHandle.ImFontChanged += (_, font) => Service<Framework>.Get().RunOnFrameworkThread(
|
||||
() =>
|
||||
{
|
||||
// Update the ImGui default font.
|
||||
unsafe
|
||||
{
|
||||
ImGui.GetIO().NativePtr->FontDefault = tk.GetFont(this.DefaultFontHandle);
|
||||
ImGui.GetIO().NativePtr->FontDefault = font;
|
||||
}
|
||||
|
||||
// Update the reference to the resources of the default font.
|
||||
this.defaultFontResourceLock.Dispose();
|
||||
this.defaultFontResourceLock = font.NewRef();
|
||||
|
||||
// Broadcast to auto-rebuilding instances.
|
||||
this.AfterBuildFonts?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
// This will wait for scene on its own. We just wait for this.dalamudAtlas.BuildTask in this.InitScene.
|
||||
_ = this.dalamudAtlas.BuildFontsAsync(false);
|
||||
_ = this.dalamudAtlas.BuildFontsAsync();
|
||||
|
||||
this.address.Setup(sigScanner);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,15 +27,4 @@ public enum FontAtlasBuildStep
|
|||
/// but it will never happen on its own.
|
||||
/// </summary>
|
||||
PostBuild = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Called after promoting staging font atlas to the actual atlas for <see cref="IFontAtlas"/>.<br />
|
||||
/// Expect <see cref="PostBuild"/> to be passed.<br />
|
||||
/// When called from <see cref="IFontAtlas.BuildStepChange"/>, this will be called <b>after</b> the delegates
|
||||
/// passed to <see cref="IFontAtlas.NewDelegateFontHandle"/>; you should not make modifications to fonts.<br />
|
||||
/// <br />
|
||||
/// This callback is not guaranteed to happen after <see cref="IFontAtlasBuildToolkitPostPromotion"/>,
|
||||
/// but it will never happen on its own.
|
||||
/// </summary>
|
||||
PostPromotion = 3,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@ namespace Dalamud.Interface.ManagedFontAtlas;
|
|||
/// <param name="toolkit">A toolkit that may help you for font building steps.</param>
|
||||
/// <remarks>
|
||||
/// An implementation of <see cref="IFontAtlasBuildToolkit"/> may implement all of
|
||||
/// <see cref="IFontAtlasBuildToolkitPreBuild"/>, <see cref="IFontAtlasBuildToolkitPostBuild"/>, and
|
||||
/// <see cref="IFontAtlasBuildToolkitPostPromotion"/>.<br />
|
||||
/// <see cref="IFontAtlasBuildToolkitPreBuild"/> and <see cref="IFontAtlasBuildToolkitPostBuild"/>.<br />
|
||||
/// Either use <see cref="IFontAtlasBuildToolkit.BuildStep"/> to identify the build step, or use
|
||||
/// <see cref="FontAtlasBuildToolkitUtilities.OnPreBuild"/>, <see cref="FontAtlasBuildToolkitUtilities.OnPostBuild"/>,
|
||||
/// and <see cref="FontAtlasBuildToolkitUtilities.OnPostPromotion"/> for routing.
|
||||
/// <see cref="FontAtlasBuildToolkitUtilities.OnPreBuild"/> and <see cref="FontAtlasBuildToolkitUtilities.OnPostBuild"/>
|
||||
/// for routing.
|
||||
/// </remarks>
|
||||
public delegate void FontAtlasBuildStepDelegate(IFontAtlasBuildToolkit toolkit);
|
||||
|
|
|
|||
|
|
@ -113,21 +113,4 @@ public static class FontAtlasBuildToolkitUtilities
|
|||
action.Invoke((IFontAtlasBuildToolkitPostBuild)toolkit);
|
||||
return toolkit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes <paramref name="action"/>
|
||||
/// if <see cref="IFontAtlasBuildToolkit.BuildStep"/> of <paramref name="toolkit"/>
|
||||
/// is <see cref="FontAtlasBuildStep.PostPromotion"/>.
|
||||
/// </summary>
|
||||
/// <param name="toolkit">The toolkit.</param>
|
||||
/// <param name="action">The action.</param>
|
||||
/// <returns>toolkit, for method chaining.</returns>
|
||||
public static IFontAtlasBuildToolkit OnPostPromotion(
|
||||
this IFontAtlasBuildToolkit toolkit,
|
||||
Action<IFontAtlasBuildToolkitPostPromotion> action)
|
||||
{
|
||||
if (toolkit.BuildStep is FontAtlasBuildStep.PostPromotion)
|
||||
action.Invoke((IFontAtlasBuildToolkitPostPromotion)toolkit);
|
||||
return toolkit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,8 +129,7 @@ public interface IFontAtlas : IDisposable
|
|||
void BuildFontsOnNextFrame();
|
||||
|
||||
/// <summary>
|
||||
/// Rebuilds fonts immediately, on the current thread.<br />
|
||||
/// Even the callback for <see cref="FontAtlasBuildStep.PostPromotion"/> will be called on the same thread.
|
||||
/// Rebuilds fonts immediately, on the current thread.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">If <see cref="AutoRebuildMode"/> is <see cref="FontAtlasAutoRebuildMode.Async"/>.</exception>
|
||||
void BuildFontsImmediately();
|
||||
|
|
@ -138,8 +137,7 @@ public interface IFontAtlas : IDisposable
|
|||
/// <summary>
|
||||
/// Rebuilds fonts asynchronously, on any thread.
|
||||
/// </summary>
|
||||
/// <param name="callPostPromotionOnMainThread">Call <see cref="FontAtlasBuildStep.PostPromotion"/> on the main thread.</param>
|
||||
/// <returns>The task.</returns>
|
||||
/// <exception cref="InvalidOperationException">If <see cref="AutoRebuildMode"/> is <see cref="FontAtlasAutoRebuildMode.OnNewFrame"/>.</exception>
|
||||
Task BuildFontsAsync(bool callPostPromotionOnMainThread = true);
|
||||
Task BuildFontsAsync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
namespace Dalamud.Interface.ManagedFontAtlas;
|
||||
|
||||
/// <summary>
|
||||
/// Toolkit for use when the build state is <see cref="FontAtlasBuildStep.PostPromotion"/>.
|
||||
/// </summary>
|
||||
public interface IFontAtlasBuildToolkitPostPromotion : IFontAtlasBuildToolkit
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
|
@ -12,14 +12,17 @@ namespace Dalamud.Interface.ManagedFontAtlas;
|
|||
public interface IFontHandle : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the built instance of <see cref="ImFontPtr"/> has been changed.<br />
|
||||
/// This event will be invoked on the same thread with
|
||||
/// <see cref="IFontAtlas"/>.<see cref="IFontAtlas.BuildStepChange"/>,
|
||||
/// when the build step is <see cref="FontAtlasBuildStep.PostPromotion"/>.<br />
|
||||
/// See <see cref="IFontAtlas.BuildFontsOnNextFrame"/>, <see cref="IFontAtlas.BuildFontsImmediately"/>, and
|
||||
/// <see cref="IFontAtlas.BuildFontsAsync"/>.
|
||||
/// Delegate for <see cref="IFontHandle.ImFontChanged"/>.
|
||||
/// </summary>
|
||||
event Action<IFontHandle> ImFontChanged;
|
||||
/// <param name="fontHandle">The relevant font handle.</param>
|
||||
/// <param name="lockedFont">The locked font for this font handle, locked during the call of this delegate.</param>
|
||||
public delegate void ImFontChangedDelegate(IFontHandle fontHandle, ImFontLocked lockedFont);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the built instance of <see cref="ImFontPtr"/> has been changed.<br />
|
||||
/// This event can be invoked outside the main thread.
|
||||
/// </summary>
|
||||
event ImFontChangedDelegate ImFontChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the load exception, if it failed to load. Otherwise, it is null.
|
||||
|
|
@ -102,6 +105,18 @@ public interface IFontHandle : IDisposable
|
|||
|
||||
public static unsafe implicit operator ImFont*(ImFontLocked l) => l.ImFont.NativePtr;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="ImFontLocked"/> with an additional reference to the owner.
|
||||
/// </summary>
|
||||
/// <returns>The new locked instance.</returns>
|
||||
public readonly ImFontLocked NewRef()
|
||||
{
|
||||
if (this.owner is null)
|
||||
throw new ObjectDisposedException(nameof(ImFontLocked));
|
||||
this.owner.AddRef();
|
||||
return new(this.ImFont, this.owner);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -80,16 +80,6 @@ internal sealed class DelegateFontHandle : FontHandle
|
|||
this.handles.Remove(cgfh);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void InvokeFontHandleImFontChanged()
|
||||
{
|
||||
if (this.Substance is not HandleSubstance hs)
|
||||
return;
|
||||
|
||||
foreach (var handle in hs.RelevantHandles)
|
||||
handle.InvokeImFontChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IFontHandleSubstance NewSubstance(IRefCountable dataRoot)
|
||||
{
|
||||
|
|
@ -133,6 +123,9 @@ internal sealed class DelegateFontHandle : FontHandle
|
|||
// Not owned by this class. Do not dispose.
|
||||
public DelegateFontHandle[] RelevantHandles { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
ICollection<FontHandle> IFontHandleSubstance.RelevantHandles => this.RelevantHandles;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IRefCountable DataRoot { get; }
|
||||
|
||||
|
|
@ -306,32 +299,5 @@ internal sealed class DelegateFontHandle : FontHandle
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnPostPromotion(IFontAtlasBuildToolkitPostPromotion toolkitPostPromotion)
|
||||
{
|
||||
foreach (var k in this.RelevantHandles)
|
||||
{
|
||||
if (!this.fonts[k].IsNotNullAndLoaded())
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
toolkitPostPromotion.Font = this.fonts[k];
|
||||
k.CallOnBuildStepChange.Invoke(toolkitPostPromotion);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.fonts[k] = default;
|
||||
this.buildExceptions[k] = e;
|
||||
|
||||
Log.Error(
|
||||
e,
|
||||
"[{name}:Substance] An error has occurred while during {delegate} PostPromotion call.",
|
||||
this.Manager.Name,
|
||||
nameof(FontAtlasBuildStepDelegate));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -677,60 +677,4 @@ internal sealed partial class FontAtlasFactory
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementations for <see cref="IFontAtlasBuildToolkitPostPromotion"/>.
|
||||
/// </summary>
|
||||
private class BuildToolkitPostPromotion : IFontAtlasBuildToolkitPostPromotion
|
||||
{
|
||||
private readonly FontAtlasBuiltData builtData;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BuildToolkitPostPromotion"/> class.
|
||||
/// </summary>
|
||||
/// <param name="builtData">The built data.</param>
|
||||
public BuildToolkitPostPromotion(FontAtlasBuiltData builtData) => this.builtData = builtData;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ImFontPtr Font { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float Scale => this.builtData.Scale;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsAsyncBuildOperation => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public FontAtlasBuildStep BuildStep => FontAtlasBuildStep.PostPromotion;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ImFontAtlasPtr NewImAtlas => this.builtData.Atlas;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public unsafe ImVectorWrapper<ImFontPtr> Fonts => new(
|
||||
&this.NewImAtlas.NativePtr->Fonts,
|
||||
x => ImGuiNative.ImFont_destroy(x->NativePtr));
|
||||
|
||||
/// <inheritdoc/>
|
||||
public T DisposeWithAtlas<T>(T disposable) where T : IDisposable => this.builtData.Garbage.Add(disposable);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public GCHandle DisposeWithAtlas(GCHandle gcHandle) => this.builtData.Garbage.Add(gcHandle);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void DisposeWithAtlas(Action action) => this.builtData.Garbage.Add(action);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ImFontPtr GetFont(IFontHandle fontHandle)
|
||||
{
|
||||
foreach (var s in this.builtData.Substances)
|
||||
{
|
||||
var f = s.GetFontPtr(fontHandle);
|
||||
if (!f.IsNull())
|
||||
return f;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -486,7 +486,7 @@ internal sealed partial class FontAtlasFactory
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task BuildFontsAsync(bool callPostPromotionOnMainThread = true)
|
||||
public Task BuildFontsAsync()
|
||||
{
|
||||
#if VeryVerboseLog
|
||||
Log.Verbose("[{name}] Called: {source}.", this.Name, nameof(this.BuildFontsAsync));
|
||||
|
|
@ -519,15 +519,7 @@ internal sealed partial class FontAtlasFactory
|
|||
if (res.Atlas.IsNull())
|
||||
return res;
|
||||
|
||||
if (callPostPromotionOnMainThread)
|
||||
{
|
||||
await this.factory.Framework.RunOnFrameworkThread(
|
||||
() => this.InvokePostPromotion(rebuildIndex, res, nameof(this.BuildFontsAsync)));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.InvokePostPromotion(rebuildIndex, res, nameof(this.BuildFontsAsync));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -536,6 +528,10 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
private void InvokePostPromotion(int rebuildIndex, FontAtlasBuiltData data, [UsedImplicitly] string source)
|
||||
{
|
||||
// Capture the locks inside the lock block, so that the fonts are guaranteed to be the ones just built.
|
||||
var fontsAndLocks = new List<(FontHandle FontHandle, IFontHandle.ImFontLocked Lock)>();
|
||||
using var garbage = new DisposeSafety.ScopedFinalizer();
|
||||
|
||||
lock (this.syncRoot)
|
||||
{
|
||||
if (this.buildIndex != rebuildIndex)
|
||||
|
|
@ -549,57 +545,26 @@ internal sealed partial class FontAtlasFactory
|
|||
prevBuiltData.ExplicitDisposeIgnoreExceptions();
|
||||
|
||||
this.buildTask = EmptyTask;
|
||||
fontsAndLocks.EnsureCapacity(data.Substances.Sum(x => x.RelevantHandles.Count));
|
||||
foreach (var substance in data.Substances)
|
||||
{
|
||||
substance.Manager.Substance = substance;
|
||||
foreach (var fontHandle in substance.RelevantHandles)
|
||||
{
|
||||
substance.DataRoot.AddRef();
|
||||
var locked = new IFontHandle.ImFontLocked(substance.GetFontPtr(fontHandle), substance.DataRoot);
|
||||
fontsAndLocks.Add((fontHandle, garbage.Add(locked)));
|
||||
}
|
||||
|
||||
lock (this.syncRootPostPromotion)
|
||||
{
|
||||
if (this.buildIndex != rebuildIndex)
|
||||
{
|
||||
data.ExplicitDisposeIgnoreExceptions();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var substance in data.Substances)
|
||||
substance.Manager.InvokeFontHandleImFontChanged();
|
||||
|
||||
var toolkit = new BuildToolkitPostPromotion(data);
|
||||
|
||||
foreach (var substance in data.Substances)
|
||||
{
|
||||
try
|
||||
{
|
||||
substance.OnPostPromotion(toolkit);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(
|
||||
e,
|
||||
"[{name}] {substance} PostPromotion error",
|
||||
this.Name,
|
||||
substance.GetType().FullName ?? substance.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.BuildStepChange?.Invoke(toolkit);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(
|
||||
e,
|
||||
"[{name}] {delegateName} PostPromotion error",
|
||||
this.Name,
|
||||
nameof(FontAtlasBuildStepDelegate));
|
||||
}
|
||||
foreach (var (fontHandle, lockedFont) in fontsAndLocks)
|
||||
fontHandle.InvokeImFontChanged(lockedFont);
|
||||
|
||||
#if VeryVerboseLog
|
||||
Log.Verbose("[{name}] Built from {source}.", this.Name, source);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private void ImGuiSceneOnNewRenderFrame()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ internal abstract class FontHandle : IFontHandle
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event Action<IFontHandle>? ImFontChanged;
|
||||
public event IFontHandle.ImFontChangedDelegate? ImFontChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event to be called on the first <see cref="IDisposable.Dispose"/> call.
|
||||
/// </summary>
|
||||
protected event Action<IFontHandle>? Disposed;
|
||||
protected event Action? Disposed;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Exception? LoadException => this.Manager.Substance?.GetBuildException(this);
|
||||
|
|
@ -70,6 +70,22 @@ internal abstract class FontHandle : IFontHandle
|
|||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes <see cref="IFontHandle.ImFontChanged"/>.
|
||||
/// </summary>
|
||||
/// <param name="font">The font, locked during the call of <see cref="ImFontChanged"/>.</param>
|
||||
public void InvokeImFontChanged(IFontHandle.ImFontLocked font)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.ImFontChanged?.Invoke(this, font);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, $"{nameof(this.InvokeImFontChanged)}: error");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtains an instance of <see cref="ImFontPtr"/> corresponding to this font handle,
|
||||
/// to be released after rendering the current frame.
|
||||
|
|
@ -220,35 +236,51 @@ internal abstract class FontHandle : IFontHandle
|
|||
|
||||
var tcs = new TaskCompletionSource<IFontHandle>();
|
||||
this.ImFontChanged += OnImFontChanged;
|
||||
this.Disposed += OnImFontChanged;
|
||||
this.Disposed += OnDisposed;
|
||||
if (this.Available)
|
||||
OnImFontChanged(this);
|
||||
OnImFontChanged(this, default);
|
||||
return tcs.Task;
|
||||
|
||||
void OnImFontChanged(IFontHandle unused)
|
||||
void OnImFontChanged(IFontHandle unused, IFontHandle.ImFontLocked unused2)
|
||||
{
|
||||
if (tcs.Task.IsCompletedSuccessfully)
|
||||
return;
|
||||
|
||||
this.ImFontChanged -= OnImFontChanged;
|
||||
this.Disposed -= OnImFontChanged;
|
||||
if (this.manager is null)
|
||||
tcs.SetException(new ObjectDisposedException(nameof(GamePrebakedFontHandle)));
|
||||
else
|
||||
this.Disposed -= OnDisposed;
|
||||
try
|
||||
{
|
||||
tcs.SetResult(this);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisposed()
|
||||
{
|
||||
if (tcs.Task.IsCompletedSuccessfully)
|
||||
return;
|
||||
|
||||
this.ImFontChanged -= OnImFontChanged;
|
||||
this.Disposed -= OnDisposed;
|
||||
try
|
||||
{
|
||||
tcs.SetException(new ObjectDisposedException(nameof(GamePrebakedFontHandle)));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes <see cref="IFontHandle.ImFontChanged"/>.
|
||||
/// </summary>
|
||||
protected void InvokeImFontChanged() => this.ImFontChanged.InvokeSafely(this);
|
||||
|
||||
/// <summary>
|
||||
/// Overrideable implementation for <see cref="IDisposable.Dispose"/>.
|
||||
/// Implementation for <see cref="IDisposable.Dispose"/>.
|
||||
/// </summary>
|
||||
/// <param name="disposing">If <c>true</c>, then the function is being called from <see cref="IDisposable.Dispose"/>.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
|
|
@ -256,7 +288,7 @@ internal abstract class FontHandle : IFontHandle
|
|||
Log.Warning($"{nameof(IFontHandle)}.{nameof(IDisposable.Dispose)}: fonts were still in a stack.");
|
||||
this.Manager.FreeFontHandle(this);
|
||||
this.manager = null;
|
||||
this.Disposed?.InvokeSafely(this);
|
||||
this.Disposed?.InvokeSafely();
|
||||
this.ImFontChanged = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,16 +172,6 @@ internal class GamePrebakedFontHandle : FontHandle
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void InvokeFontHandleImFontChanged()
|
||||
{
|
||||
if (this.Substance is not HandleSubstance hs)
|
||||
return;
|
||||
|
||||
foreach (var handle in hs.RelevantHandles)
|
||||
handle.InvokeImFontChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IFontHandleSubstance NewSubstance(IRefCountable dataRoot)
|
||||
{
|
||||
|
|
@ -232,6 +222,9 @@ internal class GamePrebakedFontHandle : FontHandle
|
|||
// Not owned by this class. Do not dispose.
|
||||
public GamePrebakedFontHandle[] RelevantHandles { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
ICollection<FontHandle> IFontHandleSubstance.RelevantHandles => this.RelevantHandles;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IRefCountable DataRoot { get; }
|
||||
|
||||
|
|
@ -413,12 +406,6 @@ internal class GamePrebakedFontHandle : FontHandle
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void OnPostPromotion(IFontAtlasBuildToolkitPostPromotion toolkitPostPromotion)
|
||||
{
|
||||
// Irrelevant
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new template font.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -32,9 +32,4 @@ internal interface IFontHandleManager : IDisposable
|
|||
/// <param name="dataRoot">The data root.</param>
|
||||
/// <returns>The new substance.</returns>
|
||||
IFontHandleSubstance NewSubstance(IRefCountable dataRoot);
|
||||
|
||||
/// <summary>
|
||||
/// Invokes <see cref="IFontHandle.ImFontChanged"/>.
|
||||
/// </summary>
|
||||
void InvokeFontHandleImFontChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using Dalamud.Utility;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Dalamud.Utility;
|
||||
|
||||
using ImGuiNET;
|
||||
|
||||
|
|
@ -32,6 +34,11 @@ internal interface IFontHandleSubstance : IDisposable
|
|||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
bool CreateFontOnAccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the relevant handles.
|
||||
/// </summary>
|
||||
public ICollection<FontHandle> RelevantHandles { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the font.
|
||||
/// </summary>
|
||||
|
|
@ -64,11 +71,4 @@ internal interface IFontHandleSubstance : IDisposable
|
|||
/// </summary>
|
||||
/// <param name="toolkitPostBuild">The toolkit.</param>
|
||||
void OnPostBuild(IFontAtlasBuildToolkitPostBuild toolkitPostBuild);
|
||||
|
||||
/// <summary>
|
||||
/// Called on the specific thread depending on <see cref="IFontAtlasBuildToolkit.IsAsyncBuildOperation"/> after
|
||||
/// promoting the staging atlas to direct use with <see cref="IFontAtlas"/>.
|
||||
/// </summary>
|
||||
/// <param name="toolkitPostPromotion">The toolkit.</param>
|
||||
void OnPostPromotion(IFontAtlasBuildToolkitPostPromotion toolkitPostPromotion);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -744,7 +744,7 @@ public sealed class UiBuilder : IDisposable
|
|||
this.wrapped.ImFontChanged += this.WrappedOnImFontChanged;
|
||||
}
|
||||
|
||||
public event Action<IFontHandle>? ImFontChanged;
|
||||
public event IFontHandle.ImFontChangedDelegate? ImFontChanged;
|
||||
|
||||
public Exception? LoadException =>
|
||||
this.wrapped!.LoadException ?? new ObjectDisposedException(nameof(FontHandleWrapper));
|
||||
|
|
@ -775,6 +775,7 @@ public sealed class UiBuilder : IDisposable
|
|||
|
||||
public override string ToString() => $"{nameof(FontHandleWrapper)}({this.wrapped})";
|
||||
|
||||
private void WrappedOnImFontChanged(IFontHandle obj) => this.ImFontChanged.InvokeSafely(this);
|
||||
private void WrappedOnImFontChanged(IFontHandle obj, IFontHandle.ImFontLocked lockedFont) =>
|
||||
this.ImFontChanged?.Invoke(obj, lockedFont);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue