From 5e41e00456a9ad03ed8565bb0159e01d43bcdf0c Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 4 Mar 2020 11:33:38 +0100 Subject: [PATCH] [d3d9] Use new common monitor functions --- src/d3d9/d3d9_adapter.cpp | 19 ++----------- src/d3d9/d3d9_monitor.cpp | 42 ----------------------------- src/d3d9/d3d9_monitor.h | 11 -------- src/d3d9/d3d9_swapchain.cpp | 54 +++++++++++++++---------------------- src/d3d9/d3d9_swapchain.h | 4 --- 5 files changed, 24 insertions(+), 106 deletions(-) diff --git a/src/d3d9/d3d9_adapter.cpp b/src/d3d9/d3d9_adapter.cpp index 7c5e60b6..2cab599c 100644 --- a/src/d3d9/d3d9_adapter.cpp +++ b/src/d3d9/d3d9_adapter.cpp @@ -674,16 +674,10 @@ namespace dxvk { if (pRotation != nullptr) *pRotation = D3DDISPLAYROTATION_IDENTITY; - MONITORINFOEXW monInfo = { }; - monInfo.cbSize = sizeof(monInfo); - - if (!::GetMonitorInfoW(GetDefaultMonitor(), reinterpret_cast(&monInfo))) - throw DxvkError("D3D9Adapter::GetAdapterDisplayModeEx: Failed to query monitor info"); - DEVMODEW devMode = DEVMODEW(); devMode.dmSize = sizeof(devMode); - if (!::EnumDisplaySettingsW(monInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode)) { + if (!GetMonitorDisplayMode(GetDefaultMonitor(), ENUM_CURRENT_SETTINGS, &devMode)) { Logger::err("D3D9Adapter::GetAdapterDisplayModeEx: Failed to enum display settings"); return D3DERR_INVALIDCALL; } @@ -694,7 +688,6 @@ namespace dxvk { pMode->RefreshRate = devMode.dmDisplayFrequency; pMode->Format = D3DFMT_X8R8G8B8; pMode->ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE; - return D3D_OK; } @@ -758,14 +751,6 @@ namespace dxvk { if (!m_modes.empty() && m_modeCacheFormat == Format) return; // We already cached the modes for this format. No need to do it again. - ::MONITORINFOEXW monInfo; - monInfo.cbSize = sizeof(monInfo); - - if (!::GetMonitorInfoW(GetDefaultMonitor(), reinterpret_cast(&monInfo))) { - Logger::err("D3D9Adapter::CacheModes: failed to query monitor info"); - return; - } - m_modes.clear(); m_modeCacheFormat = Format; @@ -784,7 +769,7 @@ namespace dxvk { const auto forcedRatio = Ratio(options.forceAspectRatio); - while (::EnumDisplaySettingsW(monInfo.szDevice, modeIndex++, &devMode)) { + while (GetMonitorDisplayMode(GetDefaultMonitor(), modeIndex++, &devMode)) { // Skip interlaced modes altogether if (devMode.dmDisplayFlags & DM_INTERLACED) continue; diff --git a/src/d3d9/d3d9_monitor.cpp b/src/d3d9/d3d9_monitor.cpp index ba7513fa..9d9812ab 100644 --- a/src/d3d9/d3d9_monitor.cpp +++ b/src/d3d9/d3d9_monitor.cpp @@ -59,46 +59,4 @@ namespace dxvk { || BackBufferFormat == D3D9Format::R5G6B5; } - - HRESULT SetMonitorDisplayMode( - HMONITOR hMonitor, - const D3DDISPLAYMODEEX* pMode) { - ::MONITORINFOEXW monInfo; - monInfo.cbSize = sizeof(monInfo); - - if (!::GetMonitorInfoW(hMonitor, reinterpret_cast(&monInfo))) { - Logger::err("D3D9: Failed to query monitor info"); - return E_FAIL; - } - - DEVMODEW devMode = { }; - devMode.dmSize = sizeof(devMode); - devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - devMode.dmPelsWidth = pMode->Width; - devMode.dmPelsHeight = pMode->Height; - devMode.dmBitsPerPel = GetMonitorFormatBpp(EnumerateFormat(pMode->Format)); - - if (pMode->RefreshRate != 0) { - devMode.dmFields |= DM_DISPLAYFREQUENCY; - devMode.dmDisplayFrequency = pMode->RefreshRate; - } - - Logger::info(str::format("D3D9: Setting display mode: ", - devMode.dmPelsWidth, "x", devMode.dmPelsHeight, "@", - devMode.dmDisplayFrequency)); - - LONG status = ::ChangeDisplaySettingsExW( - monInfo.szDevice, &devMode, nullptr, CDS_FULLSCREEN, nullptr); - - if (status != DISP_CHANGE_SUCCESSFUL) { - // Try again but without setting the frequency. - devMode.dmFields &= ~DM_DISPLAYFREQUENCY; - devMode.dmDisplayFrequency = 0; - status = ::ChangeDisplaySettingsExW( - monInfo.szDevice, &devMode, nullptr, CDS_FULLSCREEN, nullptr); - } - - return status == DISP_CHANGE_SUCCESSFUL ? D3D_OK : D3DERR_NOTAVAILABLE; - } - } \ No newline at end of file diff --git a/src/d3d9/d3d9_monitor.h b/src/d3d9/d3d9_monitor.h index ccb3f5b0..3f4f450c 100644 --- a/src/d3d9/d3d9_monitor.h +++ b/src/d3d9/d3d9_monitor.h @@ -35,15 +35,4 @@ namespace dxvk { D3D9Format BackBufferFormat, BOOL Windowed); - /** - * \brief Sets monitor display mode - * - * \param [in] hMonitor Monitor handle - * \param [in] pMode Display mode properties - * \returns S_OK on success - */ - HRESULT SetMonitorDisplayMode( - HMONITOR hMonitor, - const D3DDISPLAYMODEEX* pMode); - } \ No newline at end of file diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp index 0a92ab93..1a08662f 100644 --- a/src/d3d9/d3d9_swapchain.cpp +++ b/src/d3d9/d3d9_swapchain.cpp @@ -32,8 +32,6 @@ namespace dxvk { , m_frameLatencyCap (pDevice->GetOptions()->maxFrameLatency) , m_frameLatencySignal(new sync::Fence(m_frameId)) , m_dialog (pDevice->GetOptions()->enableDialogMode) { - UpdateMonitorInfo(); - this->NormalizePresentParameters(pPresentParams); m_presentParams = *pPresentParams; m_window = m_presentParams.hDeviceWindow; @@ -437,7 +435,7 @@ namespace dxvk { DEVMODEW devMode = DEVMODEW(); devMode.dmSize = sizeof(devMode); - if (!::EnumDisplaySettingsW(m_monInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode)) { + if (!GetMonitorDisplayMode(m_monitor, ENUM_CURRENT_SETTINGS, &devMode)) { Logger::err("D3D9SwapChainEx::GetDisplayModeEx: Failed to enum display settings"); return D3DERR_INVALIDCALL; } @@ -1277,7 +1275,6 @@ namespace dxvk { SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE); m_monitor = GetDefaultMonitor(); - return D3D_OK; } @@ -1318,7 +1315,9 @@ namespace dxvk { const D3DDISPLAYMODEEX* pFullscreenDisplayMode) { D3DDISPLAYMODEEX mode; - if (pFullscreenDisplayMode == nullptr) { + if (pFullscreenDisplayMode) { + mode = *pFullscreenDisplayMode; + } else { mode.Width = pPresentParams->BackBufferWidth; mode.Height = pPresentParams->BackBufferHeight; mode.Format = pPresentParams->BackBufferFormat; @@ -1327,7 +1326,21 @@ namespace dxvk { mode.Size = sizeof(D3DDISPLAYMODEEX); } - return SetMonitorDisplayMode(GetDefaultMonitor(), pFullscreenDisplayMode == nullptr ? &mode : pFullscreenDisplayMode); + DEVMODEW devMode = { }; + devMode.dmSize = sizeof(devMode); + devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; + devMode.dmPelsWidth = mode.Width; + devMode.dmPelsHeight = mode.Height; + devMode.dmBitsPerPel = GetMonitorFormatBpp(EnumerateFormat(mode.Format)); + + if (mode.RefreshRate != 0) { + devMode.dmFields |= DM_DISPLAYFREQUENCY; + devMode.dmDisplayFrequency = mode.RefreshRate; + } + + return SetMonitorDisplayMode(GetDefaultMonitor(), &devMode) + ? D3D_OK + : D3DERR_NOTAVAILABLE; } @@ -1335,25 +1348,9 @@ namespace dxvk { if (hMonitor == nullptr) return D3DERR_INVALIDCALL; - DEVMODEW devMode = { }; - devMode.dmSize = sizeof(devMode); - - if (!::EnumDisplaySettingsW(m_monInfo.szDevice, ENUM_REGISTRY_SETTINGS, &devMode)) - return D3DERR_INVALIDCALL; - - Logger::info(str::format("D3D9: Setting display mode: ", - devMode.dmPelsWidth, "x", devMode.dmPelsHeight, "@", - devMode.dmDisplayFrequency)); - - D3DDISPLAYMODEEX mode; - mode.Width = devMode.dmPelsWidth; - mode.Height = devMode.dmPelsHeight; - mode.RefreshRate = devMode.dmDisplayFrequency; - mode.Format = D3DFMT_X8R8G8B8; // Fix me - mode.ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE; - mode.Size = sizeof(D3DDISPLAYMODEEX); - - return SetMonitorDisplayMode(GetDefaultMonitor(), &mode); + return RestoreMonitorDisplayMode(hMonitor) + ? D3D_OK + : D3DERR_NOTAVAILABLE; } bool D3D9SwapChainEx::UpdatePresentRegion(const RECT* pSourceRect, const RECT* pDestRect) { @@ -1397,13 +1394,6 @@ namespace dxvk { std::max(m_dstRect.bottom - m_dstRect.top, 1u) }; } - void D3D9SwapChainEx::UpdateMonitorInfo() { - m_monInfo.cbSize = sizeof(m_monInfo); - - if (!::GetMonitorInfoW(GetDefaultMonitor(), reinterpret_cast(&m_monInfo))) - throw DxvkError("D3D9SwapChainEx::GetDisplayModeEx: Failed to query monitor info"); - } - VkFullScreenExclusiveEXT D3D9SwapChainEx::PickFullscreenMode() { return m_dialog diff --git a/src/d3d9/d3d9_swapchain.h b/src/d3d9/d3d9_swapchain.h index c4350a02..fded7fd7 100644 --- a/src/d3d9/d3d9_swapchain.h +++ b/src/d3d9/d3d9_swapchain.h @@ -152,8 +152,6 @@ namespace dxvk { HWND m_window = nullptr; HMONITOR m_monitor = nullptr; - MONITORINFOEXW m_monInfo; - WindowState m_windowState; void PresentImage(UINT PresentInterval); @@ -215,8 +213,6 @@ namespace dxvk { HRESULT RestoreDisplayMode(HMONITOR hMonitor); - void UpdateMonitorInfo(); - bool UpdatePresentRegion(const RECT* pSourceRect, const RECT* pDestRect); VkExtent2D GetPresentExtent();