mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-29 03:49:19 +01:00
Cleanup and reformat
This commit is contained in:
parent
858d27ab8e
commit
fa5e708a43
11 changed files with 32 additions and 75 deletions
|
|
@ -5,68 +5,42 @@ using ImGuiScene;
|
|||
// ReSharper disable once CheckNamespace
|
||||
namespace Dalamud.Interface.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// Safety harness for ImGuiScene textures that will defer destruction until
|
||||
/// the end of the frame.
|
||||
/// </summary>
|
||||
/// <summary>Safety harness for ImGuiScene textures that will defer destruction until the end of the frame.</summary>
|
||||
[Obsolete($"Use {nameof(IDalamudTextureWrap)}.")]
|
||||
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
|
||||
public class DalamudTextureWrap : IDalamudTextureWrap, IDeferredDisposable
|
||||
{
|
||||
private readonly TextureWrap wrappedWrap;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DalamudTextureWrap"/> class.
|
||||
/// </summary>
|
||||
/// <summary>Initializes a new instance of the <see cref="DalamudTextureWrap"/> class.</summary>
|
||||
/// <param name="wrappingWrap">The texture wrap to wrap.</param>
|
||||
internal DalamudTextureWrap(TextureWrap wrappingWrap)
|
||||
{
|
||||
this.wrappedWrap = wrappingWrap;
|
||||
}
|
||||
internal DalamudTextureWrap(TextureWrap wrappingWrap) => this.wrappedWrap = wrappingWrap;
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="DalamudTextureWrap"/> class.
|
||||
/// </summary>
|
||||
~DalamudTextureWrap()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
/// <summary>Finalizes an instance of the <see cref="DalamudTextureWrap"/> class.</summary>
|
||||
~DalamudTextureWrap() => this.Dispose(false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ImGui handle of the texture.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public IntPtr ImGuiHandle => this.wrappedWrap.ImGuiHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the texture.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public int Width => this.wrappedWrap.Width;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the texture.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public int Height => this.wrappedWrap.Height;
|
||||
|
||||
/// <summary>
|
||||
/// Queue the texture to be disposed once the frame ends.
|
||||
/// </summary>
|
||||
/// <summary>Queue the texture to be disposed once the frame ends.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actually dispose the wrapped texture.
|
||||
/// </summary>
|
||||
void IDeferredDisposable.RealDispose()
|
||||
{
|
||||
this.wrappedWrap.Dispose();
|
||||
}
|
||||
/// <summary>Actually dispose the wrapped texture.</summary>
|
||||
void IDeferredDisposable.RealDispose() => this.wrappedWrap.Dispose();
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Service<InterfaceManager>.GetNullable()?.EnqueueDeferredDispose(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public record struct ExistingTextureModificationArgs()
|
|||
/// <see cref="ITextureProvider.IsDxgiFormatSupportedForCreateFromExistingTextureAsync"/>. This may not necessarily
|
||||
/// match <see cref="ITextureProvider.IsDxgiFormatSupported"/>.
|
||||
/// </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>
|
||||
/// <remarks>Set to 0 to automatically calculate according to the original texture size, <see cref="Uv0"/>, and
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using TerraFX.Interop.Windows;
|
|||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Dalamud.Interface.Internal;
|
||||
// TODO(api10): fix namespace maybe?
|
||||
|
||||
/// <summary>
|
||||
/// Base TextureWrap interface for all Dalamud-owned texture wraps.
|
||||
|
|
@ -13,24 +14,16 @@ namespace Dalamud.Interface.Internal;
|
|||
/// </summary>
|
||||
public interface IDalamudTextureWrap : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a texture handle suitable for direct use with ImGui functions.
|
||||
/// </summary>
|
||||
/// <summary>Gets a texture handle suitable for direct use with ImGui functions.</summary>
|
||||
IntPtr ImGuiHandle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the texture.
|
||||
/// </summary>
|
||||
/// <summary>Gets the width of the texture.</summary>
|
||||
int Width { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the texture.
|
||||
/// </summary>
|
||||
/// <summary>Gets the height of the texture.</summary>
|
||||
int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size vector of the texture using Width, Height.
|
||||
/// </summary>
|
||||
/// <summary>Gets the size vector of the texture using Width, Height.</summary>
|
||||
Vector2 Size => new(this.Width, this.Height);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public interface ISharedImmediateTexture
|
|||
/// </remarks>
|
||||
[return: NotNullIfNotNull(nameof(defaultWrap))]
|
||||
IDalamudTextureWrap? GetWrapOrDefault(IDalamudTextureWrap? defaultWrap = null);
|
||||
|
||||
|
||||
/// <summary>Attempts to get the texture for use with the current frame.</summary>
|
||||
/// <param name="texture">An instance of <see cref="IDalamudTextureWrap"/> that is guaranteed to be available for
|
||||
/// the current frame being drawn, or <c>null</c> if texture is not loaded (yet).</param>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public record struct ImGuiViewportTextureArgs()
|
|||
/// <summary>Gets or sets a value indicating whether to automatically update the texture.</summary>
|
||||
/// <remarks>Enabling this will also update <see cref="IDalamudTextureWrap.Size"/> as needed.</remarks>
|
||||
public bool AutoUpdate { get; set; }
|
||||
|
||||
|
||||
/// <summary>Gets or sets a value indicating whether to get the texture before rendering ImGui.</summary>
|
||||
/// <remarks>It probably makes no sense to enable this unless <see cref="ViewportId"/> points to the main viewport.
|
||||
/// </remarks>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ internal sealed class FileSystemSharedImmediateTexture : SharedImmediateTexture
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ internal sealed class GamePathSharedImmediateTexture : SharedImmediateTexture
|
|||
private async Task<IDalamudTextureWrap> CreateTextureAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
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);
|
||||
if (dm.GetFile<TexFile>(substPath) is not { } file)
|
||||
throw new FileNotFoundException();
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ internal sealed class ManifestResourceSharedImmediateTexture : SharedImmediateTe
|
|||
if (stream is null)
|
||||
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);
|
||||
await stream.CopyToAsync(ms, cancellationToken);
|
||||
return tm.NoThrottleCreateFromImage(ms.GetBuffer().AsMemory(0, (int)ms.Length), cancellationToken);
|
||||
|
|
|
|||
|
|
@ -7,16 +7,12 @@ using TerraFX.Interop.Windows;
|
|||
|
||||
namespace Dalamud.Interface.Textures.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// A texture wrap that is created by cloning the underlying <see cref="IDalamudTextureWrap.ImGuiHandle"/>.
|
||||
/// </summary>
|
||||
/// <summary>A texture wrap that is created from an <see cref="IUnknown"/>.</summary>
|
||||
internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferredDisposable
|
||||
{
|
||||
private IntPtr imGuiHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UnknownTextureWrap"/> class.
|
||||
/// </summary>
|
||||
/// <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
|
||||
/// <see cref="IDalamudTextureWrap.ImGuiHandle"/>.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
|
|
@ -32,9 +28,7 @@ internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferred
|
|||
unknown->AddRef();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="UnknownTextureWrap"/> class.
|
||||
/// </summary>
|
||||
/// <summary>Finalizes an instance of the <see cref="UnknownTextureWrap"/> class.</summary>
|
||||
~UnknownTextureWrap() => this.Dispose(false);
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -49,18 +43,14 @@ internal sealed unsafe class UnknownTextureWrap : IDalamudTextureWrap, IDeferred
|
|||
/// <inheritdoc/>
|
||||
public int Height { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Queue the texture to be disposed once the frame ends.
|
||||
/// </summary>
|
||||
/// <summary>Queue the texture to be disposed once the frame ends.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actually dispose the wrapped texture.
|
||||
/// </summary>
|
||||
/// <summary>Actually dispose the wrapped texture.</summary>
|
||||
void IDeferredDisposable.RealDispose()
|
||||
{
|
||||
var handle = Interlocked.Exchange(ref this.imGuiHandle, nint.Zero);
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ internal sealed class ViewportTextureWrap : IDalamudTextureWrap, IDeferredDispos
|
|||
bottom = (uint)MathF.Round(newDesc.Height * this.args.Uv1Effective.Y),
|
||||
front = 0,
|
||||
back = 1,
|
||||
};
|
||||
};
|
||||
|
||||
if (this.desc.Width != copyBox.right - copyBox.left
|
||||
|| this.desc.Height != copyBox.bottom - copyBox.top
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ public record struct RawImageSpecification
|
|||
throw new NotSupportedException(FormatNotSupportedMessage);
|
||||
|
||||
pitch = isBlockCompression
|
||||
? Math.Max(1, (width + 3) / 4) * 2 * bitsPerPixel
|
||||
: ((width * bitsPerPixel) + 7) / 8;
|
||||
? Math.Max(1, (width + 3) / 4) * 2 * bitsPerPixel
|
||||
: ((width * bitsPerPixel) + 7) / 8;
|
||||
}
|
||||
|
||||
this.Width = width;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue