[PATCH 2/8] d3d9/tests: Restore display modes at the end of test_wndproc().
Zhiyi Zhang
zzhang at codeweavers.com
Wed Oct 28 01:37:41 CDT 2020
test_wndproc() makes a series of ChangeDisplaySettings() calls that could make the current display
mode no longer match the registry display mode. Restore display modes at the end of test_wndproc()
so that other tests are not affected.
Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
dlls/d3d9/tests/device.c | 73 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 72 insertions(+), 1 deletion(-)
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 53a83ad887b..0f0de5e3382 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -25,6 +25,7 @@
#define COBJMACROS
#include <d3d9.h>
#include "utils.h"
+#include "wine/heap.h"
struct vec3
{
@@ -158,6 +159,69 @@ static BOOL adapter_is_warp(const D3DADAPTER_IDENTIFIER9 *identifier)
return !strcmp(identifier->Driver, "d3d10warp.dll");
}
+/* Free original_modes after finished using it */
+static BOOL save_display_modes(DEVMODEW **original_modes, unsigned int *display_count)
+{
+ unsigned int number, size = 2, count = 0, index = 0;
+ DISPLAY_DEVICEW display_device;
+ DEVMODEW *modes, *tmp;
+
+ if (!(modes = heap_alloc(size * sizeof(*modes))))
+ return FALSE;
+
+ display_device.cb = sizeof(display_device);
+ while (EnumDisplayDevicesW(NULL, index++, &display_device, 0))
+ {
+ /* Skip software devices */
+ if (swscanf(display_device.DeviceName, L"\\\\.\\DISPLAY%u", &number) != 1)
+ continue;
+
+ if (!(display_device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
+ continue;
+
+ if (count >= size)
+ {
+ size *= 2;
+ if (!(tmp = heap_realloc(modes, size * sizeof(*modes))))
+ {
+ heap_free(modes);
+ return FALSE;
+ }
+ modes = tmp;
+ }
+
+ memset(&modes[count], 0, sizeof(modes[count]));
+ modes[count].dmSize = sizeof(modes[count]);
+ if (!EnumDisplaySettingsW(display_device.DeviceName, ENUM_CURRENT_SETTINGS, &modes[count]))
+ {
+ heap_free(modes);
+ return FALSE;
+ }
+
+ lstrcpyW(modes[count++].dmDeviceName, display_device.DeviceName);
+ }
+
+ *original_modes = modes;
+ *display_count = count;
+ return TRUE;
+}
+
+static BOOL restore_display_modes(DEVMODEW *modes, unsigned int count)
+{
+ unsigned int index;
+ LONG ret;
+
+ for (index = 0; index < count; ++index)
+ {
+ ret = ChangeDisplaySettingsExW(modes[index].dmDeviceName, &modes[index], NULL,
+ CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
+ if (ret != DISP_CHANGE_SUCCESSFUL)
+ return FALSE;
+ }
+ ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL);
+ return ret == DISP_CHANGE_SUCCESSFUL;
+}
+
static IDirect3DDevice9 *create_device(IDirect3D9 *d3d9, HWND focus_window, const struct device_desc *desc)
{
D3DPRESENT_PARAMETERS present_parameters = {0};
@@ -3758,6 +3822,8 @@ static DWORD WINAPI wndproc_thread(void *param)
static void test_wndproc(void)
{
struct wndproc_thread_param thread_params;
+ DEVMODEW devmode, *original_modes = NULL;
+ unsigned int display_count = 0;
struct device_desc device_desc;
static WINDOWPOS windowpos;
IDirect3DDevice9 *device;
@@ -3772,7 +3838,6 @@ static void test_wndproc(void)
HRESULT hr;
D3DDISPLAYMODE d3ddm;
DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
- DEVMODEW devmode;
LONG change_ret, device_style;
BOOL ret;
@@ -3997,6 +4062,9 @@ static void test_wndproc(void)
return;
}
+ ret = save_display_modes(&original_modes, &display_count);
+ ok(ret, "Failed to save original display modes.\n");
+
filter_messages = NULL;
expect_messages = NULL;
@@ -4435,6 +4503,9 @@ done:
CloseHandle(thread_params.test_finished);
CloseHandle(thread_params.window_created);
UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL));
+ ret = restore_display_modes(original_modes, display_count);
+ ok(ret, "Failed to restore display modes.\n");
+ heap_free(original_modes);
}
static void test_wndproc_windowed(void)
--
2.27.0
More information about the wine-devel
mailing list