diff --git a/Dalamud/Interface/Internal/IDalamudTextureWrap.cs b/Dalamud/Interface/Internal/IDalamudTextureWrap.cs index 60d96534d..8e2e56c26 100644 --- a/Dalamud/Interface/Internal/IDalamudTextureWrap.cs +++ b/Dalamud/Interface/Internal/IDalamudTextureWrap.cs @@ -8,7 +8,7 @@ namespace Dalamud.Interface.Internal; /// Base TextureWrap interface for all Dalamud-owned texture wraps. /// Used to avoid referencing ImGuiScene. /// -public interface IDalamudTextureWrap : IDisposable, ICloneable +public interface IDalamudTextureWrap : IDisposable { /// /// Gets a texture handle suitable for direct use with ImGui functions. @@ -31,17 +31,25 @@ public interface IDalamudTextureWrap : IDisposable, ICloneable Vector2 Size => new(this.Width, this.Height); /// - /// Creates a new reference to this texture wrap. + /// Creates a new reference to the resource being pointed by this instance of . /// /// The new reference to this texture wrap. - /// The default implementation will treat as an . - new unsafe IDalamudTextureWrap Clone() + /// + /// On calling this function, a new instance of will be returned, but with + /// the same . The new instance must be d, as the backing + /// resource will stay alive until all the references are released. The old instance may be disposed as needed, + /// once this function returns; the new instance will stay alive regardless of whether the old instance has been + /// disposed.
+ /// Primary purpose of this function is to share textures across plugin boundaries. When texture wraps get passed + /// across plugin boundaries for use for an indeterminate duration, the receiver should call this function to + /// obtain a new reference to the texture received, so that it gets its own "copy" of the texture and the caller + /// may dispose the texture anytime without any care for the receiver.
+ /// The default implementation will treat as an . + ///
+ unsafe IDalamudTextureWrap CreateWrapSharingLowLevelResource() { // Dalamud specific: IDalamudTextureWrap always points to an ID3D11ShaderResourceView. var handle = (IUnknown*)this.ImGuiHandle; return new UnknownTextureWrap(handle, this.Width, this.Height, true); } - - /// - object ICloneable.Clone() => this.Clone(); } diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs index 173e5409a..8d6879ac1 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/TexWidget.cs @@ -122,7 +122,7 @@ internal class TexWidget : IDataWindowWidget ImGui.SameLine(); if (ImGui.Button($"Clone##{i}")) - this.addedTextures.Add(tex.Clone()); + this.addedTextures.Add(tex.CreateWrapSharingLowLevelResource()); } }