-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'Exter-N/material-editor-adjustments'
- Loading branch information
Showing
6 changed files
with
87 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using FFXIVClientStructs.FFXIV.Client.Graphics.Render; | ||
using Penumbra.Interop.Structs; | ||
|
||
namespace Penumbra.Interop.SafeHandles; | ||
|
||
public unsafe class SafeTextureHandle : SafeHandle | ||
{ | ||
public Texture* Texture => (Texture*)handle; | ||
|
||
public override bool IsInvalid => handle == 0; | ||
|
||
public SafeTextureHandle(Texture* handle, bool incRef, bool ownsHandle = true) : base(0, ownsHandle) | ||
{ | ||
if (incRef && !ownsHandle) | ||
throw new ArgumentException("Non-owning SafeTextureHandle with IncRef is unsupported"); | ||
if (incRef && handle != null) | ||
TextureUtility.IncRef(handle); | ||
SetHandle((nint)handle); | ||
} | ||
|
||
public void Exchange(ref nint ppTexture) | ||
{ | ||
lock (this) | ||
{ | ||
handle = Interlocked.Exchange(ref ppTexture, handle); | ||
} | ||
} | ||
|
||
public static SafeTextureHandle CreateInvalid() | ||
=> new(null, incRef: false); | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
nint handle; | ||
lock (this) | ||
{ | ||
handle = this.handle; | ||
this.handle = 0; | ||
} | ||
if (handle != 0) | ||
TextureUtility.DecRef((Texture*)handle); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters