Cleanup and reformat

This commit is contained in:
Soreepeong 2024-03-03 20:50:58 +09:00
parent 858d27ab8e
commit fa5e708a43
11 changed files with 32 additions and 75 deletions

View file

@ -5,68 +5,42 @@ using ImGuiScene;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace Dalamud.Interface.Internal; namespace Dalamud.Interface.Internal;
/// <summary> /// <summary>Safety harness for ImGuiScene textures that will defer destruction until the end of the frame.</summary>
/// Safety harness for ImGuiScene textures that will defer destruction until [Obsolete($"Use {nameof(IDalamudTextureWrap)}.")]
/// the end of the frame. [Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
/// </summary>
public class DalamudTextureWrap : IDalamudTextureWrap, IDeferredDisposable public class DalamudTextureWrap : IDalamudTextureWrap, IDeferredDisposable
{ {
private readonly TextureWrap wrappedWrap; private readonly TextureWrap wrappedWrap;
/// <summary> /// <summary>Initializes a new instance of the <see cref="DalamudTextureWrap"/> class.</summary>
/// Initializes a new instance of the <see cref="DalamudTextureWrap"/> class.
/// </summary>
/// <param name="wrappingWrap">The texture wrap to wrap.</param> /// <param name="wrappingWrap">The texture wrap to wrap.</param>
internal DalamudTextureWrap(TextureWrap wrappingWrap) internal DalamudTextureWrap(TextureWrap wrappingWrap) => this.wrappedWrap = wrappingWrap;
{
this.wrappedWrap = wrappingWrap;
}
/// <summary> /// <summary>Finalizes an instance of the <see cref="DalamudTextureWrap"/> class.</summary>
/// Finalizes an instance of the <see cref="DalamudTextureWrap"/> class. ~DalamudTextureWrap() => this.Dispose(false);
/// </summary>
~DalamudTextureWrap()
{
this.Dispose(false);
}
/// <summary> /// <inheritdoc/>
/// Gets the ImGui handle of the texture.
/// </summary>
public IntPtr ImGuiHandle => this.wrappedWrap.ImGuiHandle; public IntPtr ImGuiHandle => this.wrappedWrap.ImGuiHandle;
/// <summary> /// <inheritdoc/>
/// Gets the width of the texture.
/// </summary>
public int Width => this.wrappedWrap.Width; public int Width => this.wrappedWrap.Width;
/// <summary> /// <inheritdoc/>
/// Gets the height of the texture.
/// </summary>
public int Height => this.wrappedWrap.Height; public int Height => this.wrappedWrap.Height;
/// <summary> /// <summary>Queue the texture to be disposed once the frame ends.</summary>
/// Queue the texture to be disposed once the frame ends.
/// </summary>
public void Dispose() public void Dispose()
{ {
this.Dispose(true); this.Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
/// <summary> /// <summary>Actually dispose the wrapped texture.</summary>
/// Actually dispose the wrapped texture. void IDeferredDisposable.RealDispose() => this.wrappedWrap.Dispose();
/// </summary>
void IDeferredDisposable.RealDispose()
{
this.wrappedWrap.Dispose();
}
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{
Service<InterfaceManager>.GetNullable()?.EnqueueDeferredDispose(this); Service<InterfaceManager>.GetNullable()?.EnqueueDeferredDispose(this);
}
} }
} }

View file

@ -20,7 +20,7 @@ public record struct ExistingTextureModificationArgs()
/// <see cref="ITextureProvider.IsDxgiFormatSupportedForCreateFromExistingTextureAsync"/>. This may not necessarily /// <see cref="ITextureProvider.IsDxgiFormatSupportedForCreateFromExistingTextureAsync"/>. This may not necessarily
/// match <see cref="ITextureProvider.IsDxgiFormatSupported"/>. /// match <see cref="ITextureProvider.IsDxgiFormatSupported"/>.
/// </para></remarks> /// </para></remarks>
public int DxgiFormat { get; set; } = (int)DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM; public int DxgiFormat { get; set; } = (int)DXGI_FORMAT.DXGI_FORMAT_UNKNOWN;
/// <summary>Gets or sets the new width.</summary> /// <summary>Gets or sets the new width.</summary>
/// <remarks>Set to 0 to automatically calculate according to the original texture size, <see cref="Uv0"/>, and /// <remarks>Set to 0 to automatically calculate according to the original texture size, <see cref="Uv0"/>, and

View file

@ -6,6 +6,7 @@ using TerraFX.Interop.Windows;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace Dalamud.Interface.Internal; namespace Dalamud.Interface.Internal;
// TODO(api10): fix namespace maybe?
/// <summary> /// <summary>
/// Base TextureWrap interface for all Dalamud-owned texture wraps. /// Base TextureWrap interface for all Dalamud-owned texture wraps.
@ -13,24 +14,16 @@ namespace Dalamud.Interface.Internal;
/// </summary> /// </summary>
public interface IDalamudTextureWrap : IDisposable public interface IDalamudTextureWrap : IDisposable
{ {
/// <summary> /// <summary>Gets a texture handle suitable for direct use with ImGui functions.</summary>
/// Gets a texture handle suitable for direct use with ImGui functions.
/// </summary>
IntPtr ImGuiHandle { get; } IntPtr ImGuiHandle { get; }
/// <summary> /// <summary>Gets the width of the texture.</summary>
/// Gets the width of the texture.
/// </summary>
int Width { get; } int Width { get; }
/// <summary> /// <summary>Gets the height of the texture.</summary>
/// Gets the height of the texture.
/// </summary>
int Height { get; } int Height { get; }
/// <summary> /// <summary>Gets the size vector of the texture using Width, Height.</summary>
/// Gets the size vector of the texture using Width, Height.
/// </summary>
Vector2 Size => new(this.Width, this.Height); Vector2 Size => new(this.Width, this.Height);
/// <summary> /// <summary>

View file

@ -43,7 +43,7 @@ internal sealed class FileSystemSharedImmediateTexture : SharedImmediateTexture
private async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken) private async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken)
{ {
var tm = await Service<Interface.Textures.Internal.TextureManager>.GetAsync(); var tm = await Service<TextureManager>.GetAsync();
return await tm.NoThrottleCreateFromFileAsync(this.path, cancellationToken); return await tm.NoThrottleCreateFromFileAsync(this.path, cancellationToken);
} }
} }

