Add ITextureProvider.ConvertToKernelTexture (#2003)

* Add ITextureProvider.ConvertToKernelTexture

Lets you obtain an instance of Kernel::Texture from IDalamudTextureWrap.

* Docs wip
This commit is contained in:
srkizer 2024-11-05 00:06:42 +09:00 committed by GitHub
parent 9a0bc50e23
commit 74ab9191d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 125 additions and 5 deletions

View file

@ -5,7 +5,6 @@ using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Windows.Data.Widgets;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
@ -281,4 +280,20 @@ public interface ITextureProvider
/// <returns><c>true</c> if supported.</returns>
/// <remarks><para>This function does not throw exceptions.</para></remarks>
bool IsDxgiFormatSupportedForCreateFromExistingTextureAsync(int dxgiFormat);
/// <summary>Converts an existing <see cref="IDalamudTextureWrap"/> instance to a new instance of
/// <see cref="FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture"/> which can be used to supply a custom
/// texture onto an in-game addon (UI element.)</summary>
/// <param name="wrap">Instance of <see cref="IDalamudTextureWrap"/> to convert.</param>
/// <param name="leaveWrapOpen">Whether to leave <paramref name="wrap"/> non-disposed when the returned
/// <see cref="Task{TResult}"/> completes.</param>
/// <returns>Address of the new <see cref="FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture"/>.</returns>
/// <example>See <c>PrintTextureInfo</c> in <see cref="Interface.Internal.UiDebug.PrintSimpleNode"/> for an example
/// of replacing the texture of an image node.</example>
/// <remarks>
/// <para>If the returned kernel texture is to be destroyed, call the fourth function in its vtable, by calling
/// <see cref="FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture.DecRef"/> or
/// <c>((delegate* unmanaged&lt;nint, void&gt;)(*(nint**)ptr)[3](ptr)</c>.</para>
/// </remarks>
nint ConvertToKernelTexture(IDalamudTextureWrap wrap, bool leaveWrapOpen = false);
}

View file

@ -22,6 +22,9 @@ public interface ITextureReadbackProvider
/// <remarks>
/// <para>The length of the returned <c>RawData</c> may not match
/// <see cref="RawImageSpecification.Height"/> * <see cref="RawImageSpecification.Pitch"/>.</para>
/// <para><see cref="RawImageSpecification.Pitch"/> may not be the minimal value required to represent the texture
/// bitmap data. For example, if a texture is 4x4 B8G8R8A8, the minimal pitch would be 32, but the function may
/// return 64 instead.</para>
/// <para>This function may throw an exception.</para>
/// </remarks>
Task<(RawImageSpecification Specification, byte[] RawData)> GetRawImageAsync(