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 IDirectDrawSurface *lpDDSPrimary;
33 static IDirectDrawSurface *lpDDSBack;
34 static IDirectDraw *lpDD;
36 static HWND hwnd, hwnd2;
38 static int modes_size;
39 static DDSURFACEDESC *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 test_nullcontext_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
108 LPSTR lpDriverName, LPVOID lpContext)
110 trace("test_nullcontext_callbackA: %p %s %s %p\n",
111 lpGUID, lpDriverDescription, lpDriverName, lpContext);
113 ok(!lpContext, "Expected NULL lpContext\n");
118 static BOOL WINAPI test_context_callbackA(GUID *lpGUID, LPSTR lpDriverDescription,
119 LPSTR lpDriverName, LPVOID lpContext)
121 trace("test_context_callbackA: %p %s %s %p\n",
122 lpGUID, lpDriverDescription, lpDriverName, lpContext);
124 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
129 static void test_DirectDrawEnumerateA(void)
133 if (!pDirectDrawEnumerateA)
135 win_skip("DirectDrawEnumerateA is not available\n");
139 /* Test with NULL callback parameter. */
140 ret = pDirectDrawEnumerateA(NULL, NULL);
141 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
143 /* Test with valid callback parameter and NULL context parameter. */
144 trace("Calling DirectDrawEnumerateA with test_nullcontext_callbackA callback and NULL context.\n");
145 ret = pDirectDrawEnumerateA(test_nullcontext_callbackA, NULL);
146 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
148 /* Test with valid callback parameter and valid context parameter. */
149 trace("Calling DirectDrawEnumerateA with test_context_callbackA callback and non-NULL context.\n");
150 ret = pDirectDrawEnumerateA(test_context_callbackA, (LPVOID)0xdeadbeef);
151 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
154 static BOOL WINAPI test_callbackW(GUID *lpGUID, LPWSTR lpDriverDescription,
155 LPWSTR lpDriverName, LPVOID lpContext)
157 ok(0, "The callback should not be invoked by DirectDrawEnumerateW\n");
161 static void test_DirectDrawEnumerateW(void)
165 if (!pDirectDrawEnumerateW)
167 win_skip("DirectDrawEnumerateW is not available\n");
171 /* DirectDrawEnumerateW is not implemented on Windows. */
173 /* Test with NULL callback parameter. */
174 ret = pDirectDrawEnumerateW(NULL, NULL);
175 ok(ret == DDERR_INVALIDPARAMS ||
176 ret == DDERR_UNSUPPORTED, /* Older ddraw */
177 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
179 /* Test with invalid callback parameter. */
180 ret = pDirectDrawEnumerateW((LPDDENUMCALLBACKW)0xdeadbeef, NULL);
181 ok(ret == DDERR_INVALIDPARAMS /* XP */ ||
182 ret == DDERR_UNSUPPORTED /* Win7 */,
183 "Expected DDERR_INVALIDPARAMS or DDERR_UNSUPPORTED, got %d\n", ret);
185 /* Test with valid callback parameter and NULL context parameter. */
186 ret = pDirectDrawEnumerateW(test_callbackW, NULL);
187 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
190 static BOOL WINAPI test_nullcontext_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
191 LPSTR lpDriverName, LPVOID lpContext,
194 trace("test_nullcontext_callbackExA: %p %s %s %p %p\n", lpGUID,
195 lpDriverDescription, lpDriverName, lpContext, hm);
197 ok(!lpContext, "Expected NULL lpContext\n");
202 static BOOL WINAPI test_context_callbackExA(GUID *lpGUID, LPSTR lpDriverDescription,
203 LPSTR lpDriverName, LPVOID lpContext,
206 trace("test_context_callbackExA: %p %s %s %p %p\n", lpGUID,
207 lpDriverDescription, lpDriverName, lpContext, hm);
209 ok(lpContext == (LPVOID)0xdeadbeef, "Expected non-NULL lpContext\n");
214 static void test_DirectDrawEnumerateExA(void)
218 if (!pDirectDrawEnumerateExA)
220 win_skip("DirectDrawEnumerateExA is not available\n");
224 /* Test with NULL callback parameter. */
225 ret = pDirectDrawEnumerateExA(NULL, NULL, 0);
226 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
228 /* Test with valid callback parameter and invalid flags */
229 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, ~0);
230 ok(ret == DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, got %d\n", ret);
232 /* Test with valid callback parameter and NULL context parameter. */
233 trace("Calling DirectDrawEnumerateExA with empty flags and NULL context.\n");
234 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL, 0);
235 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
237 /* Test with valid callback parameter and non-NULL context parameter. */
238 trace("Calling DirectDrawEnumerateExA with empty flags and non-NULL context.\n");
239 ret = pDirectDrawEnumerateExA(test_context_callbackExA, (LPVOID)0xdeadbeef, 0);
240 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
242 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
243 trace("Calling DirectDrawEnumerateExA with all flags set and NULL context.\n");
244 ret = pDirectDrawEnumerateExA(test_nullcontext_callbackExA, NULL,
245 DDENUM_ATTACHEDSECONDARYDEVICES |
246 DDENUM_DETACHEDSECONDARYDEVICES |
247 DDENUM_NONDISPLAYDEVICES);
248 ok(ret == DD_OK, "Expected DD_OK, got %d\n", ret);
251 static BOOL WINAPI test_callbackExW(GUID *lpGUID, LPWSTR lpDriverDescription,
252 LPWSTR lpDriverName, LPVOID lpContext,
255 ok(0, "The callback should not be invoked by DirectDrawEnumerateExW.\n");
259 static void test_DirectDrawEnumerateExW(void)
263 if (!pDirectDrawEnumerateExW)
265 win_skip("DirectDrawEnumerateExW is not available\n");
269 /* DirectDrawEnumerateExW is not implemented on Windows. */
271 /* Test with NULL callback parameter. */
272 ret = pDirectDrawEnumerateExW(NULL, NULL, 0);
273 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
275 /* Test with invalid callback parameter. */
276 ret = pDirectDrawEnumerateExW((LPDDENUMCALLBACKEXW)0xdeadbeef, NULL, 0);
277 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
279 /* Test with valid callback parameter and invalid flags */
280 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, ~0);
281 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
283 /* Test with valid callback parameter and NULL context parameter. */
284 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL, 0);
285 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
287 /* Test with valid callback parameter, NULL context parameter, and all flags set. */
288 ret = pDirectDrawEnumerateExW(test_callbackExW, NULL,
289 DDENUM_ATTACHEDSECONDARYDEVICES |
290 DDENUM_DETACHEDSECONDARYDEVICES |
291 DDENUM_NONDISPLAYDEVICES);
292 ok(ret == DDERR_UNSUPPORTED, "Expected DDERR_UNSUPPORTED, got %d\n", ret);
295 static void adddisplaymode(DDSURFACEDESC *lpddsd)
298 modes = HeapAlloc(GetProcessHeap(), 0, (modes_size = 2) * sizeof(DDSURFACEDESC));
299 if (modes_cnt == modes_size)
300 modes = HeapReAlloc(GetProcessHeap(), 0, modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
302 modes[modes_cnt++] = *lpddsd;
305 static void flushdisplaymodes(void)
307 HeapFree(GetProcessHeap(), 0, modes);
309 modes_cnt = modes_size = 0;
312 static HRESULT WINAPI enummodescallback(DDSURFACEDESC *lpddsd, void *lpContext)
314 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
315 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
316 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
318 /* Check that the pitch is valid if applicable */
319 if(lpddsd->dwFlags & DDSD_PITCH)
321 ok(U1(*lpddsd).lPitch != 0, "EnumDisplayModes callback with bad pitch\n");
324 /* Check that frequency is valid if applicable
326 * This fails on some Windows drivers or Windows versions, so it isn't important
328 if(lpddsd->dwFlags & DDSD_REFRESHRATE)
330 ok(U2(*lpddsd).dwRefreshRate != 0, "EnumDisplayModes callback with bad refresh rate\n");
334 adddisplaymode(lpddsd);
335 if(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16)
341 static HRESULT WINAPI enummodescallback_16bit(DDSURFACEDESC *lpddsd, void *lpContext)
343 trace("Width = %i, Height = %i, bpp = %i, Refresh Rate = %i, Pitch = %i, flags =%02X\n",
344 lpddsd->dwWidth, lpddsd->dwHeight, U1(lpddsd->ddpfPixelFormat).dwRGBBitCount,
345 U2(*lpddsd).dwRefreshRate, U1(*lpddsd).lPitch, lpddsd->dwFlags);
347 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
348 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
349 ok(lpddsd->ddpfPixelFormat.dwFlags == DDPF_RGB, "Wrong pixel format flag %02X\n",
350 lpddsd->ddpfPixelFormat.dwFlags);
351 ok(U1(lpddsd->ddpfPixelFormat).dwRGBBitCount == 16, "Expected 16 bpp got %i\n",
352 U1(lpddsd->ddpfPixelFormat).dwRGBBitCount);
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");
362 if(U2(*lpddsd).dwRefreshRate )
364 refresh_rate = U2(*lpddsd).dwRefreshRate;
370 if(refresh_rate == U2(*lpddsd).dwRefreshRate)
379 static HRESULT WINAPI enummodescallback_count(DDSURFACEDESC *lpddsd, void *lpContext)
381 ok(lpddsd->dwFlags == (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_REFRESHRATE),
382 "Wrong surface description flags %02X\n", lpddsd->dwFlags);
389 static void enumdisplaymodes(void)
393 int count, refresh_count;
395 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
396 ddsd.dwSize = sizeof(DDSURFACEDESC);
397 ddsd.dwFlags = DDSD_CAPS;
398 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
400 /* Flags parameter is reserved in very old ddraw versions (3 and older?) and must be 0 */
401 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback);
402 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
404 count = modes16bpp_cnt;
407 ddsd.dwFlags = DDSD_PIXELFORMAT;
408 ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
409 U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
410 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xf800;
411 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07e0;
412 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
414 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
415 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
416 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
419 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0x0000;
420 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0000;
421 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x0000;
423 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
424 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
425 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
428 U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF0F0;
429 U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x0F00;
430 U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x000F;
432 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
433 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
434 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
438 ddsd.ddpfPixelFormat.dwFlags = DDPF_YUV;
440 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
441 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
442 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
445 ddsd.ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8;
447 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
448 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
449 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
452 ddsd.dwFlags = DDSD_PIXELFORMAT;
453 ddsd.ddpfPixelFormat.dwFlags = 0;
455 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
456 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
457 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
462 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_count);
463 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
464 ok(modes16bpp_cnt == modes_cnt, "Expected %d modes got %d\n", modes_cnt, modes16bpp_cnt);
467 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_PITCH;
468 U1(ddsd).lPitch = 123;
470 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
471 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
472 ok(modes16bpp_cnt == count, "Expected %d modes got %d\n", count, modes16bpp_cnt);
475 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
476 /* Ask for a refresh rate that could not possibly be used. But note that
477 * the Windows 'Standard VGA' driver claims to run the display at 1Hz!
479 U2(ddsd).dwRefreshRate = 2;
481 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
482 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
483 ok(modes16bpp_cnt == 0, "Expected 0 modes got %d\n", modes16bpp_cnt);
486 ddsd.dwFlags = DDSD_PIXELFORMAT;
488 rc = IDirectDraw_EnumDisplayModes(lpDD, DDEDM_REFRESHRATES, &ddsd, 0, enummodescallback_16bit);
489 if(rc == DDERR_INVALIDPARAMS)
491 skip("Ddraw version too old. Skipping.\n");
494 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
495 refresh_count = refresh_rate_cnt;
500 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_REFRESHRATE;
501 U2(ddsd).dwRefreshRate = refresh_rate;
503 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, &ddsd, 0, enummodescallback_16bit);
504 ok(rc==DD_OK,"EnumDisplayModes returned: %x\n",rc);
505 ok(modes16bpp_cnt == refresh_count, "Expected %d modes got %d\n", refresh_count, modes16bpp_cnt);
508 rc = IDirectDraw_EnumDisplayModes(lpDD, 0, NULL, 0, enummodescallback);
509 ok(rc==DD_OK, "EnumDisplayModes returned: %x\n",rc);
513 static void setdisplaymode(int i)
518 SetRect(&orig_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
520 rc = IDirectDraw_SetCooperativeLevel(lpDD,
521 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
522 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
523 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
525 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
527 rc = IDirectDraw_SetDisplayMode(lpDD,
528 modes[i].dwWidth, modes[i].dwHeight,
529 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
530 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
533 RECT r, scrn, test, virt;
535 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
536 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
537 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
538 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
539 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
540 if (!EqualRect(&scrn, &orig_rect))
544 /* Check that the client rect was resized */
545 rc = GetClientRect(hwnd, &test);
546 ok(rc!=0, "GetClientRect returned %x\n", rc);
547 rc = EqualRect(&scrn, &test);
548 todo_wine ok(rc!=0, "Fullscreen window has wrong size\n");
550 /* Check that switching to normal cooperative level
551 does not restore the display mode */
552 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_NORMAL);
553 ok(rc==DD_OK, "SetCooperativeLevel returned %x\n", rc);
554 SetRect(&test, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
555 rect_result = EqualRect(&scrn, &test);
556 ok(rect_result!=0, "Setting cooperative level to DDSCL_NORMAL changed the display mode\n");
558 /* Go back to fullscreen */
559 rc = IDirectDraw_SetCooperativeLevel(lpDD,
560 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
561 ok(rc==DD_OK, "SetCooperativeLevel returned: %x\n",rc);
563 /* If the display mode was changed, set the correct mode
564 to avoid irrelevant failures */
565 if (rect_result == 0)
567 rc = IDirectDraw_SetDisplayMode(lpDD,
568 modes[i].dwWidth, modes[i].dwHeight,
569 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
570 ok(DD_OK==rc, "SetDisplayMode returned: %x\n",rc);
573 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
574 /* ddraw sets clip rect here to the screen size, even for
576 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
577 r.left, r.top, r.right, r.bottom);
579 ok(ClipCursor(NULL), "ClipCursor() failed\n");
580 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
581 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
582 r.left, r.top, r.right, r.bottom);
584 rc = IDirectDraw_RestoreDisplayMode(lpDD);
585 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
591 static void createsurface(void)
597 ddsd.dwSize = sizeof(ddsd);
598 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
599 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
602 ddsd.dwBackBufferCount = 1;
603 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
604 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
605 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
606 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
607 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
610 static void destroysurface(void)
612 if( lpDDSPrimary != NULL )
614 IDirectDrawSurface_Release(lpDDSPrimary);
619 static void testsurface(void)
621 const char* testMsg = "ddraw device context test";
625 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
626 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
627 SetBkColor(hdc, RGB(0, 0, 255));
628 SetTextColor(hdc, RGB(255, 255, 0));
629 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
630 rc = IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
631 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
635 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
636 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
642 else if (rc == DDERR_SURFACELOST)
644 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
645 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
650 static void testdisplaymodes(void)
654 for (i = 0; i < modes_cnt; ++i)
663 static void testcooperativelevels_normal(void)
667 DDSURFACEDESC surfacedesc;
668 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
670 memset(&surfacedesc, 0, sizeof(surfacedesc));
671 surfacedesc.dwSize = sizeof(surfacedesc);
672 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
673 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
674 surfacedesc.dwBackBufferCount = 1;
675 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
677 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
678 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
680 /* Do some tests with DDSCL_NORMAL mode */
682 /* Fullscreen mode + normal mode + exclusive mode */
684 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
685 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received: %x\n", rc);
689 sfw=SetForegroundWindow(hwnd2);
691 skip("Failed to create the second window\n");
693 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL);
694 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
697 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
699 /* Try creating a double buffered primary in fullscreen + exclusive + normal mode */
700 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
702 if (rc == DDERR_UNSUPPORTEDMODE)
703 skip("Unsupported mode\n");
706 ok(rc == DD_OK, "IDirectDraw_CreateSurface returned %08x\n", rc);
707 ok(surface!=NULL, "Returned NULL surface pointer\n");
709 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
711 /* Exclusive mode + normal mode */
712 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_NORMAL);
713 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_NORMAL) returned: %x\n",rc);
715 /* Fullscreen mode + normal mode */
718 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
720 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_FULLSCREEN | DDSCL_NORMAL);
721 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_FULLSCREEN | DDSCL_NORMAL) returned: %x\n",rc);
724 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
726 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_NORMAL);
727 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
729 /* Try creating a double buffered primary in fullscreen + normal mode */
730 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
731 if (rc == DDERR_UNSUPPORTEDMODE)
732 skip("Unsupported mode\n");
735 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
736 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
739 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
741 /* switching from Fullscreen mode to Normal mode */
744 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
746 rc = IDirectDraw_SetCooperativeLevel(lpDD,
748 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
751 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
753 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
754 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
756 /* Try creating a double buffered primary in normal mode */
757 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
758 if (rc == DDERR_UNSUPPORTEDMODE)
759 skip("Unsupported mode\n");
762 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
763 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
765 if(surface && surface != (IDirectDrawSurface *)0xdeadbeef) IDirectDrawSurface_Release(surface);
767 /* switching from Normal mode to Fullscreen + Normal mode */
770 if(hwnd2) sfw=SetForegroundWindow(hwnd2);
772 rc = IDirectDraw_SetCooperativeLevel(lpDD,
773 hwnd, DDSCL_NORMAL | DDSCL_FULLSCREEN);
774 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | FULLSCREEN) returned: %x\n",rc);
777 ok(GetForegroundWindow()==hwnd2,"Expected the second windows (%p) for foreground, received the main one (%p)\n",hwnd2, hwnd);
779 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL | DDSCL_FULLSCREEN);
780 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
782 /* Set the focus window */
784 rc = IDirectDraw_SetCooperativeLevel(lpDD, hwnd, DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW);
785 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW) returned: %x\n",rc);
787 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_SETFOCUSWINDOW);
789 if (rc == DDERR_INVALIDPARAMS)
791 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
795 ok(rc==DD_OK, "Expected DD_OK, received %x\n", rc);
797 rc = IDirectDraw_SetCooperativeLevel(lpDD,
798 hwnd, DDSCL_SETFOCUSWINDOW);
800 if (rc == DDERR_INVALIDPARAMS)
802 win_skip("NT4/Win95 do not support cooperative levels DDSCL_SETDEVICEWINDOW and DDSCL_SETFOCUSWINDOW\n");
806 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
808 /* Set the focus window a second time*/
809 rc = IDirectDraw_SetCooperativeLevel(lpDD,
810 hwnd, DDSCL_SETFOCUSWINDOW);
811 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
813 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
814 rc = IDirectDraw_SetCooperativeLevel(lpDD,
815 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
816 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
818 rc = IDirectDraw_SetCooperativeLevel(lpDD,
819 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
820 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
822 /* This one succeeds */
823 rc = IDirectDraw_SetCooperativeLevel(lpDD,
824 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
825 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
827 rc = IDirectDraw_SetCooperativeLevel(lpDD,
828 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
829 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
831 rc = IDirectDraw_SetCooperativeLevel(lpDD,
832 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
833 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
835 rc = IDirectDraw_SetCooperativeLevel(lpDD,
836 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
837 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
839 rc = IDirectDraw_SetCooperativeLevel(lpDD,
840 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
841 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
843 rc = IDirectDraw_SetCooperativeLevel(lpDD,
844 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
845 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
847 /* Set the device window without any other flags. Should give an error */
848 rc = IDirectDraw_SetCooperativeLevel(lpDD,
849 hwnd, DDSCL_SETDEVICEWINDOW);
850 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
852 /* Set device window with DDSCL_NORMAL */
853 rc = IDirectDraw_SetCooperativeLevel(lpDD,
854 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
855 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
857 /* Also set the focus window. Should give an error */
858 rc = IDirectDraw_SetCooperativeLevel(lpDD,
859 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
860 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
865 static void testcooperativelevels_exclusive(void)
871 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
873 /* First, resize the window so it is not the same size as any screen */
874 success = SetWindowPos(hwnd, 0, 0, 0, 281, 92, 0);
875 ok(success, "SetWindowPos failed\n");
877 /* Try to set exclusive mode only */
878 rc = IDirectDraw_SetCooperativeLevel(lpDD,
879 hwnd, DDSCL_EXCLUSIVE);
880 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
882 /* Full screen mode only */
883 rc = IDirectDraw_SetCooperativeLevel(lpDD,
884 hwnd, DDSCL_FULLSCREEN);
885 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
887 /* Full screen mode + exclusive mode */
889 rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
890 ok(rc==DDERR_INVALIDPARAMS, "Expected DDERR_INVALIDPARAMS, received %x\n", rc);
894 sfw=SetForegroundWindow(hwnd2);
896 skip("Failed to create the second window\n");
898 rc = IDirectDraw_SetCooperativeLevel(lpDD,
899 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
900 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
903 ok(GetForegroundWindow()==hwnd,"Expected the main windows (%p) for foreground, received the second one (%p)\n",hwnd, hwnd2);
905 /* rect_before_create is assumed to hold the screen rect */
906 GetClientRect(hwnd, &window_rect);
907 rc = EqualRect(&rect_before_create, &window_rect);
908 ok(rc, "Fullscreen window has wrong size.\n");
910 /* Set the focus window. Should fail */
911 rc = IDirectDraw_SetCooperativeLevel(lpDD,
912 hwnd, DDSCL_SETFOCUSWINDOW);
913 ok(rc==DDERR_HWNDALREADYSET ||
914 broken(rc==DDERR_INVALIDPARAMS) /* NT4/Win95 */,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
920 static void testddraw3(void)
922 const GUID My_IID_IDirectDraw3 = {
926 { 0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d }
930 hr = IDirectDraw_QueryInterface(lpDD, &My_IID_IDirectDraw3, (void **) &dd3);
931 ok(hr == E_NOINTERFACE, "QueryInterface for IID_IDirectDraw3 returned 0x%08x, expected E_NOINTERFACE\n", hr);
932 if(SUCCEEDED(hr) && dd3) IDirectDraw3_Release(dd3);
935 static void testddraw7(void)
939 DDDEVICEIDENTIFIER2 *pdddi2;
943 hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw7, (void **) &dd7);
944 if (hr==E_NOINTERFACE)
946 win_skip("DirectDraw7 is not supported\n");
949 ok(hr==DD_OK, "IDirectDraw7_QueryInterface returned %08x\n", hr);
953 dddi2Bytes = FIELD_OFFSET(DDDEVICEIDENTIFIER2, dwWHQLLevel) + sizeof(DWORD);
955 pdddi2 = HeapAlloc( GetProcessHeap(), 0, dddi2Bytes + 2*sizeof(DWORD) );
956 pend = (DWORD *)((char *)pdddi2 + dddi2Bytes);
957 pend[0] = 0xdeadbeef;
958 pend[1] = 0xdeadbeef;
960 hr = IDirectDraw7_GetDeviceIdentifier(dd7, pdddi2, 0);
961 ok(hr==DD_OK, "get device identifier failed with %08x\n", hr);
965 /* check how strings are copied into the structure */
966 ok(pdddi2->szDriver[MAX_DDDEVICEID_STRING - 1]==0, "szDriver not cleared\n");
967 ok(pdddi2->szDescription[MAX_DDDEVICEID_STRING - 1]==0, "szDescription not cleared\n");
968 /* verify that 8 byte structure size alignment will not overwrite memory */
969 ok(pend[0]==0xdeadbeef || broken(pend[0] != 0xdeadbeef), /* win2k */
970 "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
971 ok(pend[1]==0xdeadbeef, "memory beyond DDDEVICEIDENTIFIER2 overwritten\n");
974 IDirectDraw_Release(dd7);
975 HeapFree( GetProcessHeap(), 0, pdddi2 );
979 START_TEST(ddrawmodes)
981 init_function_pointers();
983 wc.style = CS_HREDRAW | CS_VREDRAW;
984 wc.lpfnWndProc = DefWindowProcA;
987 wc.hInstance = GetModuleHandleA(0);
988 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
989 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
990 wc.hbrBackground = GetStockObject(BLACK_BRUSH);
991 wc.lpszMenuName = NULL;
992 wc.lpszClassName = "TestWindowClass";
993 if (!RegisterClassA(&wc))
995 skip("RegisterClassA failed\n");
999 hwnd2=createwindow();
1000 hwnd=createwindow();
1004 skip("Failed to create the main window\n");
1008 if (!createdirectdraw())
1010 skip("Failed to create the direct draw object\n");
1014 test_DirectDrawEnumerateA();
1015 test_DirectDrawEnumerateW();
1016 test_DirectDrawEnumerateExA();
1017 test_DirectDrawEnumerateExW();
1020 if (winetest_interactive)
1022 flushdisplaymodes();
1025 releasedirectdraw();
1028 testcooperativelevels_normal();
1029 releasedirectdraw();
1032 testcooperativelevels_exclusive();
1033 releasedirectdraw();