From 7a22fa22a7b83aa55bdf10ae264427cb2104145a Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 14 Jun 2018 11:32:10 +0200 Subject: [PATCH] [dxgi] FindClosestMatchingMode: Handle Width/Height = 0 case When an applicationn calls this method with the width or height set to 0, we are allowed to pick any resolution, so we'll try to find one close to the *current* display mode which usually returns the current display mode itself. --- src/dxgi/dxgi_output.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/dxgi/dxgi_output.cpp b/src/dxgi/dxgi_output.cpp index c633d6de..4d3716bb 100644 --- a/src/dxgi/dxgi_output.cpp +++ b/src/dxgi/dxgi_output.cpp @@ -121,19 +121,32 @@ namespace dxvk { if (modes.size() == 0) return DXGI_ERROR_NOT_FOUND; + // If no valid resolution is specified, find the + // closest match for the current display resolution + UINT targetWidth = pModeToMatch->Width; + UINT targetHeight = pModeToMatch->Height; + + if (targetWidth == 0 || targetHeight == 0) { + DXGI_MODE_DESC activeMode; + GetDisplayMode(&activeMode, ENUM_CURRENT_SETTINGS); + + targetWidth = activeMode.Width; + targetHeight = activeMode.Height; + } + // Select mode with minimal height+width difference UINT minDifference = std::numeric_limits::max(); for (auto& mode : modes) { - UINT currDifference = std::abs(int(pModeToMatch->Width - mode.Width)) - + std::abs(int(pModeToMatch->Height - mode.Height)); + UINT currDifference = std::abs(int(targetWidth - mode.Width)) + + std::abs(int(targetHeight - mode.Height)); if (currDifference <= minDifference) { minDifference = currDifference; *pClosestMatch = mode; } } - + return S_OK; }