From 8b6a7a9c02d048949cf4b0e9b72494213d55ead2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Tue, 25 Nov 2014 10:16:54 +0100 Subject: [PATCH] d3d9: Only one fullscreen swapchain is allowed. --- dlls/d3d9/device.c | 25 +++++++++++++++++++++++++ dlls/d3d9/tests/device.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index ca902a238f..67a5629908 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -503,11 +503,36 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_CreateAdditionalSwapChain(ID struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct wined3d_swapchain_desc desc; struct d3d9_swapchain *object; + UINT i, count; HRESULT hr; TRACE("iface %p, present_parameters %p, swapchain %p.\n", iface, present_parameters, swapchain); + if (!present_parameters->Windowed) + { + WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } + + wined3d_mutex_lock(); + count = wined3d_device_get_swapchain_count(device->wined3d_device); + for (i = 0; i < count; ++i) + { + struct wined3d_swapchain *wined3d_swapchain; + + wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, i); + wined3d_swapchain_get_desc(wined3d_swapchain, &desc); + + if (!desc.windowed) + { + wined3d_mutex_unlock(); + WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n"); + return D3DERR_INVALIDCALL; + } + } + wined3d_mutex_unlock(); + wined3d_swapchain_desc_from_present_parameters(&desc, present_parameters); if (SUCCEEDED(hr = d3d9_swapchain_create(device, &desc, &object))) *swapchain = (IDirect3DSwapChain9 *)&object->IDirect3DSwapChain9Ex_iface; diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 35dad62a44..061846b87d 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -1058,12 +1058,16 @@ static void test_swapchain(void) IDirect3DDevice9 *device; IDirect3D9 *d3d; ULONG refcount; - HWND window; + HWND window, window2; HRESULT hr; + struct device_desc device_desc; window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, NULL, NULL, NULL, NULL); ok(!!window, "Failed to create a window.\n"); + window2 = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + ok(!!window2, "Failed to create a window.\n"); d3d = Direct3DCreate9(D3D_SDK_VERSION); ok(!!d3d, "Failed to create a D3D object.\n"); if (!(device = create_device(d3d, window, NULL))) @@ -1176,10 +1180,42 @@ static void test_swapchain(void) IDirect3DSwapChain9_Release(swapchain3); IDirect3DSwapChain9_Release(swapchain2); IDirect3DSwapChain9_Release(swapchain1); + + d3dpp.Windowed = FALSE; + d3dpp.hDeviceWindow = window; + d3dpp.BackBufferCount = 1; + hr = IDirect3DDevice9_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr); + d3dpp.hDeviceWindow = window2; + hr = IDirect3DDevice9_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr); + + device_desc.width = registry_mode.dmPelsWidth; + device_desc.height = registry_mode.dmPelsHeight; + device_desc.device_window = window; + device_desc.flags = CREATE_DEVICE_FULLSCREEN; + hr = reset_device(device, &device_desc); + ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr); + + d3dpp.hDeviceWindow = window; + hr = IDirect3DDevice9_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr); + d3dpp.hDeviceWindow = window2; + hr = IDirect3DDevice9_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr); + d3dpp.Windowed = TRUE; + d3dpp.hDeviceWindow = window; + hr = IDirect3DDevice9_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr); + d3dpp.hDeviceWindow = window2; + hr = IDirect3DDevice9_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr); + refcount = IDirect3DDevice9_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); cleanup: IDirect3D9_Release(d3d); + DestroyWindow(window2); DestroyWindow(window); }