mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 12:23:39 +01:00
Assign debug names for textures
This commit is contained in:
parent
6a0f774625
commit
7f12e3f3da
10 changed files with 100 additions and 35 deletions
|
|
@ -276,7 +276,9 @@ internal class PluginImageCache : IDisposable, IServiceType
|
|||
// FIXME(goat): This is a hack around this call failing randomly in certain situations. Might be related to not being called on the main thread.
|
||||
try
|
||||
{
|
||||
image = await textureManager.CreateFromImageAsync(bytes);
|
||||
image = await textureManager.CreateFromImageAsync(
|
||||
bytes,
|
||||
$"{nameof(PluginImageCache)}({name} for {manifest.InternalName} at {loc})");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -586,8 +586,12 @@ internal sealed partial class FontAtlasFactory
|
|||
var bpp = use4 ? 2 : 4;
|
||||
var width = this.NewImAtlas.TexWidth;
|
||||
var height = this.NewImAtlas.TexHeight;
|
||||
foreach (ref var texture in this.data.ImTextures.DataSpan)
|
||||
var textureSpan = this.data.ImTextures.DataSpan;
|
||||
for (var i = 0; i < textureSpan.Length; i++)
|
||||
{
|
||||
ref var texture = ref textureSpan[i];
|
||||
var name =
|
||||
$"FontAtlas.{ this.data.Owner?.Name ?? "(no owner or name)"}[0x{(long)this.data.Atlas.NativePtr:X}][{i}]";
|
||||
if (texture.TexID != 0)
|
||||
{
|
||||
// Nothing to do
|
||||
|
|
@ -596,7 +600,8 @@ internal sealed partial class FontAtlasFactory
|
|||
{
|
||||
var wrap = this.factory.TextureManager.CreateFromRaw(
|
||||
RawImageSpecification.Rgba32(width, height),
|
||||
new(texture.TexPixelsRGBA32, width * height * 4));
|
||||
new(texture.TexPixelsRGBA32, width * height * 4),
|
||||
name);
|
||||
this.data.AddExistingTexture(wrap);
|
||||
texture.TexID = wrap.ImGuiHandle;
|
||||
}
|
||||
|
|
@ -640,7 +645,8 @@ internal sealed partial class FontAtlasFactory
|
|||
height,
|
||||
(int)(use4 ? Format.B4G4R4A4_UNorm : Format.B8G8R8A8_UNorm),
|
||||
width * bpp),
|
||||
buf);
|
||||
buf,
|
||||
name);
|
||||
this.data.AddExistingTexture(wrap);
|
||||
texture.TexID = wrap.ImGuiHandle;
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -362,7 +362,8 @@ internal sealed partial class FontAtlasFactory
|
|||
? DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM
|
||||
: DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM),
|
||||
texFile.Header.Width * bpp),
|
||||
buffer));
|
||||
buffer,
|
||||
$"{nameof(FontAtlasFactory)}:{texPathFormat.Format(fileIndex)}:{channelIndex}"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ internal sealed partial class TextureManager
|
|||
IDalamudTextureWrap wrap,
|
||||
TextureModificationArgs args = default,
|
||||
bool leaveWrapOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
this.DynamicPriorityTextureLoader.LoadAsync<IDalamudTextureWrap>(
|
||||
null,
|
||||
|
|
@ -80,6 +81,7 @@ internal sealed partial class TextureManager
|
|||
true);
|
||||
this.BlameSetName(
|
||||
outWrap,
|
||||
debugName ??
|
||||
$"{nameof(this.CreateFromExistingTextureAsync)}({nameof(wrap)}, {nameof(args)}, {nameof(leaveWrapOpen)}, {nameof(cancellationToken)})");
|
||||
return outWrap;
|
||||
}
|
||||
|
|
@ -90,16 +92,19 @@ internal sealed partial class TextureManager
|
|||
/// <inheritdoc/>
|
||||
Task<IDalamudTextureWrap> ITextureProvider.CreateFromImGuiViewportAsync(
|
||||
ImGuiViewportTextureArgs args,
|
||||
CancellationToken cancellationToken) => this.CreateFromImGuiViewportAsync(args, null, cancellationToken);
|
||||
string? debugName,
|
||||
CancellationToken cancellationToken) =>
|
||||
this.CreateFromImGuiViewportAsync(args, null, debugName, cancellationToken);
|
||||
|
||||
/// <inheritdoc cref="ITextureProvider.CreateFromImGuiViewportAsync"/>
|
||||
public Task<IDalamudTextureWrap> CreateFromImGuiViewportAsync(
|
||||
ImGuiViewportTextureArgs args,
|
||||
LocalPlugin? ownerPlugin,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
args.ThrowOnInvalidValues();
|
||||
var t = new ViewportTextureWrap(args, ownerPlugin, cancellationToken);
|
||||
var t = new ViewportTextureWrap(args, debugName, ownerPlugin, cancellationToken);
|
||||
t.QueueUpdate();
|
||||
return t.FirstUpdateTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ internal sealed partial class TextureManager
|
|||
/// <inheritdoc/>
|
||||
public Task<IDalamudTextureWrap> CreateFromImageAsync(
|
||||
ReadOnlyMemory<byte> bytes,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
this.DynamicPriorityTextureLoader.LoadAsync(
|
||||
null,
|
||||
|
|
@ -125,6 +126,7 @@ internal sealed partial class TextureManager
|
|||
() =>
|
||||
this.BlameSetName(
|
||||
this.NoThrottleCreateFromImage(bytes.ToArray(), ct),
|
||||
debugName ??
|
||||
$"{nameof(this.CreateFromImageAsync)}({nameof(bytes)}, {nameof(cancellationToken)})"),
|
||||
ct),
|
||||
cancellationToken);
|
||||
|
|
@ -133,6 +135,7 @@ internal sealed partial class TextureManager
|
|||
public Task<IDalamudTextureWrap> CreateFromImageAsync(
|
||||
Stream stream,
|
||||
bool leaveOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
this.DynamicPriorityTextureLoader.LoadAsync(
|
||||
null,
|
||||
|
|
@ -142,6 +145,7 @@ internal sealed partial class TextureManager
|
|||
await stream.CopyToAsync(ms, ct).ConfigureAwait(false);
|
||||
return this.BlameSetName(
|
||||
this.NoThrottleCreateFromImage(ms.GetBuffer(), ct),
|
||||
debugName ??
|
||||
$"{nameof(this.CreateFromImageAsync)}({nameof(stream)}, {nameof(leaveOpen)}, {nameof(cancellationToken)})");
|
||||
},
|
||||
cancellationToken,
|
||||
|
|
@ -151,21 +155,24 @@ internal sealed partial class TextureManager
|
|||
// It probably doesn't make sense to throttle this, as it copies the passed bytes to GPU without any transformation.
|
||||
public IDalamudTextureWrap CreateFromRaw(
|
||||
RawImageSpecification specs,
|
||||
ReadOnlySpan<byte> bytes) =>
|
||||
ReadOnlySpan<byte> bytes,
|
||||
string? debugName = null) =>
|
||||
this.BlameSetName(
|
||||
this.NoThrottleCreateFromRaw(specs, bytes),
|
||||
$"{nameof(this.CreateFromRaw)}({nameof(specs)}, {nameof(bytes)})");
|
||||
debugName ?? $"{nameof(this.CreateFromRaw)}({nameof(specs)}, {nameof(bytes)})");
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<IDalamudTextureWrap> CreateFromRawAsync(
|
||||
RawImageSpecification specs,
|
||||
ReadOnlyMemory<byte> bytes,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
this.DynamicPriorityTextureLoader.LoadAsync(
|
||||
null,
|
||||
_ => Task.FromResult(
|
||||
this.BlameSetName(
|
||||
this.NoThrottleCreateFromRaw(specs, bytes.Span),
|
||||
debugName ??
|
||||
$"{nameof(this.CreateFromRawAsync)}({nameof(specs)}, {nameof(bytes)}, {nameof(cancellationToken)})")),
|
||||
cancellationToken);
|
||||
|
||||
|
|
@ -174,6 +181,7 @@ internal sealed partial class TextureManager
|
|||
RawImageSpecification specs,
|
||||
Stream stream,
|
||||
bool leaveOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
this.DynamicPriorityTextureLoader.LoadAsync(
|
||||
null,
|
||||
|
|
@ -183,6 +191,7 @@ internal sealed partial class TextureManager
|
|||
await stream.CopyToAsync(ms, ct).ConfigureAwait(false);
|
||||
return this.BlameSetName(
|
||||
this.NoThrottleCreateFromRaw(specs, ms.GetBuffer().AsSpan(0, (int)ms.Length)),
|
||||
debugName ??
|
||||
$"{nameof(this.CreateFromRawAsync)}({nameof(specs)}, {nameof(stream)}, {nameof(leaveOpen)}, {nameof(cancellationToken)})");
|
||||
},
|
||||
cancellationToken,
|
||||
|
|
@ -197,13 +206,14 @@ internal sealed partial class TextureManager
|
|||
/// <inheritdoc/>
|
||||
public Task<IDalamudTextureWrap> CreateFromTexFileAsync(
|
||||
TexFile file,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
this.DynamicPriorityTextureLoader.LoadAsync(
|
||||
null,
|
||||
_ => Task.FromResult(
|
||||
this.BlameSetName(
|
||||
this.NoThrottleCreateFromTexFile(file),
|
||||
$"{nameof(this.CreateFromTexFile)}({nameof(file)})")),
|
||||
debugName ?? $"{nameof(this.CreateFromTexFile)}({nameof(file)})")),
|
||||
cancellationToken);
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
IDalamudTextureWrap wrap,
|
||||
TextureModificationArgs args = default,
|
||||
bool leaveWrapOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
|
|
@ -146,6 +147,7 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
wrap,
|
||||
args,
|
||||
leaveWrapOpen,
|
||||
debugName,
|
||||
cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
|
|
@ -154,10 +156,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
/// <inheritdoc/>
|
||||
public async Task<IDalamudTextureWrap> CreateFromImGuiViewportAsync(
|
||||
ImGuiViewportTextureArgs args,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
var textureWrap = await manager.CreateFromImGuiViewportAsync(args, this.plugin, cancellationToken);
|
||||
var textureWrap = await manager.CreateFromImGuiViewportAsync(args, this.plugin, debugName, cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
@ -165,10 +168,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
/// <inheritdoc/>
|
||||
public async Task<IDalamudTextureWrap> CreateFromImageAsync(
|
||||
ReadOnlyMemory<byte> bytes,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
var textureWrap = await manager.CreateFromImageAsync(bytes, cancellationToken);
|
||||
var textureWrap = await manager.CreateFromImageAsync(bytes, debugName, cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
@ -177,10 +181,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
public async Task<IDalamudTextureWrap> CreateFromImageAsync(
|
||||
Stream stream,
|
||||
bool leaveOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
var textureWrap = await manager.CreateFromImageAsync(stream, leaveOpen, cancellationToken);
|
||||
var textureWrap = await manager.CreateFromImageAsync(stream, leaveOpen, debugName, cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
@ -188,10 +193,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
/// <inheritdoc/>
|
||||
public IDalamudTextureWrap CreateFromRaw(
|
||||
RawImageSpecification specs,
|
||||
ReadOnlySpan<byte> bytes)
|
||||
ReadOnlySpan<byte> bytes,
|
||||
string? debugName = null)
|
||||
{
|
||||
var manager = this.ManagerOrThrow;
|
||||
var textureWrap = manager.CreateFromRaw(specs, bytes);
|
||||
var textureWrap = manager.CreateFromRaw(specs, bytes, debugName);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
@ -200,10 +206,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
public async Task<IDalamudTextureWrap> CreateFromRawAsync(
|
||||
RawImageSpecification specs,
|
||||
ReadOnlyMemory<byte> bytes,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
var textureWrap = await manager.CreateFromRawAsync(specs, bytes, cancellationToken);
|
||||
var textureWrap = await manager.CreateFromRawAsync(specs, bytes, debugName, cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
@ -213,10 +220,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
RawImageSpecification specs,
|
||||
Stream stream,
|
||||
bool leaveOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
var textureWrap = await manager.CreateFromRawAsync(specs, stream, leaveOpen, cancellationToken);
|
||||
var textureWrap = await manager.CreateFromRawAsync(specs, stream, leaveOpen, debugName, cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
@ -233,10 +241,11 @@ internal sealed partial class TextureManagerPluginScoped
|
|||
/// <inheritdoc/>
|
||||
public async Task<IDalamudTextureWrap> CreateFromTexFileAsync(
|
||||
TexFile file,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var manager = await this.ManagerTask;
|
||||
var textureWrap = await manager.CreateFromTexFileAsync(file, cancellationToken);
|
||||
var textureWrap = await manager.CreateFromTexFileAsync(file, debugName, cancellationToken);
|
||||
manager.Blame(textureWrap, this.plugin);
|
||||
return textureWrap;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace Dalamud.Interface.Textures.Internal;
|
|||
/// <summary>A texture wrap that takes its buffer from the frame buffer (of swap chain).</summary>
|
||||
internal sealed class ViewportTextureWrap : IDalamudTextureWrap, IDeferredDisposable
|
||||
{
|
||||
private readonly string? debugName;
|
||||
private readonly LocalPlugin? ownerPlugin;
|
||||
private readonly CancellationToken cancellationToken;
|
||||
private readonly TaskCompletionSource<IDalamudTextureWrap> firstUpdateTaskCompletionSource = new();
|
||||
|
|
@ -34,12 +35,14 @@ internal sealed class ViewportTextureWrap : IDalamudTextureWrap, IDeferredDispos
|
|||
|
||||
/// <summary>Initializes a new instance of the <see cref="ViewportTextureWrap"/> class.</summary>
|
||||
/// <param name="args">The arguments for creating a texture.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="ownerPlugin">The owner plugin.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public ViewportTextureWrap(
|
||||
ImGuiViewportTextureArgs args, LocalPlugin? ownerPlugin, CancellationToken cancellationToken)
|
||||
ImGuiViewportTextureArgs args, string? debugName, LocalPlugin? ownerPlugin, CancellationToken cancellationToken)
|
||||
{
|
||||
this.args = args;
|
||||
this.debugName = debugName;
|
||||
this.ownerPlugin = ownerPlugin;
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
|
@ -151,7 +154,7 @@ internal sealed class ViewportTextureWrap : IDalamudTextureWrap, IDeferredDispos
|
|||
Service<TextureManager>.Get().Blame(this, this.ownerPlugin);
|
||||
Service<TextureManager>.Get().BlameSetName(
|
||||
this,
|
||||
$"{nameof(ViewportTextureWrap)}({this.args})");
|
||||
this.debugName ?? $"{nameof(ViewportTextureWrap)}({this.args})");
|
||||
}
|
||||
|
||||
// context.Get()->CopyResource((ID3D11Resource*)this.tex.Get(), (ID3D11Resource*)backBuffer.Get());
|
||||
|
|
|
|||
|
|
@ -126,7 +126,10 @@ public class UldWrapper : IDisposable
|
|||
inputSlice.CopyTo(outputSlice);
|
||||
}
|
||||
|
||||
return this.textureManager.CreateFromRaw(RawImageSpecification.Rgba32(part.W, part.H), imageData);
|
||||
return this.textureManager.CreateFromRaw(
|
||||
RawImageSpecification.Rgba32(part.W, part.H),
|
||||
imageData,
|
||||
$"{nameof(UldWrapper)}({this.Uld?.FilePath.Path}: {part.TextureId})");
|
||||
}
|
||||
|
||||
private (uint Id, int Width, int Height, bool HD, byte[] RgbaData)? GetTexture(string texturePath)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Interface.Internal.Windows.Data.Widgets;
|
||||
using Dalamud.Interface.Textures;
|
||||
|
||||
using Lumina.Data.Files;
|
||||
|
|
@ -16,6 +17,10 @@ namespace Dalamud.Plugin.Services;
|
|||
/// <summary>Service that grants you access to textures you may render via ImGui.</summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Create</b> functions will return a new texture, and the returned instance of <see cref="IDalamudTextureWrap"/>
|
||||
/// must be disposed after use.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Get</b> functions will return a shared texture, and the returnd instance of <see cref="ISharedImmediateTexture"/>
|
||||
/// do not require calling <see cref="IDisposable.Dispose"/>, unless a new reference has been created by calling
|
||||
/// <see cref="ISharedImmediateTexture.RentAsync"/>.<br />
|
||||
|
|
@ -23,8 +28,8 @@ namespace Dalamud.Plugin.Services;
|
|||
/// <see cref="IDalamudTextureWrap"/> that will stay valid for the rest of the frame.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>Create</b> functions will return a new texture, and the returned instance of <see cref="IDalamudTextureWrap"/>
|
||||
/// must be disposed after use.
|
||||
/// <c>debugName</c> parameter can be used to name your textures, to aid debugging resource leaks using
|
||||
/// <see cref="TexWidget"/>.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public partial interface ITextureProvider
|
||||
|
|
@ -36,6 +41,7 @@ public partial interface ITextureProvider
|
|||
/// <param name="args">The texture modification arguments.</param>
|
||||
/// <param name="leaveWrapOpen">Whether to leave <paramref name="wrap"/> non-disposed when the returned
|
||||
/// <see cref="Task{TResult}"/> completes.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the copied texture on success. Dispose after use.</returns>
|
||||
/// <remarks><para>This function may throw an exception.</para></remarks>
|
||||
|
|
@ -43,10 +49,12 @@ public partial interface ITextureProvider
|
|||
IDalamudTextureWrap wrap,
|
||||
TextureModificationArgs args = default,
|
||||
bool leaveWrapOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>Creates a texture from an ImGui viewport.</summary>
|
||||
/// <param name="args">The arguments for creating a texture.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the copied texture on success. Dispose after use.</returns>
|
||||
/// <remarks>
|
||||
|
|
@ -55,22 +63,26 @@ public partial interface ITextureProvider
|
|||
/// </remarks>
|
||||
Task<IDalamudTextureWrap> CreateFromImGuiViewportAsync(
|
||||
ImGuiViewportTextureArgs args,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>Gets a texture from the given bytes, trying to interpret it as a .tex file or other well-known image
|
||||
/// files, such as .png.</summary>
|
||||
/// <param name="bytes">The bytes to load.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
/// <remarks><para>This function may throw an exception.</para></remarks>
|
||||
Task<IDalamudTextureWrap> CreateFromImageAsync(
|
||||
ReadOnlyMemory<byte> bytes,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>Gets a texture from the given stream, trying to interpret it as a .tex file or other well-known image
|
||||
/// files, such as .png.</summary>
|
||||
/// <param name="stream">The stream to load data from.</param>
|
||||
/// <param name="leaveOpen">Whether to leave the stream open once the task completes, sucessfully or not.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
/// <remarks>
|
||||
|
|
@ -80,32 +92,38 @@ public partial interface ITextureProvider
|
|||
Task<IDalamudTextureWrap> CreateFromImageAsync(
|
||||
Stream stream,
|
||||
bool leaveOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>Gets a texture from the given bytes, interpreting it as a raw bitmap.</summary>
|
||||
/// <param name="specs">The specifications for the raw bitmap.</param>
|
||||
/// <param name="bytes">The bytes to load.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <returns>The texture loaded from the supplied raw bitmap. Dispose after use.</returns>
|
||||
/// <remarks><para>This function may throw an exception.</para></remarks>
|
||||
IDalamudTextureWrap CreateFromRaw(
|
||||
RawImageSpecification specs,
|
||||
ReadOnlySpan<byte> bytes);
|
||||
ReadOnlySpan<byte> bytes,
|
||||
string? debugName = null);
|
||||
|
||||
/// <summary>Gets a texture from the given bytes, interpreting it as a raw bitmap.</summary>
|
||||
/// <param name="specs">The specifications for the raw bitmap.</param>
|
||||
/// <param name="bytes">The bytes to load.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
/// <remarks><para>This function may throw an exception.</para></remarks>
|
||||
Task<IDalamudTextureWrap> CreateFromRawAsync(
|
||||
RawImageSpecification specs,
|
||||
ReadOnlyMemory<byte> bytes,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>Gets a texture from the given stream, interpreting the read data as a raw bitmap.</summary>
|
||||
/// <param name="specs">The specifications for the raw bitmap.</param>
|
||||
/// <param name="stream">The stream to load data from.</param>
|
||||
/// <param name="leaveOpen">Whether to leave the stream open once the task completes, sucessfully or not.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> containing the loaded texture on success. Dispose after use.</returns>
|
||||
/// <remarks>
|
||||
|
|
@ -117,6 +135,7 @@ public partial interface ITextureProvider
|
|||
RawImageSpecification specs,
|
||||
Stream stream,
|
||||
bool leaveOpen = false,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -130,11 +149,13 @@ public partial interface ITextureProvider
|
|||
|
||||
/// <summary>Get a texture handle for the specified Lumina <see cref="TexFile"/>.</summary>
|
||||
/// <param name="file">The texture to obtain a handle to.</param>
|
||||
/// <param name="debugName">Name for debug display purposes.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A texture wrap that can be used to render the texture. Dispose after use.</returns>
|
||||
/// <remarks><para>This function may throw an exception.</para></remarks>
|
||||
Task<IDalamudTextureWrap> CreateFromTexFileAsync(
|
||||
TexFile file,
|
||||
string? debugName = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>Gets the supported bitmap decoders.</summary>
|
||||
|
|
@ -144,8 +165,8 @@ public partial interface ITextureProvider
|
|||
/// <ul>
|
||||
/// <li><see cref="GetFromFile"/></li>
|
||||
/// <li><see cref="GetFromManifestResource"/></li>
|
||||
/// <li><see cref="CreateFromImageAsync(ReadOnlyMemory{byte},CancellationToken)"/></li>
|
||||
/// <li><see cref="CreateFromImageAsync(Stream,bool,CancellationToken)"/></li>
|
||||
/// <li><see cref="CreateFromImageAsync(ReadOnlyMemory{byte},string?,CancellationToken)"/></li>
|
||||
/// <li><see cref="CreateFromImageAsync(Stream,bool,string?,CancellationToken)"/></li>
|
||||
/// </ul>
|
||||
/// <para>This function may throw an exception.</para>
|
||||
/// </remarks>
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
|
||||
this.fileStreams = Enum.GetValues<DalamudAsset>().ToDictionary(x => x, _ => (Task<FileStream>?)null);
|
||||
this.textureWraps = Enum.GetValues<DalamudAsset>().ToDictionary(x => x, _ => (Task<IDalamudTextureWrap>?)null);
|
||||
|
||||
|
||||
// Block until all the required assets to be ready.
|
||||
var loadTimings = Timings.Start("DAM LoadAll");
|
||||
registerStartupBlocker(
|
||||
|
|
@ -72,11 +72,11 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
"Prevent Dalamud from loading more stuff, until we've ensured that all required assets are available.");
|
||||
|
||||
Task.WhenAll(
|
||||
Enum.GetValues<DalamudAsset>()
|
||||
.Where(x => x is not DalamudAsset.Empty4X4)
|
||||
.Where(x => x.GetAttribute<DalamudAssetAttribute>()?.Required is false)
|
||||
.Select(this.CreateStreamAsync)
|
||||
.Select(x => x.ToContentDisposedTask()))
|
||||
Enum.GetValues<DalamudAsset>()
|
||||
.Where(x => x is not DalamudAsset.Empty4X4)
|
||||
.Where(x => x.GetAttribute<DalamudAssetAttribute>()?.Required is false)
|
||||
.Select(this.CreateStreamAsync)
|
||||
.Select(x => x.ToContentDisposedTask()))
|
||||
.ContinueWith(r => Log.Verbose($"Optional assets load state: {r}"));
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
this.cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
for (var j = RenameAttemptCount; ; j--)
|
||||
for (var j = RenameAttemptCount;; j--)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -313,10 +313,15 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
stream.ReadExactly(buf, 0, length);
|
||||
var image = purpose switch
|
||||
{
|
||||
DalamudAssetPurpose.TextureFromPng => await tm.CreateFromImageAsync(buf),
|
||||
DalamudAssetPurpose.TextureFromPng => await tm.CreateFromImageAsync(
|
||||
buf,
|
||||
$"{nameof(DalamudAsset)}.{Enum.GetName(asset)}"),
|
||||
DalamudAssetPurpose.TextureFromRaw =>
|
||||
asset.GetAttribute<DalamudAssetRawTextureAttribute>() is { } raw
|
||||
? await tm.CreateFromRawAsync(raw.Specification, buf)
|
||||
? await tm.CreateFromRawAsync(
|
||||
raw.Specification,
|
||||
buf,
|
||||
$"{nameof(DalamudAsset)}.{Enum.GetName(asset)}")
|
||||
: throw new InvalidOperationException(
|
||||
"TextureFromRaw must accompany a DalamudAssetRawTextureAttribute."),
|
||||
_ => null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue