diff --git a/dlls/dxgi/dxgi_private.h b/dlls/dxgi/dxgi_private.h index 4967bd425f2..f74514f0d32 100644 --- a/dlls/dxgi/dxgi_private.h +++ b/dlls/dxgi/dxgi_private.h @@ -182,6 +182,8 @@ HRESULT d3d12_swapchain_create(IWineDXGIFactory *factory, ID3D12CommandQueue *qu const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc, const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc, IDXGISwapChain1 **swapchain) DECLSPEC_HIDDEN; +BOOL dxgi_validate_swapchain_desc(const DXGI_SWAP_CHAIN_DESC1 *desc) DECLSPEC_HIDDEN; + /* IDXGISurface */ struct dxgi_surface { diff --git a/dlls/dxgi/factory.c b/dlls/dxgi/factory.c index cc9075afc22..a4577ae278f 100644 --- a/dlls/dxgi/factory.c +++ b/dlls/dxgi/factory.c @@ -251,7 +251,6 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChainForHwnd(IWineDXGIFa IDXGIOutput *output, IDXGISwapChain1 **swapchain) { ID3D12CommandQueue *command_queue; - unsigned int min_buffer_count; IWineDXGIDevice *dxgi_device; HRESULT hr; @@ -270,35 +269,8 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChainForHwnd(IWineDXGIFa return DXGI_ERROR_UNSUPPORTED; } - switch (desc->SwapEffect) - { - case DXGI_SWAP_EFFECT_DISCARD: - case DXGI_SWAP_EFFECT_SEQUENTIAL: - min_buffer_count = 1; - break; - - case DXGI_SWAP_EFFECT_FLIP_DISCARD: - case DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL: - min_buffer_count = 2; - - if (desc->SampleDesc.Count != 1 || desc->SampleDesc.Quality) - { - WARN("Invalid sample desc %u, %u for swap effect %#x.\n", - desc->SampleDesc.Count, desc->SampleDesc.Quality, desc->SwapEffect); - return DXGI_ERROR_INVALID_CALL; - } - break; - - default: - WARN("Invalid swap effect %u used.\n", desc->SwapEffect); - return DXGI_ERROR_INVALID_CALL; - } - - if (desc->BufferCount < min_buffer_count || desc->BufferCount > DXGI_MAX_SWAP_CHAIN_BUFFERS) - { - WARN("BufferCount is %u.\n", desc->BufferCount); + if (!dxgi_validate_swapchain_desc(desc)) return DXGI_ERROR_INVALID_CALL; - } if (output) FIXME("Ignoring output %p.\n", output); diff --git a/dlls/dxgi/swapchain.c b/dlls/dxgi/swapchain.c index f8e4f8078e7..57d6b245c45 100644 --- a/dlls/dxgi/swapchain.c +++ b/dlls/dxgi/swapchain.c @@ -55,6 +55,43 @@ static DXGI_SWAP_EFFECT dxgi_swap_effect_from_wined3d(enum wined3d_swap_effect s } } +BOOL dxgi_validate_swapchain_desc(const DXGI_SWAP_CHAIN_DESC1 *desc) +{ + unsigned int min_buffer_count; + + switch (desc->SwapEffect) + { + case DXGI_SWAP_EFFECT_DISCARD: + case DXGI_SWAP_EFFECT_SEQUENTIAL: + min_buffer_count = 1; + break; + + case DXGI_SWAP_EFFECT_FLIP_DISCARD: + case DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL: + min_buffer_count = 2; + + if (desc->SampleDesc.Count != 1 || desc->SampleDesc.Quality) + { + WARN("Invalid sample desc %u, %u for swap effect %#x.\n", + desc->SampleDesc.Count, desc->SampleDesc.Quality, desc->SwapEffect); + return FALSE; + } + break; + + default: + WARN("Invalid swap effect %u used.\n", desc->SwapEffect); + return FALSE; + } + + if (desc->BufferCount < min_buffer_count || desc->BufferCount > DXGI_MAX_SWAP_CHAIN_BUFFERS) + { + WARN("BufferCount is %u.\n", desc->BufferCount); + return FALSE; + } + + return TRUE; +} + static inline struct d3d11_swapchain *d3d11_swapchain_from_IDXGISwapChain1(IDXGISwapChain1 *iface) { return CONTAINING_RECORD(iface, struct d3d11_swapchain, IDXGISwapChain1_iface);