From b16fa5cb463408d4d5bed7637f6630ad485ebd12 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Wed, 28 Feb 2024 20:07:13 +0900 Subject: [PATCH] Inline as seen fit --- .../SharedImmediateTexture.cs | 4 +++ .../Internal/TextureLoadThrottler.cs | 6 +++++ Dalamud/Interface/Internal/TextureManager.cs | 27 ++++++++++--------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs b/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs index e75f8d038..88316b135 100644 --- a/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs +++ b/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -210,10 +211,12 @@ internal abstract class SharedImmediateTexture } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IDalamudTextureWrap GetWrap() => this.GetWrap(Service.Get().Empty4X4); /// [return: NotNullIfNotNull(nameof(defaultWrap))] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public IDalamudTextureWrap? GetWrap(IDalamudTextureWrap? defaultWrap) { if (!this.TryGetWrap(out var texture, out _)) @@ -222,6 +225,7 @@ internal abstract class SharedImmediateTexture } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetWrap([NotNullWhen(true)] out IDalamudTextureWrap? texture, out Exception? exception) { ThreadSafety.AssertMainThread(); diff --git a/Dalamud/Interface/Internal/TextureLoadThrottler.cs b/Dalamud/Interface/Internal/TextureLoadThrottler.cs index 2b5bbb797..894e5308e 100644 --- a/Dalamud/Interface/Internal/TextureLoadThrottler.cs +++ b/Dalamud/Interface/Internal/TextureLoadThrottler.cs @@ -21,6 +21,8 @@ internal class TextureLoadThrottler : IServiceType, IDisposable private readonly Channel workTokenChannel = Channel.CreateUnbounded(); private readonly List workItemPending = new(); + private bool disposing; + [ServiceManager.ServiceConstructor] private TextureLoadThrottler() { @@ -54,6 +56,10 @@ internal class TextureLoadThrottler : IServiceType, IDisposable /// public void Dispose() { + if (this.disposing) + return; + + this.disposing = true; this.newItemChannel.Writer.Complete(); this.workTokenChannel.Writer.Complete(); this.disposeCancellationTokenSource.Cancel(); diff --git a/Dalamud/Interface/Internal/TextureManager.cs b/Dalamud/Interface/Internal/TextureManager.cs index a906a214b..65b290076 100644 --- a/Dalamud/Interface/Internal/TextureManager.cs +++ b/Dalamud/Interface/Internal/TextureManager.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -14,7 +15,6 @@ using Dalamud.IoC; using Dalamud.IoC.Internal; using Dalamud.Logging.Internal; using Dalamud.Plugin.Services; -using Dalamud.Storage.Assets; using Dalamud.Utility; using Lumina.Data.Files; @@ -26,8 +26,6 @@ using SharpDX.DXGI; namespace Dalamud.Interface.Internal; -// TODO API10: Remove keepAlive from public APIs - /// /// Service responsible for loading and disposing ImGui texture wraps. /// @@ -45,14 +43,11 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid private const string IconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}.tex"; private const string HighResolutionIconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}_hr1.tex"; - private static readonly ModuleLog Log = new("TEXM"); + private static readonly ModuleLog Log = new(nameof(TextureManager)); [ServiceManager.ServiceDependency] private readonly Dalamud dalamud = Service.Get(); - [ServiceManager.ServiceDependency] - private readonly DalamudAssetManager dalamudAssetManager = Service.Get(); - [ServiceManager.ServiceDependency] private readonly DataManager dataManager = Service.Get(); @@ -73,10 +68,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid private bool disposing; [ServiceManager.ServiceConstructor] - private TextureManager() - { - this.framework.Update += this.FrameworkOnUpdate; - } + private TextureManager() => this.framework.Update += this.FrameworkOnUpdate; /// public event ITextureSubstitutionProvider.TextureDataInterceptorDelegate? InterceptTexDataLoad; @@ -118,7 +110,8 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid this.fileSystemTextures.Clear(); } -#region API9 compat + #region API9 compat + #pragma warning disable CS0618 // Type or member is obsolete /// [Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)] @@ -162,27 +155,34 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid IDalamudTextureWrap? ITextureProvider.GetTextureFromFile(FileInfo file, bool keepAlive) => this.GetFromFile(file.FullName).GetAvailableOnAccessWrapForApi9(); #pragma warning restore CS0618 // Type or member is obsolete -#endregion + + #endregion /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public SharedImmediateTexture GetFromGameIcon(in GameIconLookup lookup) => this.GetFromGame(this.lookupToPath.GetOrAdd(lookup, this.GetIconPathByValue)); /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public SharedImmediateTexture GetFromGame(string path) => this.gamePathTextures.GetOrAdd(path, GamePathSharedImmediateTexture.CreateImmediate); /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public SharedImmediateTexture GetFromFile(string path) => this.fileSystemTextures.GetOrAdd(path, FileSystemSharedImmediateTexture.CreateImmediate); /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] ISharedImmediateTexture ITextureProvider.GetFromGameIcon(in GameIconLookup lookup) => this.GetFromGameIcon(lookup); /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] ISharedImmediateTexture ITextureProvider.GetFromGame(string path) => this.GetFromGame(path); /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] ISharedImmediateTexture ITextureProvider.GetFromFile(string path) => this.GetFromFile(path); /// @@ -519,6 +519,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid v.ContentQueried && v.ReleaseSelfReference(false) == 0 && !v.HasRevivalPossibility; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private string GetIconPathByValue(GameIconLookup lookup) => this.TryGetIconPath(lookup, out var path) ? path : throw new FileNotFoundException(); }