From fe5e215dfc116c18cf5ac19e3588fcb90fdb399b Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 16 Jul 2018 17:00:23 +0200 Subject: [PATCH] [dxgi] Support multiple outputs per adapter --- src/dxgi/dxgi_adapter.cpp | 33 ++++++++++++++++++++++++++------- src/dxgi/dxgi_adapter.h | 11 +++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 83b3e3ec2..ac5463715 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -143,14 +143,18 @@ namespace dxvk { if (ppOutput == nullptr) return E_INVALIDARG; - if (Output > 0) { - *ppOutput = nullptr; - return DXGI_ERROR_NOT_FOUND; - } + MonitorEnumInfo info; + info.iMonitorId = Output; + info.oMonitor = nullptr; - // TODO support multiple monitors - HMONITOR monitor = ::MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY); - *ppOutput = ref(new DxgiOutput(m_factory, this, monitor)); + ::EnumDisplayMonitors( + nullptr, nullptr, &MonitorEnumProc, + reinterpret_cast(&info)); + + if (info.oMonitor == nullptr) + return DXGI_ERROR_NOT_FOUND; + + *ppOutput = ref(new DxgiOutput(m_factory, this, info.oMonitor)); return S_OK; } @@ -458,4 +462,19 @@ namespace dxvk { } } + + BOOL CALLBACK DxgiAdapter::MonitorEnumProc( + HMONITOR hmon, + HDC hdc, + LPRECT rect, + LPARAM lp) { + auto data = reinterpret_cast(lp); + + if (data->iMonitorId--) + return TRUE; /* continue */ + + data->oMonitor = hmon; + return FALSE; /* stop */ + } + } diff --git a/src/dxgi/dxgi_adapter.h b/src/dxgi/dxgi_adapter.h index a0c8bc903..af3e47166 100644 --- a/src/dxgi/dxgi_adapter.h +++ b/src/dxgi/dxgi_adapter.h @@ -124,6 +124,17 @@ namespace dxvk { void runEventThread(); + struct MonitorEnumInfo { + UINT iMonitorId; + HMONITOR oMonitor; + }; + + static BOOL CALLBACK MonitorEnumProc( + HMONITOR hmon, + HDC hdc, + LPRECT rect, + LPARAM lp); + }; }