From 014870b1ffb79863465c72b0e231c673f4ca777b Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 26 May 2019 19:30:06 +0100 Subject: [PATCH] [util] Add helpers for GDI/DDI interop --- src/util/meson.build | 1 + src/util/util_gdi.cpp | 33 +++++++++++++++++++++++++++++++++ src/util/util_gdi.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/util/util_gdi.cpp create mode 100644 src/util/util_gdi.h diff --git a/src/util/meson.build b/src/util/meson.build index 50583f23c..1a18d834e 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -1,6 +1,7 @@ util_src = files([ 'util_env.cpp', 'util_string.cpp', + 'util_gdi.cpp', 'com/com_guid.cpp', 'com/com_private_data.cpp', diff --git a/src/util/util_gdi.cpp b/src/util/util_gdi.cpp new file mode 100644 index 000000000..901dd05ca --- /dev/null +++ b/src/util/util_gdi.cpp @@ -0,0 +1,33 @@ +#include "util_gdi.h" +#include "log/log.h" + +namespace dxvk { + + HMODULE GetGDIModule() { + static HMODULE module = LoadLibraryA("gdi32.dll"); + return module; + } + + NTSTATUS D3DKMTCreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY* Arg1) { + static auto func = (D3DKMTCreateDCFromMemoryType) + GetProcAddress(GetGDIModule(), "D3DKMTCreateDCFromMemory"); + + if (func != nullptr) + return func(Arg1); + + Logger::warn("D3DKMTCreateDCFromMemory: Unable to query proc address."); + return -1; + } + + NTSTATUS D3DKMTDestroyDCFromMemory(D3DKMT_DESTROYDCFROMMEMORY* Arg1) { + static auto func = (D3DKMTDestroyDCFromMemoryType) + GetProcAddress(GetGDIModule(), "D3DKMTDestroyDCFromMemory"); + + if (func != nullptr) + return func(Arg1); + + Logger::warn("D3DKMTDestroyDCFromMemory: Unable to query proc address."); + return -1; + } + +} \ No newline at end of file diff --git a/src/util/util_gdi.h b/src/util/util_gdi.h new file mode 100644 index 000000000..58724b155 --- /dev/null +++ b/src/util/util_gdi.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +namespace dxvk { + using NTSTATUS = LONG; + + // Slightly modified definitions... + struct D3DKMT_CREATEDCFROMMEMORY { + void* pMemory; + D3DFORMAT Format; + UINT Width; + UINT Height; + UINT Pitch; + HDC hDeviceDc; + PALETTEENTRY* pColorTable; + HDC hDc; + HANDLE hBitmap; + }; + + struct D3DKMT_DESTROYDCFROMMEMORY { + HDC hDC = nullptr; + HANDLE hBitmap = nullptr; + }; + + using D3DKMTCreateDCFromMemoryType = NTSTATUS(STDMETHODCALLTYPE*) (D3DKMT_CREATEDCFROMMEMORY*); + NTSTATUS D3DKMTCreateDCFromMemory (D3DKMT_CREATEDCFROMMEMORY* Arg1); + + using D3DKMTDestroyDCFromMemoryType = NTSTATUS(STDMETHODCALLTYPE*) (D3DKMT_DESTROYDCFROMMEMORY*); + NTSTATUS D3DKMTDestroyDCFromMemory(D3DKMT_DESTROYDCFROMMEMORY* Arg1); + +} \ No newline at end of file