mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +01:00
Use ReShade addon event Present (#1970)
This commit is contained in:
parent
def28b37c7
commit
818eec91a0
3 changed files with 64 additions and 20 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
using Dalamud.Interface.Internal.ReShadeHandling;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
||||||
using TerraFX.Interop.DirectX;
|
using TerraFX.Interop.DirectX;
|
||||||
|
using TerraFX.Interop.Windows;
|
||||||
|
|
||||||
namespace Dalamud.Interface.Internal;
|
namespace Dalamud.Interface.Internal;
|
||||||
|
|
||||||
|
|
@ -11,36 +13,41 @@ namespace Dalamud.Interface.Internal;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal partial class InterfaceManager
|
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<IDXGISwapChain>();
|
var swapChainNative = swapChain.GetNative<IDXGISwapChain>();
|
||||||
if (this.scene?.SwapChain.NativePointer != (nint)swapChain)
|
if (this.scene?.SwapChain.NativePointer != (nint)swapChainNative)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.scene?.OnPreResize();
|
this.scene?.OnPreResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void ReShadeAddonInterfaceOnInitSwapChain(ref ReShadeHandling.ReShadeAddonInterface.ApiObject swapchain)
|
private unsafe void ReShadeAddonInterfaceOnInitSwapChain(ref ReShadeAddonInterface.ApiObject swapChain)
|
||||||
{
|
{
|
||||||
var swapChain = swapchain.GetNative<IDXGISwapChain>();
|
var swapChainNative = swapChain.GetNative<IDXGISwapChain>();
|
||||||
if (this.scene?.SwapChain.NativePointer != (nint)swapChain)
|
if (this.scene?.SwapChain.NativePointer != (nint)swapChainNative)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DXGI_SWAP_CHAIN_DESC desc;
|
DXGI_SWAP_CHAIN_DESC desc;
|
||||||
if (swapChain->GetDesc(&desc).FAILED)
|
if (swapChainNative->GetDesc(&desc).FAILED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.scene?.OnPostResize((int)desc.BufferDesc.Width, (int)desc.BufferDesc.Height);
|
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<RECT> sourceRect,
|
||||||
|
ReadOnlySpan<RECT> destRect,
|
||||||
|
ReadOnlySpan<RECT> dirtyRects)
|
||||||
{
|
{
|
||||||
var swapChain = runtime.GetNative();
|
var swapChainNative = swapChain.GetNative();
|
||||||
|
|
||||||
if (this.scene == null)
|
if (this.scene == null)
|
||||||
this.InitScene(swapChain);
|
this.InitScene(swapChainNative);
|
||||||
|
|
||||||
if (this.scene?.SwapChain.NativePointer != swapChain)
|
if (this.scene?.SwapChain.NativePointer != swapChainNative)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Assert(this.dalamudAtlas is not null, "this.dalamudAtlas is not null");
|
Debug.Assert(this.dalamudAtlas is not null, "this.dalamudAtlas is not null");
|
||||||
|
|
|
||||||
|
|
@ -826,7 +826,7 @@ internal partial class InterfaceManager : IInternalDisposableService
|
||||||
ReShadeAddonInterface.ReShadeModule!.BaseAddress);
|
ReShadeAddonInterface.ReShadeModule!.BaseAddress);
|
||||||
this.reShadeAddonInterface.InitSwapChain += this.ReShadeAddonInterfaceOnInitSwapChain;
|
this.reShadeAddonInterface.InitSwapChain += this.ReShadeAddonInterfaceOnInitSwapChain;
|
||||||
this.reShadeAddonInterface.DestroySwapChain += this.ReShadeAddonInterfaceOnDestroySwapChain;
|
this.reShadeAddonInterface.DestroySwapChain += this.ReShadeAddonInterfaceOnDestroySwapChain;
|
||||||
this.reShadeAddonInterface.ReShadeOverlay += this.ReShadeAddonInterfaceOnReShadeOverlay;
|
this.reShadeAddonInterface.Present += this.ReShadeAddonInterfaceOnPresent;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
|
||||||
|
|
||||||
private readonly Hook<GetModuleHandleExWDelegate> addonModuleResolverHook;
|
private readonly Hook<GetModuleHandleExWDelegate> addonModuleResolverHook;
|
||||||
|
|
||||||
private readonly DelegateStorage<ReShadeOverlayDelegate> reShadeOverlayDelegate;
|
private readonly DelegateStorage<UnsafePresentDelegate> presentDelegate;
|
||||||
private readonly DelegateStorage<ReShadeInitSwapChain> initSwapChainDelegate;
|
private readonly DelegateStorage<ReShadeInitSwapChain> initSwapChainDelegate;
|
||||||
private readonly DelegateStorage<ReShadeDestroySwapChain> destroySwapChainDelegate;
|
private readonly DelegateStorage<ReShadeDestroySwapChain> destroySwapChainDelegate;
|
||||||
|
|
||||||
|
|
@ -46,8 +46,21 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
|
||||||
{
|
{
|
||||||
this.addonModuleResolverHook.Enable();
|
this.addonModuleResolverHook.Enable();
|
||||||
Exports.ReShadeRegisterEvent(
|
Exports.ReShadeRegisterEvent(
|
||||||
AddonEvent.ReShadeOverlay,
|
AddonEvent.Present,
|
||||||
this.reShadeOverlayDelegate = new((ref ApiObject rt) => this.ReShadeOverlay?.Invoke(ref rt)));
|
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(
|
Exports.ReShadeRegisterEvent(
|
||||||
AddonEvent.InitSwapChain,
|
AddonEvent.InitSwapChain,
|
||||||
this.initSwapChainDelegate = new((ref ApiObject rt) => this.InitSwapChain?.Invoke(ref rt)));
|
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();
|
~ReShadeAddonInterface() => this.ReleaseUnmanagedResources();
|
||||||
|
|
||||||
/// <summary>Delegate for <see cref="ReShadeAddonInterface.AddonEvent.ReShadeOverlay"/>.</summary>
|
/// <summary>Delegate for <see cref="ReShadeAddonInterface.AddonEvent.ReShadeOverlay"/>.</summary>
|
||||||
/// <param name="effectRuntime">Reference to the ReShade runtime.</param>
|
/// <param name="commandQueue">Current command queue. Type: <c>api::command_queue</c>.</param>
|
||||||
public delegate void ReShadeOverlayDelegate(ref ApiObject effectRuntime);
|
/// <param name="swapChain">Current swap chain. Type: <c>api::swapchain</c>.</param>
|
||||||
|
/// <param name="sourceRect">Optional; source rectangle. May contain up to 1 element.</param>
|
||||||
|
/// <param name="destRect">Optional; target rectangle. May contain up to 1 element.</param>
|
||||||
|
/// <param name="dirtyRects">Dirty rectangles.</param>
|
||||||
|
public delegate void PresentDelegate(
|
||||||
|
ref ApiObject commandQueue,
|
||||||
|
ref ApiObject swapChain,
|
||||||
|
ReadOnlySpan<RECT> sourceRect,
|
||||||
|
ReadOnlySpan<RECT> destRect,
|
||||||
|
ReadOnlySpan<RECT> dirtyRects);
|
||||||
|
|
||||||
/// <summary>Delegate for <see cref="ReShadeAddonInterface.AddonEvent.InitSwapChain"/>.</summary>
|
/// <summary>Delegate for <see cref="ReShadeAddonInterface.AddonEvent.InitSwapChain"/>.</summary>
|
||||||
/// <param name="swapChain">Reference to the ReShade SwapChain wrapper.</param>
|
/// <param name="swapChain">Reference to the ReShade SwapChain wrapper.</param>
|
||||||
|
|
@ -90,10 +112,25 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
|
||||||
/// <param name="swapChain">Reference to the ReShade SwapChain wrapper.</param>
|
/// <param name="swapChain">Reference to the ReShade SwapChain wrapper.</param>
|
||||||
public delegate void ReShadeDestroySwapChain(ref ApiObject swapChain);
|
public delegate void ReShadeDestroySwapChain(ref ApiObject swapChain);
|
||||||
|
|
||||||
|
/// <summary>Delegate for <see cref="ReShadeAddonInterface.AddonEvent.ReShadeOverlay"/>.</summary>
|
||||||
|
/// <param name="commandQueue">Current command queue. Type: <c>api::command_queue</c>.</param>
|
||||||
|
/// <param name="swapChain">Current swap chain. Type: <c>api::swapchain</c>.</param>
|
||||||
|
/// <param name="pSourceRect">Optional; source rectangle.</param>
|
||||||
|
/// <param name="pDestRect">Optional; target rectangle.</param>
|
||||||
|
/// <param name="dirtyRectCount">Number of dirty rectangles.</param>
|
||||||
|
/// <param name="pDirtyRects">Optional; dirty rectangles.</param>
|
||||||
|
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);
|
private delegate BOOL GetModuleHandleExWDelegate(uint dwFlags, ushort* lpModuleName, HMODULE* phModule);
|
||||||
|
|
||||||
/// <summary>Called on <see cref="ReShadeAddonInterface.AddonEvent.ReShadeOverlay"/>.</summary>
|
/// <summary>Called on <see cref="ReShadeAddonInterface.AddonEvent.Present"/>.</summary>
|
||||||
public event ReShadeOverlayDelegate? ReShadeOverlay;
|
public event PresentDelegate? Present;
|
||||||
|
|
||||||
/// <summary>Called on <see cref="ReShadeAddonInterface.AddonEvent.InitSwapChain"/>.</summary>
|
/// <summary>Called on <see cref="ReShadeAddonInterface.AddonEvent.InitSwapChain"/>.</summary>
|
||||||
public event ReShadeInitSwapChain? InitSwapChain;
|
public event ReShadeInitSwapChain? InitSwapChain;
|
||||||
|
|
@ -144,7 +181,7 @@ internal sealed unsafe partial class ReShadeAddonInterface : IDisposable
|
||||||
return this.addonModuleResolverHook.Original(dwFlags, lpModuleName, phModule);
|
return this.addonModuleResolverHook.Original(dwFlags, lpModuleName, phModule);
|
||||||
if (lpModuleName == this.initSwapChainDelegate ||
|
if (lpModuleName == this.initSwapChainDelegate ||
|
||||||
lpModuleName == this.destroySwapChainDelegate ||
|
lpModuleName == this.destroySwapChainDelegate ||
|
||||||
lpModuleName == this.reShadeOverlayDelegate)
|
lpModuleName == this.presentDelegate)
|
||||||
{
|
{
|
||||||
*phModule = this.hDalamudModule;
|
*phModule = this.hDalamudModule;
|
||||||
return BOOL.TRUE;
|
return BOOL.TRUE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue