diff --git a/Dalamud/Interface/Internal/InterfaceManager.AsReShadeAddon.cs b/Dalamud/Interface/Internal/InterfaceManager.AsReShadeAddon.cs index 9c08aaf06..486a3874b 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.AsReShadeAddon.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.AsReShadeAddon.cs @@ -1,8 +1,10 @@ using System.Diagnostics; +using Dalamud.Interface.Internal.ReShadeHandling; using Dalamud.Utility; using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; namespace Dalamud.Interface.Internal; @@ -11,36 +13,41 @@ namespace Dalamud.Interface.Internal; /// internal partial class InterfaceManager { - private unsafe void ReShadeAddonInterfaceOnDestroySwapChain(ref ReShadeHandling.ReShadeAddonInterface.ApiObject swapchain) + private unsafe void ReShadeAddonInterfaceOnDestroySwapChain(ref ReShadeAddonInterface.ApiObject swapChain) { - var swapChain = swapchain.GetNative(); - if (this.scene?.SwapChain.NativePointer != (nint)swapChain) + var swapChainNative = swapChain.GetNative(); + if (this.scene?.SwapChain.NativePointer != (nint)swapChainNative) return; this.scene?.OnPreResize(); } - private unsafe void ReShadeAddonInterfaceOnInitSwapChain(ref ReShadeHandling.ReShadeAddonInterface.ApiObject swapchain) + private unsafe void ReShadeAddonInterfaceOnInitSwapChain(ref ReShadeAddonInterface.ApiObject swapChain) { - var swapChain = swapchain.GetNative(); - if (this.scene?.SwapChain.NativePointer != (nint)swapChain) + var swapChainNative = swapChain.GetNative(); + if (this.scene?.SwapChain.NativePointer != (nint)swapChainNative) return; DXGI_SWAP_CHAIN_DESC desc; - if (swapChain->GetDesc(&desc).FAILED) + if (swapChainNative->GetDesc(&desc).FAILED) return; this.scene?.OnPostResize((int)desc.BufferDesc.Width, (int)desc.BufferDesc.Height); } - private void ReShadeAddonInterfaceOnReShadeOverlay(ref ReShadeHandling.ReShadeAddonInterface.ApiObject runtime) + private void ReShadeAddonInterfaceOnPresent( + ref ReShadeAddonInterface.ApiObject runtime, + ref ReShadeAddonInterface.ApiObject swapChain, + ReadOnlySpan sourceRect, + ReadOnlySpan destRect, + ReadOnlySpan dirtyRects) { - var swapChain = runtime.GetNative(); + var swapChainNative = swapChain.GetNative(); if (this.scene == null) - this.InitScene(swapChain); + this.InitScene(swapChainNative); - if (this.scene?.SwapChain.NativePointer != swapChain) + if (this.scene?.SwapChain.NativePointer != swapChainNative) return; Debug.Assert(this.dalamudAtlas is not null, "this.dalamudAtlas is not null"); diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index eeddb8334..0491fed1e 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -826,7 +826,7 @@ internal partial class InterfaceManager : IInternalDisposableService ReShadeAddonInterface.ReShadeModule!.BaseAddress); this.reShadeAddonInterface.InitSwapChain += this.ReShadeAddonInterfaceOnInitSwapChain; this.reShadeAddonInterface.DestroySwapChain += this.ReShadeAddonInterfaceOnDestroySwapChain; - this.reShadeAddonInterface.ReShadeOverlay += this.ReShadeAddonInterfaceOnReShadeOverlay; + this.reShadeAddonInterface.Present += this.ReShadeAddonInterfaceOnPresent; } else { diff --git a/Dalamud/Interface/Internal/ReShadeHandling/ReShadeAddonInterface.cs b/Dalamud/Interface/Internal/ReShadeHandling/ReShadeAddonInterface.cs index 372928725..cb4c04afa 100644 --- a/Dalamud/Interface/Internal/ReShadeHandling/ReShadeAddonInterface.cs +++ b/Dalamud/Interface/Internal/ReShadeHandling/ReShadeAddonInterface.cs @@ -21,7 +21,7 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable private readonly Hook addonModuleResolverHook; - private readonly DelegateStorage reShadeOverlayDelegate; + private readonly DelegateStorage presentDelegate; private readonly DelegateStorage initSwapChainDelegate; private readonly DelegateStorage destroySwapChainDelegate; @@ -46,8 +46,21 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable { this.addonModuleResolverHook.Enable(); Exports.ReShadeRegisterEvent( - AddonEvent.ReShadeOverlay, - this.reShadeOverlayDelegate = new((ref ApiObject rt) => this.ReShadeOverlay?.Invoke(ref rt))); + AddonEvent.Present, + this.presentDelegate = new( + ( + ref ApiObject commandQueue, + ref ApiObject swapChain, + RECT* pSourceRect, + RECT* pDestRect, + uint dirtyRectCount, + void* pDirtyRects) => + this.Present?.Invoke( + ref commandQueue, + ref swapChain, + pSourceRect is null ? default : new(pSourceRect, 1), + pDestRect is null ? default : new(pDestRect, 1), + new(pDirtyRects, (int)dirtyRectCount)))); Exports.ReShadeRegisterEvent( AddonEvent.InitSwapChain, this.initSwapChainDelegate = new((ref ApiObject rt) => this.InitSwapChain?.Invoke(ref rt))); @@ -79,8 +92,17 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable ~ReShadeAddonInterface() => this.ReleaseUnmanagedResources(); /// Delegate for . - /// Reference to the ReShade runtime. - public delegate void ReShadeOverlayDelegate(ref ApiObject effectRuntime); + /// Current command queue. Type: api::command_queue. + /// Current swap chain. Type: api::swapchain. + /// Optional; source rectangle. May contain up to 1 element. + /// Optional; target rectangle. May contain up to 1 element. + /// Dirty rectangles. + public delegate void PresentDelegate( + ref ApiObject commandQueue, + ref ApiObject swapChain, + ReadOnlySpan sourceRect, + ReadOnlySpan destRect, + ReadOnlySpan dirtyRects); /// Delegate for . /// Reference to the ReShade SwapChain wrapper. @@ -90,10 +112,25 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable /// Reference to the ReShade SwapChain wrapper. public delegate void ReShadeDestroySwapChain(ref ApiObject swapChain); + /// Delegate for . + /// Current command queue. Type: api::command_queue. + /// Current swap chain. Type: api::swapchain. + /// Optional; source rectangle. + /// Optional; target rectangle. + /// Number of dirty rectangles. + /// Optional; dirty rectangles. + private delegate void UnsafePresentDelegate( + ref ApiObject commandQueue, + ref ApiObject swapChain, + RECT* pSourceRect, + RECT* pDestRect, + uint dirtyRectCount, + void* pDirtyRects); + private delegate BOOL GetModuleHandleExWDelegate(uint dwFlags, ushort* lpModuleName, HMODULE* phModule); - /// Called on . - public event ReShadeOverlayDelegate? ReShadeOverlay; + /// Called on . + public event PresentDelegate? Present; /// Called on . public event ReShadeInitSwapChain? InitSwapChain; @@ -144,7 +181,7 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable return this.addonModuleResolverHook.Original(dwFlags, lpModuleName, phModule); if (lpModuleName == this.initSwapChainDelegate || lpModuleName == this.destroySwapChainDelegate || - lpModuleName == this.reShadeOverlayDelegate) + lpModuleName == this.presentDelegate) { *phModule = this.hDalamudModule; return BOOL.TRUE;