port from perforce
This commit is contained in:
52
intromat/Intromat/Graphics/DebugInterface.cs
Normal file
52
intromat/Intromat/Graphics/DebugInterface.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Intromat.DXExt;
|
||||
using SharpDX;
|
||||
|
||||
namespace Intromat.Graphics
|
||||
{
|
||||
internal static class DebugInterface
|
||||
{
|
||||
[Flags]
|
||||
public enum LoadLibraryFlags : uint
|
||||
{
|
||||
LoadLibrarySearchSystem32 = 0x00000800
|
||||
}
|
||||
|
||||
private static readonly GetDebugInterface? getDebugInterface;
|
||||
|
||||
static DebugInterface()
|
||||
{
|
||||
var moduleHandle = LoadLibraryEx("dxgi.dll", IntPtr.Zero, LoadLibraryFlags.LoadLibrarySearchSystem32);
|
||||
if (moduleHandle != IntPtr.Zero)
|
||||
{
|
||||
var procedureHandle = GetProcAddress(moduleHandle, "DXGIGetDebugInterface1");
|
||||
if (procedureHandle != IntPtr.Zero)
|
||||
getDebugInterface = (GetDebugInterface)Marshal.GetDelegateForFunctionPointer(procedureHandle, typeof(GetDebugInterface));
|
||||
}
|
||||
}
|
||||
|
||||
public static GraphicsAnalysis? TryCreateGraphicsAnalysis()
|
||||
{
|
||||
if (getDebugInterface == null)
|
||||
return null;
|
||||
|
||||
var guid = typeof(GraphicsAnalysis).GetTypeInfo().GUID;
|
||||
var result = getDebugInterface(0, ref guid, out var comPtr);
|
||||
if (result.Failure)
|
||||
return null;
|
||||
|
||||
return comPtr != IntPtr.Zero ? (GraphicsAnalysis)comPtr : null;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
private delegate Result GetDebugInterface(uint flags, ref Guid guid, out IntPtr result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user