[PATCH 2/4] d3d8/tests: The device restores the mode settings from the registry (v5).
Stefan Dösinger
stefan at codeweavers.com
Thu Nov 6 16:47:20 CST 2014
v5: Test width and height in the same ok statement to prevent accidental
successes inside todo_wine when switching from e.g. 1920x1080 to
1920x1200.
v4: Simplify the mode selection code and (via previous patch) use
EnumDisplaySettingsW(ENUM_REGISTRY_SETTINGS) instead of
GetSystemMetrics(SM_C?SCREEN). Retain the test for mode reset when the
device was originally created with the registry size.
v3: Make the window visible. This works around the failure of 107263 on
the W8 testbot.
The testbot failure (device::release does not restore the mode) happens
on Vista too. This problem only happens if the application is not in
foreground *and* the windows are hidden. If the application is in
foreground, the device properly restores the mode even with (manually)
hidden windows.
This is a preexisting condition, see the failure in line 3051 here:
http://test.winehq.org/data/4bb80afedcca6bdc510574488258ef1a16e4167f/win8_newtb-w8/d3d8:device.html
This patch changes the previous resolution, thus the testbot did not
filter it out.
---
dlls/d3d8/tests/device.c | 158 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 121 insertions(+), 37 deletions(-)
diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c
index 46918e8..9153139 100644
--- a/dlls/d3d8/tests/device.c
+++ b/dlls/d3d8/tests/device.c
@@ -2982,56 +2982,119 @@ static void test_unsupported_shaders(void)
static void test_mode_change(void)
{
- RECT fullscreen_rect, focus_rect, r;
+ RECT d3d_rect, focus_rect, r;
struct device_desc device_desc;
IDirect3DSurface8 *backbuffer;
IDirect3DDevice8 *device;
D3DSURFACE_DESC desc;
IDirect3D8 *d3d8;
DEVMODEW devmode;
- UINT refcount;
+ ULONG refcount;
+ UINT adapter_mode_count, i;
HRESULT hr;
- DWORD ret;
+ BOOL ret;
+ LONG change_ret;
+ D3DDISPLAYMODE d3ddm;
+ DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
- focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
- 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
- device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
- 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
ok(!!d3d8, "Failed to create a D3D object.\n");
- SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
+ adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
+ for (i = 0; i < adapter_mode_count; ++i)
+ {
+ hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
+ ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
+
+ if (d3ddm.Format != D3DFMT_X8R8G8B8)
+ continue;
+ if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
+ continue;
+ /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
+ * refuses to create a device at these sizes. */
+ if (d3ddm.Width < 640 || d3ddm.Height < 480)
+ continue;
+
+ if (!user32_width)
+ {
+ user32_width = d3ddm.Width;
+ user32_height = d3ddm.Height;
+ continue;
+ }
+
+ /* Make sure the d3d mode is smaller in width or height and at most
+ * equal in the other dimension than the mode passed to
+ * ChangeDisplaySettings. Otherwise Windows shrinks the window to
+ * the ChangeDisplaySettings parameters + 12. */
+ if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
+ continue;
+ if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
+ {
+ d3d_width = d3ddm.Width;
+ d3d_height = d3ddm.Height;
+ break;
+ }
+ if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
+ {
+ d3d_width = user32_width;
+ d3d_height = user32_height;
+ user32_width = d3ddm.Width;
+ user32_height = d3ddm.Height;
+ break;
+ }
+ }
+
+ if (!d3d_width)
+ {
+ skip("Could not find adequate modes, skipping mode tests.\n");
+ IDirect3D8_Release(d3d8);
+ return;
+ }
+
+ memset(&devmode, 0, sizeof(devmode));
+ devmode.dmSize = sizeof(devmode);
+ devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
+ devmode.dmPelsWidth = user32_width;
+ devmode.dmPelsHeight = user32_height;
+ change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
+ ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
+
+ /* Make the windows visible, otherwise device::release does not restore the mode if
+ * the application is not in foreground like on the testbot. */
+ focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
+ device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
+
+ SetRect(&d3d_rect, 0, 0, d3d_width, d3d_height);
GetWindowRect(focus_window, &focus_rect);
device_desc.device_window = device_window;
- device_desc.width = registry_mode.dmPelsWidth;
- device_desc.height = registry_mode.dmPelsHeight;
+ device_desc.width = d3d_width;
+ device_desc.height = d3d_height;
device_desc.flags = CREATE_DEVICE_FULLSCREEN;
if (!(device = create_device(d3d8, focus_window, &device_desc)))
{
skip("Failed to create a D3D device, skipping tests.\n");
+ change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
+ ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
goto done;
}
- memset(&devmode, 0, sizeof(devmode));
- devmode.dmSize = sizeof(devmode);
- devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
- devmode.dmPelsWidth = 640;
- devmode.dmPelsHeight = 480;
-
- ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
- ok(ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", ret);
+ devmode.dmPelsWidth = user32_width;
+ devmode.dmPelsHeight = user32_height;
+ change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
+ ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
- memset(&devmode, 0, sizeof(devmode));
- devmode.dmSize = sizeof(devmode);
ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
ok(ret, "Failed to get display mode.\n");
- ok(devmode.dmPelsWidth == 640, "Got unexpect width %u.\n", devmode.dmPelsWidth);
- ok(devmode.dmPelsHeight == 480, "Got unexpect height %u.\n", devmode.dmPelsHeight);
+ ok(devmode.dmPelsWidth == user32_width && devmode.dmPelsHeight == user32_height,
+ "Expected resolution %ux%u, got %ux%u.\n",
+ user32_width, user32_height, devmode.dmPelsWidth, devmode.dmPelsHeight);
GetWindowRect(device_window, &r);
- ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
- fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
+ ok(EqualRect(&r, &d3d_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
+ d3d_rect.left, d3d_rect.top, d3d_rect.right, d3d_rect.bottom,
r.left, r.top, r.right, r.bottom);
GetWindowRect(focus_window, &r);
ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
@@ -3042,31 +3105,52 @@ static void test_mode_change(void)
ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
hr = IDirect3DSurface8_GetDesc(backbuffer, &desc);
ok(SUCCEEDED(hr), "Failed to get backbuffer desc, hr %#x.\n", hr);
- ok(desc.Width == registry_mode.dmPelsWidth, "Got unexpected backbuffer width %u.\n", desc.Width);
- ok(desc.Height == registry_mode.dmPelsHeight, "Got unexpected backbuffer height %u.\n", desc.Height);
+ ok(desc.Width == d3d_width, "Got unexpected backbuffer width %u, expected %u.\n",
+ desc.Width, d3d_width);
+ ok(desc.Height == d3d_height, "Got unexpected backbuffer height %u, expected %u.\n",
+ desc.Height, d3d_height);
IDirect3DSurface8_Release(backbuffer);
refcount = IDirect3DDevice8_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
- memset(&devmode, 0, sizeof(devmode));
- devmode.dmSize = sizeof(devmode);
ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
ok(ret, "Failed to get display mode.\n");
- ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, "Got unexpect width %u.\n", devmode.dmPelsWidth);
- ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect height %u.\n", devmode.dmPelsHeight);
+ todo_wine ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
+ && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
+ "Expected resolution %ux%u, got %ux%u.\n",
+ registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
+
+ change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
+ ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
+
+ /* The mode restore also happens when the device was created at the original screen size. */
+
+ device_desc.device_window = device_window;
+ device_desc.width = registry_mode.dmPelsWidth;
+ device_desc.height = registry_mode.dmPelsHeight;
+ device_desc.flags = CREATE_DEVICE_FULLSCREEN;
+ ok(!!(device = create_device(d3d8, focus_window, &device_desc)), "Failed to create a D3D device.\n");
+
+ devmode.dmPelsWidth = user32_width;
+ devmode.dmPelsHeight = user32_height;
+ change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
+ ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
+
+ refcount = IDirect3DDevice8_Release(device);
+ ok(!refcount, "Device has %u references left.\n", refcount);
+
+ ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
+ ok(ret, "Failed to get display mode.\n");
+ ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
+ && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
+ "Expected resolution %ux%u, got %ux%u.\n",
+ registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
done:
DestroyWindow(device_window);
DestroyWindow(focus_window);
IDirect3D8_Release(d3d8);
-
- memset(&devmode, 0, sizeof(devmode));
- devmode.dmSize = sizeof(devmode);
- ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
- ok(ret, "Failed to get display mode.\n");
- ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, "Got unexpect width %u.\n", devmode.dmPelsWidth);
- ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect height %u.\n", devmode.dmPelsHeight);
}
static void test_device_window_reset(void)
--
2.0.4
More information about the wine-patches
mailing list