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;
38 static int modes_size;
39 static LPDDSURFACEDESC modes;
41 static void createwindow(void)
43 wc.style = CS_HREDRAW | CS_VREDRAW;
44 wc.lpfnWndProc = DefWindowProcA;
47 wc.hInstance = GetModuleHandleA(0);
48 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
49 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
50 wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
51 wc.lpszMenuName = NULL;
52 wc.lpszClassName = "TestWindowClass";
53 if(!RegisterClassA(&wc))
56 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
58 GetSystemMetrics(SM_CXSCREEN),
59 GetSystemMetrics(SM_CYSCREEN),
60 NULL, NULL, GetModuleHandleA(0), NULL);
63 ShowWindow(hwnd, SW_HIDE);
69 static BOOL createdirectdraw(void)
73 rc = DirectDrawCreate(NULL, &lpDD, NULL);
74 ok(rc==DD_OK || rc==DDERR_NODIRECTDRAWSUPPORT, "DirectDrawCreateEx returned: %x\n", rc);
76 trace("DirectDrawCreateEx() failed with an error %x\n", rc);
83 static void releasedirectdraw(void)
87 IDirectDraw_Release(lpDD);
92 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
95 modes = malloc((modes_size = 2) * sizeof(DDSURFACEDESC));
96 if (modes_cnt == modes_size)
97 modes = realloc(modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
99 modes[modes_cnt++] = *lpddsd;
102 static void flushdisplaymodes(void)
106 modes_cnt = modes_size = 0;
109 static HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
111 trace("Width = %i, Height = %i, Refresh Rate = %i\r\n",
112 lpddsd->dwWidth, lpddsd->dwHeight,
113 U2(*lpddsd).dwRefreshRate);
114 adddisplaymode(lpddsd);
119 static void enumdisplaymodes(void)
124 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
125 ddsd.dwSize = sizeof(DDSURFACEDESC);
126 ddsd.dwFlags = DDSD_CAPS;
127 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
129 rc = IDirectDraw_EnumDisplayModes(lpDD,
130 DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
131 ok(rc==DD_OK || rc==E_INVALIDARG,"EnumDisplayModes returned: %x\n",rc);
134 static void setdisplaymode(int i)
138 rc = IDirectDraw_SetCooperativeLevel(lpDD,
139 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
140 ok(rc==DD_OK,"SetCooperativeLevel returned: %x\n",rc);
141 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
143 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
145 rc = IDirectDraw_SetDisplayMode(lpDD,
146 modes[i].dwWidth, modes[i].dwHeight,
147 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
148 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %x\n",rc);
153 SetRect(&virt, 0, 0, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
154 OffsetRect(&virt, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN));
155 SetRect(&scrn, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
156 trace("Mode (%dx%d) [%dx%d] (%d %d)x(%d %d)\n", modes[i].dwWidth, modes[i].dwHeight,
157 scrn.right, scrn.bottom, virt.left, virt.top, virt.right, virt.bottom);
159 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
160 /* ddraw sets clip rect here to the screen size, even for
162 ok(EqualRect(&r, &scrn), "Invalid clip rect: (%d %d) x (%d %d)\n",
163 r.left, r.top, r.right, r.bottom);
165 ok(ClipCursor(NULL), "ClipCursor() failed\n");
166 ok(GetClipCursor(&r), "GetClipCursor() failed\n");
167 ok(EqualRect(&r, &virt), "Invalid clip rect: (%d %d) x (%d %d)\n",
168 r.left, r.top, r.right, r.bottom);
170 rc = IDirectDraw_RestoreDisplayMode(lpDD);
171 ok(DD_OK==rc,"RestoreDisplayMode returned: %x\n",rc);
177 static void createsurface(void)
183 ddsd.dwSize = sizeof(ddsd);
184 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
185 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
188 ddsd.dwBackBufferCount = 1;
189 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
190 ok(rc==DD_OK,"CreateSurface returned: %x\n",rc);
191 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
192 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
193 ok(rc==DD_OK,"GetAttachedSurface returned: %x\n",rc);
196 static void destroysurface(void)
198 if( lpDDSPrimary != NULL )
200 IDirectDrawSurface_Release(lpDDSPrimary);
205 static void testsurface(void)
207 const char* testMsg = "ddraw device context test";
211 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
212 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc);
213 SetBkColor(hdc, RGB(0, 0, 255));
214 SetTextColor(hdc, RGB(255, 255, 0));
215 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
216 IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
217 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc);
221 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
222 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc);
228 else if (rc == DDERR_SURFACELOST)
230 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
231 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc);
236 static void testdisplaymodes(void)
240 for (i = 0; i < modes_cnt; ++i)
249 static void testcooperativelevels_normal(void)
252 DDSURFACEDESC surfacedesc;
253 IDirectDrawSurface *surface = (IDirectDrawSurface *) 0xdeadbeef;
255 memset(&surfacedesc, 0, sizeof(surfacedesc));
256 surfacedesc.dwSize = sizeof(surfacedesc);
257 surfacedesc.ddpfPixelFormat.dwSize = sizeof(surfacedesc.ddpfPixelFormat);
258 surfacedesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
259 surfacedesc.dwBackBufferCount = 1;
260 surfacedesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
262 /* Do some tests with DDSCL_NORMAL mode */
264 rc = IDirectDraw_SetCooperativeLevel(lpDD,
266 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL) returned: %x\n",rc);
268 /* Try creating a double buffered primary in normal mode */
269 rc = IDirectDraw_CreateSurface(lpDD, &surfacedesc, &surface, NULL);
270 ok(rc == DDERR_NOEXCLUSIVEMODE, "IDirectDraw_CreateSurface returned %08x\n", rc);
271 ok(surface == NULL, "Returned surface pointer is %p\n", surface);
272 if(surface) IDirectDrawSurface_Release(surface);
274 /* Set the focus window */
275 rc = IDirectDraw_SetCooperativeLevel(lpDD,
276 hwnd, DDSCL_SETFOCUSWINDOW);
277 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
279 /* Set the focus window a second time*/
280 rc = IDirectDraw_SetCooperativeLevel(lpDD,
281 hwnd, DDSCL_SETFOCUSWINDOW);
282 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) the second time returned: %x\n",rc);
284 /* Test DDSCL_SETFOCUSWINDOW with the other flags. They should all fail, except of DDSCL_NOWINDOWCHANGES */
285 rc = IDirectDraw_SetCooperativeLevel(lpDD,
286 hwnd, DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW);
287 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
289 rc = IDirectDraw_SetCooperativeLevel(lpDD,
290 hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW);
291 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
293 /* This one succeeds */
294 rc = IDirectDraw_SetCooperativeLevel(lpDD,
295 hwnd, DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW);
296 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NOWINDOWCHANGES | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
298 rc = IDirectDraw_SetCooperativeLevel(lpDD,
299 hwnd, DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW);
300 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_MULTITHREADED | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
302 rc = IDirectDraw_SetCooperativeLevel(lpDD,
303 hwnd, DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW);
304 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUSETUP | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
306 rc = IDirectDraw_SetCooperativeLevel(lpDD,
307 hwnd, DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW);
308 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FPUPRESERVE | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
310 rc = IDirectDraw_SetCooperativeLevel(lpDD,
311 hwnd, DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW);
312 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWREBOOT | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
314 rc = IDirectDraw_SetCooperativeLevel(lpDD,
315 hwnd, DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW);
316 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_ALLOWMODEX | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
318 /* Set the device window without any other flags. Should give an error */
319 rc = IDirectDraw_SetCooperativeLevel(lpDD,
320 hwnd, DDSCL_SETDEVICEWINDOW);
321 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
323 /* Set device window with DDSCL_NORMAL */
324 rc = IDirectDraw_SetCooperativeLevel(lpDD,
325 hwnd, DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW);
326 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW) returned: %x\n",rc);
328 /* Also set the focus window. Should give an error */
329 rc = IDirectDraw_SetCooperativeLevel(lpDD,
330 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW);
331 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_NORMAL | DDSCL_SETDEVICEWINDOW | DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
336 static void testcooperativelevels_exclusive(void)
340 /* Do some tests with DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN mode */
342 /* Try to set exclusive mode only */
343 rc = IDirectDraw_SetCooperativeLevel(lpDD,
344 hwnd, DDSCL_EXCLUSIVE);
345 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_EXCLUSIVE) returned: %x\n",rc);
347 /* Full screen mode only */
348 rc = IDirectDraw_SetCooperativeLevel(lpDD,
349 hwnd, DDSCL_FULLSCREEN);
350 ok(rc==DDERR_INVALIDPARAMS,"SetCooperativeLevel(DDSCL_FULLSCREEN) returned: %x\n",rc);
352 /* Full screen mode + exclusive mode */
353 rc = IDirectDraw_SetCooperativeLevel(lpDD,
354 hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
355 ok(rc==DD_OK,"SetCooperativeLevel(DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) returned: %x\n",rc);
357 /* Set the focus window. Should fail */
358 rc = IDirectDraw_SetCooperativeLevel(lpDD,
359 hwnd, DDSCL_SETFOCUSWINDOW);
360 ok(rc==DDERR_HWNDALREADYSET,"SetCooperativeLevel(DDSCL_SETFOCUSWINDOW) returned: %x\n",rc);
366 START_TEST(ddrawmodes)
369 if (!createdirectdraw())
372 if (winetest_interactive)
378 testcooperativelevels_normal();
382 testcooperativelevels_exclusive();