ddraw/tests: Nvidia has an off-by-one rectangle handling bug.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blob31d552de29bd92258ab7ea92d367d78b9b481131
1 /*
2 * Copyright 2006, 2012-2014 Stefan Dösinger for CodeWeavers
3 * Copyright 2011 Henri Verbeet for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "wine/test.h"
22 #include <limits.h>
23 #include "d3d.h"
25 static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *guid, void **ddraw, REFIID iid, IUnknown *outer_unknown);
27 struct vec2
29 float x, y;
32 struct vec3
34 float x, y, z;
37 struct vec4
39 float x, y, z, w;
42 struct create_window_thread_param
44 HWND window;
45 HANDLE window_created;
46 HANDLE destroy_window;
47 HANDLE thread;
50 static BOOL compare_float(float f, float g, unsigned int ulps)
52 int x = *(int *)&f;
53 int y = *(int *)&g;
55 if (x < 0)
56 x = INT_MIN - x;
57 if (y < 0)
58 y = INT_MIN - y;
60 if (abs(x - y) > ulps)
61 return FALSE;
63 return TRUE;
66 static BOOL compare_vec3(struct vec3 *vec, float x, float y, float z, unsigned int ulps)
68 return compare_float(vec->x, x, ulps)
69 && compare_float(vec->y, y, ulps)
70 && compare_float(vec->z, z, ulps);
73 static BOOL compare_vec4(struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
75 return compare_float(vec->x, x, ulps)
76 && compare_float(vec->y, y, ulps)
77 && compare_float(vec->z, z, ulps)
78 && compare_float(vec->w, w, ulps);
81 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
83 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
84 c1 >>= 8; c2 >>= 8;
85 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
86 c1 >>= 8; c2 >>= 8;
87 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
88 c1 >>= 8; c2 >>= 8;
89 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
90 return TRUE;
93 static ULONG get_refcount(IUnknown *iface)
95 IUnknown_AddRef(iface);
96 return IUnknown_Release(iface);
99 static DWORD WINAPI create_window_thread_proc(void *param)
101 struct create_window_thread_param *p = param;
102 DWORD res;
103 BOOL ret;
105 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
106 0, 0, 640, 480, 0, 0, 0, 0);
107 ret = SetEvent(p->window_created);
108 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
110 for (;;)
112 MSG msg;
114 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
115 DispatchMessageA(&msg);
116 res = WaitForSingleObject(p->destroy_window, 100);
117 if (res == WAIT_OBJECT_0)
118 break;
119 if (res != WAIT_TIMEOUT)
121 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
122 break;
126 DestroyWindow(p->window);
128 return 0;
131 static void create_window_thread(struct create_window_thread_param *p)
133 DWORD res, tid;
135 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
136 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
137 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
138 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
139 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
140 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
141 res = WaitForSingleObject(p->window_created, INFINITE);
142 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
145 static void destroy_window_thread(struct create_window_thread_param *p)
147 SetEvent(p->destroy_window);
148 WaitForSingleObject(p->thread, INFINITE);
149 CloseHandle(p->destroy_window);
150 CloseHandle(p->window_created);
151 CloseHandle(p->thread);
154 static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
156 IDirectDrawSurface7 *rt, *ret;
157 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, 0};
158 HRESULT hr;
160 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
161 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
162 hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
163 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
164 IDirectDrawSurface7_Release(rt);
165 return ret;
168 static HRESULT set_display_mode(IDirectDraw7 *ddraw, DWORD width, DWORD height)
170 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
171 return DD_OK;
172 return IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0);
175 static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
177 RECT rect = {x, y, x + 1, y + 1};
178 DDSURFACEDESC2 surface_desc;
179 D3DCOLOR color;
180 HRESULT hr;
182 memset(&surface_desc, 0, sizeof(surface_desc));
183 surface_desc.dwSize = sizeof(surface_desc);
185 hr = IDirectDrawSurface7_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY, NULL);
186 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
187 if (FAILED(hr))
188 return 0xdeadbeef;
190 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
192 hr = IDirectDrawSurface7_Unlock(surface, &rect);
193 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
195 return color;
198 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
200 DDPIXELFORMAT *z_fmt = ctx;
202 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
203 *z_fmt = *format;
205 return DDENUMRET_OK;
208 static IDirectDraw7 *create_ddraw(void)
210 IDirectDraw7 *ddraw;
212 if (FAILED(pDirectDrawCreateEx(NULL, (void **)&ddraw, &IID_IDirectDraw7, NULL)))
213 return NULL;
215 return ddraw;
218 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
220 BOOL *hal_ok = ctx;
221 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
223 *hal_ok = TRUE;
224 return DDENUMRET_CANCEL;
226 return DDENUMRET_OK;
229 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
231 IDirectDrawSurface7 *surface, *ds;
232 IDirect3DDevice7 *device = NULL;
233 DDSURFACEDESC2 surface_desc;
234 DDPIXELFORMAT z_fmt;
235 IDirectDraw7 *ddraw;
236 IDirect3D7 *d3d7;
237 HRESULT hr;
238 BOOL hal_ok = FALSE;
239 const GUID *devtype = &IID_IDirect3DHALDevice;
241 if (!(ddraw = create_ddraw()))
242 return NULL;
244 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
245 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
247 memset(&surface_desc, 0, sizeof(surface_desc));
248 surface_desc.dwSize = sizeof(surface_desc);
249 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
250 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
251 surface_desc.dwWidth = 640;
252 surface_desc.dwHeight = 480;
254 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
255 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
257 if (coop_level & DDSCL_NORMAL)
259 IDirectDrawClipper *clipper;
261 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
262 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
263 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
264 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
265 hr = IDirectDrawSurface7_SetClipper(surface, clipper);
266 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
267 IDirectDrawClipper_Release(clipper);
270 hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
271 IDirectDraw7_Release(ddraw);
272 if (FAILED(hr))
274 IDirectDrawSurface7_Release(surface);
275 return NULL;
278 hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_cb, &hal_ok);
279 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
280 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
282 memset(&z_fmt, 0, sizeof(z_fmt));
283 hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
284 if (FAILED(hr) || !z_fmt.dwSize)
286 IDirect3D7_Release(d3d7);
287 IDirectDrawSurface7_Release(surface);
288 return NULL;
291 memset(&surface_desc, 0, sizeof(surface_desc));
292 surface_desc.dwSize = sizeof(surface_desc);
293 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
294 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
295 U4(surface_desc).ddpfPixelFormat = z_fmt;
296 surface_desc.dwWidth = 640;
297 surface_desc.dwHeight = 480;
298 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
299 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
300 if (FAILED(hr))
302 IDirect3D7_Release(d3d7);
303 IDirectDrawSurface7_Release(surface);
304 return NULL;
307 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
308 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
309 IDirectDrawSurface7_Release(ds);
310 if (FAILED(hr))
312 IDirect3D7_Release(d3d7);
313 IDirectDrawSurface7_Release(surface);
314 return NULL;
317 hr = IDirect3D7_CreateDevice(d3d7, devtype, surface, &device);
318 IDirect3D7_Release(d3d7);
319 IDirectDrawSurface7_Release(surface);
320 if (FAILED(hr))
321 return NULL;
323 return device;
326 static const UINT *expect_messages;
328 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
330 if (expect_messages && message == *expect_messages)
331 ++expect_messages;
333 return DefWindowProcA(hwnd, message, wparam, lparam);
336 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
337 * interface. This prevents subsequent SetCooperativeLevel() calls on a
338 * different window from failing with DDERR_HWNDALREADYSET. */
339 static void fix_wndproc(HWND window, LONG_PTR proc)
341 IDirectDraw7 *ddraw;
342 HRESULT hr;
344 if (!(ddraw = create_ddraw()))
345 return;
347 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
348 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
349 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
350 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
351 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
353 IDirectDraw7_Release(ddraw);
356 static void test_process_vertices(void)
358 IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
359 D3DVERTEXBUFFERDESC vb_desc;
360 IDirect3DDevice7 *device;
361 struct vec4 *dst_data;
362 struct vec3 *dst_data2;
363 struct vec3 *src_data;
364 IDirect3D7 *d3d7;
365 D3DVIEWPORT7 vp;
366 HWND window;
367 HRESULT hr;
369 static D3DMATRIX world =
371 0.0f, 1.0f, 0.0f, 0.0f,
372 1.0f, 0.0f, 0.0f, 0.0f,
373 0.0f, 0.0f, 0.0f, 1.0f,
374 0.0f, 1.0f, 1.0f, 1.0f,
376 static D3DMATRIX view =
378 2.0f, 0.0f, 0.0f, 0.0f,
379 0.0f, -1.0f, 0.0f, 0.0f,
380 0.0f, 0.0f, 1.0f, 0.0f,
381 0.0f, 0.0f, 0.0f, 3.0f,
383 static D3DMATRIX proj =
385 1.0f, 0.0f, 0.0f, 1.0f,
386 0.0f, 1.0f, 1.0f, 0.0f,
387 0.0f, 1.0f, 1.0f, 0.0f,
388 1.0f, 0.0f, 0.0f, 1.0f,
391 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
392 0, 0, 640, 480, 0, 0, 0, 0);
393 if (!(device = create_device(window, DDSCL_NORMAL)))
395 skip("Failed to create a 3D device, skipping test.\n");
396 DestroyWindow(window);
397 return;
400 hr = IDirect3DDevice7_GetDirect3D(device, &d3d7);
401 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
403 memset(&vb_desc, 0, sizeof(vb_desc));
404 vb_desc.dwSize = sizeof(vb_desc);
405 vb_desc.dwFVF = D3DFVF_XYZ;
406 vb_desc.dwNumVertices = 4;
407 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &src_vb, 0);
408 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
410 hr = IDirect3DVertexBuffer7_Lock(src_vb, 0, (void **)&src_data, NULL);
411 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
412 src_data[0].x = 0.0f;
413 src_data[0].y = 0.0f;
414 src_data[0].z = 0.0f;
415 src_data[1].x = 1.0f;
416 src_data[1].y = 1.0f;
417 src_data[1].z = 1.0f;
418 src_data[2].x = -1.0f;
419 src_data[2].y = -1.0f;
420 src_data[2].z = 0.5f;
421 src_data[3].x = 0.5f;
422 src_data[3].y = -0.5f;
423 src_data[3].z = 0.25f;
424 hr = IDirect3DVertexBuffer7_Unlock(src_vb);
425 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
427 memset(&vb_desc, 0, sizeof(vb_desc));
428 vb_desc.dwSize = sizeof(vb_desc);
429 vb_desc.dwFVF = D3DFVF_XYZRHW;
430 vb_desc.dwNumVertices = 4;
431 /* MSDN says that the last parameter must be 0 - check that. */
432 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb1, 4);
433 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
435 memset(&vb_desc, 0, sizeof(vb_desc));
436 vb_desc.dwSize = sizeof(vb_desc);
437 vb_desc.dwFVF = D3DFVF_XYZ;
438 vb_desc.dwNumVertices = 5;
439 /* MSDN says that the last parameter must be 0 - check that. */
440 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb2, 12345678);
441 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
443 memset(&vp, 0, sizeof(vp));
444 vp.dwX = 64;
445 vp.dwY = 64;
446 vp.dwWidth = 128;
447 vp.dwHeight = 128;
448 vp.dvMinZ = 0.0f;
449 vp.dvMaxZ = 1.0f;
450 hr = IDirect3DDevice7_SetViewport(device, &vp);
451 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
453 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
454 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
455 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb2, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
456 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
458 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
459 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
460 ok(compare_vec4(&dst_data[0], +1.280e+2f, +1.280e+2f, +0.000e+0f, +1.000e+0f, 4096),
461 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
462 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
463 ok(compare_vec4(&dst_data[1], +1.920e+2f, +6.400e+1f, +1.000e+0f, +1.000e+0f, 4096),
464 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
465 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
466 ok(compare_vec4(&dst_data[2], +6.400e+1f, +1.920e+2f, +5.000e-1f, +1.000e+0f, 4096),
467 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
468 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
469 ok(compare_vec4(&dst_data[3], +1.600e+2f, +1.600e+2f, +2.500e-1f, +1.000e+0f, 4096),
470 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
471 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
472 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
473 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
475 hr = IDirect3DVertexBuffer7_Lock(dst_vb2, 0, (void **)&dst_data2, NULL);
476 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
477 /* Small thing without much practical meaning, but I stumbled upon it,
478 * so let's check for it: If the output vertex buffer has no RHW value,
479 * the RHW value of the last vertex is written into the next vertex. */
480 ok(compare_vec3(&dst_data2[4], +1.000e+0f, +0.000e+0f, +0.000e+0f, 4096),
481 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
482 dst_data2[4].x, dst_data2[4].y, dst_data2[4].z);
483 hr = IDirect3DVertexBuffer7_Unlock(dst_vb2);
484 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
486 /* Try a more complicated viewport, same vertices. */
487 memset(&vp, 0, sizeof(vp));
488 vp.dwX = 10;
489 vp.dwY = 5;
490 vp.dwWidth = 246;
491 vp.dwHeight = 130;
492 vp.dvMinZ = -2.0f;
493 vp.dvMaxZ = 4.0f;
494 hr = IDirect3DDevice7_SetViewport(device, &vp);
495 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
497 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
498 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
500 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
501 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
502 ok(compare_vec4(&dst_data[0], +1.330e+2f, +7.000e+1f, -2.000e+0f, +1.000e+0f, 4096),
503 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
504 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
505 ok(compare_vec4(&dst_data[1], +2.560e+2f, +5.000e+0f, +4.000e+0f, +1.000e+0f, 4096),
506 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
507 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
508 ok(compare_vec4(&dst_data[2], +1.000e+1f, +1.350e+2f, +1.000e+0f, +1.000e+0f, 4096),
509 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
510 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
511 ok(compare_vec4(&dst_data[3], +1.945e+2f, +1.025e+2f, -5.000e-1f, +1.000e+0f, 4096),
512 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
513 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
514 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
515 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
517 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world);
518 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
519 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &view);
520 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
521 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj);
522 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
524 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
525 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
527 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
528 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
529 ok(compare_vec4(&dst_data[0], +2.560e+2f, +7.000e+1f, -2.000e+0f, +3.333e-1f, 4096),
530 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
531 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
532 ok(compare_vec4(&dst_data[1], +2.560e+2f, +7.813e+1f, -2.750e+0f, +1.250e-1f, 4096),
533 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
534 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
535 ok(compare_vec4(&dst_data[2], +2.560e+2f, +4.400e+1f, +4.000e-1f, +4.000e-1f, 4096),
536 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
537 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
538 ok(compare_vec4(&dst_data[3], +2.560e+2f, +8.182e+1f, -3.091e+0f, +3.636e-1f, 4096),
539 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
540 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
541 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
542 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
544 IDirect3DVertexBuffer7_Release(dst_vb2);
545 IDirect3DVertexBuffer7_Release(dst_vb1);
546 IDirect3DVertexBuffer7_Release(src_vb);
547 IDirect3D7_Release(d3d7);
548 IDirect3DDevice7_Release(device);
549 DestroyWindow(window);
552 static void test_coop_level_create_device_window(void)
554 HWND focus_window, device_window;
555 IDirectDraw7 *ddraw;
556 HRESULT hr;
558 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
559 0, 0, 640, 480, 0, 0, 0, 0);
560 ddraw = create_ddraw();
561 ok(!!ddraw, "Failed to create a ddraw object.\n");
563 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
564 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
565 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
566 ok(!device_window, "Unexpected device window found.\n");
567 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
568 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
569 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
570 ok(!device_window, "Unexpected device window found.\n");
571 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
572 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
573 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
574 ok(!device_window, "Unexpected device window found.\n");
575 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
576 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
577 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
578 ok(!device_window, "Unexpected device window found.\n");
579 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
580 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
581 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
582 ok(!device_window, "Unexpected device window found.\n");
584 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
585 if (broken(hr == DDERR_INVALIDPARAMS))
587 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
588 IDirectDraw7_Release(ddraw);
589 DestroyWindow(focus_window);
590 return;
593 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
594 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
595 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
596 ok(!device_window, "Unexpected device window found.\n");
597 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
598 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
599 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
600 ok(!device_window, "Unexpected device window found.\n");
602 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
603 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
604 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
605 ok(!device_window, "Unexpected device window found.\n");
606 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
607 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
608 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
609 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
610 ok(!!device_window, "Device window not found.\n");
612 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
613 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
614 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
615 ok(!device_window, "Unexpected device window found.\n");
616 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
617 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
618 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
619 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
620 ok(!!device_window, "Device window not found.\n");
622 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
623 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
624 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
625 ok(!device_window, "Unexpected device window found.\n");
626 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
627 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
628 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
629 ok(!device_window, "Unexpected device window found.\n");
630 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
631 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
632 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
633 ok(!device_window, "Unexpected device window found.\n");
634 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
635 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
636 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!!device_window, "Device window not found.\n");
639 IDirectDraw7_Release(ddraw);
640 DestroyWindow(focus_window);
643 static void test_clipper_blt(void)
645 IDirectDrawSurface7 *src_surface, *dst_surface;
646 RECT client_rect, src_rect;
647 IDirectDrawClipper *clipper;
648 DDSURFACEDESC2 surface_desc;
649 unsigned int i, j, x, y;
650 IDirectDraw7 *ddraw;
651 RGNDATA *rgn_data;
652 D3DCOLOR color;
653 HRGN r1, r2;
654 HWND window;
655 DDBLTFX fx;
656 HRESULT hr;
657 DWORD *ptr;
658 DWORD ret;
660 static const DWORD src_data[] =
662 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
663 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
664 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
666 static const D3DCOLOR expected1[] =
668 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
669 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
670 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
671 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
673 /* Nvidia on Windows seems to have an off-by-one error
674 * when processing source rectangles. Our left = 1 and
675 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
676 * read as well, but only for the edge pixels on the
677 * output image. The bug happens on the y axis as well,
678 * but we only read one row there, and all source rows
679 * contain the same data. This bug is not dependent on
680 * the presence of a clipper. */
681 static const D3DCOLOR expected1_broken[] =
683 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
684 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
685 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
686 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
688 static const D3DCOLOR expected2[] =
690 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
691 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
692 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
693 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
696 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
697 10, 10, 640, 480, 0, 0, 0, 0);
698 ShowWindow(window, SW_SHOW);
699 ddraw = create_ddraw();
700 ok(!!ddraw, "Failed to create a ddraw object.\n");
702 ret = GetClientRect(window, &client_rect);
703 ok(ret, "Failed to get client rect.\n");
704 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
705 ok(ret, "Failed to map client rect.\n");
707 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
708 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
710 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
711 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
712 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
713 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
714 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
715 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
716 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
717 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
718 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
719 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
720 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
721 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
722 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
723 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
724 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
725 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
726 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
727 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
728 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
729 HeapFree(GetProcessHeap(), 0, rgn_data);
731 r1 = CreateRectRgn(0, 0, 320, 240);
732 ok(!!r1, "Failed to create region.\n");
733 r2 = CreateRectRgn(320, 240, 640, 480);
734 ok(!!r2, "Failed to create region.\n");
735 CombineRgn(r1, r1, r2, RGN_OR);
736 ret = GetRegionData(r1, 0, NULL);
737 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
738 ret = GetRegionData(r1, ret, rgn_data);
739 ok(!!ret, "Failed to get region data.\n");
741 DeleteObject(r2);
742 DeleteObject(r1);
744 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
745 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
746 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
747 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
748 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
749 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
751 HeapFree(GetProcessHeap(), 0, rgn_data);
753 memset(&surface_desc, 0, sizeof(surface_desc));
754 surface_desc.dwSize = sizeof(surface_desc);
755 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
756 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
757 surface_desc.dwWidth = 640;
758 surface_desc.dwHeight = 480;
759 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
760 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
761 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
762 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
763 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
764 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
766 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
767 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
768 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
769 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
771 memset(&fx, 0, sizeof(fx));
772 fx.dwSize = sizeof(fx);
773 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
774 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
775 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
776 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
778 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
779 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
780 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
781 ptr = surface_desc.lpSurface;
782 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
783 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
784 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
785 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
786 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
788 hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
789 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
791 SetRect(&src_rect, 1, 1, 5, 2);
792 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
793 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
794 for (i = 0; i < 4; ++i)
796 for (j = 0; j < 4; ++j)
798 x = 80 * ((2 * j) + 1);
799 y = 60 * ((2 * i) + 1);
800 color = get_surface_color(dst_surface, x, y);
801 ok(compare_color(color, expected1[i * 4 + j], 1)
802 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
803 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
807 U5(fx).dwFillColor = 0xff0000ff;
808 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
809 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
810 for (i = 0; i < 4; ++i)
812 for (j = 0; j < 4; ++j)
814 x = 80 * ((2 * j) + 1);
815 y = 60 * ((2 * i) + 1);
816 color = get_surface_color(dst_surface, x, y);
817 ok(compare_color(color, expected2[i * 4 + j], 1),
818 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
822 hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
823 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
825 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
826 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
827 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
828 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
829 DestroyWindow(window);
830 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
831 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
832 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
833 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
834 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
835 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
836 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
837 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
838 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
839 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
840 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
841 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
843 IDirectDrawSurface7_Release(dst_surface);
844 IDirectDrawSurface7_Release(src_surface);
845 IDirectDrawClipper_Release(clipper);
846 IDirectDraw7_Release(ddraw);
849 static void test_coop_level_d3d_state(void)
851 IDirectDrawSurface7 *rt, *surface;
852 IDirect3DDevice7 *device;
853 IDirectDraw7 *ddraw;
854 IDirect3D7 *d3d;
855 D3DCOLOR color;
856 DWORD value;
857 HWND window;
858 HRESULT hr;
860 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
861 0, 0, 640, 480, 0, 0, 0, 0);
862 if (!(device = create_device(window, DDSCL_NORMAL)))
864 skip("Failed to create a 3D device, skipping test.\n");
865 DestroyWindow(window);
866 return;
869 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
870 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
871 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
872 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
873 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
874 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
875 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
876 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
877 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
878 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
879 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
880 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
881 color = get_surface_color(rt, 320, 240);
882 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
884 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
885 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
886 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
887 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
888 IDirect3D7_Release(d3d);
889 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
890 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
891 hr = IDirectDrawSurface7_IsLost(rt);
892 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
893 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
894 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
895 IDirectDraw7_Release(ddraw);
897 hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
898 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
899 ok(surface == rt, "Got unexpected surface %p.\n", surface);
900 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
901 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
902 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
903 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
904 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
905 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
906 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
907 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
908 color = get_surface_color(rt, 320, 240);
909 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
911 IDirectDrawSurface7_Release(surface);
912 IDirectDrawSurface7_Release(rt);
913 IDirect3DDevice7_Release(device);
914 DestroyWindow(window);
917 static void test_surface_interface_mismatch(void)
919 IDirectDraw7 *ddraw = NULL;
920 IDirect3D7 *d3d = NULL;
921 IDirectDrawSurface7 *surface = NULL, *ds;
922 IDirectDrawSurface3 *surface3 = NULL;
923 IDirect3DDevice7 *device = NULL;
924 DDSURFACEDESC2 surface_desc;
925 DDPIXELFORMAT z_fmt;
926 ULONG refcount;
927 HRESULT hr;
928 D3DCOLOR color;
929 HWND window;
931 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
932 0, 0, 640, 480, 0, 0, 0, 0);
933 ddraw = create_ddraw();
934 ok(!!ddraw, "Failed to create a ddraw object.\n");
935 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
936 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
938 memset(&surface_desc, 0, sizeof(surface_desc));
939 surface_desc.dwSize = sizeof(surface_desc);
940 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
941 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
942 surface_desc.dwWidth = 640;
943 surface_desc.dwHeight = 480;
945 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
946 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
948 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
949 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
951 if (FAILED(hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
953 skip("D3D interface is not available, skipping test.\n");
954 goto cleanup;
957 memset(&z_fmt, 0, sizeof(z_fmt));
958 hr = IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
959 if (FAILED(hr) || !z_fmt.dwSize)
961 skip("No depth buffer formats available, skipping test.\n");
962 goto cleanup;
965 memset(&surface_desc, 0, sizeof(surface_desc));
966 surface_desc.dwSize = sizeof(surface_desc);
967 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
968 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
969 U4(surface_desc).ddpfPixelFormat = z_fmt;
970 surface_desc.dwWidth = 640;
971 surface_desc.dwHeight = 480;
972 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
973 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
974 if (FAILED(hr))
975 goto cleanup;
977 /* Using a different surface interface version still works */
978 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
979 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
980 refcount = IDirectDrawSurface7_Release(ds);
981 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
982 if (FAILED(hr))
983 goto cleanup;
985 /* Here too */
986 hr = IDirect3D7_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface7 *)surface3, &device);
987 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
988 if (FAILED(hr))
989 goto cleanup;
991 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
992 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
993 color = get_surface_color(surface, 320, 240);
994 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
996 cleanup:
997 if (surface3) IDirectDrawSurface3_Release(surface3);
998 if (surface) IDirectDrawSurface7_Release(surface);
999 if (device) IDirect3DDevice7_Release(device);
1000 if (d3d) IDirect3D7_Release(d3d);
1001 if (ddraw) IDirectDraw7_Release(ddraw);
1002 DestroyWindow(window);
1005 static void test_coop_level_threaded(void)
1007 struct create_window_thread_param p;
1008 IDirectDraw7 *ddraw;
1009 HRESULT hr;
1011 ddraw = create_ddraw();
1012 ok(!!ddraw, "Failed to create a ddraw object.\n");
1013 create_window_thread(&p);
1015 hr = IDirectDraw7_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1016 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1018 IDirectDraw7_Release(ddraw);
1019 destroy_window_thread(&p);
1022 static void test_depth_blit(void)
1024 IDirect3DDevice7 *device;
1025 static struct
1027 float x, y, z;
1028 DWORD color;
1030 quad1[] =
1032 { -1.0, 1.0, 0.50f, 0xff00ff00},
1033 { 1.0, 1.0, 0.50f, 0xff00ff00},
1034 { -1.0, -1.0, 0.50f, 0xff00ff00},
1035 { 1.0, -1.0, 0.50f, 0xff00ff00},
1037 static const D3DCOLOR expected_colors[4][4] =
1039 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1040 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1041 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1042 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1044 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1046 IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
1047 RECT src_rect, dst_rect;
1048 unsigned int i, j;
1049 D3DCOLOR color;
1050 HRESULT hr;
1051 IDirect3D7 *d3d;
1052 IDirectDraw7 *ddraw;
1053 DDBLTFX fx;
1054 HWND window;
1056 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1057 0, 0, 640, 480, 0, 0, 0, 0);
1058 if (!(device = create_device(window, DDSCL_NORMAL)))
1060 skip("Failed to create a 3D device, skipping test.\n");
1061 DestroyWindow(window);
1062 return;
1065 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1066 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1067 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1068 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1069 IDirect3D7_Release(d3d);
1071 ds1 = get_depth_stencil(device);
1073 memset(&ddsd_new, 0, sizeof(ddsd_new));
1074 ddsd_new.dwSize = sizeof(ddsd_new);
1075 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1076 ddsd_existing.dwSize = sizeof(ddsd_existing);
1077 hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
1078 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1079 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1080 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1081 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1082 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1083 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1084 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1085 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1086 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1087 IDirectDraw7_Release(ddraw);
1089 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1090 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1091 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1092 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1093 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1094 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1096 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1097 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1099 /* Partial blit. */
1100 SetRect(&src_rect, 0, 0, 320, 240);
1101 SetRect(&dst_rect, 0, 0, 320, 240);
1102 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1103 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1104 /* Different locations. */
1105 SetRect(&src_rect, 0, 0, 320, 240);
1106 SetRect(&dst_rect, 320, 240, 640, 480);
1107 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1108 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1109 /* Streched. */
1110 SetRect(&src_rect, 0, 0, 320, 240);
1111 SetRect(&dst_rect, 0, 0, 640, 480);
1112 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1113 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1114 /* Flipped. */
1115 SetRect(&src_rect, 0, 480, 640, 0);
1116 SetRect(&dst_rect, 0, 0, 640, 480);
1117 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1118 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1119 SetRect(&src_rect, 0, 0, 640, 480);
1120 SetRect(&dst_rect, 0, 480, 640, 0);
1121 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1122 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1123 /* Full, explicit. */
1124 SetRect(&src_rect, 0, 0, 640, 480);
1125 SetRect(&dst_rect, 0, 0, 640, 480);
1126 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1127 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1128 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1130 /* Depth blit inside a BeginScene / EndScene pair */
1131 hr = IDirect3DDevice7_BeginScene(device);
1132 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1133 /* From the current depth stencil */
1134 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1135 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1136 /* To the current depth stencil */
1137 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1138 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1139 /* Between unbound surfaces */
1140 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1141 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1142 hr = IDirect3DDevice7_EndScene(device);
1143 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1145 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1146 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1147 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1148 * a reliable result(z = 0.0) */
1149 memset(&fx, 0, sizeof(fx));
1150 fx.dwSize = sizeof(fx);
1151 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1152 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1154 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1155 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1156 SetRect(&dst_rect, 0, 0, 320, 240);
1157 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1158 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1159 IDirectDrawSurface7_Release(ds3);
1160 IDirectDrawSurface7_Release(ds2);
1161 IDirectDrawSurface7_Release(ds1);
1163 hr = IDirect3DDevice7_BeginScene(device);
1164 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1165 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1166 quad1, 4, 0);
1167 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1168 hr = IDirect3DDevice7_EndScene(device);
1169 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1171 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1172 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1173 for (i = 0; i < 4; ++i)
1175 for (j = 0; j < 4; ++j)
1177 unsigned int x = 80 * ((2 * j) + 1);
1178 unsigned int y = 60 * ((2 * i) + 1);
1179 color = get_surface_color(rt, x, y);
1180 ok(compare_color(color, expected_colors[i][j], 1),
1181 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1185 IDirectDrawSurface7_Release(rt);
1186 IDirect3DDevice7_Release(device);
1187 DestroyWindow(window);
1190 static void test_texture_load_ckey(void)
1192 HWND window;
1193 IDirect3DDevice7 *device;
1194 IDirectDraw7 *ddraw;
1195 IDirectDrawSurface7 *src;
1196 IDirectDrawSurface7 *dst;
1197 DDSURFACEDESC2 ddsd;
1198 HRESULT hr;
1199 DDCOLORKEY ckey;
1200 IDirect3D7 *d3d;
1202 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1203 0, 0, 640, 480, 0, 0, 0, 0);
1204 if (!(device = create_device(window, DDSCL_NORMAL)))
1206 skip("Failed to create a 3D device, skipping test.\n");
1207 DestroyWindow(window);
1208 return;
1211 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1212 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1213 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1214 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1215 IDirect3D7_Release(d3d);
1217 memset(&ddsd, 0, sizeof(ddsd));
1218 ddsd.dwSize = sizeof(ddsd);
1219 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1220 ddsd.dwHeight = 128;
1221 ddsd.dwWidth = 128;
1222 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1223 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1224 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1225 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1226 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1227 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1229 /* No surface has a color key */
1230 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1231 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1232 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1233 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1234 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1235 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1236 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1238 /* Source surface has a color key */
1239 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1240 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1241 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1242 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1243 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1244 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1245 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1246 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1247 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1249 /* Both surfaces have a color key: Dest ckey is overwritten */
1250 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1251 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1252 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1253 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1254 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1255 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1256 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1257 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1258 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1260 /* Only the destination has a color key: It is deleted. This behavior differs from
1261 * IDirect3DTexture(2)::Load */
1262 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1263 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1264 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1265 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1266 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1267 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1268 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1269 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1271 IDirectDrawSurface7_Release(dst);
1272 IDirectDrawSurface7_Release(src);
1273 IDirectDraw7_Release(ddraw);
1274 IDirect3DDevice7_Release(device);
1275 DestroyWindow(window);
1278 static void test_zenable(void)
1280 static struct
1282 struct vec4 position;
1283 D3DCOLOR diffuse;
1285 tquad[] =
1287 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1288 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1289 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1290 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1292 IDirect3DDevice7 *device;
1293 IDirectDrawSurface7 *rt;
1294 D3DCOLOR color;
1295 HWND window;
1296 HRESULT hr;
1297 UINT x, y;
1298 UINT i, j;
1300 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1301 0, 0, 640, 480, 0, 0, 0, 0);
1302 if (!(device = create_device(window, DDSCL_NORMAL)))
1304 skip("Failed to create a 3D device, skipping test.\n");
1305 DestroyWindow(window);
1306 return;
1309 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1310 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1312 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1313 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1314 hr = IDirect3DDevice7_BeginScene(device);
1315 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1316 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1317 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1318 hr = IDirect3DDevice7_EndScene(device);
1319 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1321 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1322 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1323 for (i = 0; i < 4; ++i)
1325 for (j = 0; j < 4; ++j)
1327 x = 80 * ((2 * j) + 1);
1328 y = 60 * ((2 * i) + 1);
1329 color = get_surface_color(rt, x, y);
1330 ok(compare_color(color, 0x0000ff00, 1),
1331 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1334 IDirectDrawSurface7_Release(rt);
1336 IDirect3DDevice7_Release(device);
1337 DestroyWindow(window);
1340 static void test_ck_rgba(void)
1342 static struct
1344 struct vec4 position;
1345 struct vec2 texcoord;
1347 tquad[] =
1349 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1350 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1351 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1352 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1353 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1354 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1355 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1356 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1358 static const struct
1360 D3DCOLOR fill_color;
1361 BOOL color_key;
1362 BOOL blend;
1363 D3DCOLOR result1;
1364 D3DCOLOR result2;
1366 tests[] =
1368 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x000000ff},
1369 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x000000ff},
1370 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00},
1371 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1372 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00807f00},
1373 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x0000ff00},
1374 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00},
1375 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1378 IDirectDrawSurface7 *texture;
1379 DDSURFACEDESC2 surface_desc;
1380 IDirect3DDevice7 *device;
1381 IDirectDrawSurface7 *rt;
1382 IDirectDraw7 *ddraw;
1383 IDirect3D7 *d3d;
1384 D3DCOLOR color;
1385 HWND window;
1386 DDBLTFX fx;
1387 HRESULT hr;
1388 UINT i;
1390 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1391 0, 0, 640, 480, 0, 0, 0, 0);
1392 if (!(device = create_device(window, DDSCL_NORMAL)))
1394 skip("Failed to create a 3D device, skipping test.\n");
1395 DestroyWindow(window);
1396 return;
1399 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1400 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1401 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1402 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1403 IDirect3D7_Release(d3d);
1405 memset(&surface_desc, 0, sizeof(surface_desc));
1406 surface_desc.dwSize = sizeof(surface_desc);
1407 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1408 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1409 surface_desc.dwWidth = 256;
1410 surface_desc.dwHeight = 256;
1411 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1412 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1413 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1414 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1415 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1416 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1417 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1418 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1419 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1420 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1421 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1423 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1424 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1425 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1426 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1427 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1428 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1430 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1431 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1433 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1435 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1436 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1437 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1438 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1440 memset(&fx, 0, sizeof(fx));
1441 fx.dwSize = sizeof(fx);
1442 U5(fx).dwFillColor = tests[i].fill_color;
1443 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1444 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1446 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1447 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1448 hr = IDirect3DDevice7_BeginScene(device);
1449 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1450 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1451 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1452 hr = IDirect3DDevice7_EndScene(device);
1453 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1455 color = get_surface_color(rt, 320, 240);
1456 if (i == 2)
1457 todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1458 tests[i].result1, i, color);
1459 else
1460 ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1461 tests[i].result1, i, color);
1463 U5(fx).dwFillColor = 0xff0000ff;
1464 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1465 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1467 hr = IDirect3DDevice7_BeginScene(device);
1468 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1469 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1470 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1471 hr = IDirect3DDevice7_EndScene(device);
1472 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1474 /* This tests that fragments that are masked out by the color key are
1475 * discarded, instead of just fully transparent. */
1476 color = get_surface_color(rt, 320, 240);
1477 if (i == 2)
1478 todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1479 tests[i].result2, i, color);
1480 else
1481 ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1482 tests[i].result2, i, color);
1485 IDirectDrawSurface7_Release(rt);
1486 IDirectDrawSurface7_Release(texture);
1487 IDirectDraw7_Release(ddraw);
1488 IDirect3DDevice7_Release(device);
1489 DestroyWindow(window);
1492 static void test_ck_default(void)
1494 static struct
1496 struct vec4 position;
1497 struct vec2 texcoord;
1499 tquad[] =
1501 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1502 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1503 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1504 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1506 IDirectDrawSurface7 *surface, *rt;
1507 DDSURFACEDESC2 surface_desc;
1508 IDirect3DDevice7 *device;
1509 IDirectDraw7 *ddraw;
1510 IDirect3D7 *d3d;
1511 D3DCOLOR color;
1512 DWORD value;
1513 HWND window;
1514 DDBLTFX fx;
1515 HRESULT hr;
1517 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1518 0, 0, 640, 480, 0, 0, 0, 0);
1520 if (!(device = create_device(window, DDSCL_NORMAL)))
1522 skip("Failed to create a 3D device, skipping test.\n");
1523 DestroyWindow(window);
1524 return;
1527 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1528 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1529 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1530 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1531 IDirect3D7_Release(d3d);
1533 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1534 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1536 memset(&surface_desc, 0, sizeof(surface_desc));
1537 surface_desc.dwSize = sizeof(surface_desc);
1538 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1539 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1540 surface_desc.dwWidth = 256;
1541 surface_desc.dwHeight = 256;
1542 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1543 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1544 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1545 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1546 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1547 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1548 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1549 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1550 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1551 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1552 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1553 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1555 memset(&fx, 0, sizeof(fx));
1556 fx.dwSize = sizeof(fx);
1557 U5(fx).dwFillColor = 0x000000ff;
1558 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1559 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1561 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1562 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1563 hr = IDirect3DDevice7_BeginScene(device);
1564 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1565 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1566 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1567 ok(!value, "Got unexpected color keying state %#x.\n", value);
1568 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1569 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1570 hr = IDirect3DDevice7_EndScene(device);
1571 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1572 color = get_surface_color(rt, 320, 240);
1573 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1575 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1576 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1577 hr = IDirect3DDevice7_BeginScene(device);
1578 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1579 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1580 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1581 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1582 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1583 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1584 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1585 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1586 hr = IDirect3DDevice7_EndScene(device);
1587 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1588 color = get_surface_color(rt, 320, 240);
1589 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1591 IDirectDrawSurface7_Release(surface);
1592 IDirectDrawSurface7_Release(rt);
1593 IDirect3DDevice7_Release(device);
1594 IDirectDraw7_Release(ddraw);
1595 DestroyWindow(window);
1598 static void test_ck_complex(void)
1600 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1601 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
1602 DDSURFACEDESC2 surface_desc;
1603 IDirect3DDevice7 *device;
1604 DDCOLORKEY color_key;
1605 IDirectDraw7 *ddraw;
1606 IDirect3D7 *d3d;
1607 unsigned int i;
1608 ULONG refcount;
1609 HWND window;
1610 HRESULT hr;
1612 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1613 0, 0, 640, 480, 0, 0, 0, 0);
1614 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1616 skip("Failed to create a 3D device, skipping test.\n");
1617 DestroyWindow(window);
1618 return;
1620 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1621 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1622 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1623 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1624 IDirect3D7_Release(d3d);
1626 memset(&surface_desc, 0, sizeof(surface_desc));
1627 surface_desc.dwSize = sizeof(surface_desc);
1628 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1629 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1630 surface_desc.dwWidth = 128;
1631 surface_desc.dwHeight = 128;
1632 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1633 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1635 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1636 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1637 color_key.dwColorSpaceLowValue = 0x0000ff00;
1638 color_key.dwColorSpaceHighValue = 0x0000ff00;
1639 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1640 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1641 memset(&color_key, 0, sizeof(color_key));
1642 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1643 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1644 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1645 color_key.dwColorSpaceLowValue);
1646 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1647 color_key.dwColorSpaceHighValue);
1649 mipmap = surface;
1650 IDirectDrawSurface_AddRef(mipmap);
1651 for (i = 0; i < 7; ++i)
1653 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1654 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1655 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1656 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1658 color_key.dwColorSpaceLowValue = 0x000000ff;
1659 color_key.dwColorSpaceHighValue = 0x000000ff;
1660 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1661 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1663 IDirectDrawSurface_Release(mipmap);
1664 mipmap = tmp;
1667 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1668 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1669 IDirectDrawSurface_Release(mipmap);
1670 refcount = IDirectDrawSurface7_Release(surface);
1671 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1673 memset(&surface_desc, 0, sizeof(surface_desc));
1674 surface_desc.dwSize = sizeof(surface_desc);
1675 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1676 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1677 surface_desc.dwBackBufferCount = 1;
1678 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1679 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1681 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1682 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1683 color_key.dwColorSpaceLowValue = 0x0000ff00;
1684 color_key.dwColorSpaceHighValue = 0x0000ff00;
1685 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1686 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1687 memset(&color_key, 0, sizeof(color_key));
1688 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1689 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1690 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1691 color_key.dwColorSpaceLowValue);
1692 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1693 color_key.dwColorSpaceHighValue);
1695 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1696 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1698 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1699 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1700 color_key.dwColorSpaceLowValue = 0x0000ff00;
1701 color_key.dwColorSpaceHighValue = 0x0000ff00;
1702 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1703 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1704 memset(&color_key, 0, sizeof(color_key));
1705 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1706 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1707 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1708 color_key.dwColorSpaceLowValue);
1709 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1710 color_key.dwColorSpaceHighValue);
1712 IDirectDrawSurface_Release(tmp);
1714 refcount = IDirectDrawSurface7_Release(surface);
1715 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1716 IDirectDraw7_Release(ddraw);
1717 refcount = IDirect3DDevice7_Release(device);
1718 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1719 DestroyWindow(window);
1722 struct qi_test
1724 REFIID iid;
1725 REFIID refcount_iid;
1726 HRESULT hr;
1729 static void test_qi(const char *test_name, IUnknown *base_iface,
1730 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1732 ULONG refcount, expected_refcount;
1733 IUnknown *iface1, *iface2;
1734 HRESULT hr;
1735 UINT i, j;
1737 for (i = 0; i < entry_count; ++i)
1739 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1740 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1741 if (SUCCEEDED(hr))
1743 for (j = 0; j < entry_count; ++j)
1745 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1746 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1747 if (SUCCEEDED(hr))
1749 expected_refcount = 0;
1750 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1751 ++expected_refcount;
1752 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1753 ++expected_refcount;
1754 refcount = IUnknown_Release(iface2);
1755 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1756 refcount, test_name, i, j, expected_refcount);
1760 expected_refcount = 0;
1761 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1762 ++expected_refcount;
1763 refcount = IUnknown_Release(iface1);
1764 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1765 refcount, test_name, i, expected_refcount);
1770 static void test_surface_qi(void)
1772 static const struct qi_test tests[] =
1774 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1775 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1776 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1777 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1778 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1779 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1780 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1781 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1782 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1783 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1784 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1785 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1786 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1787 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1788 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1789 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1790 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1791 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1792 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1793 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1794 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1795 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1796 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1797 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1798 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1799 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1800 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1801 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1802 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1803 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1804 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1805 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1806 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1807 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1808 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1809 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1810 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1811 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1812 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1813 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1814 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1815 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1818 IDirectDrawSurface7 *surface;
1819 DDSURFACEDESC2 surface_desc;
1820 IDirect3DDevice7 *device;
1821 IDirectDraw7 *ddraw;
1822 HWND window;
1823 HRESULT hr;
1825 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1826 0, 0, 640, 480, 0, 0, 0, 0);
1827 /* Try to create a D3D device to see if the ddraw implementation supports
1828 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1829 * doesn't support e.g. the IDirect3DTexture interfaces. */
1830 if (!(device = create_device(window, DDSCL_NORMAL)))
1832 skip("Failed to create a 3D device, skipping test.\n");
1833 DestroyWindow(window);
1834 return;
1836 IDirect3DDevice_Release(device);
1837 ddraw = create_ddraw();
1838 ok(!!ddraw, "Failed to create a ddraw object.\n");
1839 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1840 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1842 memset(&surface_desc, 0, sizeof(surface_desc));
1843 surface_desc.dwSize = sizeof(surface_desc);
1844 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1845 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1846 surface_desc.dwWidth = 512;
1847 surface_desc.dwHeight = 512;
1848 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1849 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1851 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, sizeof(tests) / sizeof(*tests));
1853 IDirectDrawSurface7_Release(surface);
1854 IDirectDraw7_Release(ddraw);
1855 DestroyWindow(window);
1858 static void test_device_qi(void)
1860 static const struct qi_test tests[] =
1862 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1863 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1864 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
1865 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1866 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
1867 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
1868 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
1869 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
1870 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
1871 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
1872 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1873 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1874 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1875 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1876 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1877 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1878 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1879 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1880 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1881 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1882 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1883 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1884 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1885 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1886 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1887 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1888 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1889 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1890 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1891 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1892 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1893 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1894 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1895 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1896 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1897 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1898 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1899 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1900 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1901 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1902 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1903 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
1906 IDirect3DDevice7 *device;
1907 HWND window;
1909 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1910 0, 0, 640, 480, 0, 0, 0, 0);
1911 if (!(device = create_device(window, DDSCL_NORMAL)))
1913 skip("Failed to create a 3D device, skipping test.\n");
1914 DestroyWindow(window);
1915 return;
1918 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, sizeof(tests) / sizeof(*tests));
1920 IDirect3DDevice7_Release(device);
1921 DestroyWindow(window);
1924 static void test_wndproc(void)
1926 LONG_PTR proc, ddraw_proc;
1927 IDirectDraw7 *ddraw;
1928 WNDCLASSA wc = {0};
1929 HWND window;
1930 HRESULT hr;
1931 ULONG ref;
1933 static const UINT messages[] =
1935 WM_WINDOWPOSCHANGING,
1936 WM_MOVE,
1937 WM_SIZE,
1938 WM_WINDOWPOSCHANGING,
1939 WM_ACTIVATE,
1940 WM_SETFOCUS,
1944 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1945 ddraw = create_ddraw();
1946 ok(!!ddraw, "Failed to create a ddraw object.\n");
1948 wc.lpfnWndProc = test_proc;
1949 wc.lpszClassName = "ddraw_test_wndproc_wc";
1950 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1952 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1953 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1955 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1956 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1957 (LONG_PTR)test_proc, proc);
1958 expect_messages = messages;
1959 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1960 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1961 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
1962 expect_messages = NULL;
1963 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1964 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1965 (LONG_PTR)test_proc, proc);
1966 ref = IDirectDraw7_Release(ddraw);
1967 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1968 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1969 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1970 (LONG_PTR)test_proc, proc);
1972 /* DDSCL_NORMAL doesn't. */
1973 ddraw = create_ddraw();
1974 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1975 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1976 (LONG_PTR)test_proc, proc);
1977 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
1978 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1979 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1980 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1981 (LONG_PTR)test_proc, proc);
1982 ref = IDirectDraw7_Release(ddraw);
1983 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1984 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1985 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1986 (LONG_PTR)test_proc, proc);
1988 /* The original window proc is only restored by ddraw if the current
1989 * window proc matches the one ddraw set. This also affects switching
1990 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
1991 ddraw = create_ddraw();
1992 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1993 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1994 (LONG_PTR)test_proc, proc);
1995 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1996 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1997 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1998 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1999 (LONG_PTR)test_proc, proc);
2000 ddraw_proc = proc;
2001 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2002 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2003 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2004 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2005 (LONG_PTR)test_proc, proc);
2006 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2007 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2008 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2009 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2010 (LONG_PTR)test_proc, proc);
2011 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2012 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2013 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2014 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2015 (LONG_PTR)DefWindowProcA, proc);
2016 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2017 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2018 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2019 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2020 (LONG_PTR)DefWindowProcA, proc);
2021 ref = IDirectDraw7_Release(ddraw);
2022 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2023 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2024 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2025 (LONG_PTR)test_proc, proc);
2027 ddraw = create_ddraw();
2028 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2029 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2030 (LONG_PTR)test_proc, proc);
2031 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2032 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2033 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2034 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2035 (LONG_PTR)test_proc, proc);
2036 ref = IDirectDraw7_Release(ddraw);
2037 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2038 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2039 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2040 (LONG_PTR)DefWindowProcA, proc);
2042 fix_wndproc(window, (LONG_PTR)test_proc);
2043 expect_messages = NULL;
2044 DestroyWindow(window);
2045 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2048 static void test_window_style(void)
2050 LONG style, exstyle, tmp;
2051 RECT fullscreen_rect, r;
2052 IDirectDraw7 *ddraw;
2053 HWND window;
2054 HRESULT hr;
2055 ULONG ref;
2057 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2058 0, 0, 100, 100, 0, 0, 0, 0);
2059 ddraw = create_ddraw();
2060 ok(!!ddraw, "Failed to create a ddraw object.\n");
2062 style = GetWindowLongA(window, GWL_STYLE);
2063 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2064 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2066 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2067 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2069 tmp = GetWindowLongA(window, GWL_STYLE);
2070 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2071 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2072 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2074 GetWindowRect(window, &r);
2075 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2076 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2077 r.left, r.top, r.right, r.bottom);
2078 GetClientRect(window, &r);
2079 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2081 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2082 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2084 tmp = GetWindowLongA(window, GWL_STYLE);
2085 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2086 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2087 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2089 ref = IDirectDraw7_Release(ddraw);
2090 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2092 DestroyWindow(window);
2095 static void test_redundant_mode_set(void)
2097 DDSURFACEDESC2 surface_desc = {0};
2098 IDirectDraw7 *ddraw;
2099 HWND window;
2100 HRESULT hr;
2101 RECT r, s;
2102 ULONG ref;
2104 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2105 0, 0, 100, 100, 0, 0, 0, 0);
2106 ddraw = create_ddraw();
2107 ok(!!ddraw, "Failed to create a ddraw object.\n");
2108 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2109 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2111 surface_desc.dwSize = sizeof(surface_desc);
2112 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2113 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2115 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2116 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2117 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2119 GetWindowRect(window, &r);
2120 r.right /= 2;
2121 r.bottom /= 2;
2122 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2123 GetWindowRect(window, &s);
2124 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2125 r.left, r.top, r.right, r.bottom,
2126 s.left, s.top, s.right, s.bottom);
2128 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2129 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2130 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2132 GetWindowRect(window, &s);
2133 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2134 r.left, r.top, r.right, r.bottom,
2135 s.left, s.top, s.right, s.bottom);
2137 ref = IDirectDraw7_Release(ddraw);
2138 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2140 DestroyWindow(window);
2143 static SIZE screen_size, screen_size2;
2145 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2147 if (message == WM_SIZE)
2149 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2150 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2153 return test_proc(hwnd, message, wparam, lparam);
2156 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2158 if (message == WM_SIZE)
2160 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2161 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2164 return test_proc(hwnd, message, wparam, lparam);
2167 static void test_coop_level_mode_set(void)
2169 IDirectDrawSurface7 *primary;
2170 RECT fullscreen_rect, r, s;
2171 IDirectDraw7 *ddraw;
2172 DDSURFACEDESC2 ddsd;
2173 WNDCLASSA wc = {0};
2174 HWND window, window2;
2175 HRESULT hr;
2176 ULONG ref;
2178 static const UINT exclusive_messages[] =
2180 WM_WINDOWPOSCHANGING,
2181 WM_WINDOWPOSCHANGED,
2182 WM_SIZE,
2183 WM_DISPLAYCHANGE,
2187 static const UINT normal_messages[] =
2189 WM_DISPLAYCHANGE,
2193 ddraw = create_ddraw();
2194 ok(!!ddraw, "Failed to create a ddraw object.\n");
2196 wc.lpfnWndProc = mode_set_proc;
2197 wc.lpszClassName = "ddraw_test_wndproc_wc";
2198 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2199 wc.lpfnWndProc = mode_set_proc2;
2200 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2201 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2203 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2204 0, 0, 100, 100, 0, 0, 0, 0);
2205 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2206 0, 0, 100, 100, 0, 0, 0, 0);
2208 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2209 SetRect(&s, 0, 0, 640, 480);
2211 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2212 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2214 GetWindowRect(window, &r);
2215 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2216 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2217 r.left, r.top, r.right, r.bottom);
2219 memset(&ddsd, 0, sizeof(ddsd));
2220 ddsd.dwSize = sizeof(ddsd);
2221 ddsd.dwFlags = DDSD_CAPS;
2222 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2224 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2225 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2226 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2227 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2228 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2229 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2230 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2231 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2233 GetWindowRect(window, &r);
2234 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2235 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2236 r.left, r.top, r.right, r.bottom);
2238 expect_messages = exclusive_messages;
2239 screen_size.cx = 0;
2240 screen_size.cy = 0;
2242 hr = set_display_mode(ddraw, 640, 480);
2243 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2245 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2246 expect_messages = NULL;
2247 ok(screen_size.cx == s.right && screen_size.cy == s.bottom,
2248 "Expected screen size %ux%u, got %ux%u.\n",
2249 s.right, s.bottom, screen_size.cx, screen_size.cy);
2251 GetWindowRect(window, &r);
2252 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2253 s.left, s.top, s.right, s.bottom,
2254 r.left, r.top, r.right, r.bottom);
2256 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2257 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2258 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2259 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2260 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2261 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2262 IDirectDrawSurface7_Release(primary);
2264 memset(&ddsd, 0, sizeof(ddsd));
2265 ddsd.dwSize = sizeof(ddsd);
2266 ddsd.dwFlags = DDSD_CAPS;
2267 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2269 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2270 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2271 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2272 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2273 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2274 s.right - s.left, ddsd.dwWidth);
2275 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2276 s.bottom - s.top, ddsd.dwHeight);
2278 GetWindowRect(window, &r);
2279 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2280 s.left, s.top, s.right, s.bottom,
2281 r.left, r.top, r.right, r.bottom);
2283 expect_messages = exclusive_messages;
2284 screen_size.cx = 0;
2285 screen_size.cy = 0;
2287 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2288 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2290 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2291 expect_messages = NULL;
2292 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2293 "Expected screen size %ux%u, got %ux%u.\n",
2294 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2296 GetWindowRect(window, &r);
2297 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2298 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2299 r.left, r.top, r.right, r.bottom);
2301 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2302 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2303 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2304 s.right - s.left, ddsd.dwWidth);
2305 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2306 s.bottom - s.top, ddsd.dwHeight);
2307 IDirectDrawSurface7_Release(primary);
2309 memset(&ddsd, 0, sizeof(ddsd));
2310 ddsd.dwSize = sizeof(ddsd);
2311 ddsd.dwFlags = DDSD_CAPS;
2312 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2314 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2315 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2316 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2317 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2318 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2319 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2320 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2321 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2323 GetWindowRect(window, &r);
2324 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2325 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2326 r.left, r.top, r.right, r.bottom);
2328 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2329 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2331 GetWindowRect(window, &r);
2332 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2333 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2334 r.left, r.top, r.right, r.bottom);
2336 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2337 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2338 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2339 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2340 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2341 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2342 IDirectDrawSurface7_Release(primary);
2344 memset(&ddsd, 0, sizeof(ddsd));
2345 ddsd.dwSize = sizeof(ddsd);
2346 ddsd.dwFlags = DDSD_CAPS;
2347 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2349 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2350 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2351 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2352 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2353 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2354 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2355 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2356 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2358 GetWindowRect(window, &r);
2359 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2360 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2361 r.left, r.top, r.right, r.bottom);
2363 expect_messages = normal_messages;
2364 screen_size.cx = 0;
2365 screen_size.cy = 0;
2367 hr = set_display_mode(ddraw, 640, 480);
2368 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2370 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2371 expect_messages = NULL;
2372 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2374 GetWindowRect(window, &r);
2375 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2376 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2377 r.left, r.top, r.right, r.bottom);
2379 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2380 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2381 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2382 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2383 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2384 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2385 IDirectDrawSurface7_Release(primary);
2387 memset(&ddsd, 0, sizeof(ddsd));
2388 ddsd.dwSize = sizeof(ddsd);
2389 ddsd.dwFlags = DDSD_CAPS;
2390 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2392 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2393 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2394 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2395 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2396 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2397 s.right - s.left, ddsd.dwWidth);
2398 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2399 s.bottom - s.top, ddsd.dwHeight);
2401 GetWindowRect(window, &r);
2402 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2403 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2404 r.left, r.top, r.right, r.bottom);
2406 expect_messages = normal_messages;
2407 screen_size.cx = 0;
2408 screen_size.cy = 0;
2410 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2411 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2413 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2414 expect_messages = NULL;
2415 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2417 GetWindowRect(window, &r);
2418 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2419 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2420 r.left, r.top, r.right, r.bottom);
2422 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2423 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2424 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2425 s.right - s.left, ddsd.dwWidth);
2426 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2427 s.bottom - s.top, ddsd.dwHeight);
2428 IDirectDrawSurface7_Release(primary);
2430 memset(&ddsd, 0, sizeof(ddsd));
2431 ddsd.dwSize = sizeof(ddsd);
2432 ddsd.dwFlags = DDSD_CAPS;
2433 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2435 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2436 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2437 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2438 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2439 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2440 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2441 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2442 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2444 GetWindowRect(window, &r);
2445 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2446 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2447 r.left, r.top, r.right, r.bottom);
2449 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2450 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2451 * not DDSCL_FULLSCREEN. */
2452 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2453 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2455 GetWindowRect(window, &r);
2456 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2457 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2458 r.left, r.top, r.right, r.bottom);
2460 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2461 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2462 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2463 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2464 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2465 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2466 IDirectDrawSurface7_Release(primary);
2468 memset(&ddsd, 0, sizeof(ddsd));
2469 ddsd.dwSize = sizeof(ddsd);
2470 ddsd.dwFlags = DDSD_CAPS;
2471 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2473 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2474 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2475 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2476 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2477 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2478 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2479 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2480 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2482 GetWindowRect(window, &r);
2483 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2484 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2485 r.left, r.top, r.right, r.bottom);
2487 expect_messages = normal_messages;
2488 screen_size.cx = 0;
2489 screen_size.cy = 0;
2491 hr = set_display_mode(ddraw, 640, 480);
2492 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2494 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2495 expect_messages = NULL;
2496 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2498 GetWindowRect(window, &r);
2499 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2500 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2501 r.left, r.top, r.right, r.bottom);
2503 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2504 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2505 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2506 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2507 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2508 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2509 IDirectDrawSurface7_Release(primary);
2511 memset(&ddsd, 0, sizeof(ddsd));
2512 ddsd.dwSize = sizeof(ddsd);
2513 ddsd.dwFlags = DDSD_CAPS;
2514 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2516 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2517 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2518 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2519 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2520 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2521 s.right - s.left, ddsd.dwWidth);
2522 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2523 s.bottom - s.top, ddsd.dwHeight);
2525 GetWindowRect(window, &r);
2526 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2527 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2528 r.left, r.top, r.right, r.bottom);
2530 expect_messages = normal_messages;
2531 screen_size.cx = 0;
2532 screen_size.cy = 0;
2534 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2535 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2537 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2538 expect_messages = NULL;
2539 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2541 GetWindowRect(window, &r);
2542 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2543 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2544 r.left, r.top, r.right, r.bottom);
2546 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2547 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2548 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2549 s.right - s.left, ddsd.dwWidth);
2550 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2551 s.bottom - s.top, ddsd.dwHeight);
2552 IDirectDrawSurface7_Release(primary);
2554 memset(&ddsd, 0, sizeof(ddsd));
2555 ddsd.dwSize = sizeof(ddsd);
2556 ddsd.dwFlags = DDSD_CAPS;
2557 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2559 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2560 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2561 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2562 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2563 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2564 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2565 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2566 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2567 IDirectDrawSurface7_Release(primary);
2569 GetWindowRect(window, &r);
2570 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2571 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2572 r.left, r.top, r.right, r.bottom);
2574 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2575 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2576 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2577 hr = set_display_mode(ddraw, 640, 480);
2578 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2580 expect_messages = exclusive_messages;
2581 screen_size.cx = 0;
2582 screen_size.cy = 0;
2584 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2585 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2587 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2588 expect_messages = NULL;
2589 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2590 "Expected screen size %ux%u, got %ux%u.\n",
2591 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2593 GetWindowRect(window, &r);
2594 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2595 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2596 r.left, r.top, r.right, r.bottom);
2598 memset(&ddsd, 0, sizeof(ddsd));
2599 ddsd.dwSize = sizeof(ddsd);
2600 ddsd.dwFlags = DDSD_CAPS;
2601 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2603 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2604 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2605 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2606 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2607 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2608 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2609 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2610 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2611 IDirectDrawSurface7_Release(primary);
2613 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2614 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2615 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2616 hr = set_display_mode(ddraw, 640, 480);
2617 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2619 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2620 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2622 memset(&ddsd, 0, sizeof(ddsd));
2623 ddsd.dwSize = sizeof(ddsd);
2624 ddsd.dwFlags = DDSD_CAPS;
2625 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2627 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2628 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2629 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2630 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2631 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2632 s.right - s.left, ddsd.dwWidth);
2633 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2634 s.bottom - s.top, ddsd.dwHeight);
2635 IDirectDrawSurface7_Release(primary);
2637 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2638 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2640 /* If the window is changed at the same time, messages are sent to the new window. */
2641 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2642 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2643 hr = set_display_mode(ddraw, 640, 480);
2644 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2646 expect_messages = exclusive_messages;
2647 screen_size.cx = 0;
2648 screen_size.cy = 0;
2649 screen_size2.cx = 0;
2650 screen_size2.cy = 0;
2652 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
2653 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2655 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2656 expect_messages = NULL;
2657 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
2658 screen_size.cx, screen_size.cy);
2659 ok(screen_size2.cx == fullscreen_rect.right && screen_size2.cy == fullscreen_rect.bottom,
2660 "Expected screen size 2 %ux%u, got %ux%u.\n",
2661 fullscreen_rect.right, fullscreen_rect.bottom, screen_size2.cx, screen_size2.cy);
2663 GetWindowRect(window, &r);
2664 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2665 s.left, s.top, s.right, s.bottom,
2666 r.left, r.top, r.right, r.bottom);
2667 GetWindowRect(window2, &r);
2668 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2669 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2670 r.left, r.top, r.right, r.bottom);
2672 memset(&ddsd, 0, sizeof(ddsd));
2673 ddsd.dwSize = sizeof(ddsd);
2674 ddsd.dwFlags = DDSD_CAPS;
2675 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2677 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2678 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2679 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2680 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2681 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2682 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2683 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2684 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2685 IDirectDrawSurface7_Release(primary);
2687 ref = IDirectDraw7_Release(ddraw);
2688 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2690 GetWindowRect(window, &r);
2691 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2692 s.left, s.top, s.right, s.bottom,
2693 r.left, r.top, r.right, r.bottom);
2695 expect_messages = NULL;
2696 DestroyWindow(window);
2697 DestroyWindow(window2);
2698 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2699 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
2702 static void test_coop_level_mode_set_multi(void)
2704 IDirectDraw7 *ddraw1, *ddraw2;
2705 UINT orig_w, orig_h, w, h;
2706 HWND window;
2707 HRESULT hr;
2708 ULONG ref;
2710 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2711 0, 0, 100, 100, 0, 0, 0, 0);
2712 ddraw1 = create_ddraw();
2713 ok(!!ddraw1, "Failed to create a ddraw object.\n");
2715 orig_w = GetSystemMetrics(SM_CXSCREEN);
2716 orig_h = GetSystemMetrics(SM_CYSCREEN);
2718 /* With just a single ddraw object, the display mode is restored on
2719 * release. */
2720 hr = set_display_mode(ddraw1, 800, 600);
2721 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2722 w = GetSystemMetrics(SM_CXSCREEN);
2723 ok(w == 800, "Got unexpected screen width %u.\n", w);
2724 h = GetSystemMetrics(SM_CYSCREEN);
2725 ok(h == 600, "Got unexpected screen height %u.\n", h);
2727 ref = IDirectDraw7_Release(ddraw1);
2728 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2729 w = GetSystemMetrics(SM_CXSCREEN);
2730 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2731 h = GetSystemMetrics(SM_CYSCREEN);
2732 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2734 /* When there are multiple ddraw objects, the display mode is restored to
2735 * the initial mode, before the first SetDisplayMode() call. */
2736 ddraw1 = create_ddraw();
2737 hr = set_display_mode(ddraw1, 800, 600);
2738 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2739 w = GetSystemMetrics(SM_CXSCREEN);
2740 ok(w == 800, "Got unexpected screen width %u.\n", w);
2741 h = GetSystemMetrics(SM_CYSCREEN);
2742 ok(h == 600, "Got unexpected screen height %u.\n", h);
2744 ddraw2 = create_ddraw();
2745 hr = set_display_mode(ddraw2, 640, 480);
2746 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2747 w = GetSystemMetrics(SM_CXSCREEN);
2748 ok(w == 640, "Got unexpected screen width %u.\n", w);
2749 h = GetSystemMetrics(SM_CYSCREEN);
2750 ok(h == 480, "Got unexpected screen height %u.\n", h);
2752 ref = IDirectDraw7_Release(ddraw2);
2753 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2754 w = GetSystemMetrics(SM_CXSCREEN);
2755 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2756 h = GetSystemMetrics(SM_CYSCREEN);
2757 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2759 ref = IDirectDraw7_Release(ddraw1);
2760 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2761 w = GetSystemMetrics(SM_CXSCREEN);
2762 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2763 h = GetSystemMetrics(SM_CYSCREEN);
2764 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2766 /* Regardless of release ordering. */
2767 ddraw1 = create_ddraw();
2768 hr = set_display_mode(ddraw1, 800, 600);
2769 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2770 w = GetSystemMetrics(SM_CXSCREEN);
2771 ok(w == 800, "Got unexpected screen width %u.\n", w);
2772 h = GetSystemMetrics(SM_CYSCREEN);
2773 ok(h == 600, "Got unexpected screen height %u.\n", h);
2775 ddraw2 = create_ddraw();
2776 hr = set_display_mode(ddraw2, 640, 480);
2777 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2778 w = GetSystemMetrics(SM_CXSCREEN);
2779 ok(w == 640, "Got unexpected screen width %u.\n", w);
2780 h = GetSystemMetrics(SM_CYSCREEN);
2781 ok(h == 480, "Got unexpected screen height %u.\n", h);
2783 ref = IDirectDraw7_Release(ddraw1);
2784 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2785 w = GetSystemMetrics(SM_CXSCREEN);
2786 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2787 h = GetSystemMetrics(SM_CYSCREEN);
2788 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2790 ref = IDirectDraw7_Release(ddraw2);
2791 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2792 w = GetSystemMetrics(SM_CXSCREEN);
2793 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2794 h = GetSystemMetrics(SM_CYSCREEN);
2795 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2797 /* But only for ddraw objects that called SetDisplayMode(). */
2798 ddraw1 = create_ddraw();
2799 ddraw2 = create_ddraw();
2800 hr = set_display_mode(ddraw2, 640, 480);
2801 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2802 w = GetSystemMetrics(SM_CXSCREEN);
2803 ok(w == 640, "Got unexpected screen width %u.\n", w);
2804 h = GetSystemMetrics(SM_CYSCREEN);
2805 ok(h == 480, "Got unexpected screen height %u.\n", h);
2807 ref = IDirectDraw7_Release(ddraw1);
2808 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2809 w = GetSystemMetrics(SM_CXSCREEN);
2810 ok(w == 640, "Got unexpected screen width %u.\n", w);
2811 h = GetSystemMetrics(SM_CYSCREEN);
2812 ok(h == 480, "Got unexpected screen height %u.\n", h);
2814 ref = IDirectDraw7_Release(ddraw2);
2815 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2816 w = GetSystemMetrics(SM_CXSCREEN);
2817 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2818 h = GetSystemMetrics(SM_CYSCREEN);
2819 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2821 /* If there's a ddraw object that's currently in exclusive mode, it blocks
2822 * restoring the display mode. */
2823 ddraw1 = create_ddraw();
2824 hr = set_display_mode(ddraw1, 800, 600);
2825 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2826 w = GetSystemMetrics(SM_CXSCREEN);
2827 ok(w == 800, "Got unexpected screen width %u.\n", w);
2828 h = GetSystemMetrics(SM_CYSCREEN);
2829 ok(h == 600, "Got unexpected screen height %u.\n", h);
2831 ddraw2 = create_ddraw();
2832 hr = set_display_mode(ddraw2, 640, 480);
2833 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2834 w = GetSystemMetrics(SM_CXSCREEN);
2835 ok(w == 640, "Got unexpected screen width %u.\n", w);
2836 h = GetSystemMetrics(SM_CYSCREEN);
2837 ok(h == 480, "Got unexpected screen height %u.\n", h);
2839 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2840 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2842 ref = IDirectDraw7_Release(ddraw1);
2843 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2844 w = GetSystemMetrics(SM_CXSCREEN);
2845 ok(w == 640, "Got unexpected screen width %u.\n", w);
2846 h = GetSystemMetrics(SM_CYSCREEN);
2847 ok(h == 480, "Got unexpected screen height %u.\n", h);
2849 ref = IDirectDraw7_Release(ddraw2);
2850 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2851 w = GetSystemMetrics(SM_CXSCREEN);
2852 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2853 h = GetSystemMetrics(SM_CYSCREEN);
2854 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2856 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
2857 ddraw1 = create_ddraw();
2858 hr = set_display_mode(ddraw1, 800, 600);
2859 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2860 w = GetSystemMetrics(SM_CXSCREEN);
2861 ok(w == 800, "Got unexpected screen width %u.\n", w);
2862 h = GetSystemMetrics(SM_CYSCREEN);
2863 ok(h == 600, "Got unexpected screen height %u.\n", h);
2865 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2866 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2868 ddraw2 = create_ddraw();
2869 hr = set_display_mode(ddraw2, 640, 480);
2870 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
2872 ref = IDirectDraw7_Release(ddraw1);
2873 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2874 w = GetSystemMetrics(SM_CXSCREEN);
2875 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2876 h = GetSystemMetrics(SM_CYSCREEN);
2877 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2879 ref = IDirectDraw7_Release(ddraw2);
2880 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2881 w = GetSystemMetrics(SM_CXSCREEN);
2882 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2883 h = GetSystemMetrics(SM_CYSCREEN);
2884 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2886 DestroyWindow(window);
2889 static void test_initialize(void)
2891 IDirectDraw7 *ddraw;
2892 HRESULT hr;
2894 ddraw = create_ddraw();
2895 ok(!!ddraw, "Failed to create a ddraw object.\n");
2897 hr = IDirectDraw7_Initialize(ddraw, NULL);
2898 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
2899 IDirectDraw7_Release(ddraw);
2901 CoInitialize(NULL);
2902 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
2903 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
2904 hr = IDirectDraw7_Initialize(ddraw, NULL);
2905 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
2906 hr = IDirectDraw7_Initialize(ddraw, NULL);
2907 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
2908 IDirectDraw7_Release(ddraw);
2909 CoUninitialize();
2912 static void test_coop_level_surf_create(void)
2914 IDirectDrawSurface7 *surface;
2915 IDirectDraw7 *ddraw;
2916 DDSURFACEDESC2 ddsd;
2917 HRESULT hr;
2919 ddraw = create_ddraw();
2920 ok(!!ddraw, "Failed to create a ddraw object.\n");
2922 memset(&ddsd, 0, sizeof(ddsd));
2923 ddsd.dwSize = sizeof(ddsd);
2924 ddsd.dwFlags = DDSD_CAPS;
2925 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2926 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
2927 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
2929 IDirectDraw7_Release(ddraw);
2932 static void test_vb_discard(void)
2934 static const struct vec4 quad[] =
2936 { 0.0f, 480.0f, 0.0f, 1.0f},
2937 { 0.0f, 0.0f, 0.0f, 1.0f},
2938 {640.0f, 480.0f, 0.0f, 1.0f},
2939 {640.0f, 0.0f, 0.0f, 1.0f},
2942 IDirect3DDevice7 *device;
2943 IDirect3D7 *d3d;
2944 IDirect3DVertexBuffer7 *buffer;
2945 HWND window;
2946 HRESULT hr;
2947 D3DVERTEXBUFFERDESC desc;
2948 BYTE *data;
2949 static const unsigned int vbsize = 16;
2950 unsigned int i;
2952 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2953 0, 0, 640, 480, 0, 0, 0, 0);
2955 if (!(device = create_device(window, DDSCL_NORMAL)))
2957 skip("Failed to create a 3D device, skipping test.\n");
2958 DestroyWindow(window);
2959 return;
2962 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
2963 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
2965 memset(&desc, 0, sizeof(desc));
2966 desc.dwSize = sizeof(desc);
2967 desc.dwCaps = D3DVBCAPS_WRITEONLY;
2968 desc.dwFVF = D3DFVF_XYZRHW;
2969 desc.dwNumVertices = vbsize;
2970 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
2971 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
2973 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
2974 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
2975 memcpy(data, quad, sizeof(quad));
2976 hr = IDirect3DVertexBuffer7_Unlock(buffer);
2977 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
2979 hr = IDirect3DDevice7_BeginScene(device);
2980 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2981 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
2982 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2983 hr = IDirect3DDevice7_EndScene(device);
2984 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2986 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
2987 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
2988 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
2989 hr = IDirect3DVertexBuffer7_Unlock(buffer);
2990 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
2992 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
2993 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
2994 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
2996 if (data[i] != 0xaa)
2998 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
2999 break;
3002 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3003 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3005 IDirect3DVertexBuffer7_Release(buffer);
3006 IDirect3D7_Release(d3d);
3007 IDirect3DDevice7_Release(device);
3008 DestroyWindow(window);
3011 static void test_coop_level_multi_window(void)
3013 HWND window1, window2;
3014 IDirectDraw7 *ddraw;
3015 HRESULT hr;
3017 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3018 0, 0, 640, 480, 0, 0, 0, 0);
3019 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3020 0, 0, 640, 480, 0, 0, 0, 0);
3021 ddraw = create_ddraw();
3022 ok(!!ddraw, "Failed to create a ddraw object.\n");
3024 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3025 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3026 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3027 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3028 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3029 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3031 IDirectDraw7_Release(ddraw);
3032 DestroyWindow(window2);
3033 DestroyWindow(window1);
3036 static void test_draw_strided(void)
3038 static struct vec3 position[] =
3040 {-1.0, -1.0, 0.0},
3041 {-1.0, 1.0, 0.0},
3042 { 1.0, 1.0, 0.0},
3043 { 1.0, -1.0, 0.0},
3045 static DWORD diffuse[] =
3047 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3049 static WORD indices[] =
3051 0, 1, 2, 2, 3, 0
3054 IDirectDrawSurface7 *rt;
3055 IDirect3DDevice7 *device;
3056 D3DCOLOR color;
3057 HWND window;
3058 HRESULT hr;
3059 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3061 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3062 0, 0, 640, 480, 0, 0, 0, 0);
3064 if (!(device = create_device(window, DDSCL_NORMAL)))
3066 skip("Failed to create a 3D device, skipping test.\n");
3067 DestroyWindow(window);
3068 return;
3071 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3072 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3074 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3075 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3076 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3077 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3078 hr = IDirect3DDevice7_BeginScene(device);
3079 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3081 memset(&strided, 0x55, sizeof(strided));
3082 strided.position.lpvData = position;
3083 strided.position.dwStride = sizeof(*position);
3084 strided.diffuse.lpvData = diffuse;
3085 strided.diffuse.dwStride = sizeof(*diffuse);
3086 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3087 &strided, 4, indices, 6, 0);
3088 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3090 hr = IDirect3DDevice7_EndScene(device);
3091 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3093 color = get_surface_color(rt, 320, 240);
3094 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3096 IDirectDrawSurface7_Release(rt);
3097 IDirect3DDevice7_Release(device);
3098 DestroyWindow(window);
3101 static void test_clear_rect_count(void)
3103 IDirectDrawSurface7 *rt;
3104 IDirect3DDevice7 *device;
3105 D3DCOLOR color;
3106 HWND window;
3107 HRESULT hr;
3108 D3DRECT rect = {{0}, {0}, {640}, {480}};
3110 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3111 0, 0, 640, 480, 0, 0, 0, 0);
3112 if (!(device = create_device(window, DDSCL_NORMAL)))
3114 skip("Failed to create a 3D device, skipping test.\n");
3115 DestroyWindow(window);
3116 return;
3119 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3120 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3122 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
3123 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3124 hr = IDirect3DDevice7_Clear(device, 0, &rect, D3DCLEAR_TARGET, 0x00ff0000, 1.0f, 0);
3125 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3127 color = get_surface_color(rt, 320, 240);
3128 ok(compare_color(color, 0x00ffffff, 1),
3129 "Clear with count = 0, rect != NULL has color %#08x.\n", color);
3131 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
3132 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3133 hr = IDirect3DDevice7_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
3134 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3136 color = get_surface_color(rt, 320, 240);
3137 ok(compare_color(color, 0x0000ff00, 1),
3138 "Clear with count = 1, rect = NULL has color %#08x.\n", color);
3140 IDirectDrawSurface7_Release(rt);
3141 IDirect3DDevice7_Release(device);
3142 DestroyWindow(window);
3145 static BOOL test_mode_restored(IDirectDraw7 *ddraw, HWND window)
3147 DDSURFACEDESC2 ddsd1, ddsd2;
3148 HRESULT hr;
3150 memset(&ddsd1, 0, sizeof(ddsd1));
3151 ddsd1.dwSize = sizeof(ddsd1);
3152 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd1);
3153 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3155 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3156 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3157 hr = set_display_mode(ddraw, 640, 480);
3158 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3159 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3160 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3162 memset(&ddsd2, 0, sizeof(ddsd2));
3163 ddsd2.dwSize = sizeof(ddsd2);
3164 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd2);
3165 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3166 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3167 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3169 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
3172 static void test_coop_level_versions(void)
3174 HWND window;
3175 IDirectDraw *ddraw;
3176 HRESULT hr;
3177 BOOL restored;
3178 IDirectDrawSurface *surface;
3179 IDirectDraw7 *ddraw7;
3180 DDSURFACEDESC ddsd;
3182 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3183 0, 0, 640, 480, 0, 0, 0, 0);
3185 ddraw7 = create_ddraw();
3186 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3187 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3188 restored = test_mode_restored(ddraw7, window);
3189 ok(restored, "Display mode not restored in new ddraw object\n");
3191 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3192 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3193 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3195 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3196 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3197 restored = test_mode_restored(ddraw7, window);
3198 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3200 /* A successful one does */
3201 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3202 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3203 restored = test_mode_restored(ddraw7, window);
3204 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3206 IDirectDraw_Release(ddraw);
3207 IDirectDraw7_Release(ddraw7);
3209 ddraw7 = create_ddraw();
3210 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3211 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3212 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3214 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
3215 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3216 restored = test_mode_restored(ddraw7, window);
3217 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3219 IDirectDraw_Release(ddraw);
3220 IDirectDraw7_Release(ddraw7);
3222 /* A failing call does not restore the ddraw2+ behavior */
3223 ddraw7 = create_ddraw();
3224 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3225 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3226 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3228 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3229 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3230 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3231 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3232 restored = test_mode_restored(ddraw7, window);
3233 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3235 IDirectDraw_Release(ddraw);
3236 IDirectDraw7_Release(ddraw7);
3238 /* Neither does a sequence of successful calls with the new interface */
3239 ddraw7 = create_ddraw();
3240 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3241 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3242 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3244 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3245 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3246 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3247 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3248 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
3249 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3251 restored = test_mode_restored(ddraw7, window);
3252 ok(!restored, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
3253 IDirectDraw_Release(ddraw);
3254 IDirectDraw7_Release(ddraw7);
3256 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3257 ddraw7 = create_ddraw();
3258 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3259 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3260 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3262 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
3263 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3265 memset(&ddsd, 0, sizeof(ddsd));
3266 ddsd.dwSize = sizeof(ddsd);
3267 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3268 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3269 ddsd.dwWidth = ddsd.dwHeight = 8;
3270 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3271 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
3272 IDirectDrawSurface_Release(surface);
3273 restored = test_mode_restored(ddraw7, window);
3274 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
3276 IDirectDraw_Release(ddraw);
3277 IDirectDraw7_Release(ddraw7);
3278 DestroyWindow(window);
3281 static void test_fog_special(void)
3283 static struct
3285 struct vec3 position;
3286 D3DCOLOR diffuse;
3288 quad[] =
3290 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
3291 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00},
3292 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
3293 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
3295 static const struct
3297 DWORD vertexmode, tablemode;
3298 D3DCOLOR color_left, color_right;
3300 tests[] =
3302 {D3DFOG_LINEAR, D3DFOG_NONE, 0x00ff0000, 0x00ff0000},
3303 {D3DFOG_NONE, D3DFOG_LINEAR, 0x0000ff00, 0x00ff0000},
3305 union
3307 float f;
3308 DWORD d;
3309 } conv;
3310 D3DCOLOR color;
3311 HRESULT hr;
3312 unsigned int i;
3313 HWND window;
3314 IDirect3DDevice7 *device;
3315 IDirectDrawSurface7 *rt;
3317 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3318 0, 0, 640, 480, 0, 0, 0, 0);
3320 if (!(device = create_device(window, DDSCL_NORMAL)))
3322 skip("Failed to create a 3D device, skipping test.\n");
3323 DestroyWindow(window);
3324 return;
3327 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3328 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3330 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
3331 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
3332 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xffff0000);
3333 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
3334 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3335 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3336 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3337 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3339 conv.f = 0.5f;
3340 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, conv.d);
3341 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
3342 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, conv.d);
3343 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
3345 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3347 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0);
3348 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3350 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vertexmode);
3351 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
3352 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tablemode);
3353 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
3355 hr = IDirect3DDevice7_BeginScene(device);
3356 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3357 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
3358 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3359 hr = IDirect3DDevice7_EndScene(device);
3360 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3362 color = get_surface_color(rt, 310, 240);
3363 ok(compare_color(color, tests[i].color_left, 1),
3364 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
3365 color = get_surface_color(rt, 330, 240);
3366 ok(compare_color(color, tests[i].color_right, 1),
3367 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
3370 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3371 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3373 IDirectDrawSurface7_Release(rt);
3374 IDirect3DDevice7_Release(device);
3375 DestroyWindow(window);
3378 static void test_lighting_interface_versions(void)
3380 IDirect3DDevice7 *device;
3381 IDirectDrawSurface7 *rt;
3382 D3DCOLOR color;
3383 HWND window;
3384 HRESULT hr;
3385 DWORD rs;
3386 unsigned int i;
3387 ULONG ref;
3388 D3DMATERIAL7 material;
3389 static D3DVERTEX quad[] =
3391 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3392 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3393 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3394 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3397 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3398 static struct
3400 struct vec3 position;
3401 struct vec3 normal;
3402 DWORD diffuse, specular;
3404 quad2[] =
3406 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3407 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3408 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3409 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3412 static D3DLVERTEX lquad[] =
3414 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3415 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3416 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3417 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3420 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3421 static struct
3423 struct vec3 position;
3424 DWORD diffuse, specular;
3425 struct vec2 texcoord;
3427 lquad2[] =
3429 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3430 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3431 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3432 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3435 static D3DTLVERTEX tlquad[] =
3437 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3438 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3439 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3440 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3443 static const struct
3445 DWORD vertextype;
3446 void *data;
3447 DWORD d3drs_lighting, d3drs_specular;
3448 DWORD draw_flags;
3449 D3DCOLOR color;
3451 tests[] =
3453 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
3454 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
3455 * are not available
3457 * Note that the specular result is 0x00000000 when lighting is on even if the
3458 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
3459 * enabled */
3461 /* 0 */
3462 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x00ffffff},
3463 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
3464 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3465 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3466 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x00ffffff},
3467 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
3468 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3469 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3471 /* 8 */
3472 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x00ff0000},
3473 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
3474 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3475 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3476 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x00ff8080},
3477 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
3478 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3479 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3481 /* 16 */
3482 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
3483 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x0000ff00},
3484 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3485 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3486 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
3487 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x0000ff00},
3488 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3489 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3491 /* 24 */
3492 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
3493 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x0000ff00},
3494 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3495 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3496 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
3497 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x0000ff00},
3498 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3499 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3501 /* 32 */
3502 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
3503 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
3504 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3505 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3506 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
3507 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
3508 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3509 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3512 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3513 0, 0, 640, 480, 0, 0, 0, 0);
3515 if (!(device = create_device(window, DDSCL_NORMAL)))
3517 skip("Failed to create a 3D device, skipping test.\n");
3518 DestroyWindow(window);
3519 return;
3522 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3523 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3525 memset(&material, 0, sizeof(material));
3526 U2(U3(material).emissive).g = 1.0f;
3527 hr = IDirect3DDevice7_SetMaterial(device, &material);
3528 ok(SUCCEEDED(hr), "Failed set material, hr %#x.\n", hr);
3529 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3530 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
3532 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
3533 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
3534 ok(rs == TRUE, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs);
3535 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
3536 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
3537 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
3539 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3541 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
3542 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3544 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
3545 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
3546 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
3547 tests[i].d3drs_specular);
3548 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
3550 hr = IDirect3DDevice7_BeginScene(device);
3551 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3552 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
3553 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
3554 hr = IDirect3DDevice7_EndScene(device);
3555 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3557 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
3558 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
3559 ok(rs == tests[i].d3drs_lighting, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
3560 rs, tests[i].d3drs_lighting);
3562 color = get_surface_color(rt, 320, 240);
3563 ok(compare_color(color, tests[i].color, 1),
3564 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3565 color, tests[i].color, i);
3568 IDirectDrawSurface7_Release(rt);
3569 ref = IDirect3DDevice7_Release(device);
3570 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
3571 DestroyWindow(window);
3574 static struct
3576 BOOL received;
3577 IDirectDraw7 *ddraw;
3578 HWND window;
3579 DWORD coop_level;
3580 } activateapp_testdata;
3582 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3584 if (message == WM_ACTIVATEAPP)
3586 if (activateapp_testdata.ddraw)
3588 HRESULT hr;
3589 activateapp_testdata.received = FALSE;
3590 hr = IDirectDraw7_SetCooperativeLevel(activateapp_testdata.ddraw,
3591 activateapp_testdata.window, activateapp_testdata.coop_level);
3592 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3593 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3595 activateapp_testdata.received = TRUE;
3598 return DefWindowProcA(hwnd, message, wparam, lparam);
3601 static void test_coop_level_activateapp(void)
3603 IDirectDraw7 *ddraw;
3604 HRESULT hr;
3605 HWND window;
3606 WNDCLASSA wc = {0};
3607 DDSURFACEDESC2 ddsd;
3608 IDirectDrawSurface7 *surface;
3610 ddraw = create_ddraw();
3611 ok(!!ddraw, "Failed to create a ddraw object.\n");
3613 wc.lpfnWndProc = activateapp_test_proc;
3614 wc.lpszClassName = "ddraw_test_wndproc_wc";
3615 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3617 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3618 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3620 /* Exclusive with window already active. */
3621 SetActiveWindow(window);
3622 activateapp_testdata.received = FALSE;
3623 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3624 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3625 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3626 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3627 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3629 /* Exclusive with window not active. */
3630 SetActiveWindow(NULL);
3631 activateapp_testdata.received = FALSE;
3632 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3633 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3634 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3635 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3636 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3638 /* Normal with window not active, then exclusive with the same window. */
3639 SetActiveWindow(NULL);
3640 activateapp_testdata.received = FALSE;
3641 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3642 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3643 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3644 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3645 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3646 /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
3647 * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken. */
3648 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3649 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3650 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3651 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3653 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3654 SetActiveWindow(NULL);
3655 activateapp_testdata.received = FALSE;
3656 activateapp_testdata.ddraw = ddraw;
3657 activateapp_testdata.window = window;
3658 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3659 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3660 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3661 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3662 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3663 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3664 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3666 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3667 * succeeding. Another switch to exclusive and back to normal is needed to release the
3668 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3669 * WM_ACTIVATEAPP messages. */
3670 activateapp_testdata.ddraw = NULL;
3671 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3672 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3673 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3674 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3676 /* Setting DDSCL_NORMAL with recursive invocation. */
3677 SetActiveWindow(NULL);
3678 activateapp_testdata.received = FALSE;
3679 activateapp_testdata.ddraw = ddraw;
3680 activateapp_testdata.window = window;
3681 activateapp_testdata.coop_level = DDSCL_NORMAL;
3682 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3683 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3684 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3685 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3687 /* DDraw is in exlusive mode now. */
3688 memset(&ddsd, 0, sizeof(ddsd));
3689 ddsd.dwSize = sizeof(ddsd);
3690 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3691 ddsd.dwBackBufferCount = 1;
3692 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3693 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3694 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3695 IDirectDrawSurface7_Release(surface);
3697 /* Recover again, just to be sure. */
3698 activateapp_testdata.ddraw = NULL;
3699 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3700 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3701 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3702 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3704 DestroyWindow(window);
3705 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3706 IDirectDraw7_Release(ddraw);
3709 static void test_texturemanage(void)
3711 IDirectDraw7 *ddraw;
3712 HRESULT hr;
3713 DDSURFACEDESC2 ddsd;
3714 IDirectDrawSurface7 *surface;
3715 unsigned int i;
3716 DDCAPS hal_caps, hel_caps;
3717 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
3718 static const struct
3720 DWORD caps_in, caps2_in;
3721 HRESULT hr;
3722 DWORD caps_out, caps2_out;
3724 tests[] =
3726 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3727 ~0U, ~0U},
3728 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3729 ~0U, ~0U},
3730 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3731 ~0U, ~0U},
3732 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3733 ~0U, ~0U},
3734 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
3735 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
3736 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
3737 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
3738 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
3739 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
3740 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
3741 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
3743 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3744 ~0U, ~0U},
3745 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3746 ~0U, ~0U},
3747 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3748 ~0U, ~0U},
3749 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3750 ~0U, ~0U},
3751 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3752 ~0U, ~0U},
3753 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3754 ~0U, ~0U},
3755 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
3756 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
3757 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
3758 DDSCAPS_SYSTEMMEMORY, 0},
3761 ddraw = create_ddraw();
3762 ok(!!ddraw, "Failed to create a ddraw object.\n");
3763 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3764 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3766 memset(&hal_caps, 0, sizeof(hal_caps));
3767 hal_caps.dwSize = sizeof(hal_caps);
3768 memset(&hel_caps, 0, sizeof(hel_caps));
3769 hel_caps.dwSize = sizeof(hel_caps);
3770 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, &hel_caps);
3771 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
3772 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
3774 skip("Managed textures not supported, skipping managed texture test.\n");
3775 IDirectDraw7_Release(ddraw);
3776 return;
3779 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3781 memset(&ddsd, 0, sizeof(ddsd));
3782 ddsd.dwSize = sizeof(ddsd);
3783 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3784 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
3785 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
3786 ddsd.dwWidth = 4;
3787 ddsd.dwHeight = 4;
3789 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3790 ok(hr == tests[i].hr, "Got unexpected, hr %#x, case %u.\n", hr, i);
3791 if (FAILED(hr))
3792 continue;
3794 memset(&ddsd, 0, sizeof(ddsd));
3795 ddsd.dwSize = sizeof(ddsd);
3796 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
3797 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3799 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
3800 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
3801 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
3802 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
3803 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
3804 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
3806 IDirectDrawSurface7_Release(surface);
3809 IDirectDraw7_Release(ddraw);
3812 #define SUPPORT_DXT1 0x01
3813 #define SUPPORT_DXT2 0x02
3814 #define SUPPORT_DXT3 0x04
3815 #define SUPPORT_DXT4 0x08
3816 #define SUPPORT_DXT5 0x10
3817 #define SUPPORT_YUY2 0x20
3818 #define SUPPORT_UYVY 0x40
3820 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
3822 DWORD *supported_fmts = ctx;
3824 if (!(fmt->dwFlags & DDPF_FOURCC))
3825 return DDENUMRET_OK;
3827 switch (fmt->dwFourCC)
3829 case MAKEFOURCC('D','X','T','1'):
3830 *supported_fmts |= SUPPORT_DXT1;
3831 break;
3832 case MAKEFOURCC('D','X','T','2'):
3833 *supported_fmts |= SUPPORT_DXT2;
3834 break;
3835 case MAKEFOURCC('D','X','T','3'):
3836 *supported_fmts |= SUPPORT_DXT3;
3837 break;
3838 case MAKEFOURCC('D','X','T','4'):
3839 *supported_fmts |= SUPPORT_DXT4;
3840 break;
3841 case MAKEFOURCC('D','X','T','5'):
3842 *supported_fmts |= SUPPORT_DXT5;
3843 break;
3844 case MAKEFOURCC('Y','U','Y','2'):
3845 *supported_fmts |= SUPPORT_YUY2;
3846 break;
3847 case MAKEFOURCC('U','Y','V','Y'):
3848 *supported_fmts |= SUPPORT_UYVY;
3849 break;
3850 default:
3851 break;
3854 return DDENUMRET_OK;
3857 static void test_block_formats_creation(void)
3859 HRESULT hr, expect_hr;
3860 unsigned int i, j, w, h;
3861 HWND window;
3862 IDirectDraw7 *ddraw;
3863 IDirect3D7 *d3d;
3864 IDirect3DDevice7 *device;
3865 IDirectDrawSurface7 *surface;
3866 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
3867 DWORD num_fourcc_codes = 0, *fourcc_codes;
3868 DDSURFACEDESC2 ddsd;
3869 DDCAPS hal_caps;
3871 static const struct
3873 DWORD fourcc;
3874 const char *name;
3875 DWORD support_flag;
3876 unsigned int block_width;
3877 unsigned int block_height;
3878 BOOL create_size_checked, overlay;
3880 formats[] =
3882 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, TRUE, FALSE},
3883 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, TRUE, FALSE},
3884 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, TRUE, FALSE},
3885 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, TRUE, FALSE},
3886 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, TRUE, FALSE},
3887 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, FALSE, TRUE },
3888 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, FALSE, TRUE },
3890 const struct
3892 DWORD caps, caps2;
3893 const char *name;
3894 BOOL overlay;
3896 types[] =
3898 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
3899 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
3901 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
3902 * Other hw / drivers successfully create those surfaces. Ignore them, this
3903 * suggests that no game uses this, otherwise Nvidia would support it. */
3905 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
3906 "videomemory texture", FALSE
3909 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
3910 "videomemory overlay", TRUE
3913 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
3914 "systemmemory texture", FALSE
3917 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
3918 "managed texture", FALSE
3922 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3923 0, 0, 640, 480, 0, 0, 0, 0);
3925 if (!(device = create_device(window, DDSCL_NORMAL)))
3927 skip("Failed to create a 3D device, skipping test.\n");
3928 DestroyWindow(window);
3929 return;
3932 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3933 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3934 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
3935 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
3936 IDirect3D7_Release(d3d);
3938 hr = IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb,
3939 &supported_fmts);
3940 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
3942 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
3943 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
3944 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3945 num_fourcc_codes * sizeof(*fourcc_codes));
3946 if (!fourcc_codes)
3947 goto cleanup;
3948 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
3949 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
3950 for (i = 0; i < num_fourcc_codes; i++)
3952 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
3954 if (fourcc_codes[i] == formats[j].fourcc)
3955 supported_overlay_fmts |= formats[j].support_flag;
3958 HeapFree(GetProcessHeap(), 0, fourcc_codes);
3960 memset(&hal_caps, 0, sizeof(hal_caps));
3961 hal_caps.dwSize = sizeof(hal_caps);
3962 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
3963 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
3965 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
3967 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
3969 BOOL support;
3971 if (formats[i].overlay != types[j].overlay
3972 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
3973 continue;
3975 if (formats[i].overlay)
3976 support = supported_overlay_fmts & formats[i].support_flag;
3977 else
3978 support = supported_fmts & formats[i].support_flag;
3980 for (w = 1; w <= 8; w++)
3982 for (h = 1; h <= 8; h++)
3984 BOOL block_aligned = TRUE;
3985 BOOL todo = FALSE;
3987 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
3988 block_aligned = FALSE;
3990 memset(&ddsd, 0, sizeof(ddsd));
3991 ddsd.dwSize = sizeof(ddsd);
3992 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3993 ddsd.ddsCaps.dwCaps = types[j].caps;
3994 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
3995 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
3996 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
3997 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
3998 ddsd.dwWidth = w;
3999 ddsd.dwHeight = h;
4001 /* TODO: Handle power of two limitations. I cannot test the pow2
4002 * behavior on windows because I have no hardware that doesn't at
4003 * least support np2_conditional. There's probably no HW that
4004 * supports DXTN textures but no conditional np2 textures. */
4005 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
4006 expect_hr = DDERR_INVALIDPARAMS;
4007 else if (formats[i].create_size_checked && !block_aligned)
4009 expect_hr = DDERR_INVALIDPARAMS;
4010 if (!(types[j].caps & DDSCAPS_TEXTURE))
4011 todo = TRUE;
4013 else
4014 expect_hr = D3D_OK;
4016 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4017 if (todo)
4018 todo_wine ok(hr == expect_hr,
4019 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4020 hr, formats[i].name, types[j].name, w, h, expect_hr);
4021 else
4022 ok(hr == expect_hr,
4023 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4024 hr, formats[i].name, types[j].name, w, h, expect_hr);
4026 if (SUCCEEDED(hr))
4027 IDirectDrawSurface7_Release(surface);
4033 cleanup:
4034 IDirectDraw7_Release(ddraw);
4035 IDirect3DDevice7_Release(device);
4036 DestroyWindow(window);
4039 struct format_support_check
4041 const DDPIXELFORMAT *format;
4042 BOOL supported;
4045 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
4047 struct format_support_check *format = ctx;
4049 if (!memcmp(format->format, fmt, sizeof(*fmt)))
4051 format->supported = TRUE;
4052 return DDENUMRET_CANCEL;
4055 return DDENUMRET_OK;
4058 static void test_unsupported_formats(void)
4060 HRESULT hr;
4061 BOOL expect_success;
4062 HWND window;
4063 IDirectDraw7 *ddraw;
4064 IDirect3D7 *d3d;
4065 IDirect3DDevice7 *device;
4066 IDirectDrawSurface7 *surface;
4067 DDSURFACEDESC2 ddsd;
4068 unsigned int i, j;
4069 DWORD expected_caps;
4070 static const struct
4072 const char *name;
4073 DDPIXELFORMAT fmt;
4075 formats[] =
4078 "D3DFMT_A8R8G8B8",
4080 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
4081 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4085 "D3DFMT_P8",
4087 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4088 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4092 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
4094 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4095 0, 0, 640, 480, 0, 0, 0, 0);
4097 if (!(device = create_device(window, DDSCL_NORMAL)))
4099 skip("Failed to create a 3D device, skipping test.\n");
4100 DestroyWindow(window);
4101 return;
4104 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4105 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4106 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4107 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4108 IDirect3D7_Release(d3d);
4110 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4112 struct format_support_check check = {&formats[i].fmt, FALSE};
4113 hr = IDirect3DDevice7_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
4114 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4116 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
4118 memset(&ddsd, 0, sizeof(ddsd));
4119 ddsd.dwSize = sizeof(ddsd);
4120 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4121 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
4122 ddsd.dwWidth = 4;
4123 ddsd.dwHeight = 4;
4124 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
4126 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
4127 expect_success = FALSE;
4128 else
4129 expect_success = TRUE;
4131 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4132 ok(SUCCEEDED(hr) == expect_success,
4133 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4134 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
4135 if (FAILED(hr))
4136 continue;
4138 memset(&ddsd, 0, sizeof(ddsd));
4139 ddsd.dwSize = sizeof(ddsd);
4140 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4141 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4143 if (caps[j] & DDSCAPS_VIDEOMEMORY)
4144 expected_caps = DDSCAPS_VIDEOMEMORY;
4145 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
4146 expected_caps = DDSCAPS_SYSTEMMEMORY;
4147 else if (check.supported)
4148 expected_caps = DDSCAPS_VIDEOMEMORY;
4149 else
4150 expected_caps = DDSCAPS_SYSTEMMEMORY;
4152 ok(ddsd.ddsCaps.dwCaps & expected_caps,
4153 "Expected capability %#x, format %s, input cap %#x.\n",
4154 expected_caps, formats[i].name, caps[j]);
4156 IDirectDrawSurface7_Release(surface);
4160 IDirectDraw7_Release(ddraw);
4161 IDirect3DDevice7_Release(device);
4162 DestroyWindow(window);
4165 static void test_rt_caps(void)
4167 const GUID *devtype = &IID_IDirect3DHALDevice;
4168 PALETTEENTRY palette_entries[256];
4169 IDirectDrawPalette *palette;
4170 IDirectDraw7 *ddraw;
4171 BOOL hal_ok = FALSE;
4172 DDPIXELFORMAT z_fmt;
4173 IDirect3D7 *d3d;
4174 unsigned int i;
4175 ULONG refcount;
4176 HWND window;
4177 HRESULT hr;
4179 static const DDPIXELFORMAT p8_fmt =
4181 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4182 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4185 const struct
4187 const DDPIXELFORMAT *pf;
4188 DWORD caps_in;
4189 DWORD caps_out;
4190 HRESULT create_device_hr;
4191 HRESULT set_rt_hr, alternative_set_rt_hr;
4193 test_data[] =
4196 NULL,
4197 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4198 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4199 D3D_OK,
4200 D3D_OK,
4201 D3D_OK,
4204 NULL,
4205 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4206 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4207 D3D_OK,
4208 D3D_OK,
4209 D3D_OK,
4212 NULL,
4213 DDSCAPS_OFFSCREENPLAIN,
4214 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4215 DDERR_INVALIDCAPS,
4216 DDERR_INVALIDCAPS,
4217 DDERR_INVALIDCAPS,
4220 NULL,
4221 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4222 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4223 D3DERR_SURFACENOTINVIDMEM,
4224 DDERR_INVALIDPARAMS,
4225 D3D_OK,
4228 NULL,
4229 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4230 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4231 DDERR_INVALIDCAPS,
4232 DDERR_INVALIDCAPS,
4233 DDERR_INVALIDCAPS,
4236 NULL,
4237 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4238 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4239 D3D_OK,
4240 D3D_OK,
4241 D3D_OK,
4244 NULL,
4245 DDSCAPS_3DDEVICE,
4246 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4247 D3D_OK,
4248 D3D_OK,
4249 D3D_OK,
4252 NULL,
4254 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4255 DDERR_INVALIDCAPS,
4256 DDERR_INVALIDCAPS,
4257 DDERR_INVALIDCAPS,
4260 NULL,
4261 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4262 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4263 D3DERR_SURFACENOTINVIDMEM,
4264 DDERR_INVALIDPARAMS,
4265 D3D_OK,
4268 NULL,
4269 DDSCAPS_SYSTEMMEMORY,
4270 DDSCAPS_SYSTEMMEMORY,
4271 DDERR_INVALIDCAPS,
4272 DDERR_INVALIDCAPS,
4273 DDERR_INVALIDCAPS,
4276 &p8_fmt,
4278 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4279 DDERR_INVALIDCAPS,
4280 DDERR_INVALIDCAPS,
4281 DDERR_INVALIDCAPS,
4284 &p8_fmt,
4285 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4286 ~0U /* AMD r200 */,
4287 DDERR_NOPALETTEATTACHED,
4288 DDERR_INVALIDCAPS,
4289 DDERR_INVALIDCAPS,
4292 &p8_fmt,
4293 DDSCAPS_OFFSCREENPLAIN,
4294 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4295 DDERR_INVALIDCAPS,
4296 DDERR_INVALIDCAPS,
4297 DDERR_INVALIDCAPS,
4300 &p8_fmt,
4301 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4302 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4303 DDERR_NOPALETTEATTACHED,
4304 DDERR_INVALIDCAPS,
4305 DDERR_INVALIDCAPS,
4308 &p8_fmt,
4309 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4310 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4311 DDERR_INVALIDCAPS,
4312 DDERR_INVALIDCAPS,
4313 DDERR_INVALIDCAPS,
4316 &z_fmt,
4317 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
4318 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4319 DDERR_INVALIDCAPS,
4320 DDERR_INVALIDPIXELFORMAT,
4321 DDERR_INVALIDPIXELFORMAT,
4324 &z_fmt,
4325 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4326 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4327 DDERR_INVALIDCAPS,
4328 DDERR_INVALIDPIXELFORMAT,
4329 DDERR_INVALIDPIXELFORMAT,
4332 &z_fmt,
4333 DDSCAPS_ZBUFFER,
4334 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4335 DDERR_INVALIDCAPS,
4336 DDERR_INVALIDCAPS,
4337 DDERR_INVALIDCAPS,
4340 &z_fmt,
4341 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4342 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4343 DDERR_INVALIDCAPS,
4344 DDERR_INVALIDPARAMS,
4345 DDERR_INVALIDPIXELFORMAT,
4348 &z_fmt,
4349 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4350 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4351 DDERR_INVALIDCAPS,
4352 DDERR_INVALIDCAPS,
4353 DDERR_INVALIDCAPS,
4357 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4358 0, 0, 640, 480, 0, 0, 0, 0);
4359 ddraw = create_ddraw();
4360 ok(!!ddraw, "Failed to create a ddraw object.\n");
4361 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4362 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4364 if (FAILED(hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
4366 skip("D3D interface is not available, skipping test.\n");
4367 goto done;
4370 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
4371 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
4372 if (hal_ok)
4373 devtype = &IID_IDirect3DTnLHalDevice;
4375 memset(&z_fmt, 0, sizeof(z_fmt));
4376 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
4377 if (FAILED(hr) || !z_fmt.dwSize)
4379 skip("No depth buffer formats available, skipping test.\n");
4380 IDirect3D7_Release(d3d);
4381 goto done;
4384 memset(palette_entries, 0, sizeof(palette_entries));
4385 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
4386 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
4388 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4390 IDirectDrawSurface7 *surface, *rt, *expected_rt, *tmp;
4391 DDSURFACEDESC2 surface_desc;
4392 IDirect3DDevice7 *device;
4394 memset(&surface_desc, 0, sizeof(surface_desc));
4395 surface_desc.dwSize = sizeof(surface_desc);
4396 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4397 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4398 if (test_data[i].pf)
4400 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4401 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4403 surface_desc.dwWidth = 640;
4404 surface_desc.dwHeight = 480;
4405 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4406 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4407 i, test_data[i].caps_in, hr);
4409 memset(&surface_desc, 0, sizeof(surface_desc));
4410 surface_desc.dwSize = sizeof(surface_desc);
4411 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
4412 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4413 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
4414 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4415 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4417 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4418 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4419 i, hr, test_data[i].create_device_hr);
4420 if (FAILED(hr))
4422 if (hr == DDERR_NOPALETTEATTACHED)
4424 hr = IDirectDrawSurface7_SetPalette(surface, palette);
4425 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
4426 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4427 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
4428 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
4429 else
4430 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
4432 IDirectDrawSurface7_Release(surface);
4434 memset(&surface_desc, 0, sizeof(surface_desc));
4435 surface_desc.dwSize = sizeof(surface_desc);
4436 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4437 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4438 surface_desc.dwWidth = 640;
4439 surface_desc.dwHeight = 480;
4440 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4441 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
4443 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4444 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
4447 memset(&surface_desc, 0, sizeof(surface_desc));
4448 surface_desc.dwSize = sizeof(surface_desc);
4449 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4450 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4451 if (test_data[i].pf)
4453 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4454 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4456 surface_desc.dwWidth = 640;
4457 surface_desc.dwHeight = 480;
4458 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
4459 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4460 i, test_data[i].caps_in, hr);
4462 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
4463 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
4464 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4465 i, hr, test_data[i].set_rt_hr);
4466 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
4467 expected_rt = rt;
4468 else
4469 expected_rt = surface;
4471 hr = IDirect3DDevice7_GetRenderTarget(device, &tmp);
4472 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
4473 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
4475 IDirectDrawSurface7_Release(tmp);
4476 IDirectDrawSurface7_Release(rt);
4477 refcount = IDirect3DDevice7_Release(device);
4478 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
4479 refcount = IDirectDrawSurface7_Release(surface);
4480 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
4483 IDirectDrawPalette_Release(palette);
4484 IDirect3D7_Release(d3d);
4486 done:
4487 refcount = IDirectDraw7_Release(ddraw);
4488 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4489 DestroyWindow(window);
4492 static void test_primary_caps(void)
4494 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4495 IDirectDrawSurface7 *surface;
4496 DDSURFACEDESC2 surface_desc;
4497 IDirectDraw7 *ddraw;
4498 unsigned int i;
4499 ULONG refcount;
4500 HWND window;
4501 HRESULT hr;
4503 static const struct
4505 DWORD coop_level;
4506 DWORD caps_in;
4507 DWORD back_buffer_count;
4508 HRESULT hr;
4509 DWORD caps_out;
4511 test_data[] =
4514 DDSCL_NORMAL,
4515 DDSCAPS_PRIMARYSURFACE,
4516 ~0u,
4517 DD_OK,
4518 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
4521 DDSCL_NORMAL,
4522 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
4523 ~0u,
4524 DDERR_INVALIDCAPS,
4525 ~0u,
4528 DDSCL_NORMAL,
4529 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
4530 ~0u,
4531 DDERR_INVALIDCAPS,
4532 ~0u,
4535 DDSCL_NORMAL,
4536 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
4537 ~0u,
4538 DDERR_INVALIDCAPS,
4539 ~0u,
4542 DDSCL_NORMAL,
4543 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
4544 ~0u,
4545 DDERR_INVALIDCAPS,
4546 ~0u,
4549 DDSCL_NORMAL,
4550 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
4551 ~0u,
4552 DDERR_INVALIDCAPS,
4553 ~0u,
4556 DDSCL_NORMAL,
4557 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4558 ~0u,
4559 DDERR_INVALIDCAPS,
4560 ~0u,
4563 DDSCL_NORMAL,
4564 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4566 DDERR_INVALIDCAPS,
4567 ~0u,
4570 DDSCL_NORMAL,
4571 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4573 DDERR_NOEXCLUSIVEMODE,
4574 ~0u,
4577 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4578 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4580 DDERR_INVALIDCAPS,
4581 ~0u,
4584 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4585 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4587 DD_OK,
4588 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
4591 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4592 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
4594 DDERR_INVALIDCAPS,
4595 ~0u,
4598 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4599 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
4601 DDERR_INVALIDCAPS,
4602 ~0u,
4606 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4607 0, 0, 640, 480, 0, 0, 0, 0);
4608 ddraw = create_ddraw();
4609 ok(!!ddraw, "Failed to create a ddraw object.\n");
4611 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4613 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
4614 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4616 memset(&surface_desc, 0, sizeof(surface_desc));
4617 surface_desc.dwSize = sizeof(surface_desc);
4618 surface_desc.dwFlags = DDSD_CAPS;
4619 if (test_data[i].back_buffer_count != ~0u)
4620 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
4621 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4622 surface_desc.dwBackBufferCount = test_data[i].back_buffer_count;
4623 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4624 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
4625 if (FAILED(hr))
4626 continue;
4628 memset(&surface_desc, 0, sizeof(surface_desc));
4629 surface_desc.dwSize = sizeof(surface_desc);
4630 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
4631 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4632 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
4633 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4634 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4636 IDirectDrawSurface7_Release(surface);
4639 refcount = IDirectDraw7_Release(ddraw);
4640 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4641 DestroyWindow(window);
4644 static void test_surface_lock(void)
4646 IDirectDraw7 *ddraw;
4647 IDirect3D7 *d3d = NULL;
4648 IDirectDrawSurface7 *surface;
4649 IDirect3DDevice7 *device;
4650 HRESULT hr;
4651 HWND window;
4652 unsigned int i;
4653 DDSURFACEDESC2 ddsd;
4654 ULONG refcount;
4655 DDPIXELFORMAT z_fmt;
4656 BOOL hal_ok = FALSE;
4657 const GUID *devtype = &IID_IDirect3DHALDevice;
4658 D3DDEVICEDESC7 device_desc;
4659 BOOL cubemap_supported;
4660 static const struct
4662 DWORD caps;
4663 DWORD caps2;
4664 const char *name;
4666 tests[] =
4669 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
4671 "videomemory offscreenplain"
4674 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4676 "systemmemory offscreenplain"
4679 DDSCAPS_PRIMARYSURFACE,
4681 "primary"
4684 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
4686 "videomemory texture"
4689 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
4690 DDSCAPS2_OPAQUE,
4691 "opaque videomemory texture"
4694 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
4696 "systemmemory texture"
4699 DDSCAPS_TEXTURE,
4700 DDSCAPS2_TEXTUREMANAGE,
4701 "managed texture"
4704 DDSCAPS_TEXTURE,
4705 DDSCAPS2_D3DTEXTUREMANAGE,
4706 "managed texture"
4709 DDSCAPS_TEXTURE,
4710 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
4711 "opaque managed texture"
4714 DDSCAPS_TEXTURE,
4715 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
4716 "opaque managed texture"
4719 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4721 "render target"
4724 DDSCAPS_ZBUFFER,
4726 "Z buffer"
4729 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
4730 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
4731 "videomemory cube"
4734 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
4735 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
4736 "opaque videomemory cube"
4739 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY,
4740 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
4741 "systemmemory cube"
4744 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
4745 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
4746 "managed cube"
4749 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
4750 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
4751 "managed cube"
4754 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
4755 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
4756 "opaque managed cube"
4759 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
4760 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
4761 "opaque managed cube"
4765 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4766 0, 0, 640, 480, 0, 0, 0, 0);
4767 ddraw = create_ddraw();
4768 ok(!!ddraw, "Failed to create a ddraw object.\n");
4769 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4770 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4772 if (FAILED(hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
4774 skip("D3D interface is not available, skipping test.\n");
4775 goto done;
4778 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
4779 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
4780 if (hal_ok)
4781 devtype = &IID_IDirect3DTnLHalDevice;
4783 memset(&z_fmt, 0, sizeof(z_fmt));
4784 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
4785 if (FAILED(hr) || !z_fmt.dwSize)
4787 skip("No depth buffer formats available, skipping test.\n");
4788 goto done;
4791 memset(&ddsd, 0, sizeof(ddsd));
4792 ddsd.dwSize = sizeof(ddsd);
4793 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4794 ddsd.dwWidth = 64;
4795 ddsd.dwHeight = 64;
4796 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4797 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4798 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4800 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4801 ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr);
4802 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
4803 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4804 cubemap_supported = !!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP);
4805 IDirect3DDevice7_Release(device);
4807 IDirectDrawSurface7_Release(surface);
4809 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4811 if (!cubemap_supported && tests[i].caps2 & DDSCAPS2_CUBEMAP)
4812 continue;
4814 memset(&ddsd, 0, sizeof(ddsd));
4815 ddsd.dwSize = sizeof(ddsd);
4816 ddsd.dwFlags = DDSD_CAPS;
4817 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
4819 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
4820 ddsd.dwWidth = 64;
4821 ddsd.dwHeight = 64;
4823 if (tests[i].caps & DDSCAPS_ZBUFFER)
4825 ddsd.dwFlags |= DDSD_PIXELFORMAT;
4826 U4(ddsd).ddpfPixelFormat = z_fmt;
4828 ddsd.ddsCaps.dwCaps = tests[i].caps;
4829 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
4831 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4832 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
4834 memset(&ddsd, 0, sizeof(ddsd));
4835 ddsd.dwSize = sizeof(ddsd);
4836 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
4837 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
4838 if (SUCCEEDED(hr))
4840 hr = IDirectDrawSurface7_Unlock(surface, NULL);
4841 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
4844 IDirectDrawSurface7_Release(surface);
4847 done:
4848 if (d3d)
4849 IDirect3D7_Release(d3d);
4850 refcount = IDirectDraw7_Release(ddraw);
4851 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4852 DestroyWindow(window);
4855 static void test_surface_discard(void)
4857 IDirect3DDevice7 *device;
4858 IDirect3D7 *d3d;
4859 IDirectDraw7 *ddraw;
4860 HRESULT hr;
4861 HWND window;
4862 DDSURFACEDESC2 ddsd;
4863 IDirectDrawSurface7 *surface, *target;
4864 void *addr;
4865 static const struct
4867 DWORD caps, caps2;
4868 BOOL discard;
4870 tests[] =
4872 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
4873 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
4874 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
4875 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
4876 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
4877 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
4878 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
4879 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
4881 unsigned int i;
4883 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4884 0, 0, 640, 480, 0, 0, 0, 0);
4886 if (!(device = create_device(window, DDSCL_NORMAL)))
4888 skip("Failed to create a 3D device, skipping test.\n");
4889 DestroyWindow(window);
4890 return;
4892 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4893 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4894 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
4895 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4896 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
4897 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4899 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4901 BOOL discarded;
4903 memset(&ddsd, 0, sizeof(ddsd));
4904 ddsd.dwSize = sizeof(ddsd);
4905 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4906 ddsd.ddsCaps.dwCaps = tests[i].caps;
4907 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
4908 ddsd.dwWidth = 64;
4909 ddsd.dwHeight = 64;
4910 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4911 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
4913 memset(&ddsd, 0, sizeof(ddsd));
4914 ddsd.dwSize = sizeof(ddsd);
4915 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
4916 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4917 addr = ddsd.lpSurface;
4918 hr = IDirectDrawSurface7_Unlock(surface, NULL);
4919 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4921 memset(&ddsd, 0, sizeof(ddsd));
4922 ddsd.dwSize = sizeof(ddsd);
4923 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
4924 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4925 discarded = ddsd.lpSurface != addr;
4926 hr = IDirectDrawSurface7_Unlock(surface, NULL);
4927 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4929 hr = IDirectDrawSurface7_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
4930 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
4932 memset(&ddsd, 0, sizeof(ddsd));
4933 ddsd.dwSize = sizeof(ddsd);
4934 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
4935 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4936 discarded |= ddsd.lpSurface != addr;
4937 hr = IDirectDrawSurface7_Unlock(surface, NULL);
4938 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4940 IDirectDrawSurface7_Release(surface);
4942 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4943 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
4944 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
4947 IDirectDrawSurface7_Release(target);
4948 IDirectDraw7_Release(ddraw);
4949 IDirect3D7_Release(d3d);
4950 IDirect3DDevice7_Release(device);
4951 DestroyWindow(window);
4954 static void test_flip(void)
4956 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4957 IDirectDrawSurface7 *primary, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
4958 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, 0};
4959 DDSURFACEDESC2 surface_desc;
4960 BOOL sysmem_primary;
4961 IDirectDraw7 *ddraw;
4962 D3DCOLOR color;
4963 ULONG refcount;
4964 HWND window;
4965 DDBLTFX fx;
4966 HRESULT hr;
4968 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4969 0, 0, 640, 480, 0, 0, 0, 0);
4970 ddraw = create_ddraw();
4971 ok(!!ddraw, "Failed to create a ddraw object.\n");
4973 hr = set_display_mode(ddraw, 640, 480);
4974 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4975 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4976 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4978 memset(&surface_desc, 0, sizeof(surface_desc));
4979 surface_desc.dwSize = sizeof(surface_desc);
4980 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4981 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4982 surface_desc.dwBackBufferCount = 3;
4983 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
4984 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4986 memset(&surface_desc, 0, sizeof(surface_desc));
4987 surface_desc.dwSize = sizeof(surface_desc);
4988 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
4989 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4990 ok((surface_desc.ddsCaps.dwCaps & ~placement)
4991 == (DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX),
4992 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
4993 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4995 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &backbuffer1);
4996 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
4997 memset(&surface_desc, 0, sizeof(surface_desc));
4998 surface_desc.dwSize = sizeof(surface_desc);
4999 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer1, &surface_desc);
5000 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5001 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5002 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_BACKBUFFER),
5003 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5005 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
5006 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5007 memset(&surface_desc, 0, sizeof(surface_desc));
5008 surface_desc.dwSize = sizeof(surface_desc);
5009 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer2, &surface_desc);
5010 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5011 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5012 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5013 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5015 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
5016 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5017 memset(&surface_desc, 0, sizeof(surface_desc));
5018 surface_desc.dwSize = sizeof(surface_desc);
5019 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer3, &surface_desc);
5020 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5021 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5022 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5023 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5025 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer3, &caps, &surface);
5026 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5027 ok(surface == primary, "Got unexpected surface %p, expected %p.\n", surface, primary);
5028 IDirectDrawSurface7_Release(surface);
5030 memset(&surface_desc, 0, sizeof(surface_desc));
5031 surface_desc.dwSize = sizeof(surface_desc);
5032 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5033 surface_desc.ddsCaps.dwCaps = 0;
5034 surface_desc.dwWidth = 640;
5035 surface_desc.dwHeight = 480;
5036 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5037 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5038 hr = IDirectDrawSurface7_Flip(primary, surface, DDFLIP_WAIT);
5039 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5040 IDirectDrawSurface7_Release(surface);
5042 hr = IDirectDrawSurface7_Flip(primary, primary, DDFLIP_WAIT);
5043 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5044 hr = IDirectDrawSurface7_Flip(backbuffer1, NULL, DDFLIP_WAIT);
5045 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5046 hr = IDirectDrawSurface7_Flip(backbuffer2, NULL, DDFLIP_WAIT);
5047 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5048 hr = IDirectDrawSurface7_Flip(backbuffer3, NULL, DDFLIP_WAIT);
5049 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5051 memset(&fx, 0, sizeof(fx));
5052 fx.dwSize = sizeof(fx);
5053 U5(fx).dwFillColor = 0xffff0000;
5054 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5055 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5056 U5(fx).dwFillColor = 0xff00ff00;
5057 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5058 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5059 U5(fx).dwFillColor = 0xff0000ff;
5060 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5061 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5063 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5064 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5065 color = get_surface_color(backbuffer1, 320, 240);
5066 /* The testbot seems to just copy the contents of one surface to all the
5067 * others, instead of properly flipping. */
5068 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5069 "Got unexpected color 0x%08x.\n", color);
5070 color = get_surface_color(backbuffer2, 320, 240);
5071 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5072 U5(fx).dwFillColor = 0xffff0000;
5073 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5074 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5076 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5077 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5078 color = get_surface_color(backbuffer1, 320, 240);
5079 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5080 "Got unexpected color 0x%08x.\n", color);
5081 color = get_surface_color(backbuffer2, 320, 240);
5082 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5083 U5(fx).dwFillColor = 0xff00ff00;
5084 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5085 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5087 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5088 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5089 color = get_surface_color(backbuffer1, 320, 240);
5090 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5091 "Got unexpected color 0x%08x.\n", color);
5092 color = get_surface_color(backbuffer2, 320, 240);
5093 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5094 U5(fx).dwFillColor = 0xff0000ff;
5095 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5096 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5098 hr = IDirectDrawSurface7_Flip(primary, backbuffer1, DDFLIP_WAIT);
5099 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5100 color = get_surface_color(backbuffer2, 320, 240);
5101 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5102 "Got unexpected color 0x%08x.\n", color);
5103 color = get_surface_color(backbuffer3, 320, 240);
5104 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5105 U5(fx).dwFillColor = 0xffff0000;
5106 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5107 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5109 hr = IDirectDrawSurface7_Flip(primary, backbuffer2, DDFLIP_WAIT);
5110 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5111 color = get_surface_color(backbuffer1, 320, 240);
5112 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5113 color = get_surface_color(backbuffer3, 320, 240);
5114 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5115 "Got unexpected color 0x%08x.\n", color);
5116 U5(fx).dwFillColor = 0xff00ff00;
5117 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5118 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5120 hr = IDirectDrawSurface7_Flip(primary, backbuffer3, DDFLIP_WAIT);
5121 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5122 color = get_surface_color(backbuffer1, 320, 240);
5123 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5124 "Got unexpected color 0x%08x.\n", color);
5125 color = get_surface_color(backbuffer2, 320, 240);
5126 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5128 IDirectDrawSurface7_Release(backbuffer3);
5129 IDirectDrawSurface7_Release(backbuffer2);
5130 IDirectDrawSurface7_Release(backbuffer1);
5131 IDirectDrawSurface7_Release(primary);
5132 refcount = IDirectDraw7_Release(ddraw);
5133 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5134 DestroyWindow(window);
5137 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
5139 memset(ddsd, 0, sizeof(*ddsd));
5140 ddsd->dwSize = sizeof(*ddsd);
5143 static void test_set_surface_desc(void)
5145 IDirectDraw7 *ddraw;
5146 HWND window;
5147 HRESULT hr;
5148 DDSURFACEDESC2 ddsd;
5149 IDirectDrawSurface7 *surface;
5150 BYTE data[16*16*4];
5151 ULONG ref;
5152 unsigned int i;
5153 static const struct
5155 DWORD caps, caps2;
5156 BOOL supported;
5157 const char *name;
5159 invalid_caps_tests[] =
5161 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
5162 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
5163 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
5164 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
5165 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
5168 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5169 0, 0, 640, 480, 0, 0, 0, 0);
5170 ddraw = create_ddraw();
5171 ok(!!ddraw, "Failed to create a ddraw object.\n");
5172 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5173 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5175 reset_ddsd(&ddsd);
5176 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5177 ddsd.dwWidth = 8;
5178 ddsd.dwHeight = 8;
5179 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5180 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5181 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5182 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5183 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5184 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5185 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5187 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5188 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5190 reset_ddsd(&ddsd);
5191 ddsd.dwFlags = DDSD_LPSURFACE;
5192 ddsd.lpSurface = data;
5193 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5194 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5196 /* Redundantly setting the same lpSurface is not an error. */
5197 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5198 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5200 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5201 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5202 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5203 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
5205 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5206 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5207 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5208 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
5209 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5210 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5212 reset_ddsd(&ddsd);
5213 ddsd.dwFlags = DDSD_LPSURFACE;
5214 ddsd.lpSurface = data;
5215 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 1);
5216 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
5218 ddsd.lpSurface = NULL;
5219 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5220 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
5222 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, NULL, 0);
5223 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
5225 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5226 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5227 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5228 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5229 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5231 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5232 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5233 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
5235 ddsd.dwFlags = DDSD_CAPS;
5236 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5237 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
5239 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
5240 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
5241 ddsd.lpSurface = data;
5242 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5243 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5244 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5245 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5246 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5247 ddsd.ddsCaps.dwCaps = 0;
5248 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
5249 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5250 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5252 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5253 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5254 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5255 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5256 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5258 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5259 reset_ddsd(&ddsd);
5260 ddsd.dwFlags = DDSD_HEIGHT;
5261 ddsd.dwHeight = 16;
5262 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5263 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
5265 ddsd.lpSurface = data;
5266 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
5267 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5268 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5270 ddsd.dwHeight = 0;
5271 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5272 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
5274 reset_ddsd(&ddsd);
5275 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5276 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
5277 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5278 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5280 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5281 reset_ddsd(&ddsd);
5282 ddsd.dwFlags = DDSD_PITCH;
5283 U1(ddsd).lPitch = 8 * 4;
5284 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5285 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
5287 ddsd.dwFlags = DDSD_WIDTH;
5288 ddsd.dwWidth = 16;
5289 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5290 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
5292 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
5293 ddsd.lpSurface = data;
5294 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5295 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
5297 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
5298 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5299 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
5301 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5302 U1(ddsd).lPitch = 16 * 4;
5303 ddsd.dwWidth = 16;
5304 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5305 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5307 reset_ddsd(&ddsd);
5308 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5309 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5310 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5311 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5312 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
5314 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5316 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5317 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5318 U1(ddsd).lPitch = 4 * 4;
5319 ddsd.lpSurface = data;
5320 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5321 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5323 U1(ddsd).lPitch = 4;
5324 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5325 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5327 U1(ddsd).lPitch = 16 * 4 + 1;
5328 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5329 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5331 U1(ddsd).lPitch = 16 * 4 + 3;
5332 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5333 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5335 U1(ddsd).lPitch = -4;
5336 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5337 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
5339 U1(ddsd).lPitch = 16 * 4;
5340 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5341 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5343 reset_ddsd(&ddsd);
5344 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5345 U1(ddsd).lPitch = 0;
5346 ddsd.dwWidth = 16;
5347 ddsd.lpSurface = data;
5348 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5349 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
5351 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5352 U1(ddsd).lPitch = 16 * 4;
5353 ddsd.dwWidth = 0;
5354 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5355 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
5357 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5358 ddsd.dwFlags = DDSD_PIXELFORMAT;
5359 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5360 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5361 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5362 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5363 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5364 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5365 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5366 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
5368 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
5369 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5370 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5372 /* Can't set color keys. */
5373 reset_ddsd(&ddsd);
5374 ddsd.dwFlags = DDSD_CKSRCBLT;
5375 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
5376 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
5377 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5378 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5380 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
5381 ddsd.lpSurface = data;
5382 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5383 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5385 IDirectDrawSurface7_Release(surface);
5387 /* SetSurfaceDesc needs systemmemory surfaces.
5389 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5390 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
5392 reset_ddsd(&ddsd);
5393 ddsd.dwFlags = DDSD_CAPS;
5394 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
5395 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
5396 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5398 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5399 ddsd.dwWidth = 8;
5400 ddsd.dwHeight = 8;
5401 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5402 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5403 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5404 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5405 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5406 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5409 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5410 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW, "Failed to create surface, hr %#x.\n", hr);
5411 if (FAILED(hr))
5413 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5414 invalid_caps_tests[i].name);
5415 goto done;
5418 reset_ddsd(&ddsd);
5419 ddsd.dwFlags = DDSD_LPSURFACE;
5420 ddsd.lpSurface = data;
5421 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5422 if (invalid_caps_tests[i].supported)
5424 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5426 else
5428 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5429 invalid_caps_tests[i].name, hr);
5431 /* Check priority of error conditions. */
5432 ddsd.dwFlags = DDSD_WIDTH;
5433 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5434 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5435 invalid_caps_tests[i].name, hr);
5438 IDirectDrawSurface7_Release(surface);
5441 done:
5442 ref = IDirectDraw7_Release(ddraw);
5443 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5444 DestroyWindow(window);
5447 static void test_user_memory_getdc(void)
5449 IDirectDraw7 *ddraw;
5450 HWND window;
5451 HRESULT hr;
5452 DDSURFACEDESC2 ddsd;
5453 IDirectDrawSurface7 *surface;
5454 DWORD data[16][16];
5455 ULONG ref;
5456 HDC dc;
5457 unsigned int x, y;
5459 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5460 0, 0, 640, 480, 0, 0, 0, 0);
5461 ddraw = create_ddraw();
5462 ok(!!ddraw, "Failed to create a ddraw object.\n");
5463 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5464 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5466 reset_ddsd(&ddsd);
5467 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5468 ddsd.dwWidth = 16;
5469 ddsd.dwHeight = 16;
5470 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5471 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5472 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5473 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5474 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5475 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5476 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5477 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5478 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5480 memset(data, 0xaa, sizeof(data));
5481 reset_ddsd(&ddsd);
5482 ddsd.dwFlags = DDSD_LPSURFACE;
5483 ddsd.lpSurface = data;
5484 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5485 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5487 hr = IDirectDrawSurface7_GetDC(surface, &dc);
5488 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5489 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
5490 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
5491 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
5492 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5494 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
5495 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
5497 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
5498 ddsd.lpSurface = data;
5499 ddsd.dwWidth = 4;
5500 ddsd.dwHeight = 8;
5501 U1(ddsd).lPitch = sizeof(*data);
5502 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5503 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5505 memset(data, 0xaa, sizeof(data));
5506 hr = IDirectDrawSurface7_GetDC(surface, &dc);
5507 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5508 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
5509 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
5510 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
5511 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5513 for (y = 0; y < 4; y++)
5515 for (x = 0; x < 4; x++)
5517 if ((x == 1 || x == 2) && (y == 1 || y == 2))
5518 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5519 x, y, data[y][x]);
5520 else
5521 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
5522 x, y, data[y][x]);
5525 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5526 data[0][5]);
5527 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5528 data[7][3]);
5529 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5530 data[7][4]);
5531 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5532 data[8][0]);
5534 IDirectDrawSurface7_Release(surface);
5535 ref = IDirectDraw7_Release(ddraw);
5536 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5537 DestroyWindow(window);
5540 static void test_sysmem_overlay(void)
5542 IDirectDraw7 *ddraw;
5543 HWND window;
5544 HRESULT hr;
5545 DDSURFACEDESC2 ddsd;
5546 IDirectDrawSurface7 *surface;
5547 ULONG ref;
5549 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5550 0, 0, 640, 480, 0, 0, 0, 0);
5551 ddraw = create_ddraw();
5552 ok(!!ddraw, "Failed to create a ddraw object.\n");
5553 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5554 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5556 reset_ddsd(&ddsd);
5557 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
5558 ddsd.dwWidth = 16;
5559 ddsd.dwHeight = 16;
5560 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
5561 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5562 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5563 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5564 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5565 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5566 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5567 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5568 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
5570 ref = IDirectDraw7_Release(ddraw);
5571 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5572 DestroyWindow(window);
5575 static void test_primary_palette(void)
5577 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, 0};
5578 IDirectDrawSurface7 *primary, *backbuffer;
5579 PALETTEENTRY palette_entries[256];
5580 IDirectDrawPalette *palette, *tmp;
5581 DDSURFACEDESC2 surface_desc;
5582 IDirectDraw7 *ddraw;
5583 DWORD palette_caps;
5584 ULONG refcount;
5585 HWND window;
5586 HRESULT hr;
5588 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5589 0, 0, 640, 480, 0, 0, 0, 0);
5590 ddraw = create_ddraw();
5591 ok(!!ddraw, "Failed to create a ddraw object.\n");
5592 hr = IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0);
5593 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
5594 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5595 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5597 memset(&surface_desc, 0, sizeof(surface_desc));
5598 surface_desc.dwSize = sizeof(surface_desc);
5599 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5600 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5601 surface_desc.dwBackBufferCount = 1;
5602 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5603 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5604 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
5605 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5607 memset(palette_entries, 0, sizeof(palette_entries));
5608 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
5609 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5610 refcount = get_refcount((IUnknown *)palette);
5611 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5613 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5614 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5615 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
5617 hr = IDirectDrawSurface7_SetPalette(primary, palette);
5618 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5619 refcount = get_refcount((IUnknown *)palette);
5620 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5622 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5623 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5624 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
5625 "Got unexpected palette caps %#x.\n", palette_caps);
5627 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
5628 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5629 refcount = get_refcount((IUnknown *)palette);
5630 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5632 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5633 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5634 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
5636 hr = IDirectDrawSurface7_SetPalette(primary, palette);
5637 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5638 refcount = get_refcount((IUnknown *)palette);
5639 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5641 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
5642 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
5643 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
5644 IDirectDrawPalette_Release(tmp);
5645 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
5646 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
5648 refcount = IDirectDrawPalette_Release(palette);
5649 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5650 refcount = IDirectDrawPalette_Release(palette);
5651 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5653 /* Note that this only seems to work when the palette is attached to the
5654 * primary surface. When attached to a regular surface, attempting to get
5655 * the palette here will cause an access violation. */
5656 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
5657 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
5659 refcount = IDirectDrawSurface7_Release(backbuffer);
5660 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5661 refcount = IDirectDrawSurface7_Release(primary);
5662 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5663 refcount = IDirectDraw7_Release(ddraw);
5664 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5665 DestroyWindow(window);
5668 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
5670 UINT *surface_count = context;
5672 ++(*surface_count);
5673 IDirectDrawSurface_Release(surface);
5675 return DDENUMRET_OK;
5678 static void test_surface_attachment(void)
5680 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
5681 IDirectDrawSurface *surface1v1, *surface2v1;
5682 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0};
5683 DDSURFACEDESC2 surface_desc;
5684 IDirectDraw7 *ddraw;
5685 UINT surface_count;
5686 ULONG refcount;
5687 HWND window;
5688 HRESULT hr;
5690 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5691 0, 0, 640, 480, 0, 0, 0, 0);
5692 ddraw = create_ddraw();
5693 ok(!!ddraw, "Failed to create a ddraw object.\n");
5694 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5695 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5697 memset(&surface_desc, 0, sizeof(surface_desc));
5698 surface_desc.dwSize = sizeof(surface_desc);
5699 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
5700 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
5701 U2(surface_desc).dwMipMapCount = 3;
5702 surface_desc.dwWidth = 128;
5703 surface_desc.dwHeight = 128;
5704 if (FAILED(hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
5706 skip("Failed to create a texture, skipping tests.\n");
5707 IDirectDraw7_Release(ddraw);
5708 DestroyWindow(window);
5709 return;
5712 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
5713 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
5714 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
5715 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
5716 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
5717 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5719 surface_count = 0;
5720 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
5721 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
5722 surface_count = 0;
5723 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
5724 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
5725 surface_count = 0;
5726 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
5727 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
5729 memset(&surface_desc, 0, sizeof(surface_desc));
5730 surface_desc.dwSize = sizeof(surface_desc);
5731 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5732 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
5733 surface_desc.dwWidth = 16;
5734 surface_desc.dwHeight = 16;
5735 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
5736 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5738 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
5739 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5740 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
5741 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5742 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
5743 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5744 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
5745 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5746 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
5747 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5748 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
5749 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5751 IDirectDrawSurface7_Release(surface4);
5753 memset(&surface_desc, 0, sizeof(surface_desc));
5754 surface_desc.dwSize = sizeof(surface_desc);
5755 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5756 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5757 surface_desc.dwWidth = 16;
5758 surface_desc.dwHeight = 16;
5759 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
5760 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5762 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
5763 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5764 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
5765 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5766 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
5767 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5768 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
5769 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5770 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
5771 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5772 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
5773 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5775 IDirectDrawSurface7_Release(surface4);
5776 IDirectDrawSurface7_Release(surface3);
5777 IDirectDrawSurface7_Release(surface2);
5778 IDirectDrawSurface7_Release(surface1);
5780 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5781 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5783 /* Try a single primary and two offscreen plain surfaces. */
5784 memset(&surface_desc, 0, sizeof(surface_desc));
5785 surface_desc.dwSize = sizeof(surface_desc);
5786 surface_desc.dwFlags = DDSD_CAPS;
5787 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
5788 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
5789 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5791 memset(&surface_desc, 0, sizeof(surface_desc));
5792 surface_desc.dwSize = sizeof(surface_desc);
5793 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5794 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5795 surface_desc.dwWidth = GetSystemMetrics(SM_CXSCREEN);
5796 surface_desc.dwHeight = GetSystemMetrics(SM_CYSCREEN);
5797 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
5798 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5800 memset(&surface_desc, 0, sizeof(surface_desc));
5801 surface_desc.dwSize = sizeof(surface_desc);
5802 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5803 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5804 surface_desc.dwWidth = GetSystemMetrics(SM_CXSCREEN);
5805 surface_desc.dwHeight = GetSystemMetrics(SM_CYSCREEN);
5806 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
5807 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5809 /* This one has a different size. */
5810 memset(&surface_desc, 0, sizeof(surface_desc));
5811 surface_desc.dwSize = sizeof(surface_desc);
5812 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5813 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
5814 surface_desc.dwWidth = 128;
5815 surface_desc.dwHeight = 128;
5816 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
5817 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5819 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
5820 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5821 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
5822 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5823 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
5824 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5825 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
5826 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5827 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
5828 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5830 IDirectDrawSurface7_Release(surface4);
5831 IDirectDrawSurface7_Release(surface3);
5832 IDirectDrawSurface7_Release(surface2);
5833 IDirectDrawSurface7_Release(surface1);
5835 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5836 memset(&surface_desc, 0, sizeof(surface_desc));
5837 surface_desc.dwSize = sizeof(surface_desc);
5838 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5839 surface_desc.dwWidth = 64;
5840 surface_desc.dwHeight = 64;
5841 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5842 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
5843 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
5844 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
5845 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
5846 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
5847 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
5848 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
5849 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5850 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
5851 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5853 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
5854 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
5855 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
5856 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
5857 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
5858 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5860 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
5861 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
5862 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
5863 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
5865 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
5866 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
5867 refcount = get_refcount((IUnknown *)surface2);
5868 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5869 refcount = get_refcount((IUnknown *)surface2v1);
5870 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5871 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
5872 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
5873 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
5874 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
5875 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
5876 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
5878 /* Attaching while already attached to other surface. */
5879 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
5880 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
5881 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
5882 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
5883 IDirectDrawSurface7_Release(surface3);
5885 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
5886 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
5887 refcount = get_refcount((IUnknown *)surface2);
5888 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5889 refcount = get_refcount((IUnknown *)surface2v1);
5890 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5892 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
5893 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
5894 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
5895 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
5896 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
5897 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
5898 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
5899 refcount = IDirectDrawSurface7_Release(surface2);
5900 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5901 refcount = IDirectDrawSurface7_Release(surface1);
5902 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5904 /* Automatic detachment on release. */
5905 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
5906 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
5907 refcount = get_refcount((IUnknown *)surface2v1);
5908 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5909 refcount = IDirectDrawSurface_Release(surface1v1);
5910 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5911 refcount = IDirectDrawSurface_Release(surface2v1);
5912 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5913 refcount = IDirectDraw7_Release(ddraw);
5914 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5915 DestroyWindow(window);
5918 static void test_private_data(void)
5920 IDirectDraw7 *ddraw;
5921 IDirectDrawSurface7 *surface, *surface2;
5922 DDSURFACEDESC2 surface_desc;
5923 ULONG refcount, refcount2, refcount3;
5924 IUnknown *ptr;
5925 DWORD size = sizeof(ptr);
5926 HRESULT hr;
5927 HWND window;
5928 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
5929 DWORD data[] = {1, 2, 3, 4};
5930 DDCAPS hal_caps;
5931 static const GUID ddraw_private_data_test_guid =
5933 0xfdb37466,
5934 0x428f,
5935 0x4edf,
5936 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
5938 static const GUID ddraw_private_data_test_guid2 =
5940 0x2e5afac2,
5941 0x87b5,
5942 0x4c10,
5943 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5946 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5947 0, 0, 640, 480, 0, 0, 0, 0);
5948 ddraw = create_ddraw();
5949 ok(!!ddraw, "Failed to create a ddraw object.\n");
5950 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5951 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5953 reset_ddsd(&surface_desc);
5954 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
5955 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
5956 surface_desc.dwHeight = 4;
5957 surface_desc.dwWidth = 4;
5958 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5959 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5961 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
5962 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
5963 0, DDSPD_IUNKNOWNPOINTER);
5964 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
5965 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
5966 5, DDSPD_IUNKNOWNPOINTER);
5967 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
5968 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
5969 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
5970 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
5972 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
5973 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
5974 * erases the old content and returns an error. This behavior has
5975 * been fixed in d3d8 and d3d9. Unless an application is found
5976 * that depends on this we don't care about this behavior. */
5977 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
5978 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
5979 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5980 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
5981 0, DDSPD_IUNKNOWNPOINTER);
5982 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
5983 size = sizeof(ptr);
5984 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
5985 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
5986 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
5987 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5989 refcount = get_refcount((IUnknown *)ddraw);
5990 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
5991 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
5992 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5993 refcount2 = get_refcount((IUnknown *)ddraw);
5994 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
5996 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
5997 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5998 refcount2 = get_refcount((IUnknown *)ddraw);
5999 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6001 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6002 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6003 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6004 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
6005 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
6006 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6007 refcount2 = get_refcount((IUnknown *)ddraw);
6008 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6010 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6011 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6012 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6013 size = 2 * sizeof(ptr);
6014 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6015 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6016 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6017 refcount2 = get_refcount(ptr);
6018 /* Object is NOT addref'ed by the getter. */
6019 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
6020 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6022 ptr = (IUnknown *)0xdeadbeef;
6023 size = 1;
6024 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6025 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6026 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6027 size = 2 * sizeof(ptr);
6028 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6029 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6030 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
6031 size = 1;
6032 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6033 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6034 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6035 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6036 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
6037 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6038 size = 0xdeadbabe;
6039 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
6040 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6041 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6042 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
6043 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
6044 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6046 refcount3 = IDirectDrawSurface7_Release(surface);
6047 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
6049 /* Destroying the surface frees the reference held on the private data. It also frees
6050 * the reference the surface is holding on its creating object. */
6051 refcount2 = get_refcount((IUnknown *)ddraw);
6052 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
6054 memset(&hal_caps, 0, sizeof(hal_caps));
6055 hal_caps.dwSize = sizeof(hal_caps);
6056 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6057 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6058 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6060 reset_ddsd(&surface_desc);
6061 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
6062 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6063 surface_desc.dwHeight = 4;
6064 surface_desc.dwWidth = 4;
6065 U2(surface_desc).dwMipMapCount = 2;
6066 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6067 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6068 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
6069 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6071 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
6072 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6073 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
6074 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6076 IDirectDrawSurface7_Release(surface2);
6077 IDirectDrawSurface7_Release(surface);
6079 else
6080 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
6082 refcount = IDirectDraw7_Release(ddraw);
6083 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6084 DestroyWindow(window);
6087 static void test_pixel_format(void)
6089 HWND window, window2 = NULL;
6090 HDC hdc, hdc2 = NULL;
6091 HMODULE gl = NULL;
6092 int format, test_format;
6093 PIXELFORMATDESCRIPTOR pfd;
6094 IDirectDraw7 *ddraw = NULL;
6095 IDirectDrawClipper *clipper = NULL;
6096 DDSURFACEDESC2 ddsd;
6097 IDirectDrawSurface7 *primary = NULL;
6098 DDBLTFX fx;
6099 HRESULT hr;
6101 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6102 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6103 if (!window)
6105 skip("Failed to create window\n");
6106 return;
6109 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6110 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6112 hdc = GetDC(window);
6113 if (!hdc)
6115 skip("Failed to get DC\n");
6116 goto cleanup;
6119 if (window2)
6120 hdc2 = GetDC(window2);
6122 gl = LoadLibraryA("opengl32.dll");
6123 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6125 format = GetPixelFormat(hdc);
6126 ok(format == 0, "new window has pixel format %d\n", format);
6128 ZeroMemory(&pfd, sizeof(pfd));
6129 pfd.nSize = sizeof(pfd);
6130 pfd.nVersion = 1;
6131 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
6132 pfd.iPixelType = PFD_TYPE_RGBA;
6133 pfd.iLayerType = PFD_MAIN_PLANE;
6134 format = ChoosePixelFormat(hdc, &pfd);
6135 if (format <= 0)
6137 skip("no pixel format available\n");
6138 goto cleanup;
6141 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
6143 skip("failed to set pixel format\n");
6144 goto cleanup;
6147 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
6149 skip("failed to set pixel format on second window\n");
6150 if (hdc2)
6152 ReleaseDC(window2, hdc2);
6153 hdc2 = NULL;
6157 ddraw = create_ddraw();
6158 ok(!!ddraw, "Failed to create a ddraw object.\n");
6160 test_format = GetPixelFormat(hdc);
6161 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6163 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6164 if (FAILED(hr))
6166 skip("Failed to set cooperative level, hr %#x.\n", hr);
6167 goto cleanup;
6170 test_format = GetPixelFormat(hdc);
6171 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6173 if (hdc2)
6175 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
6176 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
6177 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
6178 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
6180 test_format = GetPixelFormat(hdc);
6181 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6183 test_format = GetPixelFormat(hdc2);
6184 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6187 memset(&ddsd, 0, sizeof(ddsd));
6188 ddsd.dwSize = sizeof(ddsd);
6189 ddsd.dwFlags = DDSD_CAPS;
6190 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6192 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
6193 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
6195 test_format = GetPixelFormat(hdc);
6196 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6198 if (hdc2)
6200 test_format = GetPixelFormat(hdc2);
6201 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6204 if (clipper)
6206 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
6207 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
6209 test_format = GetPixelFormat(hdc);
6210 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6212 test_format = GetPixelFormat(hdc2);
6213 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6216 memset(&fx, 0, sizeof(fx));
6217 fx.dwSize = sizeof(fx);
6218 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6219 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
6221 test_format = GetPixelFormat(hdc);
6222 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6224 if (hdc2)
6226 test_format = GetPixelFormat(hdc2);
6227 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6230 cleanup:
6231 if (primary) IDirectDrawSurface7_Release(primary);
6232 if (clipper) IDirectDrawClipper_Release(clipper);
6233 if (ddraw) IDirectDraw7_Release(ddraw);
6234 if (gl) FreeLibrary(gl);
6235 if (hdc) ReleaseDC(window, hdc);
6236 if (hdc2) ReleaseDC(window2, hdc2);
6237 if (window) DestroyWindow(window);
6238 if (window2) DestroyWindow(window2);
6241 static void test_create_surface_pitch(void)
6243 IDirectDrawSurface7 *surface;
6244 DDSURFACEDESC2 surface_desc;
6245 IDirectDraw7 *ddraw;
6246 unsigned int i;
6247 ULONG refcount;
6248 HWND window;
6249 HRESULT hr;
6250 void *mem;
6252 static const struct
6254 DWORD placement;
6255 DWORD flags_in;
6256 DWORD pitch_in;
6257 HRESULT hr;
6258 DWORD flags_out;
6259 DWORD pitch_out;
6261 test_data[] =
6263 {DDSCAPS_VIDEOMEMORY, 0, 0, DD_OK,
6264 DDSD_PITCH, 0x100},
6265 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x104, DD_OK,
6266 DDSD_PITCH, 0x100},
6267 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x0fc, DD_OK,
6268 DDSD_PITCH, 0x100},
6269 {DDSCAPS_VIDEOMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
6270 0, 0 },
6271 {DDSCAPS_SYSTEMMEMORY, 0, 0, DD_OK,
6272 DDSD_PITCH, 0x100},
6273 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x104, DD_OK,
6274 DDSD_PITCH, 0x100},
6275 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x0fc, DD_OK,
6276 DDSD_PITCH, 0x100},
6277 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
6278 0, 0 },
6279 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x104, DD_OK,
6280 DDSD_PITCH, 0x104},
6281 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x102, DDERR_INVALIDPARAMS,
6282 0, 0 },
6283 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DDERR_INVALIDPARAMS,
6284 0, 0 },
6286 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE;
6288 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6289 0, 0, 640, 480, 0, 0, 0, 0);
6290 ddraw = create_ddraw();
6291 ok(!!ddraw, "Failed to create a ddraw object.\n");
6292 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6293 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6295 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((64 * 4) + 4) * 64);
6297 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
6299 memset(&surface_desc, 0, sizeof(surface_desc));
6300 surface_desc.dwSize = sizeof(surface_desc);
6301 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
6302 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | test_data[i].placement;
6303 surface_desc.dwWidth = 64;
6304 surface_desc.dwHeight = 64;
6305 U1(surface_desc).lPitch = test_data[i].pitch_in;
6306 surface_desc.lpSurface = mem;
6307 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6308 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
6309 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6310 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6311 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6312 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6313 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6314 ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
6315 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
6316 if (FAILED(hr))
6317 continue;
6319 memset(&surface_desc, 0, sizeof(surface_desc));
6320 surface_desc.dwSize = sizeof(surface_desc);
6321 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
6322 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
6323 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
6324 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6325 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
6326 ok(U1(surface_desc).lPitch == test_data[i].pitch_out,
6327 "Test %u: Got unexpected pitch %u, expected %u.\n",
6328 i, U1(surface_desc).lPitch, test_data[i].pitch_out);
6330 IDirectDrawSurface7_Release(surface);
6333 HeapFree(GetProcessHeap(), 0, mem);
6334 refcount = IDirectDraw7_Release(ddraw);
6335 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6336 DestroyWindow(window);
6339 static void test_mipmap_lock(void)
6341 IDirectDrawSurface7 *surface, *surface2;
6342 DDSURFACEDESC2 surface_desc;
6343 IDirectDraw7 *ddraw;
6344 ULONG refcount;
6345 HWND window;
6346 HRESULT hr;
6347 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6348 DDCAPS hal_caps;
6350 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6351 0, 0, 640, 480, 0, 0, 0, 0);
6352 ddraw = create_ddraw();
6353 ok(!!ddraw, "Failed to create a ddraw object.\n");
6354 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6355 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6357 memset(&hal_caps, 0, sizeof(hal_caps));
6358 hal_caps.dwSize = sizeof(hal_caps);
6359 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6360 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6361 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6363 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6364 IDirectDraw7_Release(ddraw);
6365 DestroyWindow(window);
6366 return;
6369 memset(&surface_desc, 0, sizeof(surface_desc));
6370 surface_desc.dwSize = sizeof(surface_desc);
6371 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6372 surface_desc.dwWidth = 4;
6373 surface_desc.dwHeight = 4;
6374 U2(surface_desc).dwMipMapCount = 2;
6375 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
6376 | DDSCAPS_SYSTEMMEMORY;
6377 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6378 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6379 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
6380 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6382 memset(&surface_desc, 0, sizeof(surface_desc));
6383 surface_desc.dwSize = sizeof(surface_desc);
6384 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
6385 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6386 memset(&surface_desc, 0, sizeof(surface_desc));
6387 surface_desc.dwSize = sizeof(surface_desc);
6388 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
6389 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6390 IDirectDrawSurface7_Unlock(surface2, NULL);
6391 IDirectDrawSurface7_Unlock(surface, NULL);
6393 IDirectDrawSurface7_Release(surface2);
6394 IDirectDrawSurface7_Release(surface);
6395 refcount = IDirectDraw7_Release(ddraw);
6396 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6397 DestroyWindow(window);
6400 START_TEST(ddraw7)
6402 HMODULE module = GetModuleHandleA("ddraw.dll");
6403 IDirectDraw7 *ddraw;
6405 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
6407 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
6408 return;
6411 if (!(ddraw = create_ddraw()))
6413 skip("Failed to create a ddraw object, skipping tests.\n");
6414 return;
6416 IDirectDraw7_Release(ddraw);
6418 test_process_vertices();
6419 test_coop_level_create_device_window();
6420 test_clipper_blt();
6421 test_coop_level_d3d_state();
6422 test_surface_interface_mismatch();
6423 test_coop_level_threaded();
6424 test_depth_blit();
6425 test_texture_load_ckey();
6426 test_zenable();
6427 test_ck_rgba();
6428 test_ck_default();
6429 test_ck_complex();
6430 test_surface_qi();
6431 test_device_qi();
6432 test_wndproc();
6433 test_window_style();
6434 test_redundant_mode_set();
6435 test_coop_level_mode_set();
6436 test_coop_level_mode_set_multi();
6437 test_initialize();
6438 test_coop_level_surf_create();
6439 test_vb_discard();
6440 test_coop_level_multi_window();
6441 test_draw_strided();
6442 test_clear_rect_count();
6443 test_coop_level_versions();
6444 test_fog_special();
6445 test_lighting_interface_versions();
6446 test_coop_level_activateapp();
6447 test_texturemanage();
6448 test_block_formats_creation();
6449 test_unsupported_formats();
6450 test_rt_caps();
6451 test_primary_caps();
6452 test_surface_lock();
6453 test_surface_discard();
6454 test_flip();
6455 test_set_surface_desc();
6456 test_user_memory_getdc();
6457 test_sysmem_overlay();
6458 test_primary_palette();
6459 test_surface_attachment();
6460 test_private_data();
6461 test_pixel_format();
6462 test_create_surface_pitch();
6463 test_mipmap_lock();