[PATCH 2/3] d3d8/tests: The device restores the mode settings from the registry (v2).

Stefan Dösinger stefan at codeweavers.com
Mon Oct 27 17:34:07 CDT 2014


---
 dlls/d3d8/tests/device.c | 150 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 113 insertions(+), 37 deletions(-)

diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c
index 5f8f52a..fb53ee9 100644
--- a/dlls/d3d8/tests/device.c
+++ b/dlls/d3d8/tests/device.c
@@ -2977,56 +2977,134 @@ 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 mode_count = 0, adapter_mode_count, i;
     HRESULT hr;
-    DWORD ret;
+    BOOL ret;
+    LONG change_ret;
+    D3DDISPLAYMODE d3ddm, d3ddm2;
+    struct
+    {
+        UINT w;
+        UINT h;
+    } *modes = NULL;
 
-    focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
-            0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
-    device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
-            0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
     d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
     ok(!!d3d8, "Failed to create a D3D object.\n");
 
-    SetRect(&fullscreen_rect, 0, 0, screen_width, screen_height);
+    IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
+    adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
+    modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
+    for (i = 0; i < adapter_mode_count; ++i)
+    {
+        UINT j;
+
+        hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm2);
+        ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
+
+        if (d3ddm2.Format != d3ddm.Format)
+            continue;
+        if (d3ddm2.Width == screen_width && d3ddm2.Height == screen_height)
+            continue;
+        /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
+         * refuses to create a device at these sizes. */
+        if (d3ddm2.Width < 640 || d3ddm2.Height < 480)
+            continue;
+
+        for (j = 0; j < mode_count; ++j)
+        {
+            if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
+                break;
+        }
+        if (j == mode_count)
+        {
+            modes[j].w = d3ddm2.Width;
+            modes[j].h = d3ddm2.Height;
+            ++mode_count;
+        }
+    }
+
+    /* Make sure the d3d mode is smaller or equal in both width and height
+     * than the mode passed to ChangeDisplaySettings. Otherwise Windows
+     * shrinks the window to the ChangeDisplaySettings parameters + 12. */
+    d3ddm.Width = d3ddm.Height = d3ddm2.Width = d3ddm2.Height = ~0U;
+    for (i = 0; i < mode_count; i++)
+    {
+        if (modes[i].w < d3ddm.Width && modes[i].h < d3ddm.Height)
+        {
+            d3ddm.Width = modes[i].w;
+            d3ddm.Height = modes[i].h;
+        }
+    }
+    for (i = 0; i < mode_count; i++)
+    {
+        if (modes[i].w < d3ddm.Width || modes[i].h < d3ddm.Height)
+            continue;
+        if (modes[i].w == d3ddm.Width && modes[i].h == d3ddm.Height)
+            continue;
+        d3ddm2.Width = modes[i].w;
+        d3ddm2.Height = modes[i].h;
+        break;
+    }
+
+    HeapFree(GetProcessHeap(), 0, modes);
+    if (d3ddm2.Width == ~0U)
+    {
+        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 = d3ddm2.Width;
+    devmode.dmPelsHeight = d3ddm2.Height;
+    change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
+    ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
+
+    focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
+            0, 0, d3ddm2.Width / 2, d3ddm2.Height / 2, 0, 0, 0, 0);
+    device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
+            0, 0, d3ddm2.Width / 2, d3ddm2.Height / 2, 0, 0, 0, 0);
+
+    SetRect(&d3d_rect, 0, 0, d3ddm.Width, d3ddm.Height);
     GetWindowRect(focus_window, &focus_rect);
 
     device_desc.device_window = device_window;
-    device_desc.width = screen_width;
-    device_desc.height = screen_height;
+    device_desc.width = d3ddm.Width;
+    device_desc.height = d3ddm.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 = d3ddm2.Width;
+    devmode.dmPelsHeight = d3ddm2.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 == d3ddm2.Width, "Got unexpect width %u, expected %u.\n",
+            devmode.dmPelsWidth, d3ddm2.Width);
+    ok(devmode.dmPelsHeight == d3ddm2.Height, "Got unexpect height %u, expected %u.\n",
+            devmode.dmPelsHeight, d3ddm2.Height);
 
     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",
@@ -3037,31 +3115,29 @@ 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 == screen_width, "Got unexpected backbuffer width %u.\n", desc.Width);
-    ok(desc.Height == screen_height, "Got unexpected backbuffer height %u.\n", desc.Height);
+    ok(desc.Width == d3ddm.Width, "Got unexpected backbuffer width %u, expected %u.\n",
+            desc.Width, d3ddm.Width);
+    ok(desc.Height == d3ddm.Height, "Got unexpected backbuffer height %u, expected %u.\n",
+            desc.Height, d3ddm.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 == screen_width, "Got unexpect width %u.\n", devmode.dmPelsWidth);
-    ok(devmode.dmPelsHeight == screen_height, "Got unexpect height %u.\n", devmode.dmPelsHeight);
+    todo_wine ok(devmode.dmPelsWidth == screen_width, "Got unexpect width %u, expected %u.\n",
+            devmode.dmPelsWidth, screen_width);
+    todo_wine ok(devmode.dmPelsHeight == screen_height, "Got unexpect height %u, expected %u.\n",
+            devmode.dmPelsHeight, screen_height);
+
+    change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
+    ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
 
 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 == screen_width, "Got unexpect width %u.\n", devmode.dmPelsWidth);
-    ok(devmode.dmPelsHeight == screen_height, "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