From 4fe2a43f00ab66285d446e91c9e07f60dc16e0f2 Mon Sep 17 00:00:00 2001 From: derrod Date: Wed, 1 Feb 2023 22:53:29 +0100 Subject: [PATCH] libobs-d3d11: Log display DPI --- libobs-d3d11/CMakeLists.txt | 2 +- libobs-d3d11/d3d11-subsystem.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libobs-d3d11/CMakeLists.txt b/libobs-d3d11/CMakeLists.txt index 322fe9a59..8e67d6593 100644 --- a/libobs-d3d11/CMakeLists.txt +++ b/libobs-d3d11/CMakeLists.txt @@ -45,7 +45,7 @@ else() GPU_PRIORITY_VAL=${GPU_PRIORITY_VAL}) endif() -target_link_libraries(libobs-d3d11 PRIVATE OBS::libobs d3d9 d3d11 dxgi) +target_link_libraries(libobs-d3d11 PRIVATE OBS::libobs d3d9 d3d11 dxgi shcore) set_target_properties( libobs-d3d11 diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 4028bcc5a..d83a94f48 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -25,6 +25,7 @@ #include #include #include "d3d11-subsystem.hpp" +#include struct UnsupportedHWError : HRError { inline UnsupportedHWError(const char *str, HRESULT hr) @@ -1253,6 +1254,16 @@ static inline void LogAdapterMonitors(IDXGIAdapter1 *adapter) (unsigned)type); } + // These are always identical, but you still have to supply both, thanks Microsoft! + UINT dpiX, dpiY; + unsigned scaling = 100; + if (GetDpiForMonitor(desc.Monitor, MDT_EFFECTIVE_DPI, &dpiX, + &dpiY) == S_OK) { + scaling = (unsigned)(dpiX * 100.0f / 96.0f); + } else { + dpiX = 0; + } + const RECT &rect = desc.DesktopCoordinates; const ULONG nits = GetSdrWhiteNits(desc.Monitor); blog(LOG_INFO, @@ -1265,12 +1276,13 @@ static inline void LogAdapterMonitors(IDXGIAdapter1 *adapter) "\t bits_per_color=%u\n" "\t space=%s\n" "\t sdr_white_nits=%lu\n" - "\t nit_range=[min=%f, max=%f, max_full_frame=%f]", + "\t nit_range=[min=%f, max=%f, max_full_frame=%f]\n" + "\t dpi=%u (%u%%)", i, target.monitorFriendlyDeviceName, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, desc.AttachedToDesktop ? "true" : "false", refresh, bits_per_color, space, nits, min_luminance, max_luminance, - max_full_frame_luminance); + max_full_frame_luminance, dpiX, scaling); } }