From: "Gabriel Ivăncescu" Subject: [PATCH v2 2/3] dxgi: Exit fullscreen state during Present if the window is no longer topmost. Message-Id: <993867adb9d714522d26dee85f3615999b58ae42.1611929223.git.gabrielopcode@gmail.com> Date: Fri, 29 Jan 2021 16:08:23 +0200 In-Reply-To: <7080f41da892a95a35455976640aebfdca4378c4.1611929223.git.gabrielopcode@gmail.com> References: <7080f41da892a95a35455976640aebfdca4378c4.1611929223.git.gabrielopcode@gmail.com> Signed-off-by: Gabriel Ivăncescu --- dlls/dxgi/swapchain.c | 20 +++++++++++++++++++- dlls/dxgi/tests/dxgi.c | 8 ++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dlls/dxgi/swapchain.c b/dlls/dxgi/swapchain.c index 82e5fbf..5611c83 100644 --- a/dlls/dxgi/swapchain.c +++ b/dlls/dxgi/swapchain.c @@ -328,13 +328,31 @@ static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetDevice(IDXGISwapChain1 *ifac static HRESULT d3d11_swapchain_present(struct d3d11_swapchain *swapchain, unsigned int sync_interval, unsigned int flags) { + HWND hwnd = d3d11_swapchain_get_hwnd(swapchain); + BOOL fullscreen; + HRESULT hr; + if (sync_interval > 4) { WARN("Invalid sync interval %u.\n", sync_interval); return DXGI_ERROR_INVALID_CALL; } - if (IsIconic(d3d11_swapchain_get_hwnd(swapchain))) + if (IsWindowVisible(hwnd)) + { + hr = IDXGISwapChain1_GetFullscreenState(&swapchain->IDXGISwapChain1_iface, &fullscreen, NULL); + if (FAILED(hr)) + return hr; + + if (fullscreen && !(GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) + { + if (!(flags & DXGI_PRESENT_TEST)) + IDXGISwapChain1_SetFullscreenState(&swapchain->IDXGISwapChain1_iface, FALSE, NULL); + return DXGI_STATUS_OCCLUDED; + } + } + + if (IsIconic(hwnd)) return DXGI_STATUS_OCCLUDED; if (flags & ~DXGI_PRESENT_TEST) diff --git a/dlls/dxgi/tests/dxgi.c b/dlls/dxgi/tests/dxgi.c index 6c9f293..24bfad8 100644 --- a/dlls/dxgi/tests/dxgi.c +++ b/dlls/dxgi/tests/dxgi.c @@ -2854,7 +2854,7 @@ static void test_set_fullscreen(IUnknown *device, BOOL is_d3d12) ok(!!fullscreen, "Got unexpected fullscreen %#x.\n", fullscreen); hr = IDXGISwapChain_Present(swapchain, 0, DXGI_PRESENT_TEST); - todo_wine ok(hr == DXGI_STATUS_OCCLUDED, "Got unexpected hr %#x.\n", hr); + ok(hr == DXGI_STATUS_OCCLUDED, "Got unexpected hr %#x.\n", hr); hr = IDXGISwapChain_GetFullscreenState(swapchain, &fullscreen, NULL); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ok(!!fullscreen, "Got unexpected fullscreen %#x.\n", fullscreen); @@ -2865,13 +2865,13 @@ static void test_set_fullscreen(IUnknown *device, BOOL is_d3d12) ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); ok(!!fullscreen, "Got unexpected fullscreen %#x.\n", fullscreen); hr = IDXGISwapChain_Present(swapchain, 0, 0); - todo_wine ok(hr == DXGI_STATUS_OCCLUDED, "Got unexpected hr %#x.\n", hr); + ok(hr == DXGI_STATUS_OCCLUDED, "Got unexpected hr %#x.\n", hr); hr = IDXGISwapChain_GetFullscreenState(swapchain, &fullscreen, NULL); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); - todo_wine ok(!fullscreen, "Got unexpected fullscreen %#x.\n", fullscreen); + ok(!fullscreen, "Got unexpected fullscreen %#x.\n", fullscreen); hr = IDXGISwapChain_ResizeBuffers(swapchain, 0, 0, 0, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); - todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); hr = IDXGISwapChain_Present(swapchain, 0, 0); ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); hr = IDXGISwapChain_SetFullscreenState(swapchain, FALSE, NULL); -- 2.29.2