From d9cf8fdc585fae7165281a4c742479a2c0389e34 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 11 Dec 2018 15:57:09 +0100 Subject: [PATCH] [dxgi] Use new mode switch API for DxgiSwapChain --- src/dxgi/dxgi_swapchain.cpp | 33 +++++++++++++-------------------- src/dxgi/dxgi_swapchain.h | 2 +- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index aebecf2e5..024a6f356 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -43,10 +43,7 @@ namespace dxvk { DxgiSwapChain::~DxgiSwapChain() { - Com output; - - if (SUCCEEDED(GetOutputFromMonitor(m_monitor, &output))) - RestoreDisplayMode(output.ptr()); + RestoreDisplayMode(m_monitor); // Decouple swap chain from monitor if necessary DXGI_VK_MONITOR_DATA* monitorInfo = nullptr; @@ -584,13 +581,10 @@ namespace dxvk { HRESULT DxgiSwapChain::LeaveFullscreenMode() { - Com output; - if (!IsWindow(m_window)) return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE; - if (FAILED(GetOutputFromMonitor(m_monitor, &output)) - || FAILED(RestoreDisplayMode(output.ptr()))) + if (FAILED(RestoreDisplayMode(m_monitor))) Logger::warn("DXGI: LeaveFullscreenMode: Failed to restore display mode"); // Reset gamma control and decouple swap chain from monitor @@ -633,19 +627,20 @@ namespace dxvk { HRESULT DxgiSwapChain::ChangeDisplayMode( IDXGIOutput* pOutput, const DXGI_MODE_DESC* pDisplayMode) { - auto output = static_cast(pOutput); - - if (output == nullptr) + if (!pOutput) return DXGI_ERROR_INVALID_CALL; // Find a mode that the output supports + DXGI_OUTPUT_DESC outputDesc; + pOutput->GetDesc(&outputDesc); + DXGI_MODE_DESC preferredMode = *pDisplayMode; DXGI_MODE_DESC selectedMode; if (preferredMode.Format == DXGI_FORMAT_UNKNOWN) preferredMode.Format = m_desc.Format; - HRESULT hr = output->FindClosestMatchingMode( + HRESULT hr = pOutput->FindClosestMatchingMode( &preferredMode, &selectedMode, nullptr); if (FAILED(hr)) { @@ -657,26 +652,24 @@ namespace dxvk { return hr; } - return output->SetDisplayMode(&selectedMode); + return SetMonitorDisplayMode(outputDesc.Monitor, &selectedMode); } - HRESULT DxgiSwapChain::RestoreDisplayMode(IDXGIOutput* pOutput) { - auto output = static_cast(pOutput); - - if (output == nullptr) + HRESULT DxgiSwapChain::RestoreDisplayMode(HMONITOR hMonitor) { + if (!hMonitor) return DXGI_ERROR_INVALID_CALL; // Restore registry settings DXGI_MODE_DESC mode; - HRESULT hr = output->GetDisplayMode( - &mode, ENUM_REGISTRY_SETTINGS); + HRESULT hr = GetMonitorDisplayMode( + hMonitor, ENUM_REGISTRY_SETTINGS, &mode); if (FAILED(hr)) return hr; - return output->SetDisplayMode(&mode); + return SetMonitorDisplayMode(hMonitor, &mode); } diff --git a/src/dxgi/dxgi_swapchain.h b/src/dxgi/dxgi_swapchain.h index 4b56f3ac4..b18cabc12 100644 --- a/src/dxgi/dxgi_swapchain.h +++ b/src/dxgi/dxgi_swapchain.h @@ -195,7 +195,7 @@ namespace dxvk { const DXGI_MODE_DESC* pDisplayMode); HRESULT RestoreDisplayMode( - IDXGIOutput* pOutput); + HMONITOR hMonitor); HRESULT GetSampleCount( UINT Count,