2 * Unit tests for ddraw functions
5 * Part of this test involves changing the screen resolution. But this is
6 * really disrupting if the user is doing something else and is not very nice
7 * to CRT screens. Plus, ideally it needs someone watching it to check that
8 * each mode displays correctly.
9 * So this is only done if the test is being run in interactive mode.
11 * Copyright (C) 2003 Sami Aario
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
32 static LPDIRECTDRAW lpDD = NULL;
33 static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
34 static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
36 static HWND hwnd, hwnd2;
38 static int modes_size;
39 static LPDDSURFACEDESC modes;
40 static RECT rect_before_create;
41 static RECT rect_after_delete;
42 static int modes16bpp_cnt;
43 static int refresh_rate;
44 static int refresh_rate_cnt;
46 static HRESULT (WINAPI *pDirectDrawEnumerateA)(LPDDENUMCALLBACKA,LPVOID);
47 static HRESULT (WINAPI *pDirectDrawEnumerateW)(LPDDENUMCALLBACKW,LPVOID);
48 static HRESULT (WINAPI *pDirectDrawEnumerateExA)(LPDDENUMCALLBACKEXA,LPVOID,DWORD);
49 static HRESULT (WINAPI *pDirectDrawEnumerateExW)(LPDDENUMCALLBACKEXW,LPVOID,DWORD);
51 static void init_function_pointers(void)
53 HMODULE hmod = GetModuleHandleA("ddraw.dll");
54 pDirectDrawEnumerateA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateA");
55 pDirectDrawEnumerateW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateW");
56 pDirectDrawEnumerateExA = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExA");
57 pDirectDrawEnumerateExW = (void*)GetProcAddress(hmod, "DirectDrawEnumerateExW");
60 static HWND createwindow(void)
64 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
66 GetSystemMetrics(SM_CXSCREEN),
67 GetSystemMetrics(SM_CYSCREEN),
68 NULL, NULL, GetModuleHandleA(0), NULL);
70 ShowWindow(hwnd, SW_HIDE);
77 static BOOL createdirectdraw(void)
81 SetRect(&rect_before_create, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
83 rc = DirectDrawCreate(NULL, &lpDD, NULL);
84 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
86 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
93 static void releasedirectdraw(void)
97 IDirectDraw_Release(lpDD);
99 SetRect(&rect_after_delete, 0, 0,
100 GetSystemMetrics(SM_CXSCREEN),
101 GetSystemMetrics(SM_CYSCREEN));
102 ok(EqualRect(&rect_before_create, &rect_after_delete) != 0,
103 "Original display mode was not restored\n");
107 static BOOL WINAPI crash_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
108 LPSTR lpDriverName, LPVOID lpContext)
110 *(volatile char*)0 = 2;
114 static BOOL WINAPI test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
115 LPSTR lpDriverName, LPVOID lpContext)
117 trace("test_nullcontext_callbackA: %p %s %s %p\n",
118 lpGUID, lpDriverDescription, lpDriverName, lpContext);
120 ok(!lpContext, "Expected NULL lpContext\n");
125 static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
126 LPSTR lpDriverName, LPVOID lpContext)
128 trace("test_context_callbackA: %p %s %s %p\n",
129 lpGUID, lpDriverDescription, lpDriverName, lpContext);
131 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
136 static void test_DirectDrawEnumerateA(void)
140 if (!pDirectDrawEnumerateA)
142 win_skip("DirectDrawEnumerateA is not available\n");
146 /* Test with NULL callback parameter. */
147 ret = pDirectDrawEnumerateA(NULL, NULL);
148 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
150 /* Test with invalid callback parameter. */
151 ret = pDirectDrawEnumerateA((LPDDENUMCALLBACKA)0xdeadbeef, NULL);
152 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
154 if (pDirectDrawEnumerateExA)
156 /* Test with callback that crashes. */
157 ret = pDirectDrawEnumerateA(crash_callbackA, NULL);
158 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
161 win_skip("Test would crash on older ddraw\n");
163 /* Test with valid callback parameter and NULL context parameter. */
164 trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
165 ret = pDirectDrawEnumerateA(test_nullcontext_callbackA, NULL);
166 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
168 /* Test with valid callback parameter and valid context parameter. */
169 trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
170 ret = pDirectDrawEnumerateA(test_context_callbackA, (LPVOID)0xdeadbeef);
171 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
174 static BOOL WINAPI test_callbackW(GUID *lpGUID, LPWSTR lpDriverDescription,
175 LPWSTR lpDriverName, LPVOID lpContext)
177 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
181 static void test_DirectDrawEnumerateW(void)
185 if (!pDirectDrawEnumerateW)
187 win_skip("DirectDrawEnumerateW is not available\n");
191 /* DirectDrawEnumerateW is not implemented on Windows. */
193 /* Test with NULL callback parameter. */
194 ret = pDirectDrawEnumerateW(NULL, NULL);
195 ok(ret == DDERR_INVALIDPARAMS ||
196 ret == DDERR_UNSUPPORTED, /* Older ddraw */
197 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
199 /* Test with invalid callback parameter. */
200 ret = pDirectDrawEnumerateW((LPDDENUMCALLBACKW)0xdeadbeef, NULL);
201 ok(ret == DDERR_INVALIDPARAMS /* XP */ ||
202 ret == DDERR_UNSUPPORTED /* Win7 */,
203 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
205 /* Test with valid callback parameter and NULL context parameter. */
206 ret = pDirectDrawEnumerateW(test_callbackW, NULL);
207 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
210 static BOOL WINAPI crash_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
211 LPSTR lpDriverName, LPVOID lpContext,
214 *(volatile char*)0 = 2;
218 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
219 LPSTR lpDriverName, LPVOID lpContext,
222 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
223 lpDriverDescription, lpDriverName, lpContext, hm);
225 ok(!lpContext, "Expected NULL lpContext\n");
230 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
231 LPSTR lpDriverName, LPVOID lpContext,
234 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
235 lpDriverDescription, lpDriverName, lpContext, hm);
237 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
242 static void test_DirectDrawEnumerateExA(void)
246 if (!pDirectDrawEnumerateExA)
248 win_skip("DirectDrawEnumerateExA is not available\n");
252 /* Test with NULL callback parameter. */
253 ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
254 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
256 /* Test with invalid callback parameter. */
257 ret = pDirectDrawEnumerateExA((LPDDENUMCALLBACKEXA)0xdeadbeef, NULL, 0);
258 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
260 /* Test with callback that crashes. */
261 ret = pDirectDrawEnumerateExA(crash_callbackExA, NULL, 0);
262 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
264 /* Test with valid callback parameter and invalid flags */
265 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, ~0);
266 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
268 /* Test with valid callback parameter and NULL context parameter. */
269 trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
270 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, 0);
271 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
273 /* Test with valid callback parameter and non-NULL context parameter. */
274 trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
275 ret = pDirectDrawEnumerateExA(test_context_callbackExA, (LPVOID)0xdeadbeef, 0);
276 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
278 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
279 trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
280 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL,
281 DDENUM_ATTACHEDSECONDARYDEVICES |
282 DDENUM_DETACHEDSECONDARYDEVICES |
283 DDENUM_NONDISPLAYDEVICES);
284 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
287 static BOOL WINAPI test_callbackExW(GUID *lpGUID, LPWSTR lpDriverDescription,
288 LPWSTR lpDriverName, LPVOID lpContext,
291 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
295 static void test_DirectDrawEnumerateExW(void)
299 if (!pDirectDrawEnumerateExW)
301 win_skip("DirectDrawEnumerateExW is not available\n");
305 /* DirectDrawEnumerateExW is not implemented on Windows. */
307 /* Test with NULL callback parameter. */
308 ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
309 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
311 /* Test with invalid callback parameter. */
312 ret = pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW)0xdeadbeef, NULL, 0);
313 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
315 /* Test with valid callback parameter and invalid flags */
316 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, ~0);
317 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
319 /* Test with valid callback parameter and NULL context parameter. */
320 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, 0);
321 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
323 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
324 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL,
325 DDENUM_ATTACHEDSECONDARYDEVICES |
326 DDENUM_DETACHEDSECONDARYDEVICES |
327 DDENUM_NONDISPLAYDEVICES);
328 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
331 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
334 modes = HeapAlloc(GetProcessHeap(), 0, (modes_size = 2) * sizeof(DDSURFACEDESC));
335 if (modes_cnt == modes_size)
336 modes = HeapReAlloc(GetProcessHeap(), 0, modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
338 modes[modes_cnt++] = *lpddsd;
341 static void flushdisplaymodes(void)
343 HeapFree(GetProcessHeap(), 0, modes);
345 modes_cnt = modes_size = 0;
348 static HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
350 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
351 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
352 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
354 /* Check that the pitch is valid if applicable */
355 if(lpddsd->dwFlags & DDSD_PITCH)
357 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
360 /* Check that frequency is valid if applicable
362 * This fails on some Windows drivers or Windows versions, so it isn't important
364 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
366 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
370 adddisplaymode(lpddsd);
371 if(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16)
377 static HRESULT WINAPI enummodescallback_16bit(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
379 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
380 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
381 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
383 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
384 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
385 ok(lpddsd->ddpfPixelFormat.dwFlags == DDPF_RGB, "Wrong pixel format flag %02X\n",
386 lpddsd->ddpfPixelFormat.dwFlags);
387 ok(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16, "Expected 16 bpp got %i\n",
388 U1(lpddsd->ddpfPixelFormat).dwRGBBitCount);
390 /* Check that the pitch is valid if applicable */
391 if(lpddsd->dwFlags & DDSD_PITCH)
393 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
398 if(U2(*lpddsd).dwRefreshRate )
400 refresh_rate = U2(*lpddsd).dwRefreshRate;
406 if(refresh_rate == U2(*lpddsd).dwRefreshRate)
415 static HRESULT WINAPI enummodescallback_count(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
417 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
418 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
425 static void enumdisplaymodes(void)
429 int count, refresh_count;
431 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
432 ddsd.dwSize = sizeof(DDSURFACEDESC);
433 ddsd.dwFlags = DDSD_CAPS;
434 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
436 /* Flags parameter is reserved in very old ddraw versions (3 and older?) and must be 0 */
437 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback);
438 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
440 count = modes16bpp_cnt;
443 ddsd.dwFlags = DDSD_PIXELFORMAT;
444 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
445 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
446 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x7C00;
447 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x03E0;
448 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
450 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
451 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
452 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
455 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x0000;
456 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000;
457 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000;
459 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
460 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
461 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
464 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF0F0;
465 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0F00;
466 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000F;
468 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
469 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
470 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
474 ddsd.ddpfPixelFormat.dwFlags = DDPF_YUV;
476 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
477 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
478 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
481 ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8;
483 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
484 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
485 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
488 ddsd.dwFlags = DDSD_PIXELFORMAT;
489 ddsd.ddpfPixelFormat.dwFlags = 0;
491 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
492 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
493 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
498 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_count);
499 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
500 ok(modes16bpp_cnt == modes_cnt, "Expected %d modes got %d\n", modes_cnt, modes16bpp_cnt);
503 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_PITCH;
504 U1(ddsd).lPitch = 123;
506 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
507 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
508 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
511 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
512 U2(ddsd).dwRefreshRate = 1;
514 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
515 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
516 ok(modes16bpp_cnt == 0, "Expected 0 modes got %d\n", modes16bpp_cnt);
519 ddsd.dwFlags = DDSD_PIXELFORMAT;
521 rc = IDirectDraw_EnumDisplayModes(lpDD, DDEDM_REFRESHRATES, &ddsd, 0, enummodescallback_16bit);
522 if(rc == DDERR_INVALIDPARAMS)
524 skip("Ddraw version too old. Skipping.\n");
527 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
528 refresh_count = refresh_rate_cnt;
533 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
534 U2(ddsd).dwRefreshRate = refresh_rate;
536 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
537 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
538 ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
542 static void setdisplaymode(int i)
547 SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
549 rc = IDirectDraw_SetCooperativeLevel(lpDD,
550 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
551 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
552 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
554 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
556 rc = IDirectDraw_SetDisplayMode(lpDD,
557 modes[i].dwWidth, modes[i].dwHeight,
558 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
559 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
562 RECT r, scrn, test, virt;
564 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
565 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
566 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
567 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
568 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
569 if (!EqualRect(&scrn, &orig_rect))
573 /* Check that the client rect was resized */
574 rc = GetClientRect(hwnd, &test);
575 ok(rc!=0, "GetClientRect returned %x\n", rc);
576 rc = EqualRect(&scrn, &test);
577 todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
579 /* Check that switching to normal cooperative level
580 does not restore the display mode */
581 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
582 ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
583 SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
584 rect_result = EqualRect(&scrn, &test);
585 ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
587 /* Go back to fullscreen */
588 rc = IDirectDraw_SetCooperativeLevel(lpDD,
589 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
590 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
592 /* If the display mode was changed, set the correct mode
593 to avoid irrelevant failures */
594 if (rect_result == 0)
596 rc = IDirectDraw_SetDisplayMode(lpDD,
597 modes[i].dwWidth, modes[i].dwHeight,
598 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
599 ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
602 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
603 /* ddraw sets clip rect here to the screen size, even for
605 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
606 r.left, r.top, r.right, r.bottom);
608 ok(ClipCursor(NULL), "ClipCursor() failed\n");
609 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
610 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
611 r.left, r.top, r.right, r.bottom);
613 rc = IDirectDraw_RestoreDisplayMode(lpDD);
614 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
620 static void createsurface(void)
626 ddsd.dwSize = sizeof(ddsd);
627 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
628 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
631 ddsd.dwBackBufferCount = 1;
632 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
633 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
634 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
635 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
636 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
639 static void destroysurface(void)
641 if( lpDDSPrimary != NULL )
643 IDirectDrawSurface_Release(lpDDSPrimary);
648 static void testsurface(void)
650 const char* testMsg = "ddraw device context test";
654 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
655 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
656 SetBkColor(hdc, RGB(0, 0, 255));
657 SetTextColor(hdc, RGB(255, 255, 0));
658 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
659 IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
660 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
664 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
665 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
671 else if (rc == DDERR_SURFACELOST)
673 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
674 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
679 static void testdisplaymodes(void)
683 for (i = 0; i < modes_cnt; ++i)
692 static void testcooperativelevels_normal(void)
696 DDSURFACEDESC surfacedesc;
697 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
699 memset(&surfacedesc, 0, sizeof(surfacedesc));
700 surfacedesc.dwSize = sizeof(surfacedesc);
701 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
702 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
703 surfacedesc.dwBackBufferCount = 1;
704 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
706 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
707 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
709 /* Do some tests with DDSCL_NORMAL mode */
711 /* Fullscreen mode + normal mode + exclusive mode */
713 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
714 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
718 sfw=SetForegroundWindow(hwnd2);
720 skip("Failed to create the second window\n");
722 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
723 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
726 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
728 /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
729 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
731 if (rc == DDERR_UNSUPPORTEDMODE)
732 skip("Unsupported mode\n");
735 ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
736 ok(surface!=NULL, "Returned NULL surface pointer\n");
738 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
740 /* Exclusive mode + normal mode */
741 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
742 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
744 /* Fullscreen mode + normal mode */
747 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
749 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
750 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
753 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
755 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
756 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
758 /* Try creating a double buffered primary in fullscreen + normal mode */
759 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
760 if (rc == DDERR_UNSUPPORTEDMODE)
761 skip("Unsupported mode\n");
764 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
765 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
768 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
770 /* switching from Fullscreen mode to Normal mode */
773 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
775 rc = IDirectDraw_SetCooperativeLevel(lpDD,
777 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
780 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
782 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
783 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
785 /* Try creating a double buffered primary in normal mode */
786 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
787 if (rc == DDERR_UNSUPPORTEDMODE)
788 skip("Unsupported mode\n");
791 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
792 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
794 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
796 /* switching from Normal mode to Fullscreen + Normal mode */
799 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
801 rc = IDirectDraw_SetCooperativeLevel(lpDD,
802 hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
803 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
806 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
808 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
809 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
811 /* Set the focus window */
813 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
814 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
816 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
818 if (rc == DDERR_INVALIDPARAMS)
820 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
824 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
826 rc = IDirectDraw_SetCooperativeLevel(lpDD,
827 hwnd, DDSCL_SETFOCUSWINDOW);
829 if (rc == DDERR_INVALIDPARAMS)
831 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
835 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
837 /* Set the focus window a second time*/
838 rc = IDirectDraw_SetCooperativeLevel(lpDD,
839 hwnd, DDSCL_SETFOCUSWINDOW);
840 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
842 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
843 rc = IDirectDraw_SetCooperativeLevel(lpDD,
844 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
845 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
847 rc = IDirectDraw_SetCooperativeLevel(lpDD,
848 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
849 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
851 /* This one succeeds */
852 rc = IDirectDraw_SetCooperativeLevel(lpDD,
853 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
854 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
856 rc = IDirectDraw_SetCooperativeLevel(lpDD,
857 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
858 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
860 rc = IDirectDraw_SetCooperativeLevel(lpDD,
861 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
862 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
864 rc = IDirectDraw_SetCooperativeLevel(lpDD,
865 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
866 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
868 rc = IDirectDraw_SetCooperativeLevel(lpDD,
869 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
870 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
872 rc = IDirectDraw_SetCooperativeLevel(lpDD,
873 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
874 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
876 /* Set the device window without any other flags. Should give an error */
877 rc = IDirectDraw_SetCooperativeLevel(lpDD,
878 hwnd, DDSCL_SETDEVICEWINDOW);
879 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
881 /* Set device window with DDSCL_NORMAL */
882 rc = IDirectDraw_SetCooperativeLevel(lpDD,
883 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
884 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
886 /* Also set the focus window. Should give an error */
887 rc = IDirectDraw_SetCooperativeLevel(lpDD,
888 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
889 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
894 static void testcooperativelevels_exclusive(void)
900 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
902 /* First, resize the window so it is not the same size as any screen */
903 success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
904 ok(success, "SetWindowPos failed\n");
906 /* Try to set exclusive mode only */
907 rc = IDirectDraw_SetCooperativeLevel(lpDD,
908 hwnd, DDSCL_EXCLUSIVE);
909 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
911 /* Full screen mode only */
912 rc = IDirectDraw_SetCooperativeLevel(lpDD,
913 hwnd, DDSCL_FULLSCREEN);
914 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
916 /* Full screen mode + exclusive mode */
918 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
919 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
923 sfw=SetForegroundWindow(hwnd2);
925 skip("Failed to create the second window\n");
927 rc = IDirectDraw_SetCooperativeLevel(lpDD,
928 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
929 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
932 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
934 /* rect_before_create is assumed to hold the screen rect */
935 GetClientRect(hwnd, &window_rect);
936 rc = EqualRect(&rect_before_create, &window_rect);
937 ok(rc, "Fullscreen window has wrong size.\n");
939 /* Set the focus window. Should fail */
940 rc = IDirectDraw_SetCooperativeLevel(lpDD,
941 hwnd, DDSCL_SETFOCUSWINDOW);
942 ok(rc==DDERR_HWNDALREADYSET ||
943 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
949 static void testddraw3(void)
951 const GUID My_IID_IDirectDraw3 = {
955 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
959 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
960 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
961 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
964 static void testddraw7(void)
968 DDDEVICEIDENTIFIER2 *pdddi2;
972 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
973 if (hr==E_NOINTERFACE)
975 win_skip("DirectDraw7 is not supported\n");
978 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
982 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
984 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
985 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
986 pend[0] = 0xdeadbeef;
987 pend[1] = 0xdeadbeef;
989 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
990 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
994 /* check how strings are copied into the structure */
995 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
996 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
997 /* verify that 8 byte structure size alignment will not overwrite memory */
998 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
999 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1000 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
1003 IDirectDraw_Release(dd7);
1004 HeapFree( GetProcessHeap(), 0, pdddi2 );
1008 START_TEST(ddrawmodes)
1010 init_function_pointers();
1012 wc.style = CS_HREDRAW | CS_VREDRAW;
1013 wc.lpfnWndProc = DefWindowProcA;
1016 wc.hInstance = GetModuleHandleA(0);
1017 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
1018 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
1019 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
1020 wc.lpszMenuName = NULL;
1021 wc.lpszClassName = "TestWindowClass";
1022 if (!RegisterClassA(&wc))
1024 skip("RegisterClassA failed\n");
1028 hwnd2=createwindow();
1029 hwnd=createwindow();
1033 skip("Failed to create the main window\n");
1037 if (!createdirectdraw())
1039 skip("Failed to create the direct draw object\n");
1043 test_DirectDrawEnumerateA();
1044 test_DirectDrawEnumerateW();
1045 test_DirectDrawEnumerateExA();
1046 test_DirectDrawEnumerateExW();
1049 if (winetest_interactive)
1051 flushdisplaymodes();
1054 releasedirectdraw();
1057 testcooperativelevels_normal();
1058 releasedirectdraw();
1061 testcooperativelevels_exclusive();
1062 releasedirectdraw();