View file

@ -48,7 +48,7 @@ internal sealed class GamePathSharedImmediateTexture : SharedImmediateTexture
private async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken) private async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken)
{ {
var dm = await Service<DataManager>.GetAsync(); var dm = await Service<DataManager>.GetAsync();
var tm = await Service<Interface.Textures.Internal.TextureManager>.GetAsync(); var tm = await Service<TextureManager>.GetAsync();
var substPath = tm.GetSubstitutedPath(this.path); var substPath = tm.GetSubstitutedPath(this.path);
if (dm.GetFile<TexFile>(substPath) is not { } file) if (dm.GetFile<TexFile>(substPath) is not { } file)
throw new FileNotFoundException(); throw new FileNotFoundException();

View file

@ -57,7 +57,7 @@ internal sealed class ManifestResourceSharedImmediateTexture : SharedImmediateTe
if (stream is null) if (stream is null)
throw new FileNotFoundException("The resource file could not be found."); throw new FileNotFoundException("The resource file could not be found.");
var tm = await Service<Interface.Textures.Internal.TextureManager>.GetAsync(); var tm = await Service<TextureManager>.GetAsync();
var ms = new MemoryStream(stream.CanSeek ? (int)stream.Length : 0); var ms = new MemoryStream(stream.CanSeek ? (int)stream.Length : 0);
await stream.CopyToAsync(ms, cancellationToken); await stream.CopyToAsync(ms, cancellationToken);
return tm.NoThrottleCreateFromImage(ms.GetBuffer().AsMemory(0, (int)ms.Length), cancellationToken); return tm.NoThrottleCreateFromImage(ms.GetBuffer().AsMemory(0, (int)ms.Length), cancellationToken);

View file

@ -7,16 +7,12 @@ using TerraFX.Interop.Windows;
namespace Dalamud.Interface.Textures.Internal; namespace Dalamud.Interface.Textures.Internal;
/// <summary> /// <summary>A texture wrap that is created from an <see cref="IUnknown"/>.</summary>
/// A texture wrap that is created by cloning the underlying <see cref="IDalamudTextureWrap.ImGuiHandle"/>.
/// </summary>
internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferredDisposable internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferredDisposable
{ {
private IntPtr imGuiHandle; private IntPtr imGuiHandle;
/// <summary> /// <summary>Initializes a new instance of the <see cref="UnknownTextureWrap"/> class.</summary>
/// Initializes a new instance of the <see cref="UnknownTextureWrap"/> class.
/// </summary>
/// <param name="unknown">The pointer to <see cref="IUnknown"/> that is suitable for use with /// <param name="unknown">The pointer to <see cref="IUnknown"/> that is suitable for use with
/// <see cref="IDalamudTextureWrap.ImGuiHandle"/>.</param> /// <see cref="IDalamudTextureWrap.ImGuiHandle"/>.</param>
/// <param name="width">The width of the texture.</param> /// <param name="width">The width of the texture.</param>
@ -32,9 +28,7 @@ internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferred
unknown->AddRef(); unknown->AddRef();
} }
/// <summary> /// <summary>Finalizes an instance of the <see cref="UnknownTextureWrap"/> class.</summary>
/// Finalizes an instance of the <see cref="UnknownTextureWrap"/> class.
/// </summary>
~UnknownTextureWrap() => this.Dispose(false); ~UnknownTextureWrap() => this.Dispose(false);
/// <inheritdoc/> /// <inheritdoc/>
@ -49,18 +43,14 @@ internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferred
/// <inheritdoc/> /// <inheritdoc/>
public int Height { get; } public int Height { get; }
/// <summary> /// <summary>Queue the texture to be disposed once the frame ends.</summary>
/// Queue the texture to be disposed once the frame ends.
/// </summary>
public void Dispose() public void Dispose()
{ {
this.Dispose(true); this.Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
/// <summary> /// <summary>Actually dispose the wrapped texture.</summary>
/// Actually dispose the wrapped texture.
/// </summary>
void IDeferredDisposable.RealDispose() void IDeferredDisposable.RealDispose()
{ {
var handle = Interlocked.Exchange(ref this.imGuiHandle, nint.Zero); var handle = Interlocked.Exchange(ref this.imGuiHandle, nint.Zero);

View file

@ -21,8 +21,8 @@ public record struct RawImageSpecification
throw new NotSupportedException(FormatNotSupportedMessage); throw new NotSupportedException(FormatNotSupportedMessage);
pitch = isBlockCompression pitch = isBlockCompression
? Math.Max(1, (width + 3) / 4) * 2 * bitsPerPixel ? Math.Max(1, (width + 3) / 4) * 2 * bitsPerPixel
: ((width * bitsPerPixel) + 7) / 8; : ((width * bitsPerPixel) + 7) / 8;
} }
this.Width = width; this.Width = width;