From 15078357dc4d2adf1100a21bbcc20de762bbb03e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 21 Dec 2018 15:14:07 +0100 Subject: [PATCH] [dxgi] Implement and use GetWindowClientSize fuction This new function provides a cleaner way to retrieve a window's client size and can be used outside the swap chain functions. --- src/dxgi/dxgi_monitor.cpp | 15 +++++++++++++++ src/dxgi/dxgi_monitor.h | 12 ++++++++++++ src/dxgi/dxgi_swapchain.cpp | 30 +++++++++--------------------- src/dxgi/dxgi_swapchain.h | 2 -- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/dxgi/dxgi_monitor.cpp b/src/dxgi/dxgi_monitor.cpp index 9af164ad..9227b1a7 100644 --- a/src/dxgi/dxgi_monitor.cpp +++ b/src/dxgi/dxgi_monitor.cpp @@ -127,5 +127,20 @@ namespace dxvk { return status == DISP_CHANGE_SUCCESSFUL ? S_OK : DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;; } + + + void GetWindowClientSize( + HWND hWnd, + UINT* pWidth, + UINT* pHeight) { + RECT rect = { }; + ::GetClientRect(hWnd, &rect); + + if (pWidth) + *pWidth = rect.right - rect.left; + + if (pHeight) + *pHeight = rect.bottom - rect.top; + } } \ No newline at end of file diff --git a/src/dxgi/dxgi_monitor.h b/src/dxgi/dxgi_monitor.h index 281d960c..9e03155a 100644 --- a/src/dxgi/dxgi_monitor.h +++ b/src/dxgi/dxgi_monitor.h @@ -85,5 +85,17 @@ namespace dxvk { HRESULT SetMonitorDisplayMode( HMONITOR hMonitor, const DXGI_MODE_DESC* pMode); + + /** + * \brief Queries window client size + * + * \param [in] hWnd Window to query + * \param [out] pWidth Client width + * \param [out] pHeight Client height + */ + void GetWindowClientSize( + HWND hWnd, + UINT* pWidth, + UINT* pHeight); } \ No newline at end of file diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index 024a6f35..d56eb972 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -24,10 +24,9 @@ namespace dxvk { // Adjust initial back buffer size. If zero, these // shall be set to the current window size. - const VkExtent2D windowSize = GetWindowSize(); - - if (m_desc.Width == 0) m_desc.Width = windowSize.width; - if (m_desc.Height == 0) m_desc.Height = windowSize.height; + GetWindowClientSize(m_window, + m_desc.Width ? nullptr : &m_desc.Width, + m_desc.Height ? nullptr : &m_desc.Height); // Create presenter, which also serves as an interface to the device if (FAILED(CreatePresenter(pDevice, &m_presenter))) @@ -287,11 +286,13 @@ namespace dxvk { if (!IsWindow(m_window)) return DXGI_ERROR_INVALID_CALL; - const VkExtent2D windowSize = GetWindowSize(); - std::lock_guard lock(m_lockBuffer); - m_desc.Width = Width != 0 ? Width : windowSize.width; - m_desc.Height = Height != 0 ? Height : windowSize.height; + m_desc.Width = Width; + m_desc.Height = Height; + + GetWindowClientSize(m_window, + m_desc.Width ? nullptr : &m_desc.Width, + m_desc.Height ? nullptr : &m_desc.Height); if (BufferCount != 0) m_desc.BufferCount = BufferCount; @@ -491,19 +492,6 @@ namespace dxvk { } - VkExtent2D DxgiSwapChain::GetWindowSize() const { - RECT windowRect; - - if (!::GetClientRect(m_window, &windowRect)) - windowRect = RECT(); - - VkExtent2D result; - result.width = windowRect.right; - result.height = windowRect.bottom; - return result; - } - - HRESULT DxgiSwapChain::EnterFullscreenMode(IDXGIOutput* pTarget) { Com output = static_cast(pTarget); diff --git a/src/dxgi/dxgi_swapchain.h b/src/dxgi/dxgi_swapchain.h index b18cabc1..5e7f2eed 100644 --- a/src/dxgi/dxgi_swapchain.h +++ b/src/dxgi/dxgi_swapchain.h @@ -183,8 +183,6 @@ namespace dxvk { HMONITOR m_monitor; WindowState m_windowState; - VkExtent2D GetWindowSize() const; - HRESULT EnterFullscreenMode( IDXGIOutput *pTarget);