ddraw: Handle DDBLT_ROP in ddraw.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blob66f8cff5eee89f534226cb9cf3b5a7089355b66c
1 /*
2 * Copyright 2006, 2012-2014 Stefan Dösinger for CodeWeavers
3 * Copyright 2011-2014 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);
26 static DEVMODEW registry_mode;
28 struct vec2
30 float x, y;
33 struct vec3
35 float x, y, z;
38 struct vec4
40 float x, y, z, w;
43 struct create_window_thread_param
45 HWND window;
46 HANDLE window_created;
47 HANDLE destroy_window;
48 HANDLE thread;
51 static BOOL compare_float(float f, float g, unsigned int ulps)
53 int x = *(int *)&f;
54 int y = *(int *)&g;
56 if (x < 0)
57 x = INT_MIN - x;
58 if (y < 0)
59 y = INT_MIN - y;
61 if (abs(x - y) > ulps)
62 return FALSE;
64 return TRUE;
67 static BOOL compare_vec3(struct vec3 *vec, float x, float y, float z, unsigned int ulps)
69 return compare_float(vec->x, x, ulps)
70 && compare_float(vec->y, y, ulps)
71 && compare_float(vec->z, z, ulps);
74 static BOOL compare_vec4(struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
76 return compare_float(vec->x, x, ulps)
77 && compare_float(vec->y, y, ulps)
78 && compare_float(vec->z, z, ulps)
79 && compare_float(vec->w, w, ulps);
82 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
84 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
85 c1 >>= 8; c2 >>= 8;
86 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
87 c1 >>= 8; c2 >>= 8;
88 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
89 c1 >>= 8; c2 >>= 8;
90 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
91 return TRUE;
94 static ULONG get_refcount(IUnknown *iface)
96 IUnknown_AddRef(iface);
97 return IUnknown_Release(iface);
100 static DWORD WINAPI create_window_thread_proc(void *param)
102 struct create_window_thread_param *p = param;
103 DWORD res;
104 BOOL ret;
106 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
107 0, 0, 640, 480, 0, 0, 0, 0);
108 ret = SetEvent(p->window_created);
109 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
111 for (;;)
113 MSG msg;
115 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
116 DispatchMessageA(&msg);
117 res = WaitForSingleObject(p->destroy_window, 100);
118 if (res == WAIT_OBJECT_0)
119 break;
120 if (res != WAIT_TIMEOUT)
122 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
123 break;
127 DestroyWindow(p->window);
129 return 0;
132 static void create_window_thread(struct create_window_thread_param *p)
134 DWORD res, tid;
136 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
137 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
138 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
139 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
140 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
141 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
142 res = WaitForSingleObject(p->window_created, INFINITE);
143 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
146 static void destroy_window_thread(struct create_window_thread_param *p)
148 SetEvent(p->destroy_window);
149 WaitForSingleObject(p->thread, INFINITE);
150 CloseHandle(p->destroy_window);
151 CloseHandle(p->window_created);
152 CloseHandle(p->thread);
155 static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
157 IDirectDrawSurface7 *rt, *ret;
158 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
159 HRESULT hr;
161 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
162 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
163 hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
164 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
165 IDirectDrawSurface7_Release(rt);
166 return ret;
169 static HRESULT set_display_mode(IDirectDraw7 *ddraw, DWORD width, DWORD height)
171 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
172 return DD_OK;
173 return IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0);
176 static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
178 RECT rect = {x, y, x + 1, y + 1};
179 DDSURFACEDESC2 surface_desc;
180 D3DCOLOR color;
181 HRESULT hr;
183 memset(&surface_desc, 0, sizeof(surface_desc));
184 surface_desc.dwSize = sizeof(surface_desc);
186 hr = IDirectDrawSurface7_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY, NULL);
187 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
188 if (FAILED(hr))
189 return 0xdeadbeef;
191 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
193 hr = IDirectDrawSurface7_Unlock(surface, &rect);
194 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
196 return color;
199 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
201 DDPIXELFORMAT *z_fmt = ctx;
203 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
204 *z_fmt = *format;
206 return DDENUMRET_OK;
209 static IDirectDraw7 *create_ddraw(void)
211 IDirectDraw7 *ddraw;
213 if (FAILED(pDirectDrawCreateEx(NULL, (void **)&ddraw, &IID_IDirectDraw7, NULL)))
214 return NULL;
216 return ddraw;
219 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
221 BOOL *hal_ok = ctx;
222 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
224 *hal_ok = TRUE;
225 return DDENUMRET_CANCEL;
227 return DDENUMRET_OK;
230 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
232 IDirectDrawSurface7 *surface, *ds;
233 IDirect3DDevice7 *device = NULL;
234 DDSURFACEDESC2 surface_desc;
235 DDPIXELFORMAT z_fmt;
236 IDirectDraw7 *ddraw;
237 IDirect3D7 *d3d7;
238 HRESULT hr;
239 BOOL hal_ok = FALSE;
240 const GUID *devtype = &IID_IDirect3DHALDevice;
242 if (!(ddraw = create_ddraw()))
243 return NULL;
245 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
246 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
248 memset(&surface_desc, 0, sizeof(surface_desc));
249 surface_desc.dwSize = sizeof(surface_desc);
250 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
251 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
252 surface_desc.dwWidth = 640;
253 surface_desc.dwHeight = 480;
255 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
256 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
258 if (coop_level & DDSCL_NORMAL)
260 IDirectDrawClipper *clipper;
262 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
263 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
264 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
265 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
266 hr = IDirectDrawSurface7_SetClipper(surface, clipper);
267 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
268 IDirectDrawClipper_Release(clipper);
271 hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
272 IDirectDraw7_Release(ddraw);
273 if (FAILED(hr))
275 IDirectDrawSurface7_Release(surface);
276 return NULL;
279 hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_cb, &hal_ok);
280 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
281 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
283 memset(&z_fmt, 0, sizeof(z_fmt));
284 hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
285 if (FAILED(hr) || !z_fmt.dwSize)
287 IDirect3D7_Release(d3d7);
288 IDirectDrawSurface7_Release(surface);
289 return NULL;
292 memset(&surface_desc, 0, sizeof(surface_desc));
293 surface_desc.dwSize = sizeof(surface_desc);
294 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
295 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
296 U4(surface_desc).ddpfPixelFormat = z_fmt;
297 surface_desc.dwWidth = 640;
298 surface_desc.dwHeight = 480;
299 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
300 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
301 if (FAILED(hr))
303 IDirect3D7_Release(d3d7);
304 IDirectDrawSurface7_Release(surface);
305 return NULL;
308 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
309 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
310 IDirectDrawSurface7_Release(ds);
311 if (FAILED(hr))
313 IDirect3D7_Release(d3d7);
314 IDirectDrawSurface7_Release(surface);
315 return NULL;
318 hr = IDirect3D7_CreateDevice(d3d7, devtype, surface, &device);
319 IDirect3D7_Release(d3d7);
320 IDirectDrawSurface7_Release(surface);
321 if (FAILED(hr))
322 return NULL;
324 return device;
327 struct message
329 UINT message;
330 BOOL check_wparam;
331 WPARAM expect_wparam;
334 static const struct message *expect_messages;
336 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
338 if (expect_messages && message == expect_messages->message)
340 if (expect_messages->check_wparam)
341 ok (wparam == expect_messages->expect_wparam,
342 "Got unexpected wparam %lx for message %x, expected %lx.\n",
343 wparam, message, expect_messages->expect_wparam);
345 ++expect_messages;
348 return DefWindowProcA(hwnd, message, wparam, lparam);
351 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
352 * interface. This prevents subsequent SetCooperativeLevel() calls on a
353 * different window from failing with DDERR_HWNDALREADYSET. */
354 static void fix_wndproc(HWND window, LONG_PTR proc)
356 IDirectDraw7 *ddraw;
357 HRESULT hr;
359 if (!(ddraw = create_ddraw()))
360 return;
362 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
363 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
364 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
365 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
366 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
368 IDirectDraw7_Release(ddraw);
371 static void test_process_vertices(void)
373 IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
374 D3DVERTEXBUFFERDESC vb_desc;
375 IDirect3DDevice7 *device;
376 struct vec4 *dst_data;
377 struct vec3 *dst_data2;
378 struct vec3 *src_data;
379 IDirect3D7 *d3d7;
380 D3DVIEWPORT7 vp;
381 HWND window;
382 HRESULT hr;
384 static D3DMATRIX world =
386 0.0f, 1.0f, 0.0f, 0.0f,
387 1.0f, 0.0f, 0.0f, 0.0f,
388 0.0f, 0.0f, 0.0f, 1.0f,
389 0.0f, 1.0f, 1.0f, 1.0f,
391 static D3DMATRIX view =
393 2.0f, 0.0f, 0.0f, 0.0f,
394 0.0f, -1.0f, 0.0f, 0.0f,
395 0.0f, 0.0f, 1.0f, 0.0f,
396 0.0f, 0.0f, 0.0f, 3.0f,
398 static D3DMATRIX proj =
400 1.0f, 0.0f, 0.0f, 1.0f,
401 0.0f, 1.0f, 1.0f, 0.0f,
402 0.0f, 1.0f, 1.0f, 0.0f,
403 1.0f, 0.0f, 0.0f, 1.0f,
406 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
407 0, 0, 640, 480, 0, 0, 0, 0);
408 if (!(device = create_device(window, DDSCL_NORMAL)))
410 skip("Failed to create a 3D device, skipping test.\n");
411 DestroyWindow(window);
412 return;
415 hr = IDirect3DDevice7_GetDirect3D(device, &d3d7);
416 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
418 memset(&vb_desc, 0, sizeof(vb_desc));
419 vb_desc.dwSize = sizeof(vb_desc);
420 vb_desc.dwFVF = D3DFVF_XYZ;
421 vb_desc.dwNumVertices = 4;
422 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &src_vb, 0);
423 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
425 hr = IDirect3DVertexBuffer7_Lock(src_vb, 0, (void **)&src_data, NULL);
426 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
427 src_data[0].x = 0.0f;
428 src_data[0].y = 0.0f;
429 src_data[0].z = 0.0f;
430 src_data[1].x = 1.0f;
431 src_data[1].y = 1.0f;
432 src_data[1].z = 1.0f;
433 src_data[2].x = -1.0f;
434 src_data[2].y = -1.0f;
435 src_data[2].z = 0.5f;
436 src_data[3].x = 0.5f;
437 src_data[3].y = -0.5f;
438 src_data[3].z = 0.25f;
439 hr = IDirect3DVertexBuffer7_Unlock(src_vb);
440 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
442 memset(&vb_desc, 0, sizeof(vb_desc));
443 vb_desc.dwSize = sizeof(vb_desc);
444 vb_desc.dwFVF = D3DFVF_XYZRHW;
445 vb_desc.dwNumVertices = 4;
446 /* MSDN says that the last parameter must be 0 - check that. */
447 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb1, 4);
448 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
450 memset(&vb_desc, 0, sizeof(vb_desc));
451 vb_desc.dwSize = sizeof(vb_desc);
452 vb_desc.dwFVF = D3DFVF_XYZ;
453 vb_desc.dwNumVertices = 5;
454 /* MSDN says that the last parameter must be 0 - check that. */
455 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb2, 12345678);
456 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
458 memset(&vp, 0, sizeof(vp));
459 vp.dwX = 64;
460 vp.dwY = 64;
461 vp.dwWidth = 128;
462 vp.dwHeight = 128;
463 vp.dvMinZ = 0.0f;
464 vp.dvMaxZ = 1.0f;
465 hr = IDirect3DDevice7_SetViewport(device, &vp);
466 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
468 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
469 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
470 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb2, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
471 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
473 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
474 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
475 ok(compare_vec4(&dst_data[0], +1.280e+2f, +1.280e+2f, +0.000e+0f, +1.000e+0f, 4096),
476 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
477 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
478 ok(compare_vec4(&dst_data[1], +1.920e+2f, +6.400e+1f, +1.000e+0f, +1.000e+0f, 4096),
479 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
480 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
481 ok(compare_vec4(&dst_data[2], +6.400e+1f, +1.920e+2f, +5.000e-1f, +1.000e+0f, 4096),
482 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
483 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
484 ok(compare_vec4(&dst_data[3], +1.600e+2f, +1.600e+2f, +2.500e-1f, +1.000e+0f, 4096),
485 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
486 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
487 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
488 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
490 hr = IDirect3DVertexBuffer7_Lock(dst_vb2, 0, (void **)&dst_data2, NULL);
491 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
492 /* Small thing without much practical meaning, but I stumbled upon it,
493 * so let's check for it: If the output vertex buffer has no RHW value,
494 * the RHW value of the last vertex is written into the next vertex. */
495 ok(compare_vec3(&dst_data2[4], +1.000e+0f, +0.000e+0f, +0.000e+0f, 4096),
496 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
497 dst_data2[4].x, dst_data2[4].y, dst_data2[4].z);
498 hr = IDirect3DVertexBuffer7_Unlock(dst_vb2);
499 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
501 /* Try a more complicated viewport, same vertices. */
502 memset(&vp, 0, sizeof(vp));
503 vp.dwX = 10;
504 vp.dwY = 5;
505 vp.dwWidth = 246;
506 vp.dwHeight = 130;
507 vp.dvMinZ = -2.0f;
508 vp.dvMaxZ = 4.0f;
509 hr = IDirect3DDevice7_SetViewport(device, &vp);
510 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
512 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
513 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
515 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
516 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
517 ok(compare_vec4(&dst_data[0], +1.330e+2f, +7.000e+1f, -2.000e+0f, +1.000e+0f, 4096),
518 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
519 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
520 ok(compare_vec4(&dst_data[1], +2.560e+2f, +5.000e+0f, +4.000e+0f, +1.000e+0f, 4096),
521 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
522 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
523 ok(compare_vec4(&dst_data[2], +1.000e+1f, +1.350e+2f, +1.000e+0f, +1.000e+0f, 4096),
524 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
525 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
526 ok(compare_vec4(&dst_data[3], +1.945e+2f, +1.025e+2f, -5.000e-1f, +1.000e+0f, 4096),
527 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
528 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
529 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
530 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
532 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world);
533 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
534 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &view);
535 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
536 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj);
537 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
539 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
540 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
542 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
543 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
544 ok(compare_vec4(&dst_data[0], +2.560e+2f, +7.000e+1f, -2.000e+0f, +3.333e-1f, 4096),
545 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
546 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
547 ok(compare_vec4(&dst_data[1], +2.560e+2f, +7.813e+1f, -2.750e+0f, +1.250e-1f, 4096),
548 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
549 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
550 ok(compare_vec4(&dst_data[2], +2.560e+2f, +4.400e+1f, +4.000e-1f, +4.000e-1f, 4096),
551 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
552 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
553 ok(compare_vec4(&dst_data[3], +2.560e+2f, +8.182e+1f, -3.091e+0f, +3.636e-1f, 4096),
554 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
555 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
556 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
557 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
559 IDirect3DVertexBuffer7_Release(dst_vb2);
560 IDirect3DVertexBuffer7_Release(dst_vb1);
561 IDirect3DVertexBuffer7_Release(src_vb);
562 IDirect3D7_Release(d3d7);
563 IDirect3DDevice7_Release(device);
564 DestroyWindow(window);
567 static void test_coop_level_create_device_window(void)
569 HWND focus_window, device_window;
570 IDirectDraw7 *ddraw;
571 HRESULT hr;
573 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
574 0, 0, 640, 480, 0, 0, 0, 0);
575 ddraw = create_ddraw();
576 ok(!!ddraw, "Failed to create a ddraw object.\n");
578 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
579 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
580 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
581 ok(!device_window, "Unexpected device window found.\n");
582 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
583 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
584 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
585 ok(!device_window, "Unexpected device window found.\n");
586 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
587 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
588 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
589 ok(!device_window, "Unexpected device window found.\n");
590 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
591 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
592 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
593 ok(!device_window, "Unexpected device window found.\n");
594 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
595 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
596 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
597 ok(!device_window, "Unexpected device window found.\n");
599 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
600 if (broken(hr == DDERR_INVALIDPARAMS))
602 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
603 IDirectDraw7_Release(ddraw);
604 DestroyWindow(focus_window);
605 return;
608 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
609 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
610 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
611 ok(!device_window, "Unexpected device window found.\n");
612 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
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");
617 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
618 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
619 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
620 ok(!device_window, "Unexpected device window found.\n");
621 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
622 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
623 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
624 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
625 ok(!!device_window, "Device window not found.\n");
627 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
628 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
629 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
630 ok(!device_window, "Unexpected device window found.\n");
631 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
632 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
633 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
634 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
635 ok(!!device_window, "Device window not found.\n");
637 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
638 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
639 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
640 ok(!device_window, "Unexpected device window found.\n");
641 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
642 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
643 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
644 ok(!device_window, "Unexpected device window found.\n");
645 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
646 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
647 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
648 ok(!device_window, "Unexpected device window found.\n");
649 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
650 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
651 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
652 ok(!!device_window, "Device window not found.\n");
654 IDirectDraw7_Release(ddraw);
655 DestroyWindow(focus_window);
658 static void test_clipper_blt(void)
660 IDirectDrawSurface7 *src_surface, *dst_surface;
661 RECT client_rect, src_rect;
662 IDirectDrawClipper *clipper;
663 DDSURFACEDESC2 surface_desc;
664 unsigned int i, j, x, y;
665 IDirectDraw7 *ddraw;
666 RGNDATA *rgn_data;
667 D3DCOLOR color;
668 HRGN r1, r2;
669 HWND window;
670 DDBLTFX fx;
671 HRESULT hr;
672 DWORD *ptr;
673 DWORD ret;
675 static const DWORD src_data[] =
677 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
678 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
679 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
681 static const D3DCOLOR expected1[] =
683 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
684 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
685 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
686 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
688 /* Nvidia on Windows seems to have an off-by-one error
689 * when processing source rectangles. Our left = 1 and
690 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
691 * read as well, but only for the edge pixels on the
692 * output image. The bug happens on the y axis as well,
693 * but we only read one row there, and all source rows
694 * contain the same data. This bug is not dependent on
695 * the presence of a clipper. */
696 static const D3DCOLOR expected1_broken[] =
698 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
699 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
700 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
701 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
703 static const D3DCOLOR expected2[] =
705 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
706 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
707 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
708 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
711 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
712 10, 10, 640, 480, 0, 0, 0, 0);
713 ShowWindow(window, SW_SHOW);
714 ddraw = create_ddraw();
715 ok(!!ddraw, "Failed to create a ddraw object.\n");
717 ret = GetClientRect(window, &client_rect);
718 ok(ret, "Failed to get client rect.\n");
719 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
720 ok(ret, "Failed to map client rect.\n");
722 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
723 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
725 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
726 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
727 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
728 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
729 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
730 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
731 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
732 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
733 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
734 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
735 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
736 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
737 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
738 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
739 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
740 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
741 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
742 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
743 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
744 HeapFree(GetProcessHeap(), 0, rgn_data);
746 r1 = CreateRectRgn(0, 0, 320, 240);
747 ok(!!r1, "Failed to create region.\n");
748 r2 = CreateRectRgn(320, 240, 640, 480);
749 ok(!!r2, "Failed to create region.\n");
750 CombineRgn(r1, r1, r2, RGN_OR);
751 ret = GetRegionData(r1, 0, NULL);
752 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
753 ret = GetRegionData(r1, ret, rgn_data);
754 ok(!!ret, "Failed to get region data.\n");
756 DeleteObject(r2);
757 DeleteObject(r1);
759 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
760 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
761 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
762 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
763 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
764 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
766 HeapFree(GetProcessHeap(), 0, rgn_data);
768 memset(&surface_desc, 0, sizeof(surface_desc));
769 surface_desc.dwSize = sizeof(surface_desc);
770 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
771 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
772 surface_desc.dwWidth = 640;
773 surface_desc.dwHeight = 480;
774 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
775 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
776 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
777 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
778 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
779 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
781 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
782 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
783 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
784 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
786 memset(&fx, 0, sizeof(fx));
787 fx.dwSize = sizeof(fx);
788 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
789 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
790 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
791 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
793 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
794 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
795 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
796 ptr = surface_desc.lpSurface;
797 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
798 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
799 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
800 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
801 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
803 hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
804 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
806 SetRect(&src_rect, 1, 1, 5, 2);
807 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
808 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
809 for (i = 0; i < 4; ++i)
811 for (j = 0; j < 4; ++j)
813 x = 80 * ((2 * j) + 1);
814 y = 60 * ((2 * i) + 1);
815 color = get_surface_color(dst_surface, x, y);
816 ok(compare_color(color, expected1[i * 4 + j], 1)
817 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
818 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
822 U5(fx).dwFillColor = 0xff0000ff;
823 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
824 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
825 for (i = 0; i < 4; ++i)
827 for (j = 0; j < 4; ++j)
829 x = 80 * ((2 * j) + 1);
830 y = 60 * ((2 * i) + 1);
831 color = get_surface_color(dst_surface, x, y);
832 ok(compare_color(color, expected2[i * 4 + j], 1),
833 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
837 hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
838 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
840 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
841 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
842 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
843 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
844 DestroyWindow(window);
845 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
846 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
847 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
848 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
849 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
850 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
851 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
852 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
853 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
854 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
855 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
856 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
858 IDirectDrawSurface7_Release(dst_surface);
859 IDirectDrawSurface7_Release(src_surface);
860 IDirectDrawClipper_Release(clipper);
861 IDirectDraw7_Release(ddraw);
864 static void test_coop_level_d3d_state(void)
866 IDirectDrawSurface7 *rt, *surface;
867 IDirect3DDevice7 *device;
868 IDirectDraw7 *ddraw;
869 IDirect3D7 *d3d;
870 D3DCOLOR color;
871 DWORD value;
872 HWND window;
873 HRESULT hr;
875 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
876 0, 0, 640, 480, 0, 0, 0, 0);
877 if (!(device = create_device(window, DDSCL_NORMAL)))
879 skip("Failed to create a 3D device, skipping test.\n");
880 DestroyWindow(window);
881 return;
884 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
885 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
886 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
887 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
888 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
889 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
890 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
891 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
892 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
893 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
894 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
895 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
896 color = get_surface_color(rt, 320, 240);
897 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
899 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
900 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
901 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
902 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
903 IDirect3D7_Release(d3d);
904 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
905 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
906 hr = IDirectDrawSurface7_IsLost(rt);
907 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
908 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
909 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
910 IDirectDraw7_Release(ddraw);
912 hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
913 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
914 ok(surface == rt, "Got unexpected surface %p.\n", surface);
915 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
916 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
917 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
918 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
919 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
920 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
921 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
922 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
923 color = get_surface_color(rt, 320, 240);
924 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
926 IDirectDrawSurface7_Release(surface);
927 IDirectDrawSurface7_Release(rt);
928 IDirect3DDevice7_Release(device);
929 DestroyWindow(window);
932 static void test_surface_interface_mismatch(void)
934 IDirectDraw7 *ddraw = NULL;
935 IDirect3D7 *d3d = NULL;
936 IDirectDrawSurface7 *surface = NULL, *ds;
937 IDirectDrawSurface3 *surface3 = NULL;
938 IDirect3DDevice7 *device = NULL;
939 DDSURFACEDESC2 surface_desc;
940 DDPIXELFORMAT z_fmt;
941 ULONG refcount;
942 HRESULT hr;
943 D3DCOLOR color;
944 HWND window;
946 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
947 0, 0, 640, 480, 0, 0, 0, 0);
948 ddraw = create_ddraw();
949 ok(!!ddraw, "Failed to create a ddraw object.\n");
950 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
951 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
953 memset(&surface_desc, 0, sizeof(surface_desc));
954 surface_desc.dwSize = sizeof(surface_desc);
955 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
956 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
957 surface_desc.dwWidth = 640;
958 surface_desc.dwHeight = 480;
960 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
961 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
963 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
964 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
966 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
968 skip("D3D interface is not available, skipping test.\n");
969 goto cleanup;
972 memset(&z_fmt, 0, sizeof(z_fmt));
973 hr = IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
974 if (FAILED(hr) || !z_fmt.dwSize)
976 skip("No depth buffer formats available, skipping test.\n");
977 goto cleanup;
980 memset(&surface_desc, 0, sizeof(surface_desc));
981 surface_desc.dwSize = sizeof(surface_desc);
982 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
983 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
984 U4(surface_desc).ddpfPixelFormat = z_fmt;
985 surface_desc.dwWidth = 640;
986 surface_desc.dwHeight = 480;
987 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
988 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
989 if (FAILED(hr))
990 goto cleanup;
992 /* Using a different surface interface version still works */
993 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
994 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
995 refcount = IDirectDrawSurface7_Release(ds);
996 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
997 if (FAILED(hr))
998 goto cleanup;
1000 /* Here too */
1001 hr = IDirect3D7_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface7 *)surface3, &device);
1002 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1003 if (FAILED(hr))
1004 goto cleanup;
1006 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1007 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1008 color = get_surface_color(surface, 320, 240);
1009 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1011 cleanup:
1012 if (surface3) IDirectDrawSurface3_Release(surface3);
1013 if (surface) IDirectDrawSurface7_Release(surface);
1014 if (device) IDirect3DDevice7_Release(device);
1015 if (d3d) IDirect3D7_Release(d3d);
1016 if (ddraw) IDirectDraw7_Release(ddraw);
1017 DestroyWindow(window);
1020 static void test_coop_level_threaded(void)
1022 struct create_window_thread_param p;
1023 IDirectDraw7 *ddraw;
1024 HRESULT hr;
1026 ddraw = create_ddraw();
1027 ok(!!ddraw, "Failed to create a ddraw object.\n");
1028 create_window_thread(&p);
1030 hr = IDirectDraw7_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1031 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1033 IDirectDraw7_Release(ddraw);
1034 destroy_window_thread(&p);
1037 static void test_depth_blit(void)
1039 IDirect3DDevice7 *device;
1040 static struct
1042 float x, y, z;
1043 DWORD color;
1045 quad1[] =
1047 { -1.0, 1.0, 0.50f, 0xff00ff00},
1048 { 1.0, 1.0, 0.50f, 0xff00ff00},
1049 { -1.0, -1.0, 0.50f, 0xff00ff00},
1050 { 1.0, -1.0, 0.50f, 0xff00ff00},
1052 static const D3DCOLOR expected_colors[4][4] =
1054 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1055 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1056 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1057 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1059 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1061 IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
1062 RECT src_rect, dst_rect;
1063 unsigned int i, j;
1064 D3DCOLOR color;
1065 HRESULT hr;
1066 IDirect3D7 *d3d;
1067 IDirectDraw7 *ddraw;
1068 DDBLTFX fx;
1069 HWND window;
1071 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1072 0, 0, 640, 480, 0, 0, 0, 0);
1073 if (!(device = create_device(window, DDSCL_NORMAL)))
1075 skip("Failed to create a 3D device, skipping test.\n");
1076 DestroyWindow(window);
1077 return;
1080 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1081 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1082 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1083 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1084 IDirect3D7_Release(d3d);
1086 ds1 = get_depth_stencil(device);
1088 memset(&ddsd_new, 0, sizeof(ddsd_new));
1089 ddsd_new.dwSize = sizeof(ddsd_new);
1090 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1091 ddsd_existing.dwSize = sizeof(ddsd_existing);
1092 hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
1093 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
1094 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1095 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1096 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1097 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1098 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1099 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1100 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1101 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1102 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1103 IDirectDraw7_Release(ddraw);
1105 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1106 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1107 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1108 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1109 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1110 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1112 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1113 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1115 /* Partial blit. */
1116 SetRect(&src_rect, 0, 0, 320, 240);
1117 SetRect(&dst_rect, 0, 0, 320, 240);
1118 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1119 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1120 /* Different locations. */
1121 SetRect(&src_rect, 0, 0, 320, 240);
1122 SetRect(&dst_rect, 320, 240, 640, 480);
1123 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1124 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1125 /* Streched. */
1126 SetRect(&src_rect, 0, 0, 320, 240);
1127 SetRect(&dst_rect, 0, 0, 640, 480);
1128 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1129 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1130 /* Flipped. */
1131 SetRect(&src_rect, 0, 480, 640, 0);
1132 SetRect(&dst_rect, 0, 0, 640, 480);
1133 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1134 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1135 SetRect(&src_rect, 0, 0, 640, 480);
1136 SetRect(&dst_rect, 0, 480, 640, 0);
1137 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1138 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1139 /* Full, explicit. */
1140 SetRect(&src_rect, 0, 0, 640, 480);
1141 SetRect(&dst_rect, 0, 0, 640, 480);
1142 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1143 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1144 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1146 /* Depth blit inside a BeginScene / EndScene pair */
1147 hr = IDirect3DDevice7_BeginScene(device);
1148 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1149 /* From the current depth stencil */
1150 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1151 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1152 /* To the current depth stencil */
1153 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1154 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1155 /* Between unbound surfaces */
1156 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1157 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1158 hr = IDirect3DDevice7_EndScene(device);
1159 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1161 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1162 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1163 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1164 * a reliable result(z = 0.0) */
1165 memset(&fx, 0, sizeof(fx));
1166 fx.dwSize = sizeof(fx);
1167 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1168 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1170 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1171 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1172 SetRect(&dst_rect, 0, 0, 320, 240);
1173 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1174 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1175 IDirectDrawSurface7_Release(ds3);
1176 IDirectDrawSurface7_Release(ds2);
1177 IDirectDrawSurface7_Release(ds1);
1179 hr = IDirect3DDevice7_BeginScene(device);
1180 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1181 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1182 quad1, 4, 0);
1183 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1184 hr = IDirect3DDevice7_EndScene(device);
1185 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1187 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1188 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1189 for (i = 0; i < 4; ++i)
1191 for (j = 0; j < 4; ++j)
1193 unsigned int x = 80 * ((2 * j) + 1);
1194 unsigned int y = 60 * ((2 * i) + 1);
1195 color = get_surface_color(rt, x, y);
1196 ok(compare_color(color, expected_colors[i][j], 1),
1197 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1201 IDirectDrawSurface7_Release(rt);
1202 IDirect3DDevice7_Release(device);
1203 DestroyWindow(window);
1206 static void test_texture_load_ckey(void)
1208 HWND window;
1209 IDirect3DDevice7 *device;
1210 IDirectDraw7 *ddraw;
1211 IDirectDrawSurface7 *src;
1212 IDirectDrawSurface7 *dst;
1213 DDSURFACEDESC2 ddsd;
1214 HRESULT hr;
1215 DDCOLORKEY ckey;
1216 IDirect3D7 *d3d;
1218 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1219 0, 0, 640, 480, 0, 0, 0, 0);
1220 if (!(device = create_device(window, DDSCL_NORMAL)))
1222 skip("Failed to create a 3D device, skipping test.\n");
1223 DestroyWindow(window);
1224 return;
1227 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1228 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1229 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1230 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1231 IDirect3D7_Release(d3d);
1233 memset(&ddsd, 0, sizeof(ddsd));
1234 ddsd.dwSize = sizeof(ddsd);
1235 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1236 ddsd.dwHeight = 128;
1237 ddsd.dwWidth = 128;
1238 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1239 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1240 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1241 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1242 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1243 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1245 /* No surface has a color key */
1246 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1247 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1248 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1249 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1250 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1251 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1252 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1254 /* Source surface has a color key */
1255 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1256 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1257 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1258 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1259 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1260 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1261 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1262 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1263 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1265 /* Both surfaces have a color key: Dest ckey is overwritten */
1266 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1267 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1268 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1269 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1270 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1271 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1272 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1273 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1274 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1276 /* Only the destination has a color key: It is deleted. This behavior differs from
1277 * IDirect3DTexture(2)::Load */
1278 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1279 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1280 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1281 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1282 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1283 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1284 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1285 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1287 IDirectDrawSurface7_Release(dst);
1288 IDirectDrawSurface7_Release(src);
1289 IDirectDraw7_Release(ddraw);
1290 IDirect3DDevice7_Release(device);
1291 DestroyWindow(window);
1294 static void test_zenable(void)
1296 static struct
1298 struct vec4 position;
1299 D3DCOLOR diffuse;
1301 tquad[] =
1303 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1304 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1305 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1306 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1308 IDirect3DDevice7 *device;
1309 IDirectDrawSurface7 *rt;
1310 D3DCOLOR color;
1311 HWND window;
1312 HRESULT hr;
1313 UINT x, y;
1314 UINT i, j;
1316 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1317 0, 0, 640, 480, 0, 0, 0, 0);
1318 if (!(device = create_device(window, DDSCL_NORMAL)))
1320 skip("Failed to create a 3D device, skipping test.\n");
1321 DestroyWindow(window);
1322 return;
1325 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1326 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1328 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1329 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1330 hr = IDirect3DDevice7_BeginScene(device);
1331 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1332 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1333 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1334 hr = IDirect3DDevice7_EndScene(device);
1335 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1337 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1338 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1339 for (i = 0; i < 4; ++i)
1341 for (j = 0; j < 4; ++j)
1343 x = 80 * ((2 * j) + 1);
1344 y = 60 * ((2 * i) + 1);
1345 color = get_surface_color(rt, x, y);
1346 ok(compare_color(color, 0x0000ff00, 1),
1347 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1350 IDirectDrawSurface7_Release(rt);
1352 IDirect3DDevice7_Release(device);
1353 DestroyWindow(window);
1356 static void test_ck_rgba(void)
1358 static struct
1360 struct vec4 position;
1361 struct vec2 texcoord;
1363 tquad[] =
1365 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1366 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1367 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1368 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1369 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1370 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1371 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1372 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1374 static const struct
1376 D3DCOLOR fill_color;
1377 BOOL color_key;
1378 BOOL blend;
1379 D3DCOLOR result1, result1_broken;
1380 D3DCOLOR result2, result2_broken;
1382 tests[] =
1384 /* r200 on Windows doesn't check the alpha component when applying the color
1385 * key, so the key matches on every texel. */
1386 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1387 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1388 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1389 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1390 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1391 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1392 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1393 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1396 IDirectDrawSurface7 *texture;
1397 DDSURFACEDESC2 surface_desc;
1398 IDirect3DDevice7 *device;
1399 IDirectDrawSurface7 *rt;
1400 IDirectDraw7 *ddraw;
1401 IDirect3D7 *d3d;
1402 D3DCOLOR color;
1403 HWND window;
1404 DDBLTFX fx;
1405 HRESULT hr;
1406 UINT i;
1408 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1409 0, 0, 640, 480, 0, 0, 0, 0);
1410 if (!(device = create_device(window, DDSCL_NORMAL)))
1412 skip("Failed to create a 3D device, skipping test.\n");
1413 DestroyWindow(window);
1414 return;
1417 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1418 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1419 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1420 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1421 IDirect3D7_Release(d3d);
1423 memset(&surface_desc, 0, sizeof(surface_desc));
1424 surface_desc.dwSize = sizeof(surface_desc);
1425 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1426 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1427 surface_desc.dwWidth = 256;
1428 surface_desc.dwHeight = 256;
1429 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1430 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1431 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1432 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1433 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1434 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1435 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1436 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1437 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1438 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1439 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1441 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1442 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1443 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1444 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1445 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1446 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1448 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1449 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1451 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1453 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1454 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1455 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1456 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1458 memset(&fx, 0, sizeof(fx));
1459 fx.dwSize = sizeof(fx);
1460 U5(fx).dwFillColor = tests[i].fill_color;
1461 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1462 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1464 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1465 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1466 hr = IDirect3DDevice7_BeginScene(device);
1467 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1468 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1469 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1470 hr = IDirect3DDevice7_EndScene(device);
1471 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1473 color = get_surface_color(rt, 320, 240);
1474 if (i == 2)
1475 todo_wine ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1476 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1477 tests[i].result1, i, color);
1478 else
1479 ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1480 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1481 tests[i].result1, i, color);
1483 U5(fx).dwFillColor = 0xff0000ff;
1484 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1485 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1487 hr = IDirect3DDevice7_BeginScene(device);
1488 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1489 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1490 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1491 hr = IDirect3DDevice7_EndScene(device);
1492 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1494 /* This tests that fragments that are masked out by the color key are
1495 * discarded, instead of just fully transparent. */
1496 color = get_surface_color(rt, 320, 240);
1497 if (i == 2)
1498 todo_wine ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1499 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1500 tests[i].result2, i, color);
1501 else
1502 ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1503 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1504 tests[i].result2, i, color);
1507 IDirectDrawSurface7_Release(rt);
1508 IDirectDrawSurface7_Release(texture);
1509 IDirectDraw7_Release(ddraw);
1510 IDirect3DDevice7_Release(device);
1511 DestroyWindow(window);
1514 static void test_ck_default(void)
1516 static struct
1518 struct vec4 position;
1519 struct vec2 texcoord;
1521 tquad[] =
1523 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1524 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1525 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1526 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1528 IDirectDrawSurface7 *surface, *rt;
1529 DDSURFACEDESC2 surface_desc;
1530 IDirect3DDevice7 *device;
1531 IDirectDraw7 *ddraw;
1532 IDirect3D7 *d3d;
1533 D3DCOLOR color;
1534 DWORD value;
1535 HWND window;
1536 DDBLTFX fx;
1537 HRESULT hr;
1539 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1540 0, 0, 640, 480, 0, 0, 0, 0);
1542 if (!(device = create_device(window, DDSCL_NORMAL)))
1544 skip("Failed to create a 3D device, skipping test.\n");
1545 DestroyWindow(window);
1546 return;
1549 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1550 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1551 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1552 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1553 IDirect3D7_Release(d3d);
1555 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1556 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1558 memset(&surface_desc, 0, sizeof(surface_desc));
1559 surface_desc.dwSize = sizeof(surface_desc);
1560 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1561 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1562 surface_desc.dwWidth = 256;
1563 surface_desc.dwHeight = 256;
1564 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1565 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1566 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1567 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1568 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1569 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1570 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1571 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1572 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1573 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1574 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1575 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1577 memset(&fx, 0, sizeof(fx));
1578 fx.dwSize = sizeof(fx);
1579 U5(fx).dwFillColor = 0x000000ff;
1580 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1581 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1583 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1584 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1585 hr = IDirect3DDevice7_BeginScene(device);
1586 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1587 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1588 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1589 ok(!value, "Got unexpected color keying state %#x.\n", value);
1590 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1591 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1592 hr = IDirect3DDevice7_EndScene(device);
1593 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1594 color = get_surface_color(rt, 320, 240);
1595 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1597 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1598 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1599 hr = IDirect3DDevice7_BeginScene(device);
1600 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1601 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1602 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1603 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1604 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1605 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1606 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1607 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1608 hr = IDirect3DDevice7_EndScene(device);
1609 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1610 color = get_surface_color(rt, 320, 240);
1611 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1613 IDirectDrawSurface7_Release(surface);
1614 IDirectDrawSurface7_Release(rt);
1615 IDirect3DDevice7_Release(device);
1616 IDirectDraw7_Release(ddraw);
1617 DestroyWindow(window);
1620 static void test_ck_complex(void)
1622 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1623 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
1624 DDSURFACEDESC2 surface_desc;
1625 IDirect3DDevice7 *device;
1626 DDCOLORKEY color_key;
1627 IDirectDraw7 *ddraw;
1628 IDirect3D7 *d3d;
1629 unsigned int i;
1630 ULONG refcount;
1631 HWND window;
1632 HRESULT hr;
1634 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1635 0, 0, 640, 480, 0, 0, 0, 0);
1636 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1638 skip("Failed to create a 3D device, skipping test.\n");
1639 DestroyWindow(window);
1640 return;
1642 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1643 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1644 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1645 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1646 IDirect3D7_Release(d3d);
1648 memset(&surface_desc, 0, sizeof(surface_desc));
1649 surface_desc.dwSize = sizeof(surface_desc);
1650 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1651 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1652 surface_desc.dwWidth = 128;
1653 surface_desc.dwHeight = 128;
1654 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1655 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1657 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1658 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1659 color_key.dwColorSpaceLowValue = 0x0000ff00;
1660 color_key.dwColorSpaceHighValue = 0x0000ff00;
1661 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1662 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1663 memset(&color_key, 0, sizeof(color_key));
1664 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1665 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1666 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1667 color_key.dwColorSpaceLowValue);
1668 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1669 color_key.dwColorSpaceHighValue);
1671 mipmap = surface;
1672 IDirectDrawSurface_AddRef(mipmap);
1673 for (i = 0; i < 7; ++i)
1675 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1676 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1677 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1678 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1680 color_key.dwColorSpaceLowValue = 0x000000ff;
1681 color_key.dwColorSpaceHighValue = 0x000000ff;
1682 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1683 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1685 IDirectDrawSurface_Release(mipmap);
1686 mipmap = tmp;
1689 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1690 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1691 IDirectDrawSurface_Release(mipmap);
1692 refcount = IDirectDrawSurface7_Release(surface);
1693 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1695 memset(&surface_desc, 0, sizeof(surface_desc));
1696 surface_desc.dwSize = sizeof(surface_desc);
1697 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1698 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1699 U5(surface_desc).dwBackBufferCount = 1;
1700 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1701 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1703 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1704 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1705 color_key.dwColorSpaceLowValue = 0x0000ff00;
1706 color_key.dwColorSpaceHighValue = 0x0000ff00;
1707 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1708 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1709 memset(&color_key, 0, sizeof(color_key));
1710 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1711 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1712 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1713 color_key.dwColorSpaceLowValue);
1714 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1715 color_key.dwColorSpaceHighValue);
1717 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1718 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1720 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1721 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1722 color_key.dwColorSpaceLowValue = 0x0000ff00;
1723 color_key.dwColorSpaceHighValue = 0x0000ff00;
1724 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1725 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1726 memset(&color_key, 0, sizeof(color_key));
1727 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1728 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1729 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1730 color_key.dwColorSpaceLowValue);
1731 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1732 color_key.dwColorSpaceHighValue);
1734 IDirectDrawSurface_Release(tmp);
1736 refcount = IDirectDrawSurface7_Release(surface);
1737 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1738 IDirectDraw7_Release(ddraw);
1739 refcount = IDirect3DDevice7_Release(device);
1740 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1741 DestroyWindow(window);
1744 struct qi_test
1746 REFIID iid;
1747 REFIID refcount_iid;
1748 HRESULT hr;
1751 static void test_qi(const char *test_name, IUnknown *base_iface,
1752 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1754 ULONG refcount, expected_refcount;
1755 IUnknown *iface1, *iface2;
1756 HRESULT hr;
1757 UINT i, j;
1759 for (i = 0; i < entry_count; ++i)
1761 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1762 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1763 if (SUCCEEDED(hr))
1765 for (j = 0; j < entry_count; ++j)
1767 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1768 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1769 if (SUCCEEDED(hr))
1771 expected_refcount = 0;
1772 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1773 ++expected_refcount;
1774 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1775 ++expected_refcount;
1776 refcount = IUnknown_Release(iface2);
1777 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1778 refcount, test_name, i, j, expected_refcount);
1782 expected_refcount = 0;
1783 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1784 ++expected_refcount;
1785 refcount = IUnknown_Release(iface1);
1786 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1787 refcount, test_name, i, expected_refcount);
1792 static void test_surface_qi(void)
1794 static const struct qi_test tests[] =
1796 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1797 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1798 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1799 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1800 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1801 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1802 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1803 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1804 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1805 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1806 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1807 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1808 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1809 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1810 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1811 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1812 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1813 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1814 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1815 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1816 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1817 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1818 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1819 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1820 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1821 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1822 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1823 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1824 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1825 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1826 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1827 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1828 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1829 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1830 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1831 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1832 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1833 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1834 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1835 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1836 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1837 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1840 IDirectDrawSurface7 *surface;
1841 DDSURFACEDESC2 surface_desc;
1842 IDirect3DDevice7 *device;
1843 IDirectDraw7 *ddraw;
1844 HWND window;
1845 HRESULT hr;
1847 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1848 0, 0, 640, 480, 0, 0, 0, 0);
1849 /* Try to create a D3D device to see if the ddraw implementation supports
1850 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1851 * doesn't support e.g. the IDirect3DTexture interfaces. */
1852 if (!(device = create_device(window, DDSCL_NORMAL)))
1854 skip("Failed to create a 3D device, skipping test.\n");
1855 DestroyWindow(window);
1856 return;
1858 IDirect3DDevice_Release(device);
1859 ddraw = create_ddraw();
1860 ok(!!ddraw, "Failed to create a ddraw object.\n");
1861 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1862 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1864 memset(&surface_desc, 0, sizeof(surface_desc));
1865 surface_desc.dwSize = sizeof(surface_desc);
1866 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1867 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1868 surface_desc.dwWidth = 512;
1869 surface_desc.dwHeight = 512;
1870 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1871 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1873 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, sizeof(tests) / sizeof(*tests));
1875 IDirectDrawSurface7_Release(surface);
1876 IDirectDraw7_Release(ddraw);
1877 DestroyWindow(window);
1880 static void test_device_qi(void)
1882 static const struct qi_test tests[] =
1884 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1885 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1886 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
1887 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1888 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
1889 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
1890 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
1891 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
1892 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
1893 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
1894 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1895 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1896 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1897 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1898 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1899 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1900 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1901 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1902 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1903 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1904 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1905 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1906 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1907 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1908 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1909 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1910 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1911 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1912 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1913 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1914 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1915 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1916 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1917 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1918 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1919 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1920 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1921 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1922 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1923 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1924 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1925 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
1928 IDirect3DDevice7 *device;
1929 HWND window;
1931 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1932 0, 0, 640, 480, 0, 0, 0, 0);
1933 if (!(device = create_device(window, DDSCL_NORMAL)))
1935 skip("Failed to create a 3D device, skipping test.\n");
1936 DestroyWindow(window);
1937 return;
1940 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, sizeof(tests) / sizeof(*tests));
1942 IDirect3DDevice7_Release(device);
1943 DestroyWindow(window);
1946 static void test_wndproc(void)
1948 LONG_PTR proc, ddraw_proc;
1949 IDirectDraw7 *ddraw;
1950 WNDCLASSA wc = {0};
1951 HWND window;
1952 HRESULT hr;
1953 ULONG ref;
1955 static struct message messages[] =
1957 {WM_WINDOWPOSCHANGING, FALSE, 0},
1958 {WM_MOVE, FALSE, 0},
1959 {WM_SIZE, FALSE, 0},
1960 {WM_WINDOWPOSCHANGING, FALSE, 0},
1961 {WM_ACTIVATE, FALSE, 0},
1962 {WM_SETFOCUS, FALSE, 0},
1963 {0, FALSE, 0},
1966 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1967 ddraw = create_ddraw();
1968 ok(!!ddraw, "Failed to create a ddraw object.\n");
1970 wc.lpfnWndProc = test_proc;
1971 wc.lpszClassName = "ddraw_test_wndproc_wc";
1972 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1974 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1975 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1977 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1978 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1979 (LONG_PTR)test_proc, proc);
1980 expect_messages = messages;
1981 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1982 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1983 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
1984 expect_messages = NULL;
1985 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1986 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1987 (LONG_PTR)test_proc, proc);
1988 ref = IDirectDraw7_Release(ddraw);
1989 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1990 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1991 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1992 (LONG_PTR)test_proc, proc);
1994 /* DDSCL_NORMAL doesn't. */
1995 ddraw = create_ddraw();
1996 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1997 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1998 (LONG_PTR)test_proc, proc);
1999 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2000 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2001 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2002 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2003 (LONG_PTR)test_proc, proc);
2004 ref = IDirectDraw7_Release(ddraw);
2005 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2006 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2007 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2008 (LONG_PTR)test_proc, proc);
2010 /* The original window proc is only restored by ddraw if the current
2011 * window proc matches the one ddraw set. This also affects switching
2012 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2013 ddraw = create_ddraw();
2014 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2015 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2016 (LONG_PTR)test_proc, proc);
2017 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2018 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2019 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2020 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2021 (LONG_PTR)test_proc, proc);
2022 ddraw_proc = proc;
2023 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2024 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2025 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2026 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2027 (LONG_PTR)test_proc, proc);
2028 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2029 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2030 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2031 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2032 (LONG_PTR)test_proc, proc);
2033 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2034 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2035 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2036 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2037 (LONG_PTR)DefWindowProcA, proc);
2038 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2039 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2040 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2041 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2042 (LONG_PTR)DefWindowProcA, proc);
2043 ref = IDirectDraw7_Release(ddraw);
2044 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2045 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2046 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2047 (LONG_PTR)test_proc, proc);
2049 ddraw = create_ddraw();
2050 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2051 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2052 (LONG_PTR)test_proc, proc);
2053 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2054 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2055 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2056 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2057 (LONG_PTR)test_proc, proc);
2058 ref = IDirectDraw7_Release(ddraw);
2059 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2060 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2061 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2062 (LONG_PTR)DefWindowProcA, proc);
2064 fix_wndproc(window, (LONG_PTR)test_proc);
2065 expect_messages = NULL;
2066 DestroyWindow(window);
2067 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2070 static void test_window_style(void)
2072 LONG style, exstyle, tmp, expected_style;
2073 RECT fullscreen_rect, r;
2074 IDirectDraw7 *ddraw;
2075 HWND window;
2076 HRESULT hr;
2077 ULONG ref;
2078 BOOL ret;
2080 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2081 0, 0, 100, 100, 0, 0, 0, 0);
2082 ddraw = create_ddraw();
2083 ok(!!ddraw, "Failed to create a ddraw object.\n");
2085 style = GetWindowLongA(window, GWL_STYLE);
2086 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2087 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2089 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2090 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2092 tmp = GetWindowLongA(window, GWL_STYLE);
2093 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2094 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2095 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2097 GetWindowRect(window, &r);
2098 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2099 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2100 r.left, r.top, r.right, r.bottom);
2101 GetClientRect(window, &r);
2102 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2104 ret = SetForegroundWindow(GetDesktopWindow());
2105 ok(ret, "Failed to set foreground window.\n");
2107 tmp = GetWindowLongA(window, GWL_STYLE);
2108 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2109 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2110 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2112 ret = SetForegroundWindow(window);
2113 ok(ret, "Failed to set foreground window.\n");
2114 /* Windows 7 (but not Vista and XP) show the window when it receives focus. Hide it again,
2115 * the next tests expect this. */
2116 ShowWindow(window, SW_HIDE);
2118 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2119 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2121 tmp = GetWindowLongA(window, GWL_STYLE);
2122 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2123 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2124 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2126 ShowWindow(window, SW_SHOW);
2127 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2128 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2130 tmp = GetWindowLongA(window, GWL_STYLE);
2131 expected_style = style | WS_VISIBLE;
2132 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2133 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2134 expected_style = exstyle | WS_EX_TOPMOST;
2135 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2137 ret = SetForegroundWindow(GetDesktopWindow());
2138 ok(ret, "Failed to set foreground window.\n");
2139 tmp = GetWindowLongA(window, GWL_STYLE);
2140 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2141 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2142 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2143 expected_style = exstyle | WS_EX_TOPMOST;
2144 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2146 ref = IDirectDraw7_Release(ddraw);
2147 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2149 DestroyWindow(window);
2152 static void test_redundant_mode_set(void)
2154 DDSURFACEDESC2 surface_desc = {0};
2155 IDirectDraw7 *ddraw;
2156 HWND window;
2157 HRESULT hr;
2158 RECT r, s;
2159 ULONG ref;
2161 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2162 0, 0, 100, 100, 0, 0, 0, 0);
2163 ddraw = create_ddraw();
2164 ok(!!ddraw, "Failed to create a ddraw object.\n");
2165 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2166 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2168 surface_desc.dwSize = sizeof(surface_desc);
2169 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2170 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2172 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2173 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2174 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2176 GetWindowRect(window, &r);
2177 r.right /= 2;
2178 r.bottom /= 2;
2179 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2180 GetWindowRect(window, &s);
2181 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2182 r.left, r.top, r.right, r.bottom,
2183 s.left, s.top, s.right, s.bottom);
2185 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2186 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2187 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2189 GetWindowRect(window, &s);
2190 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2191 r.left, r.top, r.right, r.bottom,
2192 s.left, s.top, s.right, s.bottom);
2194 ref = IDirectDraw7_Release(ddraw);
2195 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2197 DestroyWindow(window);
2200 static SIZE screen_size, screen_size2;
2202 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2204 if (message == WM_SIZE)
2206 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2207 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2210 return test_proc(hwnd, message, wparam, lparam);
2213 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2215 if (message == WM_SIZE)
2217 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2218 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2221 return test_proc(hwnd, message, wparam, lparam);
2224 struct test_coop_level_mode_set_enum_param
2226 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2229 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2231 struct test_coop_level_mode_set_enum_param *param = context;
2233 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2234 return DDENUMRET_OK;
2235 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2236 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2237 return DDENUMRET_OK;
2239 if (!param->ddraw_width)
2241 param->ddraw_width = surface_desc->dwWidth;
2242 param->ddraw_height = surface_desc->dwHeight;
2243 return DDENUMRET_OK;
2245 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2246 return DDENUMRET_OK;
2248 param->user32_width = surface_desc->dwWidth;
2249 param->user32_height = surface_desc->dwHeight;
2250 return DDENUMRET_CANCEL;
2253 static void test_coop_level_mode_set(void)
2255 IDirectDrawSurface7 *primary;
2256 RECT registry_rect, ddraw_rect, user32_rect, r;
2257 IDirectDraw7 *ddraw;
2258 DDSURFACEDESC2 ddsd;
2259 WNDCLASSA wc = {0};
2260 HWND window, window2;
2261 HRESULT hr;
2262 ULONG ref;
2263 MSG msg;
2264 struct test_coop_level_mode_set_enum_param param;
2265 DEVMODEW devmode;
2266 BOOL ret;
2267 LONG change_ret;
2269 static const struct message exclusive_messages[] =
2271 {WM_WINDOWPOSCHANGING, FALSE, 0},
2272 {WM_WINDOWPOSCHANGED, FALSE, 0},
2273 {WM_SIZE, FALSE, 0},
2274 {WM_DISPLAYCHANGE, FALSE, 0},
2275 {0, FALSE, 0},
2277 static const struct message exclusive_focus_loss_messages[] =
2279 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2280 {WM_DISPLAYCHANGE, FALSE, 0},
2281 {WM_WINDOWPOSCHANGING, FALSE, 0},
2282 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2283 * SW_MINIMIZED, causing a recursive window activation that does not
2284 * produe the same result in Wine yet. Ignore the difference for now.
2285 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2286 {WM_WINDOWPOSCHANGED, FALSE, 0},
2287 {WM_MOVE, FALSE, 0},
2288 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2289 {WM_ACTIVATEAPP, TRUE, FALSE},
2290 {0, FALSE, 0},
2292 static const struct message exclusive_focus_restore_messages[] =
2294 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2295 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2296 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2297 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2298 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2299 /* Native redundantly sets the window size here. */
2300 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2301 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2302 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2303 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2304 {0, FALSE, 0},
2306 static const struct message sc_restore_messages[] =
2308 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2309 {WM_WINDOWPOSCHANGING, FALSE, 0},
2310 {WM_WINDOWPOSCHANGED, FALSE, 0},
2311 {WM_SIZE, TRUE, SIZE_RESTORED},
2312 {0, FALSE, 0},
2314 static const struct message sc_minimize_messages[] =
2316 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2317 {WM_WINDOWPOSCHANGING, FALSE, 0},
2318 {WM_WINDOWPOSCHANGED, FALSE, 0},
2319 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2320 {0, FALSE, 0},
2322 static const struct message sc_maximize_messages[] =
2324 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2325 {WM_WINDOWPOSCHANGING, FALSE, 0},
2326 {WM_WINDOWPOSCHANGED, FALSE, 0},
2327 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2328 {0, FALSE, 0},
2331 static const struct message normal_messages[] =
2333 {WM_DISPLAYCHANGE, FALSE, 0},
2334 {0, FALSE, 0},
2337 ddraw = create_ddraw();
2338 ok(!!ddraw, "Failed to create a ddraw object.\n");
2340 memset(&param, 0, sizeof(param));
2341 hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2342 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2343 ref = IDirectDraw7_Release(ddraw);
2344 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2346 if (!param.user32_height)
2348 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2349 return;
2352 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2353 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2354 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2356 memset(&devmode, 0, sizeof(devmode));
2357 devmode.dmSize = sizeof(devmode);
2358 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2359 devmode.dmPelsWidth = param.user32_width;
2360 devmode.dmPelsHeight = param.user32_height;
2361 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2362 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2364 ddraw = create_ddraw();
2365 ok(!!ddraw, "Failed to create a ddraw object.\n");
2367 wc.lpfnWndProc = mode_set_proc;
2368 wc.lpszClassName = "ddraw_test_wndproc_wc";
2369 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2370 wc.lpfnWndProc = mode_set_proc2;
2371 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2372 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2374 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2375 0, 0, 100, 100, 0, 0, 0, 0);
2376 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2377 0, 0, 100, 100, 0, 0, 0, 0);
2379 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2380 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2382 GetWindowRect(window, &r);
2383 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2384 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2385 r.left, r.top, r.right, r.bottom);
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 == param.user32_width, "Expected surface width %u, got %u.\n",
2397 param.user32_width, ddsd.dwWidth);
2398 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2399 param.user32_height, ddsd.dwHeight);
2401 GetWindowRect(window, &r);
2402 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2403 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2404 r.left, r.top, r.right, r.bottom);
2406 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2407 expect_messages = exclusive_messages;
2408 screen_size.cx = 0;
2409 screen_size.cy = 0;
2411 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2412 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2414 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2415 expect_messages = NULL;
2416 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2417 "Expected screen size %ux%u, got %ux%u.\n",
2418 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2420 GetWindowRect(window, &r);
2421 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2422 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2423 r.left, r.top, r.right, r.bottom);
2425 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2426 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2427 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2428 param.user32_width, ddsd.dwWidth);
2429 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2430 param.user32_height, ddsd.dwHeight);
2431 IDirectDrawSurface7_Release(primary);
2433 memset(&ddsd, 0, sizeof(ddsd));
2434 ddsd.dwSize = sizeof(ddsd);
2435 ddsd.dwFlags = DDSD_CAPS;
2436 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2438 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2439 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2440 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2441 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2442 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2443 param.ddraw_width, ddsd.dwWidth);
2444 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2445 param.ddraw_height, ddsd.dwHeight);
2447 GetWindowRect(window, &r);
2448 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2449 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2450 r.left, r.top, r.right, r.bottom);
2452 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2453 expect_messages = exclusive_messages;
2454 screen_size.cx = 0;
2455 screen_size.cy = 0;
2457 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2458 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2460 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2461 expect_messages = NULL;
2462 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2463 "Expected screen size %ux%u, got %ux%u.\n",
2464 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2466 GetWindowRect(window, &r);
2467 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2468 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2469 r.left, r.top, r.right, r.bottom);
2471 expect_messages = exclusive_focus_loss_messages;
2472 ret = SetForegroundWindow(GetDesktopWindow());
2473 ok(ret, "Failed to set foreground window.\n");
2474 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2475 memset(&devmode, 0, sizeof(devmode));
2476 devmode.dmSize = sizeof(devmode);
2477 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2478 ok(ret, "Failed to get display mode.\n");
2479 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2480 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2481 devmode.dmPelsWidth, devmode.dmPelsHeight);
2483 expect_messages = exclusive_focus_restore_messages;
2484 ShowWindow(window, SW_RESTORE);
2485 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2487 GetWindowRect(window, &r);
2488 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2489 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2490 r.left, r.top, r.right, r.bottom);
2491 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2492 ok(ret, "Failed to get display mode.\n");
2493 ok(devmode.dmPelsWidth == param.ddraw_width
2494 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2495 devmode.dmPelsWidth, devmode.dmPelsHeight);
2497 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2498 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2499 /* Normally the primary should be restored here. Unfortunately this causes the
2500 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2501 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2502 * the point of the GetSurfaceDesc call. */
2504 expect_messages = sc_minimize_messages;
2505 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2506 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2507 expect_messages = NULL;
2509 expect_messages = sc_restore_messages;
2510 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2511 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2512 expect_messages = NULL;
2514 expect_messages = sc_maximize_messages;
2515 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2516 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2517 expect_messages = NULL;
2519 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2520 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2522 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2523 expect_messages = exclusive_messages;
2524 screen_size.cx = 0;
2525 screen_size.cy = 0;
2527 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2528 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2530 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2531 expect_messages = NULL;
2532 ok(screen_size.cx == registry_mode.dmPelsWidth
2533 && screen_size.cy == registry_mode.dmPelsHeight,
2534 "Expected screen size %ux%u, got %ux%u.\n",
2535 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2537 GetWindowRect(window, &r);
2538 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2539 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2540 r.left, r.top, r.right, r.bottom);
2542 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2543 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2544 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2545 param.ddraw_width, ddsd.dwWidth);
2546 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2547 param.ddraw_height, ddsd.dwHeight);
2548 IDirectDrawSurface7_Release(primary);
2550 /* For Wine. */
2551 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2552 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
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 == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2564 registry_mode.dmPelsWidth, ddsd.dwWidth);
2565 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2566 registry_mode.dmPelsHeight, ddsd.dwHeight);
2568 GetWindowRect(window, &r);
2569 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2570 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2571 r.left, r.top, r.right, r.bottom);
2573 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2574 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2576 GetWindowRect(window, &r);
2577 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2578 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2579 r.left, r.top, r.right, r.bottom);
2581 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2582 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2583 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2584 registry_mode.dmPelsWidth, ddsd.dwWidth);
2585 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2586 registry_mode.dmPelsHeight, ddsd.dwHeight);
2587 IDirectDrawSurface7_Release(primary);
2589 memset(&ddsd, 0, sizeof(ddsd));
2590 ddsd.dwSize = sizeof(ddsd);
2591 ddsd.dwFlags = DDSD_CAPS;
2592 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2594 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2595 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2596 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2597 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2598 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2599 registry_mode.dmPelsWidth, ddsd.dwWidth);
2600 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2601 registry_mode.dmPelsHeight, ddsd.dwHeight);
2603 GetWindowRect(window, &r);
2604 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2605 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2606 r.left, r.top, r.right, r.bottom);
2608 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2609 expect_messages = normal_messages;
2610 screen_size.cx = 0;
2611 screen_size.cy = 0;
2613 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2614 devmode.dmPelsWidth = param.user32_width;
2615 devmode.dmPelsHeight = param.user32_height;
2616 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2617 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2619 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2620 expect_messages = NULL;
2621 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2623 GetWindowRect(window, &r);
2624 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2625 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2626 r.left, r.top, r.right, r.bottom);
2628 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2629 expect_messages = normal_messages;
2630 screen_size.cx = 0;
2631 screen_size.cy = 0;
2633 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2634 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2636 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2637 expect_messages = NULL;
2638 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2640 GetWindowRect(window, &r);
2641 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2642 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2643 r.left, r.top, r.right, r.bottom);
2645 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2646 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2647 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2648 registry_mode.dmPelsWidth, ddsd.dwWidth);
2649 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2650 registry_mode.dmPelsHeight, ddsd.dwHeight);
2651 IDirectDrawSurface7_Release(primary);
2653 memset(&ddsd, 0, sizeof(ddsd));
2654 ddsd.dwSize = sizeof(ddsd);
2655 ddsd.dwFlags = DDSD_CAPS;
2656 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2658 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2659 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2660 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2661 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2662 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2663 param.ddraw_width, ddsd.dwWidth);
2664 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2665 param.ddraw_height, ddsd.dwHeight);
2667 GetWindowRect(window, &r);
2668 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2669 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2670 r.left, r.top, r.right, r.bottom);
2672 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2673 expect_messages = normal_messages;
2674 screen_size.cx = 0;
2675 screen_size.cy = 0;
2677 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2678 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2680 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2681 expect_messages = NULL;
2682 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2684 GetWindowRect(window, &r);
2685 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2686 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2687 r.left, r.top, r.right, r.bottom);
2689 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2690 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2691 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2692 param.ddraw_width, ddsd.dwWidth);
2693 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2694 param.ddraw_height, ddsd.dwHeight);
2695 IDirectDrawSurface7_Release(primary);
2697 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2698 ok(ret, "Failed to get display mode.\n");
2699 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2700 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2701 "Expected resolution %ux%u, got %ux%u.\n",
2702 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2703 devmode.dmPelsWidth, devmode.dmPelsHeight);
2704 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2705 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2707 memset(&ddsd, 0, sizeof(ddsd));
2708 ddsd.dwSize = sizeof(ddsd);
2709 ddsd.dwFlags = DDSD_CAPS;
2710 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2712 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2713 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2714 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2715 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2716 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2717 registry_mode.dmPelsWidth, ddsd.dwWidth);
2718 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2719 registry_mode.dmPelsHeight, ddsd.dwHeight);
2721 GetWindowRect(window, &r);
2722 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2723 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2724 r.left, r.top, r.right, r.bottom);
2726 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2727 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2728 * not DDSCL_FULLSCREEN. */
2729 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2730 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2732 GetWindowRect(window, &r);
2733 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2734 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2735 r.left, r.top, r.right, r.bottom);
2737 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2738 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2739 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2740 registry_mode.dmPelsWidth, ddsd.dwWidth);
2741 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2742 registry_mode.dmPelsHeight, ddsd.dwHeight);
2743 IDirectDrawSurface7_Release(primary);
2745 memset(&ddsd, 0, sizeof(ddsd));
2746 ddsd.dwSize = sizeof(ddsd);
2747 ddsd.dwFlags = DDSD_CAPS;
2748 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2750 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2751 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2752 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2753 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2754 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2755 registry_mode.dmPelsWidth, ddsd.dwWidth);
2756 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2757 registry_mode.dmPelsHeight, ddsd.dwHeight);
2759 GetWindowRect(window, &r);
2760 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2761 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2762 r.left, r.top, r.right, r.bottom);
2764 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2765 expect_messages = normal_messages;
2766 screen_size.cx = 0;
2767 screen_size.cy = 0;
2769 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2770 devmode.dmPelsWidth = param.user32_width;
2771 devmode.dmPelsHeight = param.user32_height;
2772 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2773 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2775 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2776 expect_messages = NULL;
2777 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2779 GetWindowRect(window, &r);
2780 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2781 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2782 r.left, r.top, r.right, r.bottom);
2784 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2785 expect_messages = normal_messages;
2786 screen_size.cx = 0;
2787 screen_size.cy = 0;
2789 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2790 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2792 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2793 expect_messages = NULL;
2794 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2796 GetWindowRect(window, &r);
2797 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2798 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2799 r.left, r.top, r.right, r.bottom);
2801 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2802 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2803 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2804 registry_mode.dmPelsWidth, ddsd.dwWidth);
2805 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2806 registry_mode.dmPelsHeight, ddsd.dwHeight);
2807 IDirectDrawSurface7_Release(primary);
2809 memset(&ddsd, 0, sizeof(ddsd));
2810 ddsd.dwSize = sizeof(ddsd);
2811 ddsd.dwFlags = DDSD_CAPS;
2812 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2814 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2815 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2816 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2817 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2818 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2819 param.ddraw_width, ddsd.dwWidth);
2820 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2821 param.ddraw_height, ddsd.dwHeight);
2823 GetWindowRect(window, &r);
2824 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2825 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2826 r.left, r.top, r.right, r.bottom);
2828 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2829 expect_messages = normal_messages;
2830 screen_size.cx = 0;
2831 screen_size.cy = 0;
2833 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2834 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2836 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2837 expect_messages = NULL;
2838 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2840 GetWindowRect(window, &r);
2841 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2842 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2843 r.left, r.top, r.right, r.bottom);
2845 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2846 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2847 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2848 param.ddraw_width, ddsd.dwWidth);
2849 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2850 param.ddraw_height, ddsd.dwHeight);
2851 IDirectDrawSurface7_Release(primary);
2853 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2854 ok(ret, "Failed to get display mode.\n");
2855 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2856 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2857 "Expected resolution %ux%u, got %ux%u.\n",
2858 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2859 devmode.dmPelsWidth, devmode.dmPelsHeight);
2860 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2861 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2863 memset(&ddsd, 0, sizeof(ddsd));
2864 ddsd.dwSize = sizeof(ddsd);
2865 ddsd.dwFlags = DDSD_CAPS;
2866 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2868 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2869 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2870 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2871 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2872 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2873 registry_mode.dmPelsWidth, ddsd.dwWidth);
2874 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2875 registry_mode.dmPelsHeight, ddsd.dwHeight);
2876 IDirectDrawSurface7_Release(primary);
2878 GetWindowRect(window, &r);
2879 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2880 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2881 r.left, r.top, r.right, r.bottom);
2883 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2884 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2885 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2886 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2887 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2889 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2890 expect_messages = exclusive_messages;
2891 screen_size.cx = 0;
2892 screen_size.cy = 0;
2894 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2895 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2897 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2898 expect_messages = NULL;
2899 ok(screen_size.cx == registry_mode.dmPelsWidth
2900 && screen_size.cy == registry_mode.dmPelsHeight,
2901 "Expected screen size %ux%u, got %ux%u.\n",
2902 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2903 screen_size.cx, screen_size.cy);
2905 GetWindowRect(window, &r);
2906 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2907 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2908 r.left, r.top, r.right, r.bottom);
2910 memset(&ddsd, 0, sizeof(ddsd));
2911 ddsd.dwSize = sizeof(ddsd);
2912 ddsd.dwFlags = DDSD_CAPS;
2913 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2915 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2916 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2917 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2918 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2919 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2920 registry_mode.dmPelsWidth, ddsd.dwWidth);
2921 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2922 registry_mode.dmPelsHeight, ddsd.dwHeight);
2923 IDirectDrawSurface7_Release(primary);
2925 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2926 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2927 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2928 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2929 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2931 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2932 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2934 memset(&ddsd, 0, sizeof(ddsd));
2935 ddsd.dwSize = sizeof(ddsd);
2936 ddsd.dwFlags = DDSD_CAPS;
2937 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2939 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2940 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2941 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2942 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2943 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2944 param.ddraw_width, ddsd.dwWidth);
2945 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2946 param.ddraw_height, ddsd.dwHeight);
2947 IDirectDrawSurface7_Release(primary);
2949 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2950 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2952 /* If the window is changed at the same time, messages are sent to the new window. */
2953 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2954 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2955 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2956 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2958 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2959 expect_messages = exclusive_messages;
2960 screen_size.cx = 0;
2961 screen_size.cy = 0;
2962 screen_size2.cx = 0;
2963 screen_size2.cy = 0;
2965 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
2966 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2968 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2969 expect_messages = NULL;
2970 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
2971 screen_size.cx, screen_size.cy);
2972 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
2973 "Expected screen size 2 %ux%u, got %ux%u.\n",
2974 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
2976 GetWindowRect(window, &r);
2977 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2978 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2979 r.left, r.top, r.right, r.bottom);
2980 GetWindowRect(window2, &r);
2981 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2982 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2983 r.left, r.top, r.right, r.bottom);
2985 memset(&ddsd, 0, sizeof(ddsd));
2986 ddsd.dwSize = sizeof(ddsd);
2987 ddsd.dwFlags = DDSD_CAPS;
2988 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2990 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2991 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2992 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2993 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2994 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2995 registry_mode.dmPelsWidth, ddsd.dwWidth);
2996 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2997 registry_mode.dmPelsHeight, ddsd.dwHeight);
2998 IDirectDrawSurface7_Release(primary);
3000 ref = IDirectDraw7_Release(ddraw);
3001 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3003 GetWindowRect(window, &r);
3004 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3005 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
3006 r.left, r.top, r.right, r.bottom);
3008 expect_messages = NULL;
3009 DestroyWindow(window);
3010 DestroyWindow(window2);
3011 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3012 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3015 static void test_coop_level_mode_set_multi(void)
3017 IDirectDraw7 *ddraw1, *ddraw2;
3018 UINT w, h;
3019 HWND window;
3020 HRESULT hr;
3021 ULONG ref;
3023 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3024 0, 0, 100, 100, 0, 0, 0, 0);
3025 ddraw1 = create_ddraw();
3026 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3028 /* With just a single ddraw object, the display mode is restored on
3029 * release. */
3030 hr = set_display_mode(ddraw1, 800, 600);
3031 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3032 w = GetSystemMetrics(SM_CXSCREEN);
3033 ok(w == 800, "Got unexpected screen width %u.\n", w);
3034 h = GetSystemMetrics(SM_CYSCREEN);
3035 ok(h == 600, "Got unexpected screen height %u.\n", h);
3037 ref = IDirectDraw7_Release(ddraw1);
3038 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3039 w = GetSystemMetrics(SM_CXSCREEN);
3040 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3041 h = GetSystemMetrics(SM_CYSCREEN);
3042 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3044 /* When there are multiple ddraw objects, the display mode is restored to
3045 * the initial mode, before the first SetDisplayMode() call. */
3046 ddraw1 = create_ddraw();
3047 hr = set_display_mode(ddraw1, 800, 600);
3048 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3049 w = GetSystemMetrics(SM_CXSCREEN);
3050 ok(w == 800, "Got unexpected screen width %u.\n", w);
3051 h = GetSystemMetrics(SM_CYSCREEN);
3052 ok(h == 600, "Got unexpected screen height %u.\n", h);
3054 ddraw2 = create_ddraw();
3055 hr = set_display_mode(ddraw2, 640, 480);
3056 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3057 w = GetSystemMetrics(SM_CXSCREEN);
3058 ok(w == 640, "Got unexpected screen width %u.\n", w);
3059 h = GetSystemMetrics(SM_CYSCREEN);
3060 ok(h == 480, "Got unexpected screen height %u.\n", h);
3062 ref = IDirectDraw7_Release(ddraw2);
3063 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3064 w = GetSystemMetrics(SM_CXSCREEN);
3065 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3066 h = GetSystemMetrics(SM_CYSCREEN);
3067 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3069 ref = IDirectDraw7_Release(ddraw1);
3070 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3071 w = GetSystemMetrics(SM_CXSCREEN);
3072 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3073 h = GetSystemMetrics(SM_CYSCREEN);
3074 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3076 /* Regardless of release ordering. */
3077 ddraw1 = create_ddraw();
3078 hr = set_display_mode(ddraw1, 800, 600);
3079 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3080 w = GetSystemMetrics(SM_CXSCREEN);
3081 ok(w == 800, "Got unexpected screen width %u.\n", w);
3082 h = GetSystemMetrics(SM_CYSCREEN);
3083 ok(h == 600, "Got unexpected screen height %u.\n", h);
3085 ddraw2 = create_ddraw();
3086 hr = set_display_mode(ddraw2, 640, 480);
3087 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3088 w = GetSystemMetrics(SM_CXSCREEN);
3089 ok(w == 640, "Got unexpected screen width %u.\n", w);
3090 h = GetSystemMetrics(SM_CYSCREEN);
3091 ok(h == 480, "Got unexpected screen height %u.\n", h);
3093 ref = IDirectDraw7_Release(ddraw1);
3094 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3095 w = GetSystemMetrics(SM_CXSCREEN);
3096 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3097 h = GetSystemMetrics(SM_CYSCREEN);
3098 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3100 ref = IDirectDraw7_Release(ddraw2);
3101 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3102 w = GetSystemMetrics(SM_CXSCREEN);
3103 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3104 h = GetSystemMetrics(SM_CYSCREEN);
3105 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3107 /* But only for ddraw objects that called SetDisplayMode(). */
3108 ddraw1 = create_ddraw();
3109 ddraw2 = create_ddraw();
3110 hr = set_display_mode(ddraw2, 640, 480);
3111 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3112 w = GetSystemMetrics(SM_CXSCREEN);
3113 ok(w == 640, "Got unexpected screen width %u.\n", w);
3114 h = GetSystemMetrics(SM_CYSCREEN);
3115 ok(h == 480, "Got unexpected screen height %u.\n", h);
3117 ref = IDirectDraw7_Release(ddraw1);
3118 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3119 w = GetSystemMetrics(SM_CXSCREEN);
3120 ok(w == 640, "Got unexpected screen width %u.\n", w);
3121 h = GetSystemMetrics(SM_CYSCREEN);
3122 ok(h == 480, "Got unexpected screen height %u.\n", h);
3124 ref = IDirectDraw7_Release(ddraw2);
3125 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3126 w = GetSystemMetrics(SM_CXSCREEN);
3127 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3128 h = GetSystemMetrics(SM_CYSCREEN);
3129 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3131 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3132 * restoring the display mode. */
3133 ddraw1 = create_ddraw();
3134 hr = set_display_mode(ddraw1, 800, 600);
3135 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3136 w = GetSystemMetrics(SM_CXSCREEN);
3137 ok(w == 800, "Got unexpected screen width %u.\n", w);
3138 h = GetSystemMetrics(SM_CYSCREEN);
3139 ok(h == 600, "Got unexpected screen height %u.\n", h);
3141 ddraw2 = create_ddraw();
3142 hr = set_display_mode(ddraw2, 640, 480);
3143 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3144 w = GetSystemMetrics(SM_CXSCREEN);
3145 ok(w == 640, "Got unexpected screen width %u.\n", w);
3146 h = GetSystemMetrics(SM_CYSCREEN);
3147 ok(h == 480, "Got unexpected screen height %u.\n", h);
3149 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3150 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3152 ref = IDirectDraw7_Release(ddraw1);
3153 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3154 w = GetSystemMetrics(SM_CXSCREEN);
3155 ok(w == 640, "Got unexpected screen width %u.\n", w);
3156 h = GetSystemMetrics(SM_CYSCREEN);
3157 ok(h == 480, "Got unexpected screen height %u.\n", h);
3159 ref = IDirectDraw7_Release(ddraw2);
3160 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3161 w = GetSystemMetrics(SM_CXSCREEN);
3162 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3163 h = GetSystemMetrics(SM_CYSCREEN);
3164 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3166 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3167 ddraw1 = create_ddraw();
3168 hr = set_display_mode(ddraw1, 800, 600);
3169 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3170 w = GetSystemMetrics(SM_CXSCREEN);
3171 ok(w == 800, "Got unexpected screen width %u.\n", w);
3172 h = GetSystemMetrics(SM_CYSCREEN);
3173 ok(h == 600, "Got unexpected screen height %u.\n", h);
3175 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3176 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3178 ddraw2 = create_ddraw();
3179 hr = set_display_mode(ddraw2, 640, 480);
3180 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3182 ref = IDirectDraw7_Release(ddraw1);
3183 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3184 w = GetSystemMetrics(SM_CXSCREEN);
3185 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3186 h = GetSystemMetrics(SM_CYSCREEN);
3187 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3189 ref = IDirectDraw7_Release(ddraw2);
3190 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3191 w = GetSystemMetrics(SM_CXSCREEN);
3192 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3193 h = GetSystemMetrics(SM_CYSCREEN);
3194 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3196 DestroyWindow(window);
3199 static void test_initialize(void)
3201 IDirectDraw7 *ddraw;
3202 HRESULT hr;
3204 ddraw = create_ddraw();
3205 ok(!!ddraw, "Failed to create a ddraw object.\n");
3207 hr = IDirectDraw7_Initialize(ddraw, NULL);
3208 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3209 IDirectDraw7_Release(ddraw);
3211 CoInitialize(NULL);
3212 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
3213 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
3214 hr = IDirectDraw7_Initialize(ddraw, NULL);
3215 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3216 hr = IDirectDraw7_Initialize(ddraw, NULL);
3217 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3218 IDirectDraw7_Release(ddraw);
3219 CoUninitialize();
3222 static void test_coop_level_surf_create(void)
3224 IDirectDrawSurface7 *surface;
3225 IDirectDraw7 *ddraw;
3226 DDSURFACEDESC2 ddsd;
3227 HRESULT hr;
3229 ddraw = create_ddraw();
3230 ok(!!ddraw, "Failed to create a ddraw object.\n");
3232 memset(&ddsd, 0, sizeof(ddsd));
3233 ddsd.dwSize = sizeof(ddsd);
3234 ddsd.dwFlags = DDSD_CAPS;
3235 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3236 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3237 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3239 IDirectDraw7_Release(ddraw);
3242 static void test_vb_discard(void)
3244 static const struct vec4 quad[] =
3246 { 0.0f, 480.0f, 0.0f, 1.0f},
3247 { 0.0f, 0.0f, 0.0f, 1.0f},
3248 {640.0f, 480.0f, 0.0f, 1.0f},
3249 {640.0f, 0.0f, 0.0f, 1.0f},
3252 IDirect3DDevice7 *device;
3253 IDirect3D7 *d3d;
3254 IDirect3DVertexBuffer7 *buffer;
3255 HWND window;
3256 HRESULT hr;
3257 D3DVERTEXBUFFERDESC desc;
3258 BYTE *data;
3259 static const unsigned int vbsize = 16;
3260 unsigned int i;
3262 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3263 0, 0, 640, 480, 0, 0, 0, 0);
3265 if (!(device = create_device(window, DDSCL_NORMAL)))
3267 skip("Failed to create a 3D device, skipping test.\n");
3268 DestroyWindow(window);
3269 return;
3272 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3273 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3275 memset(&desc, 0, sizeof(desc));
3276 desc.dwSize = sizeof(desc);
3277 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3278 desc.dwFVF = D3DFVF_XYZRHW;
3279 desc.dwNumVertices = vbsize;
3280 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
3281 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3283 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3284 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3285 memcpy(data, quad, sizeof(quad));
3286 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3287 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3289 hr = IDirect3DDevice7_BeginScene(device);
3290 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3291 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3292 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3293 hr = IDirect3DDevice7_EndScene(device);
3294 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3296 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3297 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3298 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3299 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3300 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3302 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3303 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3304 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3306 if (data[i] != 0xaa)
3308 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3309 break;
3312 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3313 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3315 IDirect3DVertexBuffer7_Release(buffer);
3316 IDirect3D7_Release(d3d);
3317 IDirect3DDevice7_Release(device);
3318 DestroyWindow(window);
3321 static void test_coop_level_multi_window(void)
3323 HWND window1, window2;
3324 IDirectDraw7 *ddraw;
3325 HRESULT hr;
3327 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3328 0, 0, 640, 480, 0, 0, 0, 0);
3329 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3330 0, 0, 640, 480, 0, 0, 0, 0);
3331 ddraw = create_ddraw();
3332 ok(!!ddraw, "Failed to create a ddraw object.\n");
3334 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3335 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3336 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3337 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3338 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3339 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3341 IDirectDraw7_Release(ddraw);
3342 DestroyWindow(window2);
3343 DestroyWindow(window1);
3346 static void test_draw_strided(void)
3348 static struct vec3 position[] =
3350 {-1.0, -1.0, 0.0},
3351 {-1.0, 1.0, 0.0},
3352 { 1.0, 1.0, 0.0},
3353 { 1.0, -1.0, 0.0},
3355 static DWORD diffuse[] =
3357 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3359 static WORD indices[] =
3361 0, 1, 2, 2, 3, 0
3364 IDirectDrawSurface7 *rt;
3365 IDirect3DDevice7 *device;
3366 D3DCOLOR color;
3367 HWND window;
3368 HRESULT hr;
3369 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3371 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3372 0, 0, 640, 480, 0, 0, 0, 0);
3374 if (!(device = create_device(window, DDSCL_NORMAL)))
3376 skip("Failed to create a 3D device, skipping test.\n");
3377 DestroyWindow(window);
3378 return;
3381 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3382 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3384 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3385 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3386 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3387 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3388 hr = IDirect3DDevice7_BeginScene(device);
3389 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3391 memset(&strided, 0x55, sizeof(strided));
3392 strided.position.lpvData = position;
3393 strided.position.dwStride = sizeof(*position);
3394 strided.diffuse.lpvData = diffuse;
3395 strided.diffuse.dwStride = sizeof(*diffuse);
3396 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3397 &strided, 4, indices, 6, 0);
3398 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3400 hr = IDirect3DDevice7_EndScene(device);
3401 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3403 color = get_surface_color(rt, 320, 240);
3404 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3406 IDirectDrawSurface7_Release(rt);
3407 IDirect3DDevice7_Release(device);
3408 DestroyWindow(window);
3411 static void test_clear_rect_count(void)
3413 IDirectDrawSurface7 *rt;
3414 IDirect3DDevice7 *device;
3415 D3DCOLOR color;
3416 HWND window;
3417 HRESULT hr;
3418 D3DRECT rect = {{0}, {0}, {640}, {480}};
3420 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3421 0, 0, 640, 480, 0, 0, 0, 0);
3422 if (!(device = create_device(window, DDSCL_NORMAL)))
3424 skip("Failed to create a 3D device, skipping test.\n");
3425 DestroyWindow(window);
3426 return;
3429 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3430 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3432 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
3433 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3434 hr = IDirect3DDevice7_Clear(device, 0, &rect, D3DCLEAR_TARGET, 0x00ff0000, 1.0f, 0);
3435 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3437 color = get_surface_color(rt, 320, 240);
3438 ok(compare_color(color, 0x00ffffff, 1),
3439 "Clear with count = 0, rect != NULL has color %#08x.\n", color);
3441 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
3442 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3443 hr = IDirect3DDevice7_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
3444 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3446 color = get_surface_color(rt, 320, 240);
3447 ok(compare_color(color, 0x0000ff00, 1),
3448 "Clear with count = 1, rect = NULL has color %#08x.\n", color);
3450 IDirectDrawSurface7_Release(rt);
3451 IDirect3DDevice7_Release(device);
3452 DestroyWindow(window);
3455 static BOOL test_mode_restored(IDirectDraw7 *ddraw, HWND window)
3457 DDSURFACEDESC2 ddsd1, ddsd2;
3458 HRESULT hr;
3460 memset(&ddsd1, 0, sizeof(ddsd1));
3461 ddsd1.dwSize = sizeof(ddsd1);
3462 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd1);
3463 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3465 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3466 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3467 hr = set_display_mode(ddraw, 640, 480);
3468 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3469 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3470 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3472 memset(&ddsd2, 0, sizeof(ddsd2));
3473 ddsd2.dwSize = sizeof(ddsd2);
3474 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd2);
3475 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3476 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3477 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3479 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
3482 static void test_coop_level_versions(void)
3484 HWND window;
3485 IDirectDraw *ddraw;
3486 HRESULT hr;
3487 BOOL restored;
3488 IDirectDrawSurface *surface;
3489 IDirectDraw7 *ddraw7;
3490 DDSURFACEDESC ddsd;
3492 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3493 0, 0, 640, 480, 0, 0, 0, 0);
3495 ddraw7 = create_ddraw();
3496 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3497 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3498 restored = test_mode_restored(ddraw7, window);
3499 ok(restored, "Display mode not restored in new ddraw object\n");
3501 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3502 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3503 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3505 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3506 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3507 restored = test_mode_restored(ddraw7, window);
3508 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3510 /* A successful one does */
3511 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3512 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3513 restored = test_mode_restored(ddraw7, window);
3514 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3516 IDirectDraw_Release(ddraw);
3517 IDirectDraw7_Release(ddraw7);
3519 ddraw7 = create_ddraw();
3520 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3521 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3522 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3524 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
3525 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3526 restored = test_mode_restored(ddraw7, window);
3527 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3529 IDirectDraw_Release(ddraw);
3530 IDirectDraw7_Release(ddraw7);
3532 /* A failing call does not restore the ddraw2+ behavior */
3533 ddraw7 = create_ddraw();
3534 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3535 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3536 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3538 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3539 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3540 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3541 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3542 restored = test_mode_restored(ddraw7, window);
3543 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3545 IDirectDraw_Release(ddraw);
3546 IDirectDraw7_Release(ddraw7);
3548 /* Neither does a sequence of successful calls with the new interface */
3549 ddraw7 = create_ddraw();
3550 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3551 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3552 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3554 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3555 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3556 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3557 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3558 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
3559 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3561 restored = test_mode_restored(ddraw7, window);
3562 ok(!restored, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
3563 IDirectDraw_Release(ddraw);
3564 IDirectDraw7_Release(ddraw7);
3566 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3567 ddraw7 = create_ddraw();
3568 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3569 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3570 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3572 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
3573 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3575 memset(&ddsd, 0, sizeof(ddsd));
3576 ddsd.dwSize = sizeof(ddsd);
3577 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3578 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3579 ddsd.dwWidth = ddsd.dwHeight = 8;
3580 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3581 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
3582 IDirectDrawSurface_Release(surface);
3583 restored = test_mode_restored(ddraw7, window);
3584 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
3586 IDirectDraw_Release(ddraw);
3587 IDirectDraw7_Release(ddraw7);
3588 DestroyWindow(window);
3591 static void test_fog_special(void)
3593 static struct
3595 struct vec3 position;
3596 D3DCOLOR diffuse;
3598 quad[] =
3600 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
3601 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00},
3602 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
3603 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
3605 static const struct
3607 DWORD vertexmode, tablemode;
3608 D3DCOLOR color_left, color_right;
3610 tests[] =
3612 {D3DFOG_LINEAR, D3DFOG_NONE, 0x00ff0000, 0x00ff0000},
3613 {D3DFOG_NONE, D3DFOG_LINEAR, 0x0000ff00, 0x00ff0000},
3615 union
3617 float f;
3618 DWORD d;
3619 } conv;
3620 D3DCOLOR color;
3621 HRESULT hr;
3622 unsigned int i;
3623 HWND window;
3624 IDirect3DDevice7 *device;
3625 IDirectDrawSurface7 *rt;
3627 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3628 0, 0, 640, 480, 0, 0, 0, 0);
3630 if (!(device = create_device(window, DDSCL_NORMAL)))
3632 skip("Failed to create a 3D device, skipping test.\n");
3633 DestroyWindow(window);
3634 return;
3637 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3638 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3640 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
3641 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
3642 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xffff0000);
3643 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
3644 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3645 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3646 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3647 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3649 conv.f = 0.5f;
3650 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, conv.d);
3651 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
3652 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, conv.d);
3653 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
3655 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3657 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0);
3658 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3660 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vertexmode);
3661 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
3662 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tablemode);
3663 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
3665 hr = IDirect3DDevice7_BeginScene(device);
3666 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3667 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
3668 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3669 hr = IDirect3DDevice7_EndScene(device);
3670 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3672 color = get_surface_color(rt, 310, 240);
3673 ok(compare_color(color, tests[i].color_left, 1),
3674 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
3675 color = get_surface_color(rt, 330, 240);
3676 ok(compare_color(color, tests[i].color_right, 1),
3677 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
3680 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3681 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3683 IDirectDrawSurface7_Release(rt);
3684 IDirect3DDevice7_Release(device);
3685 DestroyWindow(window);
3688 static void test_lighting_interface_versions(void)
3690 IDirect3DDevice7 *device;
3691 IDirectDrawSurface7 *rt;
3692 D3DCOLOR color;
3693 HWND window;
3694 HRESULT hr;
3695 DWORD rs;
3696 unsigned int i;
3697 ULONG ref;
3698 D3DMATERIAL7 material;
3699 static D3DVERTEX quad[] =
3701 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3702 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3703 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3704 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3707 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3708 static struct
3710 struct vec3 position;
3711 struct vec3 normal;
3712 DWORD diffuse, specular;
3714 quad2[] =
3716 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3717 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3718 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3719 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3722 static D3DLVERTEX lquad[] =
3724 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3725 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3726 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3727 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3730 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3731 static struct
3733 struct vec3 position;
3734 DWORD diffuse, specular;
3735 struct vec2 texcoord;
3737 lquad2[] =
3739 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3740 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3741 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3742 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3745 static D3DTLVERTEX tlquad[] =
3747 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3748 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3749 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3750 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3753 static const struct
3755 DWORD vertextype;
3756 void *data;
3757 DWORD d3drs_lighting, d3drs_specular;
3758 DWORD draw_flags;
3759 D3DCOLOR color;
3761 tests[] =
3763 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
3764 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
3765 * are not available
3767 * Note that the specular result is 0x00000000 when lighting is on even if the
3768 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
3769 * enabled */
3771 /* 0 */
3772 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x00ffffff},
3773 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
3774 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3775 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3776 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x00ffffff},
3777 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
3778 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3779 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3781 /* 8 */
3782 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x00ff0000},
3783 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
3784 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3785 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3786 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x00ff8080},
3787 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
3788 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3789 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3791 /* 16 */
3792 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
3793 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x0000ff00},
3794 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3795 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3796 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
3797 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x0000ff00},
3798 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3799 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3801 /* 24 */
3802 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
3803 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x0000ff00},
3804 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3805 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3806 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
3807 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x0000ff00},
3808 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3809 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3811 /* 32 */
3812 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
3813 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
3814 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3815 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3816 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
3817 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
3818 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3819 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3822 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3823 0, 0, 640, 480, 0, 0, 0, 0);
3825 if (!(device = create_device(window, DDSCL_NORMAL)))
3827 skip("Failed to create a 3D device, skipping test.\n");
3828 DestroyWindow(window);
3829 return;
3832 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3833 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3835 memset(&material, 0, sizeof(material));
3836 U2(U3(material).emissive).g = 1.0f;
3837 hr = IDirect3DDevice7_SetMaterial(device, &material);
3838 ok(SUCCEEDED(hr), "Failed set material, hr %#x.\n", hr);
3839 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3840 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
3842 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
3843 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
3844 ok(rs == TRUE, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs);
3845 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
3846 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
3847 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
3849 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3851 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
3852 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3854 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
3855 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
3856 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
3857 tests[i].d3drs_specular);
3858 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
3860 hr = IDirect3DDevice7_BeginScene(device);
3861 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3862 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
3863 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
3864 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3865 hr = IDirect3DDevice7_EndScene(device);
3866 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3868 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
3869 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
3870 ok(rs == tests[i].d3drs_lighting, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
3871 rs, tests[i].d3drs_lighting);
3873 color = get_surface_color(rt, 320, 240);
3874 ok(compare_color(color, tests[i].color, 1),
3875 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3876 color, tests[i].color, i);
3879 IDirectDrawSurface7_Release(rt);
3880 ref = IDirect3DDevice7_Release(device);
3881 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
3882 DestroyWindow(window);
3885 static struct
3887 BOOL received;
3888 IDirectDraw7 *ddraw;
3889 HWND window;
3890 DWORD coop_level;
3891 } activateapp_testdata;
3893 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3895 if (message == WM_ACTIVATEAPP)
3897 if (activateapp_testdata.ddraw)
3899 HRESULT hr;
3900 activateapp_testdata.received = FALSE;
3901 hr = IDirectDraw7_SetCooperativeLevel(activateapp_testdata.ddraw,
3902 activateapp_testdata.window, activateapp_testdata.coop_level);
3903 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3904 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3906 activateapp_testdata.received = TRUE;
3909 return DefWindowProcA(hwnd, message, wparam, lparam);
3912 static void test_coop_level_activateapp(void)
3914 IDirectDraw7 *ddraw;
3915 HRESULT hr;
3916 HWND window;
3917 WNDCLASSA wc = {0};
3918 DDSURFACEDESC2 ddsd;
3919 IDirectDrawSurface7 *surface;
3921 ddraw = create_ddraw();
3922 ok(!!ddraw, "Failed to create a ddraw object.\n");
3924 wc.lpfnWndProc = activateapp_test_proc;
3925 wc.lpszClassName = "ddraw_test_wndproc_wc";
3926 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3928 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3929 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3931 /* Exclusive with window already active. */
3932 SetForegroundWindow(window);
3933 activateapp_testdata.received = FALSE;
3934 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3935 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3936 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3937 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3938 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3940 /* Exclusive with window not active. */
3941 SetForegroundWindow(GetDesktopWindow());
3942 activateapp_testdata.received = FALSE;
3943 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3944 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3945 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3946 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3947 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3949 /* Normal with window not active, then exclusive with the same window. */
3950 SetForegroundWindow(GetDesktopWindow());
3951 activateapp_testdata.received = FALSE;
3952 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3953 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3954 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3955 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3956 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3957 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3958 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3959 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3961 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3962 SetForegroundWindow(GetDesktopWindow());
3963 activateapp_testdata.received = FALSE;
3964 activateapp_testdata.ddraw = ddraw;
3965 activateapp_testdata.window = window;
3966 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3967 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3968 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3969 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3970 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3971 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3973 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3974 * succeeding. Another switch to exclusive and back to normal is needed to release the
3975 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3976 * WM_ACTIVATEAPP messages. */
3977 activateapp_testdata.ddraw = NULL;
3978 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3979 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3980 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3981 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3983 /* Setting DDSCL_NORMAL with recursive invocation. */
3984 SetForegroundWindow(GetDesktopWindow());
3985 activateapp_testdata.received = FALSE;
3986 activateapp_testdata.ddraw = ddraw;
3987 activateapp_testdata.window = window;
3988 activateapp_testdata.coop_level = DDSCL_NORMAL;
3989 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3990 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3991 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3993 /* DDraw is in exlusive mode now. */
3994 memset(&ddsd, 0, sizeof(ddsd));
3995 ddsd.dwSize = sizeof(ddsd);
3996 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3997 U5(ddsd).dwBackBufferCount = 1;
3998 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3999 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4000 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4001 IDirectDrawSurface7_Release(surface);
4003 /* Recover again, just to be sure. */
4004 activateapp_testdata.ddraw = NULL;
4005 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4006 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4007 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4008 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4010 DestroyWindow(window);
4011 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
4012 IDirectDraw7_Release(ddraw);
4015 static void test_texturemanage(void)
4017 IDirectDraw7 *ddraw;
4018 HRESULT hr;
4019 DDSURFACEDESC2 ddsd;
4020 IDirectDrawSurface7 *surface;
4021 unsigned int i;
4022 DDCAPS hal_caps, hel_caps;
4023 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
4024 static const struct
4026 DWORD caps_in, caps2_in;
4027 HRESULT hr;
4028 DWORD caps_out, caps2_out;
4030 tests[] =
4032 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4033 ~0U, ~0U},
4034 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4035 ~0U, ~0U},
4036 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4037 ~0U, ~0U},
4038 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4039 ~0U, ~0U},
4040 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
4041 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
4042 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
4043 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
4044 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4045 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
4046 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4047 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
4049 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4050 ~0U, ~0U},
4051 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4052 ~0U, ~0U},
4053 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4054 ~0U, ~0U},
4055 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4056 ~0U, ~0U},
4057 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4058 ~0U, ~0U},
4059 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4060 ~0U, ~0U},
4061 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
4062 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
4063 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
4064 DDSCAPS_SYSTEMMEMORY, 0},
4067 ddraw = create_ddraw();
4068 ok(!!ddraw, "Failed to create a ddraw object.\n");
4069 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4070 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4072 memset(&hal_caps, 0, sizeof(hal_caps));
4073 hal_caps.dwSize = sizeof(hal_caps);
4074 memset(&hel_caps, 0, sizeof(hel_caps));
4075 hel_caps.dwSize = sizeof(hel_caps);
4076 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, &hel_caps);
4077 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4078 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4080 skip("Managed textures not supported, skipping managed texture test.\n");
4081 IDirectDraw7_Release(ddraw);
4082 return;
4085 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4087 memset(&ddsd, 0, sizeof(ddsd));
4088 ddsd.dwSize = sizeof(ddsd);
4089 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4090 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4091 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4092 ddsd.dwWidth = 4;
4093 ddsd.dwHeight = 4;
4095 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4096 ok(hr == tests[i].hr, "Got unexpected, hr %#x, case %u.\n", hr, i);
4097 if (FAILED(hr))
4098 continue;
4100 memset(&ddsd, 0, sizeof(ddsd));
4101 ddsd.dwSize = sizeof(ddsd);
4102 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4103 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4105 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4106 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4107 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4108 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4109 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4110 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4112 IDirectDrawSurface7_Release(surface);
4115 IDirectDraw7_Release(ddraw);
4118 #define SUPPORT_DXT1 0x01
4119 #define SUPPORT_DXT2 0x02
4120 #define SUPPORT_DXT3 0x04
4121 #define SUPPORT_DXT4 0x08
4122 #define SUPPORT_DXT5 0x10
4123 #define SUPPORT_YUY2 0x20
4124 #define SUPPORT_UYVY 0x40
4126 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4128 DWORD *supported_fmts = ctx;
4130 if (!(fmt->dwFlags & DDPF_FOURCC))
4131 return DDENUMRET_OK;
4133 switch (fmt->dwFourCC)
4135 case MAKEFOURCC('D','X','T','1'):
4136 *supported_fmts |= SUPPORT_DXT1;
4137 break;
4138 case MAKEFOURCC('D','X','T','2'):
4139 *supported_fmts |= SUPPORT_DXT2;
4140 break;
4141 case MAKEFOURCC('D','X','T','3'):
4142 *supported_fmts |= SUPPORT_DXT3;
4143 break;
4144 case MAKEFOURCC('D','X','T','4'):
4145 *supported_fmts |= SUPPORT_DXT4;
4146 break;
4147 case MAKEFOURCC('D','X','T','5'):
4148 *supported_fmts |= SUPPORT_DXT5;
4149 break;
4150 case MAKEFOURCC('Y','U','Y','2'):
4151 *supported_fmts |= SUPPORT_YUY2;
4152 break;
4153 case MAKEFOURCC('U','Y','V','Y'):
4154 *supported_fmts |= SUPPORT_UYVY;
4155 break;
4156 default:
4157 break;
4160 return DDENUMRET_OK;
4163 static void test_block_formats_creation(void)
4165 HRESULT hr, expect_hr;
4166 unsigned int i, j, w, h;
4167 HWND window;
4168 IDirectDraw7 *ddraw;
4169 IDirect3D7 *d3d;
4170 IDirect3DDevice7 *device;
4171 IDirectDrawSurface7 *surface;
4172 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
4173 DWORD num_fourcc_codes = 0, *fourcc_codes;
4174 DDSURFACEDESC2 ddsd;
4175 DDCAPS hal_caps;
4176 void *mem;
4178 static const struct
4180 DWORD fourcc;
4181 const char *name;
4182 DWORD support_flag;
4183 unsigned int block_width;
4184 unsigned int block_height;
4185 unsigned int block_size;
4186 BOOL create_size_checked, overlay;
4188 formats[] =
4190 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
4191 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
4192 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
4193 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
4194 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
4195 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
4196 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
4198 static const struct
4200 DWORD caps, caps2;
4201 const char *name;
4202 BOOL overlay;
4204 types[] =
4206 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4207 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4209 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4210 * Other hw / drivers successfully create those surfaces. Ignore them, this
4211 * suggests that no game uses this, otherwise Nvidia would support it. */
4213 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4214 "videomemory texture", FALSE
4217 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4218 "videomemory overlay", TRUE
4221 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4222 "systemmemory texture", FALSE
4225 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4226 "managed texture", FALSE
4229 enum size_type
4231 SIZE_TYPE_ZERO,
4232 SIZE_TYPE_PITCH,
4233 SIZE_TYPE_SIZE,
4235 static const struct
4237 DWORD flags;
4238 enum size_type size_type;
4239 int rel_size;
4240 HRESULT hr;
4242 user_mem_tests[] =
4244 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
4245 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4246 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4247 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4248 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4249 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4250 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4251 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4252 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
4253 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
4254 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4255 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4256 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4257 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4260 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4261 0, 0, 640, 480, 0, 0, 0, 0);
4263 if (!(device = create_device(window, DDSCL_NORMAL)))
4265 skip("Failed to create a 3D device, skipping test.\n");
4266 DestroyWindow(window);
4267 return;
4270 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4271 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4272 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4273 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4274 IDirect3D7_Release(d3d);
4276 hr = IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb,
4277 &supported_fmts);
4278 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4280 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4281 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4282 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4283 num_fourcc_codes * sizeof(*fourcc_codes));
4284 if (!fourcc_codes)
4285 goto cleanup;
4286 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
4287 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4288 for (i = 0; i < num_fourcc_codes; i++)
4290 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
4292 if (fourcc_codes[i] == formats[j].fourcc)
4293 supported_overlay_fmts |= formats[j].support_flag;
4296 HeapFree(GetProcessHeap(), 0, fourcc_codes);
4298 memset(&hal_caps, 0, sizeof(hal_caps));
4299 hal_caps.dwSize = sizeof(hal_caps);
4300 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
4301 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4303 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
4305 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4307 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
4309 BOOL support;
4311 if (formats[i].overlay != types[j].overlay
4312 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
4313 continue;
4315 if (formats[i].overlay)
4316 support = supported_overlay_fmts & formats[i].support_flag;
4317 else
4318 support = supported_fmts & formats[i].support_flag;
4320 for (w = 1; w <= 8; w++)
4322 for (h = 1; h <= 8; h++)
4324 BOOL block_aligned = TRUE;
4325 BOOL todo = FALSE;
4327 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
4328 block_aligned = FALSE;
4330 memset(&ddsd, 0, sizeof(ddsd));
4331 ddsd.dwSize = sizeof(ddsd);
4332 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4333 ddsd.ddsCaps.dwCaps = types[j].caps;
4334 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
4335 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4336 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4337 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4338 ddsd.dwWidth = w;
4339 ddsd.dwHeight = h;
4341 /* TODO: Handle power of two limitations. I cannot test the pow2
4342 * behavior on windows because I have no hardware that doesn't at
4343 * least support np2_conditional. There's probably no HW that
4344 * supports DXTN textures but no conditional np2 textures. */
4345 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
4346 expect_hr = DDERR_INVALIDPARAMS;
4347 else if (formats[i].create_size_checked && !block_aligned)
4349 expect_hr = DDERR_INVALIDPARAMS;
4350 if (!(types[j].caps & DDSCAPS_TEXTURE))
4351 todo = TRUE;
4353 else
4354 expect_hr = D3D_OK;
4356 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4357 if (todo)
4358 todo_wine ok(hr == expect_hr,
4359 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4360 hr, formats[i].name, types[j].name, w, h, expect_hr);
4361 else
4362 ok(hr == expect_hr,
4363 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4364 hr, formats[i].name, types[j].name, w, h, expect_hr);
4366 if (SUCCEEDED(hr))
4367 IDirectDrawSurface7_Release(surface);
4372 if (formats[i].overlay)
4373 continue;
4375 for (j = 0; j < sizeof(user_mem_tests) / sizeof(*user_mem_tests); ++j)
4377 memset(&ddsd, 0, sizeof(ddsd));
4378 ddsd.dwSize = sizeof(ddsd);
4379 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
4380 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
4382 switch (user_mem_tests[j].size_type)
4384 case SIZE_TYPE_ZERO:
4385 U1(ddsd).dwLinearSize = 0;
4386 break;
4388 case SIZE_TYPE_PITCH:
4389 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
4390 break;
4392 case SIZE_TYPE_SIZE:
4393 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
4394 break;
4396 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
4398 ddsd.lpSurface = mem;
4399 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4400 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4401 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4402 ddsd.dwWidth = 8;
4403 ddsd.dwHeight = 8;
4405 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4406 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
4408 if (FAILED(hr))
4409 continue;
4411 memset(&ddsd, 0, sizeof(ddsd));
4412 ddsd.dwSize = sizeof(ddsd);
4413 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4414 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
4415 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
4416 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
4417 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
4418 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
4419 j, U1(ddsd).dwLinearSize);
4420 else
4421 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
4422 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
4423 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
4424 IDirectDrawSurface7_Release(surface);
4428 HeapFree(GetProcessHeap(), 0, mem);
4429 cleanup:
4430 IDirectDraw7_Release(ddraw);
4431 IDirect3DDevice7_Release(device);
4432 DestroyWindow(window);
4435 struct format_support_check
4437 const DDPIXELFORMAT *format;
4438 BOOL supported;
4441 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
4443 struct format_support_check *format = ctx;
4445 if (!memcmp(format->format, fmt, sizeof(*fmt)))
4447 format->supported = TRUE;
4448 return DDENUMRET_CANCEL;
4451 return DDENUMRET_OK;
4454 static void test_unsupported_formats(void)
4456 HRESULT hr;
4457 BOOL expect_success;
4458 HWND window;
4459 IDirectDraw7 *ddraw;
4460 IDirect3D7 *d3d;
4461 IDirect3DDevice7 *device;
4462 IDirectDrawSurface7 *surface;
4463 DDSURFACEDESC2 ddsd;
4464 unsigned int i, j;
4465 DWORD expected_caps;
4466 static const struct
4468 const char *name;
4469 DDPIXELFORMAT fmt;
4471 formats[] =
4474 "D3DFMT_A8R8G8B8",
4476 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
4477 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4481 "D3DFMT_P8",
4483 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4484 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4488 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
4490 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4491 0, 0, 640, 480, 0, 0, 0, 0);
4493 if (!(device = create_device(window, DDSCL_NORMAL)))
4495 skip("Failed to create a 3D device, skipping test.\n");
4496 DestroyWindow(window);
4497 return;
4500 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4501 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4502 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4503 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4504 IDirect3D7_Release(d3d);
4506 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4508 struct format_support_check check = {&formats[i].fmt, FALSE};
4509 hr = IDirect3DDevice7_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
4510 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4512 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
4514 memset(&ddsd, 0, sizeof(ddsd));
4515 ddsd.dwSize = sizeof(ddsd);
4516 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4517 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
4518 ddsd.dwWidth = 4;
4519 ddsd.dwHeight = 4;
4520 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
4522 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
4523 expect_success = FALSE;
4524 else
4525 expect_success = TRUE;
4527 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4528 ok(SUCCEEDED(hr) == expect_success,
4529 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4530 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
4531 if (FAILED(hr))
4532 continue;
4534 memset(&ddsd, 0, sizeof(ddsd));
4535 ddsd.dwSize = sizeof(ddsd);
4536 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4537 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4539 if (caps[j] & DDSCAPS_VIDEOMEMORY)
4540 expected_caps = DDSCAPS_VIDEOMEMORY;
4541 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
4542 expected_caps = DDSCAPS_SYSTEMMEMORY;
4543 else if (check.supported)
4544 expected_caps = DDSCAPS_VIDEOMEMORY;
4545 else
4546 expected_caps = DDSCAPS_SYSTEMMEMORY;
4548 ok(ddsd.ddsCaps.dwCaps & expected_caps,
4549 "Expected capability %#x, format %s, input cap %#x.\n",
4550 expected_caps, formats[i].name, caps[j]);
4552 IDirectDrawSurface7_Release(surface);
4556 IDirectDraw7_Release(ddraw);
4557 IDirect3DDevice7_Release(device);
4558 DestroyWindow(window);
4561 static void test_rt_caps(void)
4563 const GUID *devtype = &IID_IDirect3DHALDevice;
4564 PALETTEENTRY palette_entries[256];
4565 IDirectDrawPalette *palette;
4566 IDirectDraw7 *ddraw;
4567 BOOL hal_ok = FALSE;
4568 DDPIXELFORMAT z_fmt;
4569 IDirect3D7 *d3d;
4570 unsigned int i;
4571 ULONG refcount;
4572 HWND window;
4573 HRESULT hr;
4575 static const DDPIXELFORMAT p8_fmt =
4577 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4578 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4581 const struct
4583 const DDPIXELFORMAT *pf;
4584 DWORD caps_in;
4585 DWORD caps_out;
4586 HRESULT create_device_hr;
4587 HRESULT set_rt_hr, alternative_set_rt_hr;
4589 test_data[] =
4592 NULL,
4593 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4594 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4595 D3D_OK,
4596 D3D_OK,
4597 D3D_OK,
4600 NULL,
4601 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4602 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4603 D3D_OK,
4604 D3D_OK,
4605 D3D_OK,
4608 NULL,
4609 DDSCAPS_OFFSCREENPLAIN,
4610 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4611 DDERR_INVALIDCAPS,
4612 DDERR_INVALIDCAPS,
4613 DDERR_INVALIDCAPS,
4616 NULL,
4617 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4618 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4619 D3DERR_SURFACENOTINVIDMEM,
4620 DDERR_INVALIDPARAMS,
4621 D3D_OK,
4624 NULL,
4625 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4626 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4627 DDERR_INVALIDCAPS,
4628 DDERR_INVALIDCAPS,
4629 DDERR_INVALIDCAPS,
4632 NULL,
4633 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4634 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4635 D3D_OK,
4636 D3D_OK,
4637 D3D_OK,
4640 NULL,
4641 DDSCAPS_3DDEVICE,
4642 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4643 D3D_OK,
4644 D3D_OK,
4645 D3D_OK,
4648 NULL,
4650 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4651 DDERR_INVALIDCAPS,
4652 DDERR_INVALIDCAPS,
4653 DDERR_INVALIDCAPS,
4656 NULL,
4657 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4658 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4659 D3DERR_SURFACENOTINVIDMEM,
4660 DDERR_INVALIDPARAMS,
4661 D3D_OK,
4664 NULL,
4665 DDSCAPS_SYSTEMMEMORY,
4666 DDSCAPS_SYSTEMMEMORY,
4667 DDERR_INVALIDCAPS,
4668 DDERR_INVALIDCAPS,
4669 DDERR_INVALIDCAPS,
4672 &p8_fmt,
4674 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4675 DDERR_INVALIDCAPS,
4676 DDERR_INVALIDCAPS,
4677 DDERR_INVALIDCAPS,
4680 &p8_fmt,
4681 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4682 ~0U /* AMD r200 */,
4683 DDERR_NOPALETTEATTACHED,
4684 DDERR_INVALIDCAPS,
4685 DDERR_INVALIDCAPS,
4688 &p8_fmt,
4689 DDSCAPS_OFFSCREENPLAIN,
4690 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4691 DDERR_INVALIDCAPS,
4692 DDERR_INVALIDCAPS,
4693 DDERR_INVALIDCAPS,
4696 &p8_fmt,
4697 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4698 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4699 DDERR_NOPALETTEATTACHED,
4700 DDERR_INVALIDCAPS,
4701 DDERR_INVALIDCAPS,
4704 &p8_fmt,
4705 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4706 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4707 DDERR_INVALIDCAPS,
4708 DDERR_INVALIDCAPS,
4709 DDERR_INVALIDCAPS,
4712 &z_fmt,
4713 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
4714 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4715 DDERR_INVALIDCAPS,
4716 DDERR_INVALIDPIXELFORMAT,
4717 DDERR_INVALIDPIXELFORMAT,
4720 &z_fmt,
4721 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4722 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4723 DDERR_INVALIDCAPS,
4724 DDERR_INVALIDPIXELFORMAT,
4725 DDERR_INVALIDPIXELFORMAT,
4728 &z_fmt,
4729 DDSCAPS_ZBUFFER,
4730 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4731 DDERR_INVALIDCAPS,
4732 DDERR_INVALIDCAPS,
4733 DDERR_INVALIDCAPS,
4736 &z_fmt,
4737 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4738 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4739 DDERR_INVALIDCAPS,
4740 DDERR_INVALIDPARAMS,
4741 DDERR_INVALIDPIXELFORMAT,
4744 &z_fmt,
4745 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4746 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4747 DDERR_INVALIDCAPS,
4748 DDERR_INVALIDCAPS,
4749 DDERR_INVALIDCAPS,
4753 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4754 0, 0, 640, 480, 0, 0, 0, 0);
4755 ddraw = create_ddraw();
4756 ok(!!ddraw, "Failed to create a ddraw object.\n");
4757 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4758 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4760 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
4762 skip("D3D interface is not available, skipping test.\n");
4763 goto done;
4766 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
4767 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
4768 if (hal_ok)
4769 devtype = &IID_IDirect3DTnLHalDevice;
4771 memset(&z_fmt, 0, sizeof(z_fmt));
4772 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
4773 if (FAILED(hr) || !z_fmt.dwSize)
4775 skip("No depth buffer formats available, skipping test.\n");
4776 IDirect3D7_Release(d3d);
4777 goto done;
4780 memset(palette_entries, 0, sizeof(palette_entries));
4781 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
4782 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
4784 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4786 IDirectDrawSurface7 *surface, *rt, *expected_rt, *tmp;
4787 DDSURFACEDESC2 surface_desc;
4788 IDirect3DDevice7 *device;
4790 memset(&surface_desc, 0, sizeof(surface_desc));
4791 surface_desc.dwSize = sizeof(surface_desc);
4792 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4793 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4794 if (test_data[i].pf)
4796 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4797 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4799 surface_desc.dwWidth = 640;
4800 surface_desc.dwHeight = 480;
4801 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4802 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4803 i, test_data[i].caps_in, hr);
4805 memset(&surface_desc, 0, sizeof(surface_desc));
4806 surface_desc.dwSize = sizeof(surface_desc);
4807 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
4808 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4809 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
4810 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4811 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4813 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4814 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4815 i, hr, test_data[i].create_device_hr);
4816 if (FAILED(hr))
4818 if (hr == DDERR_NOPALETTEATTACHED)
4820 hr = IDirectDrawSurface7_SetPalette(surface, palette);
4821 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
4822 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4823 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
4824 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
4825 else
4826 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
4828 IDirectDrawSurface7_Release(surface);
4830 memset(&surface_desc, 0, sizeof(surface_desc));
4831 surface_desc.dwSize = sizeof(surface_desc);
4832 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4833 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4834 surface_desc.dwWidth = 640;
4835 surface_desc.dwHeight = 480;
4836 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4837 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
4839 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4840 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
4843 memset(&surface_desc, 0, sizeof(surface_desc));
4844 surface_desc.dwSize = sizeof(surface_desc);
4845 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4846 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4847 if (test_data[i].pf)
4849 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4850 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4852 surface_desc.dwWidth = 640;
4853 surface_desc.dwHeight = 480;
4854 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
4855 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4856 i, test_data[i].caps_in, hr);
4858 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
4859 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
4860 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4861 i, hr, test_data[i].set_rt_hr);
4862 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
4863 expected_rt = rt;
4864 else
4865 expected_rt = surface;
4867 hr = IDirect3DDevice7_GetRenderTarget(device, &tmp);
4868 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
4869 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
4871 IDirectDrawSurface7_Release(tmp);
4872 IDirectDrawSurface7_Release(rt);
4873 refcount = IDirect3DDevice7_Release(device);
4874 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
4875 refcount = IDirectDrawSurface7_Release(surface);
4876 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
4879 IDirectDrawPalette_Release(palette);
4880 IDirect3D7_Release(d3d);
4882 done:
4883 refcount = IDirectDraw7_Release(ddraw);
4884 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4885 DestroyWindow(window);
4888 static void test_primary_caps(void)
4890 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4891 IDirectDrawSurface7 *surface;
4892 DDSURFACEDESC2 surface_desc;
4893 IDirectDraw7 *ddraw;
4894 unsigned int i;
4895 ULONG refcount;
4896 HWND window;
4897 HRESULT hr;
4899 static const struct
4901 DWORD coop_level;
4902 DWORD caps_in;
4903 DWORD back_buffer_count;
4904 HRESULT hr;
4905 DWORD caps_out;
4907 test_data[] =
4910 DDSCL_NORMAL,
4911 DDSCAPS_PRIMARYSURFACE,
4912 ~0u,
4913 DD_OK,
4914 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
4917 DDSCL_NORMAL,
4918 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
4919 ~0u,
4920 DDERR_INVALIDCAPS,
4921 ~0u,
4924 DDSCL_NORMAL,
4925 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
4926 ~0u,
4927 DDERR_INVALIDCAPS,
4928 ~0u,
4931 DDSCL_NORMAL,
4932 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
4933 ~0u,
4934 DDERR_INVALIDCAPS,
4935 ~0u,
4938 DDSCL_NORMAL,
4939 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
4940 ~0u,
4941 DDERR_INVALIDCAPS,
4942 ~0u,
4945 DDSCL_NORMAL,
4946 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
4947 ~0u,
4948 DDERR_INVALIDCAPS,
4949 ~0u,
4952 DDSCL_NORMAL,
4953 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4954 ~0u,
4955 DDERR_INVALIDCAPS,
4956 ~0u,
4959 DDSCL_NORMAL,
4960 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4962 DDERR_INVALIDCAPS,
4963 ~0u,
4966 DDSCL_NORMAL,
4967 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4969 DDERR_NOEXCLUSIVEMODE,
4970 ~0u,
4973 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4974 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4976 DDERR_INVALIDCAPS,
4977 ~0u,
4980 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4981 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4983 DD_OK,
4984 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
4987 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4988 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
4990 DDERR_INVALIDCAPS,
4991 ~0u,
4994 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4995 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
4997 DDERR_INVALIDCAPS,
4998 ~0u,
5002 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5003 0, 0, 640, 480, 0, 0, 0, 0);
5004 ddraw = create_ddraw();
5005 ok(!!ddraw, "Failed to create a ddraw object.\n");
5007 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5009 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
5010 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5012 memset(&surface_desc, 0, sizeof(surface_desc));
5013 surface_desc.dwSize = sizeof(surface_desc);
5014 surface_desc.dwFlags = DDSD_CAPS;
5015 if (test_data[i].back_buffer_count != ~0u)
5016 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
5017 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5018 U5(surface_desc).dwBackBufferCount = test_data[i].back_buffer_count;
5019 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5020 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5021 if (FAILED(hr))
5022 continue;
5024 memset(&surface_desc, 0, sizeof(surface_desc));
5025 surface_desc.dwSize = sizeof(surface_desc);
5026 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5027 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5028 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
5029 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5030 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5032 IDirectDrawSurface7_Release(surface);
5035 refcount = IDirectDraw7_Release(ddraw);
5036 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5037 DestroyWindow(window);
5040 static void test_surface_lock(void)
5042 IDirectDraw7 *ddraw;
5043 IDirect3D7 *d3d = NULL;
5044 IDirectDrawSurface7 *surface;
5045 IDirect3DDevice7 *device;
5046 HRESULT hr;
5047 HWND window;
5048 unsigned int i;
5049 DDSURFACEDESC2 ddsd;
5050 ULONG refcount;
5051 DDPIXELFORMAT z_fmt;
5052 BOOL hal_ok = FALSE;
5053 const GUID *devtype = &IID_IDirect3DHALDevice;
5054 D3DDEVICEDESC7 device_desc;
5055 BOOL cubemap_supported;
5056 static const struct
5058 DWORD caps;
5059 DWORD caps2;
5060 const char *name;
5062 tests[] =
5065 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
5067 "videomemory offscreenplain"
5070 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5072 "systemmemory offscreenplain"
5075 DDSCAPS_PRIMARYSURFACE,
5077 "primary"
5080 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5082 "videomemory texture"
5085 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5086 DDSCAPS2_OPAQUE,
5087 "opaque videomemory texture"
5090 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5092 "systemmemory texture"
5095 DDSCAPS_TEXTURE,
5096 DDSCAPS2_TEXTUREMANAGE,
5097 "managed texture"
5100 DDSCAPS_TEXTURE,
5101 DDSCAPS2_D3DTEXTUREMANAGE,
5102 "managed texture"
5105 DDSCAPS_TEXTURE,
5106 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5107 "opaque managed texture"
5110 DDSCAPS_TEXTURE,
5111 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5112 "opaque managed texture"
5115 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5117 "render target"
5120 DDSCAPS_ZBUFFER,
5122 "Z buffer"
5125 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5126 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5127 "videomemory cube"
5130 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5131 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5132 "opaque videomemory cube"
5135 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY,
5136 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5137 "systemmemory cube"
5140 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5141 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5142 "managed cube"
5145 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5146 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5147 "managed cube"
5150 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5151 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5152 "opaque managed cube"
5155 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5156 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5157 "opaque managed cube"
5161 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5162 0, 0, 640, 480, 0, 0, 0, 0);
5163 ddraw = create_ddraw();
5164 ok(!!ddraw, "Failed to create a ddraw object.\n");
5165 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5166 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5168 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5170 skip("D3D interface is not available, skipping test.\n");
5171 goto done;
5174 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5175 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5176 if (hal_ok)
5177 devtype = &IID_IDirect3DTnLHalDevice;
5179 memset(&z_fmt, 0, sizeof(z_fmt));
5180 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5181 if (FAILED(hr) || !z_fmt.dwSize)
5183 skip("No depth buffer formats available, skipping test.\n");
5184 goto done;
5187 memset(&ddsd, 0, sizeof(ddsd));
5188 ddsd.dwSize = sizeof(ddsd);
5189 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5190 ddsd.dwWidth = 64;
5191 ddsd.dwHeight = 64;
5192 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5193 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5194 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5196 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5197 ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr);
5198 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
5199 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5200 cubemap_supported = !!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP);
5201 IDirect3DDevice7_Release(device);
5203 IDirectDrawSurface7_Release(surface);
5205 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5207 if (!cubemap_supported && tests[i].caps2 & DDSCAPS2_CUBEMAP)
5208 continue;
5210 memset(&ddsd, 0, sizeof(ddsd));
5211 ddsd.dwSize = sizeof(ddsd);
5212 ddsd.dwFlags = DDSD_CAPS;
5213 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5215 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5216 ddsd.dwWidth = 64;
5217 ddsd.dwHeight = 64;
5219 if (tests[i].caps & DDSCAPS_ZBUFFER)
5221 ddsd.dwFlags |= DDSD_PIXELFORMAT;
5222 U4(ddsd).ddpfPixelFormat = z_fmt;
5224 ddsd.ddsCaps.dwCaps = tests[i].caps;
5225 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5227 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5228 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
5230 memset(&ddsd, 0, sizeof(ddsd));
5231 ddsd.dwSize = sizeof(ddsd);
5232 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5233 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
5234 if (SUCCEEDED(hr))
5236 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5237 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5240 IDirectDrawSurface7_Release(surface);
5243 done:
5244 if (d3d)
5245 IDirect3D7_Release(d3d);
5246 refcount = IDirectDraw7_Release(ddraw);
5247 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5248 DestroyWindow(window);
5251 static void test_surface_discard(void)
5253 IDirect3DDevice7 *device;
5254 IDirect3D7 *d3d;
5255 IDirectDraw7 *ddraw;
5256 HRESULT hr;
5257 HWND window;
5258 DDSURFACEDESC2 ddsd;
5259 IDirectDrawSurface7 *surface, *target;
5260 void *addr;
5261 static const struct
5263 DWORD caps, caps2;
5264 BOOL discard;
5266 tests[] =
5268 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5269 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5270 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5271 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5272 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
5273 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5274 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
5275 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5277 unsigned int i;
5279 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5280 0, 0, 640, 480, 0, 0, 0, 0);
5282 if (!(device = create_device(window, DDSCL_NORMAL)))
5284 skip("Failed to create a 3D device, skipping test.\n");
5285 DestroyWindow(window);
5286 return;
5288 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5289 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5290 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
5291 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5292 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
5293 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5295 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5297 BOOL discarded;
5299 memset(&ddsd, 0, sizeof(ddsd));
5300 ddsd.dwSize = sizeof(ddsd);
5301 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5302 ddsd.ddsCaps.dwCaps = tests[i].caps;
5303 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5304 ddsd.dwWidth = 64;
5305 ddsd.dwHeight = 64;
5306 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5307 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
5309 memset(&ddsd, 0, sizeof(ddsd));
5310 ddsd.dwSize = sizeof(ddsd);
5311 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5312 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5313 addr = ddsd.lpSurface;
5314 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5315 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5317 memset(&ddsd, 0, sizeof(ddsd));
5318 ddsd.dwSize = sizeof(ddsd);
5319 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5320 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5321 discarded = ddsd.lpSurface != addr;
5322 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5323 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5325 hr = IDirectDrawSurface7_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
5326 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
5328 memset(&ddsd, 0, sizeof(ddsd));
5329 ddsd.dwSize = sizeof(ddsd);
5330 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5331 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5332 discarded |= ddsd.lpSurface != addr;
5333 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5334 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5336 IDirectDrawSurface7_Release(surface);
5338 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5339 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5340 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
5343 IDirectDrawSurface7_Release(target);
5344 IDirectDraw7_Release(ddraw);
5345 IDirect3D7_Release(d3d);
5346 IDirect3DDevice7_Release(device);
5347 DestroyWindow(window);
5350 static void test_flip(void)
5352 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5353 IDirectDrawSurface7 *primary, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
5354 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, {0}};
5355 DDSURFACEDESC2 surface_desc;
5356 BOOL sysmem_primary;
5357 IDirectDraw7 *ddraw;
5358 D3DCOLOR color;
5359 ULONG refcount;
5360 HWND window;
5361 DDBLTFX fx;
5362 HRESULT hr;
5364 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5365 0, 0, 640, 480, 0, 0, 0, 0);
5366 ddraw = create_ddraw();
5367 ok(!!ddraw, "Failed to create a ddraw object.\n");
5369 hr = set_display_mode(ddraw, 640, 480);
5370 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
5371 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5372 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5374 memset(&surface_desc, 0, sizeof(surface_desc));
5375 surface_desc.dwSize = sizeof(surface_desc);
5376 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5377 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5378 U5(surface_desc).dwBackBufferCount = 3;
5379 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5380 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5382 memset(&surface_desc, 0, sizeof(surface_desc));
5383 surface_desc.dwSize = sizeof(surface_desc);
5384 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
5385 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5386 ok((surface_desc.ddsCaps.dwCaps & ~placement)
5387 == (DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5388 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5389 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
5391 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &backbuffer1);
5392 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5393 memset(&surface_desc, 0, sizeof(surface_desc));
5394 surface_desc.dwSize = sizeof(surface_desc);
5395 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer1, &surface_desc);
5396 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5397 ok(!U5(surface_desc).dwBackBufferCount, "Got unexpected back buffer count %u.\n", U5(surface_desc).dwBackBufferCount);
5398 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_BACKBUFFER),
5399 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5401 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
5402 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5403 memset(&surface_desc, 0, sizeof(surface_desc));
5404 surface_desc.dwSize = sizeof(surface_desc);
5405 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer2, &surface_desc);
5406 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5407 ok(!U5(surface_desc).dwBackBufferCount, "Got unexpected back buffer count %u.\n", U5(surface_desc).dwBackBufferCount);
5408 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5409 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5411 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
5412 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5413 memset(&surface_desc, 0, sizeof(surface_desc));
5414 surface_desc.dwSize = sizeof(surface_desc);
5415 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer3, &surface_desc);
5416 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5417 ok(!U5(surface_desc).dwBackBufferCount, "Got unexpected back buffer count %u.\n", U5(surface_desc).dwBackBufferCount);
5418 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5419 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5421 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer3, &caps, &surface);
5422 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5423 ok(surface == primary, "Got unexpected surface %p, expected %p.\n", surface, primary);
5424 IDirectDrawSurface7_Release(surface);
5426 memset(&surface_desc, 0, sizeof(surface_desc));
5427 surface_desc.dwSize = sizeof(surface_desc);
5428 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5429 surface_desc.ddsCaps.dwCaps = 0;
5430 surface_desc.dwWidth = 640;
5431 surface_desc.dwHeight = 480;
5432 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5433 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5434 hr = IDirectDrawSurface7_Flip(primary, surface, DDFLIP_WAIT);
5435 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5436 IDirectDrawSurface7_Release(surface);
5438 hr = IDirectDrawSurface7_Flip(primary, primary, DDFLIP_WAIT);
5439 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5440 hr = IDirectDrawSurface7_Flip(backbuffer1, NULL, DDFLIP_WAIT);
5441 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5442 hr = IDirectDrawSurface7_Flip(backbuffer2, NULL, DDFLIP_WAIT);
5443 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5444 hr = IDirectDrawSurface7_Flip(backbuffer3, NULL, DDFLIP_WAIT);
5445 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5447 memset(&fx, 0, sizeof(fx));
5448 fx.dwSize = sizeof(fx);
5449 U5(fx).dwFillColor = 0xffff0000;
5450 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5451 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5452 U5(fx).dwFillColor = 0xff00ff00;
5453 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5454 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5455 U5(fx).dwFillColor = 0xff0000ff;
5456 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5457 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5459 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5460 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5461 color = get_surface_color(backbuffer1, 320, 240);
5462 /* The testbot seems to just copy the contents of one surface to all the
5463 * others, instead of properly flipping. */
5464 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5465 "Got unexpected color 0x%08x.\n", color);
5466 color = get_surface_color(backbuffer2, 320, 240);
5467 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5468 U5(fx).dwFillColor = 0xffff0000;
5469 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5470 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5472 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5473 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5474 color = get_surface_color(backbuffer1, 320, 240);
5475 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5476 "Got unexpected color 0x%08x.\n", color);
5477 color = get_surface_color(backbuffer2, 320, 240);
5478 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5479 U5(fx).dwFillColor = 0xff00ff00;
5480 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5481 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5483 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5484 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5485 color = get_surface_color(backbuffer1, 320, 240);
5486 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5487 "Got unexpected color 0x%08x.\n", color);
5488 color = get_surface_color(backbuffer2, 320, 240);
5489 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5490 U5(fx).dwFillColor = 0xff0000ff;
5491 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5492 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5494 hr = IDirectDrawSurface7_Flip(primary, backbuffer1, DDFLIP_WAIT);
5495 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5496 color = get_surface_color(backbuffer2, 320, 240);
5497 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5498 "Got unexpected color 0x%08x.\n", color);
5499 color = get_surface_color(backbuffer3, 320, 240);
5500 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5501 U5(fx).dwFillColor = 0xffff0000;
5502 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5503 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5505 hr = IDirectDrawSurface7_Flip(primary, backbuffer2, DDFLIP_WAIT);
5506 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5507 color = get_surface_color(backbuffer1, 320, 240);
5508 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5509 color = get_surface_color(backbuffer3, 320, 240);
5510 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5511 "Got unexpected color 0x%08x.\n", color);
5512 U5(fx).dwFillColor = 0xff00ff00;
5513 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5514 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5516 hr = IDirectDrawSurface7_Flip(primary, backbuffer3, DDFLIP_WAIT);
5517 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5518 color = get_surface_color(backbuffer1, 320, 240);
5519 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5520 "Got unexpected color 0x%08x.\n", color);
5521 color = get_surface_color(backbuffer2, 320, 240);
5522 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5524 IDirectDrawSurface7_Release(backbuffer3);
5525 IDirectDrawSurface7_Release(backbuffer2);
5526 IDirectDrawSurface7_Release(backbuffer1);
5527 IDirectDrawSurface7_Release(primary);
5528 refcount = IDirectDraw7_Release(ddraw);
5529 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5530 DestroyWindow(window);
5533 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
5535 memset(ddsd, 0, sizeof(*ddsd));
5536 ddsd->dwSize = sizeof(*ddsd);
5539 static void test_set_surface_desc(void)
5541 IDirectDraw7 *ddraw;
5542 HWND window;
5543 HRESULT hr;
5544 DDSURFACEDESC2 ddsd;
5545 IDirectDrawSurface7 *surface;
5546 BYTE data[16*16*4];
5547 ULONG ref;
5548 unsigned int i;
5549 static const struct
5551 DWORD caps, caps2;
5552 BOOL supported;
5553 const char *name;
5555 invalid_caps_tests[] =
5557 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
5558 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
5559 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
5560 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
5561 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
5564 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5565 0, 0, 640, 480, 0, 0, 0, 0);
5566 ddraw = create_ddraw();
5567 ok(!!ddraw, "Failed to create a ddraw object.\n");
5568 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5569 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5571 reset_ddsd(&ddsd);
5572 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5573 ddsd.dwWidth = 8;
5574 ddsd.dwHeight = 8;
5575 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5576 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5577 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5578 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5579 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5580 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5581 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5583 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5584 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5586 reset_ddsd(&ddsd);
5587 ddsd.dwFlags = DDSD_LPSURFACE;
5588 ddsd.lpSurface = data;
5589 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5590 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5592 /* Redundantly setting the same lpSurface is not an error. */
5593 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5594 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5596 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5597 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5598 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5599 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
5601 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5602 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5603 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5604 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
5605 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5606 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5608 reset_ddsd(&ddsd);
5609 ddsd.dwFlags = DDSD_LPSURFACE;
5610 ddsd.lpSurface = data;
5611 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 1);
5612 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
5614 ddsd.lpSurface = NULL;
5615 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5616 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
5618 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, NULL, 0);
5619 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
5621 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5622 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5623 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5624 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5625 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5627 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5628 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5629 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
5631 ddsd.dwFlags = DDSD_CAPS;
5632 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5633 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
5635 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
5636 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
5637 ddsd.lpSurface = data;
5638 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5639 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5640 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5641 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5642 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5643 ddsd.ddsCaps.dwCaps = 0;
5644 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
5645 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5646 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5648 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5649 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5650 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5651 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5652 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5654 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5655 reset_ddsd(&ddsd);
5656 ddsd.dwFlags = DDSD_HEIGHT;
5657 ddsd.dwHeight = 16;
5658 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5659 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
5661 ddsd.lpSurface = data;
5662 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
5663 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5664 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5666 ddsd.dwHeight = 0;
5667 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5668 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
5670 reset_ddsd(&ddsd);
5671 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5672 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
5673 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5674 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5676 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5677 reset_ddsd(&ddsd);
5678 ddsd.dwFlags = DDSD_PITCH;
5679 U1(ddsd).lPitch = 8 * 4;
5680 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5681 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
5683 ddsd.dwFlags = DDSD_WIDTH;
5684 ddsd.dwWidth = 16;
5685 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5686 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
5688 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
5689 ddsd.lpSurface = data;
5690 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5691 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
5693 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
5694 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5695 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
5697 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5698 U1(ddsd).lPitch = 16 * 4;
5699 ddsd.dwWidth = 16;
5700 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5701 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5703 reset_ddsd(&ddsd);
5704 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5705 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5706 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5707 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5708 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
5710 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5712 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5713 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5714 U1(ddsd).lPitch = 4 * 4;
5715 ddsd.lpSurface = data;
5716 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5717 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5719 U1(ddsd).lPitch = 4;
5720 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5721 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5723 U1(ddsd).lPitch = 16 * 4 + 1;
5724 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5725 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5727 U1(ddsd).lPitch = 16 * 4 + 3;
5728 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5729 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5731 U1(ddsd).lPitch = -4;
5732 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5733 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
5735 U1(ddsd).lPitch = 16 * 4;
5736 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5737 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5739 reset_ddsd(&ddsd);
5740 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5741 U1(ddsd).lPitch = 0;
5742 ddsd.dwWidth = 16;
5743 ddsd.lpSurface = data;
5744 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5745 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
5747 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5748 U1(ddsd).lPitch = 16 * 4;
5749 ddsd.dwWidth = 0;
5750 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5751 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
5753 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5754 ddsd.dwFlags = DDSD_PIXELFORMAT;
5755 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5756 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5757 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5758 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5759 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5760 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5761 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5762 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
5764 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
5765 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5766 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5768 /* Can't set color keys. */
5769 reset_ddsd(&ddsd);
5770 ddsd.dwFlags = DDSD_CKSRCBLT;
5771 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
5772 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
5773 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5774 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5776 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
5777 ddsd.lpSurface = data;
5778 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5779 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5781 IDirectDrawSurface7_Release(surface);
5783 /* SetSurfaceDesc needs systemmemory surfaces.
5785 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5786 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
5788 reset_ddsd(&ddsd);
5789 ddsd.dwFlags = DDSD_CAPS;
5790 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
5791 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
5792 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5794 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5795 ddsd.dwWidth = 8;
5796 ddsd.dwHeight = 8;
5797 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5798 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5799 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5800 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5801 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5802 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5805 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5806 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW, "Failed to create surface, hr %#x.\n", hr);
5807 if (FAILED(hr))
5809 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5810 invalid_caps_tests[i].name);
5811 goto done;
5814 reset_ddsd(&ddsd);
5815 ddsd.dwFlags = DDSD_LPSURFACE;
5816 ddsd.lpSurface = data;
5817 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5818 if (invalid_caps_tests[i].supported)
5820 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5822 else
5824 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5825 invalid_caps_tests[i].name, hr);
5827 /* Check priority of error conditions. */
5828 ddsd.dwFlags = DDSD_WIDTH;
5829 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5830 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5831 invalid_caps_tests[i].name, hr);
5834 IDirectDrawSurface7_Release(surface);
5837 done:
5838 ref = IDirectDraw7_Release(ddraw);
5839 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5840 DestroyWindow(window);
5843 static void test_user_memory_getdc(void)
5845 IDirectDraw7 *ddraw;
5846 HWND window;
5847 HRESULT hr;
5848 DDSURFACEDESC2 ddsd;
5849 IDirectDrawSurface7 *surface;
5850 DWORD data[16][16];
5851 ULONG ref;
5852 HDC dc;
5853 unsigned int x, y;
5855 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5856 0, 0, 640, 480, 0, 0, 0, 0);
5857 ddraw = create_ddraw();
5858 ok(!!ddraw, "Failed to create a ddraw object.\n");
5859 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5860 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5862 reset_ddsd(&ddsd);
5863 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5864 ddsd.dwWidth = 16;
5865 ddsd.dwHeight = 16;
5866 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5867 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5868 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5869 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5870 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5871 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5872 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5873 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5874 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5876 memset(data, 0xaa, sizeof(data));
5877 reset_ddsd(&ddsd);
5878 ddsd.dwFlags = DDSD_LPSURFACE;
5879 ddsd.lpSurface = data;
5880 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5881 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5883 hr = IDirectDrawSurface7_GetDC(surface, &dc);
5884 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5885 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
5886 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
5887 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
5888 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5890 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
5891 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
5893 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
5894 ddsd.lpSurface = data;
5895 ddsd.dwWidth = 4;
5896 ddsd.dwHeight = 8;
5897 U1(ddsd).lPitch = sizeof(*data);
5898 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5899 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5901 memset(data, 0xaa, sizeof(data));
5902 hr = IDirectDrawSurface7_GetDC(surface, &dc);
5903 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5904 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
5905 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
5906 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
5907 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5909 for (y = 0; y < 4; y++)
5911 for (x = 0; x < 4; x++)
5913 if ((x == 1 || x == 2) && (y == 1 || y == 2))
5914 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5915 x, y, data[y][x]);
5916 else
5917 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
5918 x, y, data[y][x]);
5921 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5922 data[0][5]);
5923 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5924 data[7][3]);
5925 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5926 data[7][4]);
5927 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5928 data[8][0]);
5930 IDirectDrawSurface7_Release(surface);
5931 ref = IDirectDraw7_Release(ddraw);
5932 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5933 DestroyWindow(window);
5936 static void test_sysmem_overlay(void)
5938 IDirectDraw7 *ddraw;
5939 HWND window;
5940 HRESULT hr;
5941 DDSURFACEDESC2 ddsd;
5942 IDirectDrawSurface7 *surface;
5943 ULONG ref;
5945 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5946 0, 0, 640, 480, 0, 0, 0, 0);
5947 ddraw = create_ddraw();
5948 ok(!!ddraw, "Failed to create a ddraw object.\n");
5949 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5950 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5952 reset_ddsd(&ddsd);
5953 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
5954 ddsd.dwWidth = 16;
5955 ddsd.dwHeight = 16;
5956 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
5957 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5958 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5959 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5960 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5961 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5962 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5963 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5964 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
5966 ref = IDirectDraw7_Release(ddraw);
5967 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5968 DestroyWindow(window);
5971 static void test_primary_palette(void)
5973 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
5974 IDirectDrawSurface7 *primary, *backbuffer;
5975 PALETTEENTRY palette_entries[256];
5976 IDirectDrawPalette *palette, *tmp;
5977 DDSURFACEDESC2 surface_desc;
5978 IDirectDraw7 *ddraw;
5979 DWORD palette_caps;
5980 ULONG refcount;
5981 HWND window;
5982 HRESULT hr;
5984 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5985 0, 0, 640, 480, 0, 0, 0, 0);
5986 ddraw = create_ddraw();
5987 ok(!!ddraw, "Failed to create a ddraw object.\n");
5988 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
5990 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5991 IDirectDraw7_Release(ddraw);
5992 DestroyWindow(window);
5993 return;
5995 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5996 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5998 memset(&surface_desc, 0, sizeof(surface_desc));
5999 surface_desc.dwSize = sizeof(surface_desc);
6000 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6001 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6002 U5(surface_desc).dwBackBufferCount = 1;
6003 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6004 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6005 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
6006 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6008 memset(palette_entries, 0, sizeof(palette_entries));
6009 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
6010 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6011 refcount = get_refcount((IUnknown *)palette);
6012 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6014 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6015 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6016 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6018 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6019 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6021 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6022 * and is generally somewhat broken with respect to 8 bpp / palette
6023 * handling. */
6024 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer, &tmp)))
6026 win_skip("Broken palette handling detected, skipping tests.\n");
6027 IDirectDrawPalette_Release(tmp);
6028 IDirectDrawPalette_Release(palette);
6029 /* The Windows 8 testbot keeps extra references to the primary and
6030 * backbuffer while in 8 bpp mode. */
6031 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
6032 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6033 goto done;
6036 refcount = get_refcount((IUnknown *)palette);
6037 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6039 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6040 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6041 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
6042 "Got unexpected palette caps %#x.\n", palette_caps);
6044 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
6045 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6046 refcount = get_refcount((IUnknown *)palette);
6047 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6049 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6050 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6051 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6053 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6054 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6055 refcount = get_refcount((IUnknown *)palette);
6056 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6058 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6059 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6060 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6061 IDirectDrawPalette_Release(tmp);
6062 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
6063 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6065 refcount = IDirectDrawPalette_Release(palette);
6066 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6067 refcount = IDirectDrawPalette_Release(palette);
6068 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6070 /* Note that this only seems to work when the palette is attached to the
6071 * primary surface. When attached to a regular surface, attempting to get
6072 * the palette here will cause an access violation. */
6073 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6074 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6076 done:
6077 refcount = IDirectDrawSurface7_Release(backbuffer);
6078 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6079 refcount = IDirectDrawSurface7_Release(primary);
6080 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6081 refcount = IDirectDraw7_Release(ddraw);
6082 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6083 DestroyWindow(window);
6086 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
6088 UINT *surface_count = context;
6090 ++(*surface_count);
6091 IDirectDrawSurface_Release(surface);
6093 return DDENUMRET_OK;
6096 static void test_surface_attachment(void)
6098 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
6099 IDirectDrawSurface *surface1v1, *surface2v1;
6100 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
6101 DDSURFACEDESC2 surface_desc;
6102 IDirectDraw7 *ddraw;
6103 UINT surface_count;
6104 ULONG refcount;
6105 HWND window;
6106 HRESULT hr;
6108 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6109 0, 0, 640, 480, 0, 0, 0, 0);
6110 ddraw = create_ddraw();
6111 ok(!!ddraw, "Failed to create a ddraw object.\n");
6112 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6113 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6115 memset(&surface_desc, 0, sizeof(surface_desc));
6116 surface_desc.dwSize = sizeof(surface_desc);
6117 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6118 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6119 U2(surface_desc).dwMipMapCount = 3;
6120 surface_desc.dwWidth = 128;
6121 surface_desc.dwHeight = 128;
6122 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
6124 skip("Failed to create a texture, skipping tests.\n");
6125 IDirectDraw7_Release(ddraw);
6126 DestroyWindow(window);
6127 return;
6130 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
6131 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6132 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
6133 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6134 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
6135 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6137 surface_count = 0;
6138 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
6139 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6140 surface_count = 0;
6141 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
6142 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6143 surface_count = 0;
6144 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
6145 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
6147 memset(&surface_desc, 0, sizeof(surface_desc));
6148 surface_desc.dwSize = sizeof(surface_desc);
6149 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6150 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6151 surface_desc.dwWidth = 16;
6152 surface_desc.dwHeight = 16;
6153 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6154 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6156 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6157 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6158 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6159 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6160 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
6161 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6162 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
6163 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6164 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
6165 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6166 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
6167 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6169 IDirectDrawSurface7_Release(surface4);
6171 memset(&surface_desc, 0, sizeof(surface_desc));
6172 surface_desc.dwSize = sizeof(surface_desc);
6173 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6174 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6175 surface_desc.dwWidth = 16;
6176 surface_desc.dwHeight = 16;
6177 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6178 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6180 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6181 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6182 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6183 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6184 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
6185 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6186 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
6187 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6188 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
6189 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6190 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
6191 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6193 IDirectDrawSurface7_Release(surface4);
6194 IDirectDrawSurface7_Release(surface3);
6195 IDirectDrawSurface7_Release(surface2);
6196 IDirectDrawSurface7_Release(surface1);
6198 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6199 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6201 /* Try a single primary and two offscreen plain surfaces. */
6202 memset(&surface_desc, 0, sizeof(surface_desc));
6203 surface_desc.dwSize = sizeof(surface_desc);
6204 surface_desc.dwFlags = DDSD_CAPS;
6205 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6206 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6207 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6209 memset(&surface_desc, 0, sizeof(surface_desc));
6210 surface_desc.dwSize = sizeof(surface_desc);
6211 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6212 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6213 surface_desc.dwWidth = registry_mode.dmPelsWidth;
6214 surface_desc.dwHeight = registry_mode.dmPelsHeight;
6215 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6216 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6218 memset(&surface_desc, 0, sizeof(surface_desc));
6219 surface_desc.dwSize = sizeof(surface_desc);
6220 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6221 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6222 surface_desc.dwWidth = registry_mode.dmPelsWidth;
6223 surface_desc.dwHeight = registry_mode.dmPelsHeight;
6224 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6225 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6227 /* This one has a different size. */
6228 memset(&surface_desc, 0, sizeof(surface_desc));
6229 surface_desc.dwSize = sizeof(surface_desc);
6230 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6231 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6232 surface_desc.dwWidth = 128;
6233 surface_desc.dwHeight = 128;
6234 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6235 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6237 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6238 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6239 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
6240 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6241 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
6242 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6243 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6244 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6245 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6246 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6248 IDirectDrawSurface7_Release(surface4);
6249 IDirectDrawSurface7_Release(surface3);
6250 IDirectDrawSurface7_Release(surface2);
6251 IDirectDrawSurface7_Release(surface1);
6253 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6254 memset(&surface_desc, 0, sizeof(surface_desc));
6255 surface_desc.dwSize = sizeof(surface_desc);
6256 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6257 surface_desc.dwWidth = 64;
6258 surface_desc.dwHeight = 64;
6259 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
6260 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6261 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
6262 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
6263 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
6264 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
6265 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
6266 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6267 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6268 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6269 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6271 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
6272 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
6273 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
6274 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
6275 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6276 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6278 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
6279 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6280 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
6281 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6283 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6284 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6285 refcount = get_refcount((IUnknown *)surface2);
6286 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6287 refcount = get_refcount((IUnknown *)surface2v1);
6288 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6289 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6290 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
6291 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6292 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6293 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6294 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6296 /* Attaching while already attached to other surface. */
6297 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
6298 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6299 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
6300 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6301 IDirectDrawSurface7_Release(surface3);
6303 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
6304 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6305 refcount = get_refcount((IUnknown *)surface2);
6306 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6307 refcount = get_refcount((IUnknown *)surface2v1);
6308 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6310 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6311 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6312 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6313 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
6314 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6315 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6316 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6317 refcount = IDirectDrawSurface7_Release(surface2);
6318 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6319 refcount = IDirectDrawSurface7_Release(surface1);
6320 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6322 /* Automatic detachment on release. */
6323 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6324 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6325 refcount = get_refcount((IUnknown *)surface2v1);
6326 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6327 refcount = IDirectDrawSurface_Release(surface1v1);
6328 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6329 refcount = IDirectDrawSurface_Release(surface2v1);
6330 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6331 refcount = IDirectDraw7_Release(ddraw);
6332 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6333 DestroyWindow(window);
6336 static void test_private_data(void)
6338 IDirectDraw7 *ddraw;
6339 IDirectDrawSurface7 *surface, *surface2;
6340 DDSURFACEDESC2 surface_desc;
6341 ULONG refcount, refcount2, refcount3;
6342 IUnknown *ptr;
6343 DWORD size = sizeof(ptr);
6344 HRESULT hr;
6345 HWND window;
6346 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
6347 DWORD data[] = {1, 2, 3, 4};
6348 DDCAPS hal_caps;
6349 static const GUID ddraw_private_data_test_guid =
6351 0xfdb37466,
6352 0x428f,
6353 0x4edf,
6354 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6356 static const GUID ddraw_private_data_test_guid2 =
6358 0x2e5afac2,
6359 0x87b5,
6360 0x4c10,
6361 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6364 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6365 0, 0, 640, 480, 0, 0, 0, 0);
6366 ddraw = create_ddraw();
6367 ok(!!ddraw, "Failed to create a ddraw object.\n");
6368 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6369 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6371 reset_ddsd(&surface_desc);
6372 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
6373 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
6374 surface_desc.dwHeight = 4;
6375 surface_desc.dwWidth = 4;
6376 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6377 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6379 /* NULL pointers are not valid, but don't cause a crash. */
6380 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
6381 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
6382 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6383 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
6384 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6385 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
6386 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6388 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6389 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6390 0, DDSPD_IUNKNOWNPOINTER);
6391 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6392 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6393 5, DDSPD_IUNKNOWNPOINTER);
6394 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6395 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6396 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
6397 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6399 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6400 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6401 * erases the old content and returns an error. This behavior has
6402 * been fixed in d3d8 and d3d9. Unless an application is found
6403 * that depends on this we don't care about this behavior. */
6404 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6405 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6406 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6407 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6408 0, DDSPD_IUNKNOWNPOINTER);
6409 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6410 size = sizeof(ptr);
6411 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6412 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6413 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
6414 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6416 refcount = get_refcount((IUnknown *)ddraw);
6417 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6418 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6419 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6420 refcount2 = get_refcount((IUnknown *)ddraw);
6421 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6423 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
6424 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6425 refcount2 = get_refcount((IUnknown *)ddraw);
6426 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6428 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6429 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6430 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6431 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
6432 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
6433 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6434 refcount2 = get_refcount((IUnknown *)ddraw);
6435 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6437 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6438 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6439 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6440 size = 2 * sizeof(ptr);
6441 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6442 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6443 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6444 refcount2 = get_refcount(ptr);
6445 /* Object is NOT addref'ed by the getter. */
6446 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
6447 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6449 ptr = (IUnknown *)0xdeadbeef;
6450 size = 1;
6451 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6452 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6453 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6454 size = 2 * sizeof(ptr);
6455 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6456 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6457 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
6458 size = 1;
6459 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6460 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6461 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6462 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6463 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
6464 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6465 size = 0xdeadbabe;
6466 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
6467 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6468 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6469 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
6470 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
6471 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6473 refcount3 = IDirectDrawSurface7_Release(surface);
6474 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
6476 /* Destroying the surface frees the reference held on the private data. It also frees
6477 * the reference the surface is holding on its creating object. */
6478 refcount2 = get_refcount((IUnknown *)ddraw);
6479 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
6481 memset(&hal_caps, 0, sizeof(hal_caps));
6482 hal_caps.dwSize = sizeof(hal_caps);
6483 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6484 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6485 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6487 reset_ddsd(&surface_desc);
6488 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
6489 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6490 surface_desc.dwHeight = 4;
6491 surface_desc.dwWidth = 4;
6492 U2(surface_desc).dwMipMapCount = 2;
6493 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6494 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6495 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
6496 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6498 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
6499 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6500 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
6501 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6503 IDirectDrawSurface7_Release(surface2);
6504 IDirectDrawSurface7_Release(surface);
6506 else
6507 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
6509 refcount = IDirectDraw7_Release(ddraw);
6510 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6511 DestroyWindow(window);
6514 static void test_pixel_format(void)
6516 HWND window, window2 = NULL;
6517 HDC hdc, hdc2 = NULL;
6518 HMODULE gl = NULL;
6519 int format, test_format;
6520 PIXELFORMATDESCRIPTOR pfd;
6521 IDirectDraw7 *ddraw = NULL;
6522 IDirectDrawClipper *clipper = NULL;
6523 DDSURFACEDESC2 ddsd;
6524 IDirectDrawSurface7 *primary = NULL;
6525 DDBLTFX fx;
6526 HRESULT hr;
6528 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6529 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6530 if (!window)
6532 skip("Failed to create window\n");
6533 return;
6536 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6537 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6539 hdc = GetDC(window);
6540 if (!hdc)
6542 skip("Failed to get DC\n");
6543 goto cleanup;
6546 if (window2)
6547 hdc2 = GetDC(window2);
6549 gl = LoadLibraryA("opengl32.dll");
6550 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6552 format = GetPixelFormat(hdc);
6553 ok(format == 0, "new window has pixel format %d\n", format);
6555 ZeroMemory(&pfd, sizeof(pfd));
6556 pfd.nSize = sizeof(pfd);
6557 pfd.nVersion = 1;
6558 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
6559 pfd.iPixelType = PFD_TYPE_RGBA;
6560 pfd.iLayerType = PFD_MAIN_PLANE;
6561 format = ChoosePixelFormat(hdc, &pfd);
6562 if (format <= 0)
6564 skip("no pixel format available\n");
6565 goto cleanup;
6568 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
6570 skip("failed to set pixel format\n");
6571 goto cleanup;
6574 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
6576 skip("failed to set pixel format on second window\n");
6577 if (hdc2)
6579 ReleaseDC(window2, hdc2);
6580 hdc2 = NULL;
6584 ddraw = create_ddraw();
6585 ok(!!ddraw, "Failed to create a ddraw object.\n");
6587 test_format = GetPixelFormat(hdc);
6588 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6590 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6591 if (FAILED(hr))
6593 skip("Failed to set cooperative level, hr %#x.\n", hr);
6594 goto cleanup;
6597 test_format = GetPixelFormat(hdc);
6598 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6600 if (hdc2)
6602 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
6603 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
6604 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
6605 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
6607 test_format = GetPixelFormat(hdc);
6608 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6610 test_format = GetPixelFormat(hdc2);
6611 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6614 memset(&ddsd, 0, sizeof(ddsd));
6615 ddsd.dwSize = sizeof(ddsd);
6616 ddsd.dwFlags = DDSD_CAPS;
6617 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6619 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
6620 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
6622 test_format = GetPixelFormat(hdc);
6623 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6625 if (hdc2)
6627 test_format = GetPixelFormat(hdc2);
6628 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6631 if (clipper)
6633 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
6634 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
6636 test_format = GetPixelFormat(hdc);
6637 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6639 test_format = GetPixelFormat(hdc2);
6640 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6643 memset(&fx, 0, sizeof(fx));
6644 fx.dwSize = sizeof(fx);
6645 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6646 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
6648 test_format = GetPixelFormat(hdc);
6649 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6651 if (hdc2)
6653 test_format = GetPixelFormat(hdc2);
6654 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6657 cleanup:
6658 if (primary) IDirectDrawSurface7_Release(primary);
6659 if (clipper) IDirectDrawClipper_Release(clipper);
6660 if (ddraw) IDirectDraw7_Release(ddraw);
6661 if (gl) FreeLibrary(gl);
6662 if (hdc) ReleaseDC(window, hdc);
6663 if (hdc2) ReleaseDC(window2, hdc2);
6664 if (window) DestroyWindow(window);
6665 if (window2) DestroyWindow(window2);
6668 static void test_create_surface_pitch(void)
6670 IDirectDrawSurface7 *surface;
6671 DDSURFACEDESC2 surface_desc;
6672 IDirectDraw7 *ddraw;
6673 unsigned int i;
6674 ULONG refcount;
6675 HWND window;
6676 HRESULT hr;
6677 void *mem;
6679 static const struct
6681 DWORD placement;
6682 DWORD flags_in;
6683 DWORD pitch_in;
6684 HRESULT hr;
6685 DWORD flags_out;
6686 DWORD pitch_out32;
6687 DWORD pitch_out64;
6689 test_data[] =
6691 {DDSCAPS_VIDEOMEMORY, 0, 0, DD_OK,
6692 DDSD_PITCH, 0x100, 0x100},
6693 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x104, DD_OK,
6694 DDSD_PITCH, 0x100, 0x100},
6695 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
6696 DDSD_PITCH, 0x100, 0x100},
6697 {DDSCAPS_VIDEOMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
6698 0, 0, 0 },
6699 {DDSCAPS_SYSTEMMEMORY, 0, 0, DD_OK,
6700 DDSD_PITCH, 0x100, 0x0fc},
6701 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x104, DD_OK,
6702 DDSD_PITCH, 0x100, 0x0fc},
6703 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
6704 DDSD_PITCH, 0x100, 0x0fc},
6705 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
6706 DDSD_PITCH, 0x100, 0x0fc},
6707 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
6708 0, 0, 0 },
6709 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
6710 DDSD_PITCH, 0x100, 0x100},
6711 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
6712 0, 0, 0 },
6713 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
6714 DDSD_PITCH, 0x0fc, 0x0fc},
6715 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
6716 0, 0, 0 },
6717 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
6718 0, 0, 0 },
6719 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
6720 0, 0, 0 },
6721 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
6722 DDSD_PITCH, 0x100, 0x100},
6724 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
6726 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6727 0, 0, 640, 480, 0, 0, 0, 0);
6728 ddraw = create_ddraw();
6729 ok(!!ddraw, "Failed to create a ddraw object.\n");
6730 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6731 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6733 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
6735 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
6737 memset(&surface_desc, 0, sizeof(surface_desc));
6738 surface_desc.dwSize = sizeof(surface_desc);
6739 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
6740 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | test_data[i].placement;
6741 surface_desc.dwWidth = 63;
6742 surface_desc.dwHeight = 63;
6743 U1(surface_desc).lPitch = test_data[i].pitch_in;
6744 surface_desc.lpSurface = mem;
6745 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6746 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
6747 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6748 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6749 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6750 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6751 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6752 ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
6753 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
6754 if (FAILED(hr))
6755 continue;
6757 memset(&surface_desc, 0, sizeof(surface_desc));
6758 surface_desc.dwSize = sizeof(surface_desc);
6759 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
6760 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
6761 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
6762 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6763 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
6764 if (sizeof(void *) != sizeof(DWORD) && test_data[i].pitch_out32 != test_data[i].pitch_out64)
6765 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
6766 "Test %u: Got unexpected pitch %u, expected %u.\n",
6767 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
6768 else
6769 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
6770 "Test %u: Got unexpected pitch %u, expected %u.\n",
6771 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
6772 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
6774 IDirectDrawSurface7_Release(surface);
6777 HeapFree(GetProcessHeap(), 0, mem);
6778 refcount = IDirectDraw7_Release(ddraw);
6779 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6780 DestroyWindow(window);
6783 static void test_mipmap_lock(void)
6785 IDirectDrawSurface7 *surface, *surface2;
6786 DDSURFACEDESC2 surface_desc;
6787 IDirectDraw7 *ddraw;
6788 ULONG refcount;
6789 HWND window;
6790 HRESULT hr;
6791 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
6792 DDCAPS hal_caps;
6794 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6795 0, 0, 640, 480, 0, 0, 0, 0);
6796 ddraw = create_ddraw();
6797 ok(!!ddraw, "Failed to create a ddraw object.\n");
6798 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6799 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6801 memset(&hal_caps, 0, sizeof(hal_caps));
6802 hal_caps.dwSize = sizeof(hal_caps);
6803 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6804 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6805 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6807 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6808 IDirectDraw7_Release(ddraw);
6809 DestroyWindow(window);
6810 return;
6813 memset(&surface_desc, 0, sizeof(surface_desc));
6814 surface_desc.dwSize = sizeof(surface_desc);
6815 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6816 surface_desc.dwWidth = 4;
6817 surface_desc.dwHeight = 4;
6818 U2(surface_desc).dwMipMapCount = 2;
6819 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
6820 | DDSCAPS_SYSTEMMEMORY;
6821 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6822 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6823 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
6824 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6826 memset(&surface_desc, 0, sizeof(surface_desc));
6827 surface_desc.dwSize = sizeof(surface_desc);
6828 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
6829 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6830 memset(&surface_desc, 0, sizeof(surface_desc));
6831 surface_desc.dwSize = sizeof(surface_desc);
6832 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
6833 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6834 IDirectDrawSurface7_Unlock(surface2, NULL);
6835 IDirectDrawSurface7_Unlock(surface, NULL);
6837 IDirectDrawSurface7_Release(surface2);
6838 IDirectDrawSurface7_Release(surface);
6839 refcount = IDirectDraw7_Release(ddraw);
6840 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6841 DestroyWindow(window);
6844 static void test_palette_complex(void)
6846 IDirectDrawSurface7 *surface, *mipmap, *tmp;
6847 DDSURFACEDESC2 surface_desc;
6848 IDirectDraw7 *ddraw;
6849 IDirectDrawPalette *palette, *palette2;
6850 ULONG refcount;
6851 HWND window;
6852 HRESULT hr;
6853 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
6854 DDCAPS hal_caps;
6855 PALETTEENTRY palette_entries[256];
6856 unsigned int i;
6858 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6859 0, 0, 640, 480, 0, 0, 0, 0);
6860 ddraw = create_ddraw();
6861 ok(!!ddraw, "Failed to create a ddraw object.\n");
6862 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6863 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6865 memset(&hal_caps, 0, sizeof(hal_caps));
6866 hal_caps.dwSize = sizeof(hal_caps);
6867 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6868 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6869 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6871 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6872 IDirectDraw7_Release(ddraw);
6873 DestroyWindow(window);
6874 return;
6877 memset(&surface_desc, 0, sizeof(surface_desc));
6878 surface_desc.dwSize = sizeof(surface_desc);
6879 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6880 surface_desc.dwWidth = 128;
6881 surface_desc.dwHeight = 128;
6882 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6883 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6884 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
6885 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
6886 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6887 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6889 memset(palette_entries, 0, sizeof(palette_entries));
6890 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6891 palette_entries, &palette, NULL);
6892 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6894 palette2 = (void *)0xdeadbeef;
6895 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
6896 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6897 ok(!palette2, "Got unexpected palette %p.\n", palette2);
6898 hr = IDirectDrawSurface7_SetPalette(surface, palette);
6899 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6900 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
6901 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6902 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
6903 IDirectDrawPalette_Release(palette2);
6905 mipmap = surface;
6906 IDirectDrawSurface7_AddRef(mipmap);
6907 for (i = 0; i < 7; ++i)
6909 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
6910 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
6911 palette2 = (void *)0xdeadbeef;
6912 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
6913 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
6914 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
6916 hr = IDirectDrawSurface7_SetPalette(tmp, palette);
6917 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
6919 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
6920 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
6921 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
6923 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
6924 * ddraw versions. Combined with the test results above this means no
6925 * palette is available. So depending on the driver either GetDC fails
6926 * or the DIB color table contains random data. */
6928 IDirectDrawSurface7_Release(mipmap);
6929 mipmap = tmp;
6932 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
6933 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6934 IDirectDrawSurface7_Release(mipmap);
6935 refcount = IDirectDrawSurface7_Release(surface);
6936 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6938 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
6939 memset(&surface_desc, 0, sizeof(surface_desc));
6940 surface_desc.dwSize = sizeof(surface_desc);
6941 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6942 surface_desc.dwWidth = 128;
6943 surface_desc.dwHeight = 128;
6944 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6945 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6946 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
6947 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6948 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6949 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6950 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6951 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6952 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6954 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
6955 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6956 hr = IDirectDrawSurface7_SetPalette(mipmap, palette);
6957 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x.\n", hr);
6959 IDirectDrawSurface7_Release(mipmap);
6960 refcount = IDirectDrawSurface7_Release(surface);
6961 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6962 refcount = IDirectDrawPalette_Release(palette);
6963 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6965 refcount = IDirectDraw7_Release(ddraw);
6966 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6967 DestroyWindow(window);
6970 static void test_p8_rgb_blit(void)
6972 IDirectDrawSurface7 *src, *dst;
6973 DDSURFACEDESC2 surface_desc;
6974 IDirectDraw7 *ddraw;
6975 IDirectDrawPalette *palette;
6976 ULONG refcount;
6977 HWND window;
6978 HRESULT hr;
6979 PALETTEENTRY palette_entries[256];
6980 unsigned int x;
6981 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6982 static const D3DCOLOR expected[] =
6984 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6985 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6987 D3DCOLOR color;
6989 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6990 0, 0, 640, 480, 0, 0, 0, 0);
6991 ddraw = create_ddraw();
6992 ok(!!ddraw, "Failed to create a ddraw object.\n");
6993 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6994 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6996 memset(palette_entries, 0, sizeof(palette_entries));
6997 palette_entries[1].peGreen = 0xff;
6998 palette_entries[2].peBlue = 0xff;
6999 palette_entries[3].peFlags = 0xff;
7000 palette_entries[4].peRed = 0xff;
7001 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7002 palette_entries, &palette, NULL);
7003 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7005 memset(&surface_desc, 0, sizeof(surface_desc));
7006 surface_desc.dwSize = sizeof(surface_desc);
7007 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7008 surface_desc.dwWidth = 8;
7009 surface_desc.dwHeight = 1;
7010 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7011 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7012 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7013 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7014 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
7015 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7017 memset(&surface_desc, 0, sizeof(surface_desc));
7018 surface_desc.dwSize = sizeof(surface_desc);
7019 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7020 surface_desc.dwWidth = 8;
7021 surface_desc.dwHeight = 1;
7022 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7023 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7024 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
7025 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7026 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7027 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7028 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7029 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
7030 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
7031 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7033 memset(&surface_desc, 0, sizeof(surface_desc));
7034 surface_desc.dwSize = sizeof(surface_desc);
7035 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, 0, NULL);
7036 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
7037 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
7038 hr = IDirectDrawSurface7_Unlock(src, NULL);
7039 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
7041 hr = IDirectDrawSurface7_SetPalette(src, palette);
7042 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7043 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
7044 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7045 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7046 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
7047 "Failed to blit, hr %#x.\n", hr);
7049 if (SUCCEEDED(hr))
7051 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
7053 color = get_surface_color(dst, x, 0);
7054 todo_wine ok(compare_color(color, expected[x], 0),
7055 "Pixel %u: Got color %#x, expected %#x.\n",
7056 x, color, expected[x]);
7060 IDirectDrawSurface7_Release(src);
7061 IDirectDrawSurface7_Release(dst);
7062 IDirectDrawPalette_Release(palette);
7064 refcount = IDirectDraw7_Release(ddraw);
7065 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7066 DestroyWindow(window);
7069 static void test_material(void)
7071 static const D3DCOLORVALUE null_color;
7072 IDirect3DDevice7 *device;
7073 D3DMATERIAL7 material;
7074 ULONG refcount;
7075 HWND window;
7076 HRESULT hr;
7078 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7079 0, 0, 640, 480, 0, 0, 0, 0);
7080 if (!(device = create_device(window, DDSCL_NORMAL)))
7082 skip("Failed to create a 3D device, skipping test.\n");
7083 DestroyWindow(window);
7084 return;
7087 hr = IDirect3DDevice7_GetMaterial(device, &material);
7088 ok(SUCCEEDED(hr), "Failed to get material, hr %#x.\n", hr);
7089 ok(!memcmp(&U(material).diffuse, &null_color, sizeof(null_color)),
7090 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
7091 U1(U(material).diffuse).r, U2(U(material).diffuse).g,
7092 U3(U(material).diffuse).b, U4(U(material).diffuse).a);
7093 ok(!memcmp(&U1(material).ambient, &null_color, sizeof(null_color)),
7094 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
7095 U1(U1(material).ambient).r, U2(U1(material).ambient).g,
7096 U3(U1(material).ambient).b, U4(U1(material).ambient).a);
7097 ok(!memcmp(&U2(material).specular, &null_color, sizeof(null_color)),
7098 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
7099 U1(U2(material).specular).r, U2(U2(material).specular).g,
7100 U3(U2(material).specular).b, U4(U2(material).specular).a);
7101 ok(!memcmp(&U3(material).emissive, &null_color, sizeof(null_color)),
7102 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
7103 U1(U3(material).emissive).r, U2(U3(material).emissive).g,
7104 U3(U3(material).emissive).b, U4(U3(material).emissive).a);
7105 ok(U4(material).power == 0.0f, "Got unexpected power %.8e.\n", U4(material).power);
7107 refcount = IDirect3DDevice7_Release(device);
7108 ok(!refcount, "Device has %u references left.\n", refcount);
7109 DestroyWindow(window);
7112 static void test_palette_gdi(void)
7114 IDirectDrawSurface7 *surface, *primary;
7115 DDSURFACEDESC2 surface_desc;
7116 IDirectDraw7 *ddraw;
7117 IDirectDrawPalette *palette, *palette2;
7118 ULONG refcount;
7119 HWND window;
7120 HRESULT hr;
7121 PALETTEENTRY palette_entries[256];
7122 UINT i;
7123 HDC dc;
7124 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7125 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7126 * not the point of this test. */
7127 static const RGBQUAD expected1[] =
7129 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7130 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7132 static const RGBQUAD expected2[] =
7134 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7135 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7137 static const RGBQUAD expected3[] =
7139 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7140 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7142 HPALETTE ddraw_palette_handle;
7143 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7144 RGBQUAD rgbquad[255];
7145 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
7147 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7148 0, 0, 640, 480, 0, 0, 0, 0);
7149 ddraw = create_ddraw();
7150 ok(!!ddraw, "Failed to create a ddraw object.\n");
7151 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7152 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7154 memset(&surface_desc, 0, sizeof(surface_desc));
7155 surface_desc.dwSize = sizeof(surface_desc);
7156 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7157 surface_desc.dwWidth = 16;
7158 surface_desc.dwHeight = 16;
7159 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7160 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7161 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7162 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7163 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7164 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7166 /* Avoid colors from the Windows default palette. */
7167 memset(palette_entries, 0, sizeof(palette_entries));
7168 palette_entries[1].peRed = 0x01;
7169 palette_entries[2].peGreen = 0x02;
7170 palette_entries[3].peBlue = 0x03;
7171 palette_entries[4].peRed = 0x13;
7172 palette_entries[4].peGreen = 0x14;
7173 palette_entries[4].peBlue = 0x15;
7174 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7175 palette_entries, &palette, NULL);
7176 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7178 /* If there is no palette assigned and the display mode is not 8 bpp, some
7179 * drivers refuse to create a DC while others allow it. If a DC is created,
7180 * the DIB color table is uninitialized and contains random colors. No error
7181 * is generated when trying to read pixels and random garbage is returned.
7183 * The most likely explanation is that if the driver creates a DC, it (or
7184 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7185 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7186 * contains uninitialized garbage. See comments below for the P8 case. */
7188 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7189 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7190 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7191 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7192 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7193 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
7194 "Got unexpected palette %p, expected %p.\n",
7195 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7197 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7198 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7199 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
7201 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
7202 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7203 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7204 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
7206 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7208 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7209 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7210 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7213 /* Update the palette while the DC is in use. This does not modify the DC. */
7214 palette_entries[4].peRed = 0x23;
7215 palette_entries[4].peGreen = 0x24;
7216 palette_entries[4].peBlue = 0x25;
7217 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
7218 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
7220 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7221 ok(i == 1, "Expected count 1, got %u.\n", i);
7222 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7223 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7224 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7225 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7227 /* Neither does re-setting the palette. */
7228 hr = IDirectDrawSurface7_SetPalette(surface, NULL);
7229 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7230 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7231 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7233 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7234 ok(i == 1, "Expected count 1, got %u.\n", i);
7235 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7236 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7237 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7238 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7240 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7241 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7243 /* Refresh the DC. This updates the palette. */
7244 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7245 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7246 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7247 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7248 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7250 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7251 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7252 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7253 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7255 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7257 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7258 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7259 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7261 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7262 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7264 refcount = IDirectDrawSurface7_Release(surface);
7265 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7267 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7269 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7270 IDirectDrawPalette_Release(palette);
7271 IDirectDraw7_Release(ddraw);
7272 DestroyWindow(window);
7273 return;
7275 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
7276 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
7277 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7279 memset(&surface_desc, 0, sizeof(surface_desc));
7280 surface_desc.dwSize = sizeof(surface_desc);
7281 surface_desc.dwFlags = DDSD_CAPS;
7282 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7283 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
7284 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7286 hr = IDirectDrawSurface7_SetPalette(primary, palette);
7287 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7288 hr = IDirectDrawSurface7_GetDC(primary, &dc);
7289 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7290 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7291 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7292 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE) || broken(TRUE),
7293 "Got unexpected palette %p, expected %p.\n",
7294 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7295 SelectPalette(dc, ddraw_palette_handle, FALSE);
7297 /* The primary uses the system palette. In exclusive mode, the system palette matches
7298 * the ddraw palette attached to the primary, so the result is what you would expect
7299 * from a regular surface. Tests for the interaction between the ddraw palette and
7300 * the system palette are not included pending an application that depends on this.
7301 * The relation between those causes problems on Windows Vista and newer for games
7302 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
7303 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7304 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7305 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7307 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7308 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7309 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7310 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7312 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7314 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7315 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7316 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7318 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
7319 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7321 memset(&surface_desc, 0, sizeof(surface_desc));
7322 surface_desc.dwSize = sizeof(surface_desc);
7323 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7324 surface_desc.dwWidth = 16;
7325 surface_desc.dwHeight = 16;
7326 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7327 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7328 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7330 /* Here the offscreen surface appears to use the primary's palette,
7331 * but in all likelihood it is actually the system palette. */
7332 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7333 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7334 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7335 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7336 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7338 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7339 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7340 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7341 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7343 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7345 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7346 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7347 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7349 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7350 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7352 /* On real hardware a change to the primary surface's palette applies immediately,
7353 * even on device contexts from offscreen surfaces that do not have their own
7354 * palette. On the testbot VMs this is not the case. Don't test this until we
7355 * know of an application that depends on this. */
7357 memset(palette_entries, 0, sizeof(palette_entries));
7358 palette_entries[1].peBlue = 0x40;
7359 palette_entries[2].peRed = 0x40;
7360 palette_entries[3].peGreen = 0x40;
7361 palette_entries[4].peRed = 0x12;
7362 palette_entries[4].peGreen = 0x34;
7363 palette_entries[4].peBlue = 0x56;
7364 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7365 palette_entries, &palette2, NULL);
7366 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7367 hr = IDirectDrawSurface7_SetPalette(surface, palette2);
7368 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7370 /* A palette assigned to the offscreen surface overrides the primary / system
7371 * palette. */
7372 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7373 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7374 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7375 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7376 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
7378 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
7379 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7380 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7381 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
7383 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7385 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7386 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7387 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7389 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7390 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7392 refcount = IDirectDrawSurface7_Release(surface);
7393 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7395 /* The Windows 8 testbot keeps extra references to the primary and
7396 * backbuffer while in 8 bpp mode. */
7397 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
7398 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7400 refcount = IDirectDrawSurface7_Release(primary);
7401 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7402 refcount = IDirectDrawPalette_Release(palette2);
7403 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7404 refcount = IDirectDrawPalette_Release(palette);
7405 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7406 refcount = IDirectDraw7_Release(ddraw);
7407 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7408 DestroyWindow(window);
7411 static void test_palette_alpha(void)
7413 IDirectDrawSurface7 *surface;
7414 DDSURFACEDESC2 surface_desc;
7415 IDirectDraw7 *ddraw;
7416 IDirectDrawPalette *palette;
7417 ULONG refcount;
7418 HWND window;
7419 HRESULT hr;
7420 PALETTEENTRY palette_entries[256];
7421 unsigned int i;
7422 static const struct
7424 DWORD caps, flags;
7425 BOOL attach_allowed;
7426 const char *name;
7428 test_data[] =
7430 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
7431 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
7432 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
7435 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7436 0, 0, 640, 480, 0, 0, 0, 0);
7437 ddraw = create_ddraw();
7438 ok(!!ddraw, "Failed to create a ddraw object.\n");
7439 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7441 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7442 IDirectDraw7_Release(ddraw);
7443 DestroyWindow(window);
7444 return;
7446 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7447 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7449 memset(palette_entries, 0, sizeof(palette_entries));
7450 palette_entries[1].peFlags = 0x42;
7451 palette_entries[2].peFlags = 0xff;
7452 palette_entries[3].peFlags = 0x80;
7453 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
7454 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7456 memset(palette_entries, 0x66, sizeof(palette_entries));
7457 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
7458 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
7459 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7460 palette_entries[0].peFlags);
7461 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7462 palette_entries[1].peFlags);
7463 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7464 palette_entries[2].peFlags);
7465 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7466 palette_entries[3].peFlags);
7468 IDirectDrawPalette_Release(palette);
7470 memset(palette_entries, 0, sizeof(palette_entries));
7471 palette_entries[1].peFlags = 0x42;
7472 palette_entries[1].peRed = 0xff;
7473 palette_entries[2].peFlags = 0xff;
7474 palette_entries[3].peFlags = 0x80;
7475 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
7476 palette_entries, &palette, NULL);
7477 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7479 memset(palette_entries, 0x66, sizeof(palette_entries));
7480 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
7481 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
7482 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7483 palette_entries[0].peFlags);
7484 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7485 palette_entries[1].peFlags);
7486 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7487 palette_entries[2].peFlags);
7488 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7489 palette_entries[3].peFlags);
7491 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7493 memset(&surface_desc, 0, sizeof(surface_desc));
7494 surface_desc.dwSize = sizeof(surface_desc);
7495 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
7496 surface_desc.dwWidth = 128;
7497 surface_desc.dwHeight = 128;
7498 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7499 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7500 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
7502 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7503 if (test_data[i].attach_allowed)
7504 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
7505 else
7506 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
7508 if (SUCCEEDED(hr))
7510 HDC dc;
7511 RGBQUAD rgbquad;
7512 UINT retval;
7514 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7515 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
7516 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
7517 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
7518 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7519 rgbquad.rgbRed, test_data[i].name);
7520 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7521 rgbquad.rgbGreen, test_data[i].name);
7522 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7523 rgbquad.rgbBlue, test_data[i].name);
7524 todo_wine ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7525 rgbquad.rgbReserved, test_data[i].name);
7526 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7527 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7529 IDirectDrawSurface7_Release(surface);
7532 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7533 memset(&surface_desc, 0, sizeof(surface_desc));
7534 surface_desc.dwSize = sizeof(surface_desc);
7535 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7536 surface_desc.dwWidth = 128;
7537 surface_desc.dwHeight = 128;
7538 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7539 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7540 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7541 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7542 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7543 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7544 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7545 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7546 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7547 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7548 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
7549 IDirectDrawSurface7_Release(surface);
7551 /* The Windows 8 testbot keeps extra references to the primary
7552 * while in 8 bpp mode. */
7553 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
7554 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7556 refcount = IDirectDrawPalette_Release(palette);
7557 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7558 refcount = IDirectDraw7_Release(ddraw);
7559 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7560 DestroyWindow(window);
7563 static void test_vb_writeonly(void)
7565 IDirect3DDevice7 *device;
7566 IDirect3D7 *d3d;
7567 IDirect3DVertexBuffer7 *buffer;
7568 HWND window;
7569 HRESULT hr;
7570 D3DVERTEXBUFFERDESC desc;
7571 void *ptr;
7572 static const struct vec4 quad[] =
7574 { 0.0f, 480.0f, 0.0f, 1.0f},
7575 { 0.0f, 0.0f, 0.0f, 1.0f},
7576 {640.0f, 480.0f, 0.0f, 1.0f},
7577 {640.0f, 0.0f, 0.0f, 1.0f},
7580 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7581 0, 0, 640, 480, 0, 0, 0, 0);
7583 if (!(device = create_device(window, DDSCL_NORMAL)))
7585 skip("Failed to create a 3D device, skipping test.\n");
7586 DestroyWindow(window);
7587 return;
7590 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
7591 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
7593 memset(&desc, 0, sizeof(desc));
7594 desc.dwSize = sizeof(desc);
7595 desc.dwCaps = D3DVBCAPS_WRITEONLY;
7596 desc.dwFVF = D3DFVF_XYZRHW;
7597 desc.dwNumVertices = sizeof(quad) / sizeof(*quad);
7598 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
7599 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
7601 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
7602 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7603 memcpy(ptr, quad, sizeof(quad));
7604 hr = IDirect3DVertexBuffer7_Unlock(buffer);
7605 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7607 hr = IDirect3DDevice7_BeginScene(device);
7608 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7609 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
7610 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7611 hr = IDirect3DDevice7_EndScene(device);
7612 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7614 hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL);
7615 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7616 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7617 hr = IDirect3DVertexBuffer7_Unlock(buffer);
7618 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7620 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
7621 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7622 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7623 hr = IDirect3DVertexBuffer7_Unlock(buffer);
7624 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7626 IDirect3DVertexBuffer7_Release(buffer);
7627 IDirect3D7_Release(d3d);
7628 IDirect3DDevice7_Release(device);
7629 DestroyWindow(window);
7632 static void test_lost_device(void)
7634 IDirectDrawSurface7 *surface;
7635 DDSURFACEDESC2 surface_desc;
7636 IDirectDraw7 *ddraw;
7637 ULONG refcount;
7638 HWND window;
7639 HRESULT hr;
7640 BOOL ret;
7642 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7643 0, 0, 640, 480, 0, 0, 0, 0);
7644 ddraw = create_ddraw();
7645 ok(!!ddraw, "Failed to create a ddraw object.\n");
7646 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7647 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7649 memset(&surface_desc, 0, sizeof(surface_desc));
7650 surface_desc.dwSize = sizeof(surface_desc);
7651 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
7652 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
7653 U5(surface_desc).dwBackBufferCount = 1;
7654 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7655 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7657 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7658 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7659 hr = IDirectDrawSurface7_IsLost(surface);
7660 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7661 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7662 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7664 ret = SetForegroundWindow(GetDesktopWindow());
7665 ok(ret, "Failed to set foreground window.\n");
7666 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7667 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
7668 hr = IDirectDrawSurface7_IsLost(surface);
7669 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7670 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7671 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7673 ret = SetForegroundWindow(window);
7674 ok(ret, "Failed to set foreground window.\n");
7675 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7676 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7677 hr = IDirectDrawSurface7_IsLost(surface);
7678 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7679 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7680 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7682 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
7683 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7684 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7685 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7686 hr = IDirectDrawSurface7_IsLost(surface);
7687 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7688 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7689 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7691 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7692 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7693 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7694 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7695 hr = IDirectDrawSurface7_IsLost(surface);
7696 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7697 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7698 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7700 /* Trying to restore the primary will crash, probably because flippable
7701 * surfaces can't exist in DDSCL_NORMAL. */
7702 IDirectDrawSurface7_Release(surface);
7703 memset(&surface_desc, 0, sizeof(surface_desc));
7704 surface_desc.dwSize = sizeof(surface_desc);
7705 surface_desc.dwFlags = DDSD_CAPS;
7706 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7707 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7708 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7710 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7711 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7712 hr = IDirectDrawSurface7_IsLost(surface);
7713 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7715 ret = SetForegroundWindow(GetDesktopWindow());
7716 ok(ret, "Failed to set foreground window.\n");
7717 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7718 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7719 hr = IDirectDrawSurface7_IsLost(surface);
7720 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7722 ret = SetForegroundWindow(window);
7723 ok(ret, "Failed to set foreground window.\n");
7724 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7725 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7726 hr = IDirectDrawSurface7_IsLost(surface);
7727 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7729 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7730 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7731 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7732 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7733 hr = IDirectDrawSurface7_IsLost(surface);
7734 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7736 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
7737 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7738 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7739 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7740 hr = IDirectDrawSurface7_IsLost(surface);
7741 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7743 IDirectDrawSurface7_Release(surface);
7744 refcount = IDirectDraw7_Release(ddraw);
7745 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7746 DestroyWindow(window);
7749 static void test_resource_priority(void)
7751 IDirectDrawSurface7 *surface, *mipmap;
7752 DDSURFACEDESC2 surface_desc;
7753 IDirectDraw7 *ddraw;
7754 ULONG refcount;
7755 HWND window;
7756 HRESULT hr;
7757 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7758 DDCAPS hal_caps;
7759 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_MIPMAP;
7760 unsigned int i;
7761 DWORD priority;
7762 static const struct
7764 DWORD caps, caps2;
7765 const char *name;
7766 HRESULT hr;
7767 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
7768 BOOL crash;
7770 test_data[] =
7772 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS, FALSE},
7773 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS, FALSE},
7774 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK, FALSE},
7775 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, "managed texture", DD_OK, FALSE},
7776 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
7777 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
7780 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7781 0, 0, 640, 480, 0, 0, 0, 0);
7782 ddraw = create_ddraw();
7783 ok(!!ddraw, "Failed to create a ddraw object.\n");
7784 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7785 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7787 memset(&hal_caps, 0, sizeof(hal_caps));
7788 hal_caps.dwSize = sizeof(hal_caps);
7789 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7790 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7791 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
7792 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
7794 skip("Required surface types not supported, skipping test.\n");
7795 goto done;
7798 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7800 memset(&surface_desc, 0, sizeof(surface_desc));
7801 surface_desc.dwSize = sizeof(surface_desc);
7802 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
7803 surface_desc.dwWidth = 32;
7804 surface_desc.dwHeight = 32;
7805 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7806 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2;
7807 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7808 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, test_data[i].name);
7810 /* Priority == NULL segfaults. */
7811 priority = 0xdeadbeef;
7812 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
7813 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7814 if (SUCCEEDED(test_data[i].hr))
7815 ok(priority == 0, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7816 else
7817 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7819 if (!test_data[i].crash)
7821 hr = IDirectDrawSurface7_SetPriority(surface, 1);
7822 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7823 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
7824 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7825 if (SUCCEEDED(test_data[i].hr))
7827 ok(priority == 1, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7828 hr = IDirectDrawSurface7_SetPriority(surface, 2);
7829 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7831 else
7832 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7835 IDirectDrawSurface7_Release(surface);
7838 memset(&surface_desc, 0, sizeof(surface_desc));
7839 surface_desc.dwSize = sizeof(surface_desc);
7840 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
7841 surface_desc.dwWidth = 32;
7842 surface_desc.dwHeight = 32;
7843 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7844 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
7845 U2(surface_desc).dwMipMapCount = 2;
7846 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7847 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7848 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
7849 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7851 priority = 0xdeadbeef;
7852 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
7853 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type managed mipmap.\n", hr);
7854 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority);
7855 /* SetPriority on the mipmap surface crashes. */
7856 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
7857 ok(SUCCEEDED(hr), "Failed to get priority, hr %#x.\n", hr);
7858 ok(priority == 0, "Got unexpected priority %u, type managed mipmap.\n", priority);
7860 IDirectDrawSurface7_Release(mipmap);
7861 refcount = IDirectDrawSurface7_Release(surface);
7862 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7864 done:
7865 refcount = IDirectDraw7_Release(ddraw);
7866 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7867 DestroyWindow(window);
7870 static void test_surface_desc_lock(void)
7872 IDirectDrawSurface7 *surface;
7873 DDSURFACEDESC2 surface_desc;
7874 IDirectDraw7 *ddraw;
7875 ULONG refcount;
7876 HWND window;
7877 HRESULT hr;
7879 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7880 0, 0, 640, 480, 0, 0, 0, 0);
7881 ddraw = create_ddraw();
7882 ok(!!ddraw, "Failed to create a ddraw object.\n");
7883 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7884 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7886 memset(&surface_desc, 0, sizeof(surface_desc));
7887 surface_desc.dwSize = sizeof(surface_desc);
7888 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7889 surface_desc.dwWidth = 16;
7890 surface_desc.dwHeight = 16;
7891 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7892 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7893 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7895 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7896 surface_desc.dwSize = sizeof(surface_desc);
7897 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7898 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
7899 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7901 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7902 surface_desc.dwSize = sizeof(surface_desc);
7903 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
7904 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7905 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7906 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7907 surface_desc.dwSize = sizeof(surface_desc);
7908 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7909 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
7910 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7911 hr = IDirectDrawSurface7_Unlock(surface, NULL);
7912 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7914 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7915 surface_desc.dwSize = sizeof(surface_desc);
7916 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7917 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
7918 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7920 IDirectDrawSurface7_Release(surface);
7921 refcount = IDirectDraw7_Release(ddraw);
7922 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7923 DestroyWindow(window);
7926 static void test_fog_interpolation(void)
7928 HRESULT hr;
7929 IDirect3DDevice7 *device;
7930 IDirectDrawSurface7 *rt;
7931 ULONG refcount;
7932 HWND window;
7933 D3DCOLOR color;
7934 static struct
7936 struct vec3 position;
7937 D3DCOLOR diffuse;
7938 D3DCOLOR specular;
7940 quad[] =
7942 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
7943 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
7944 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
7945 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
7947 union
7949 DWORD d;
7950 float f;
7951 } conv;
7952 unsigned int i;
7953 static const struct
7955 D3DFOGMODE vfog, tfog;
7956 D3DSHADEMODE shade;
7957 D3DCOLOR middle_color;
7958 BOOL todo;
7960 tests[] =
7962 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
7963 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
7964 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
7965 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
7966 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
7967 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
7968 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
7969 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
7971 D3DDEVICEDESC7 caps;
7973 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7974 0, 0, 640, 480, 0, 0, 0, 0);
7976 if (!(device = create_device(window, DDSCL_NORMAL)))
7978 skip("Failed to create a 3D device, skipping test.\n");
7979 DestroyWindow(window);
7980 return;
7983 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
7984 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7985 hr = IDirect3DDevice7_GetCaps(device, &caps);
7986 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7987 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
7988 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
7990 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
7991 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7992 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
7993 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7994 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
7995 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7996 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
7997 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7998 conv.f = 5.0;
7999 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGDENSITY, conv.d);
8000 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8002 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
8003 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8004 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
8005 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8006 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x000000ff);
8007 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8009 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
8011 if(!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
8012 continue;
8014 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
8015 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8017 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shade);
8018 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8019 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
8020 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8021 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
8022 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8023 hr = IDirect3DDevice7_BeginScene(device);
8024 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8025 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8026 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, quad, 4, 0);
8027 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8028 hr = IDirect3DDevice7_EndScene(device);
8029 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8031 color = get_surface_color(rt, 0, 240);
8032 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
8033 color = get_surface_color(rt, 320, 240);
8034 if (tests[i].todo)
8035 todo_wine ok(compare_color(color, tests[i].middle_color, 2),
8036 "Got unexpected color 0x%08x, case %u.\n", color, i);
8037 else
8038 ok(compare_color(color, tests[i].middle_color, 2),
8039 "Got unexpected color 0x%08x, case %u.\n", color, i);
8040 color = get_surface_color(rt, 639, 240);
8041 ok(compare_color(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
8044 IDirectDrawSurface7_Release(rt);
8045 refcount = IDirect3DDevice7_Release(device);
8046 ok(!refcount, "Device has %u references left.\n", refcount);
8047 DestroyWindow(window);
8050 static void test_negative_fixedfunction_fog(void)
8052 HRESULT hr;
8053 IDirect3DDevice7 *device;
8054 IDirectDrawSurface7 *rt;
8055 ULONG refcount;
8056 HWND window;
8057 D3DCOLOR color;
8058 static struct
8060 struct vec3 position;
8061 D3DCOLOR diffuse;
8063 quad[] =
8065 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
8066 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
8067 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
8068 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
8070 static struct
8072 struct vec4 position;
8073 D3DCOLOR diffuse;
8075 tquad[] =
8077 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
8078 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
8079 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
8080 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
8082 unsigned int i;
8083 static D3DMATRIX zero =
8085 1.0f, 0.0f, 0.0f, 0.0f,
8086 0.0f, 1.0f, 0.0f, 0.0f,
8087 0.0f, 0.0f, 0.0f, 0.0f,
8088 0.0f, 0.0f, 0.0f, 1.0f
8090 static D3DMATRIX identity =
8092 1.0f, 0.0f, 0.0f, 0.0f,
8093 0.0f, 1.0f, 0.0f, 0.0f,
8094 0.0f, 0.0f, 1.0f, 0.0f,
8095 0.0f, 0.0f, 0.0f, 1.0f
8097 static const struct
8099 DWORD pos_type;
8100 void *quad;
8101 D3DMATRIX *matrix;
8102 union
8104 float f;
8105 DWORD d;
8106 } start, end;
8107 D3DFOGMODE vfog, tfog;
8108 DWORD color, color_broken, color_broken2;
8110 tests[] =
8112 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
8114 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
8115 {D3DFVF_XYZRHW, tquad, &identity, { 0.0f}, {1.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
8116 0x00ff0000, 0x00808000, 0x00808000},
8117 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
8118 * parameters to 0.0 and 1.0 in the table fog case. */
8119 {D3DFVF_XYZRHW, tquad, &identity, {-1.0f}, {0.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
8120 0x00808000, 0x00ff0000, 0x0000ff00},
8121 /* test_fog_interpolation shows that vertex fog evaluates the fog
8122 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
8123 * that the abs happens before the fog equation is evaluated.
8125 * Vertex fog abs() behavior is the same on all GPUs. */
8126 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
8127 0x00808000, 0x00808000, 0x00808000},
8128 {D3DFVF_XYZ, quad, &zero, {-1.0f}, {0.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
8129 0x0000ff00, 0x0000ff00, 0x0000ff00},
8130 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_EXP, D3DFOG_NONE,
8131 0x009b6400, 0x009b6400, 0x009b6400},
8133 D3DDEVICEDESC7 caps;
8135 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8136 0, 0, 640, 480, 0, 0, 0, 0);
8138 if (!(device = create_device(window, DDSCL_NORMAL)))
8140 skip("Failed to create a 3D device, skipping test.\n");
8141 DestroyWindow(window);
8142 return;
8145 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8146 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8147 hr = IDirect3DDevice7_GetCaps(device, &caps);
8148 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8149 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
8150 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
8152 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
8153 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8154 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
8155 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8156 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
8157 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8158 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
8159 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8160 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
8161 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
8163 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
8165 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
8166 continue;
8168 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
8169 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8171 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].matrix);
8172 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
8173 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, tests[i].start.d);
8174 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8175 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, tests[i].end.d);
8176 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8177 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
8178 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8179 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
8180 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8182 hr = IDirect3DDevice7_BeginScene(device);
8183 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8184 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8185 tests[i].pos_type | D3DFVF_DIFFUSE, tests[i].quad, 4, 0);
8186 hr = IDirect3DDevice7_EndScene(device);
8187 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8189 color = get_surface_color(rt, 0, 240);
8190 ok(compare_color(color, tests[i].color, 2) || broken(compare_color(color, tests[i].color_broken, 2))
8191 || broken(compare_color(color, tests[i].color_broken2, 2)),
8192 "Got unexpected color 0x%08x, case %u.\n", color, i);
8195 IDirectDrawSurface7_Release(rt);
8196 refcount = IDirect3DDevice7_Release(device);
8197 ok(!refcount, "Device has %u references left.\n", refcount);
8198 DestroyWindow(window);
8201 static void test_table_fog_zw(void)
8203 HRESULT hr;
8204 IDirect3DDevice7 *device;
8205 IDirectDrawSurface7 *rt;
8206 ULONG refcount;
8207 HWND window;
8208 D3DCOLOR color;
8209 static struct
8211 struct vec4 position;
8212 D3DCOLOR diffuse;
8214 quad[] =
8216 {{ 0.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
8217 {{640.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
8218 {{ 0.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
8219 {{640.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
8221 static D3DMATRIX identity =
8223 1.0f, 0.0f, 0.0f, 0.0f,
8224 0.0f, 1.0f, 0.0f, 0.0f,
8225 0.0f, 0.0f, 1.0f, 0.0f,
8226 0.0f, 0.0f, 0.0f, 1.0f
8228 D3DDEVICEDESC7 caps;
8229 static const struct
8231 float z, w;
8232 D3DZBUFFERTYPE z_test;
8233 D3DCOLOR color;
8235 tests[] =
8237 {0.7f, 0.0f, D3DZB_TRUE, 0x004cb200},
8238 {0.7f, 0.0f, D3DZB_FALSE, 0x004cb200},
8239 {0.7f, 0.3f, D3DZB_TRUE, 0x004cb200},
8240 {0.7f, 0.3f, D3DZB_FALSE, 0x004cb200},
8241 {0.7f, 3.0f, D3DZB_TRUE, 0x004cb200},
8242 {0.7f, 3.0f, D3DZB_FALSE, 0x004cb200},
8243 {0.3f, 0.0f, D3DZB_TRUE, 0x00b24c00},
8244 {0.3f, 0.0f, D3DZB_FALSE, 0x00b24c00},
8246 unsigned int i;
8248 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8249 0, 0, 640, 480, 0, 0, 0, 0);
8251 if (!(device = create_device(window, DDSCL_NORMAL)))
8253 skip("Failed to create a 3D device, skipping test.\n");
8254 DestroyWindow(window);
8255 return;
8258 hr = IDirect3DDevice7_GetCaps(device, &caps);
8259 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8260 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
8262 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
8263 goto done;
8265 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8266 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8268 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
8269 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8270 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
8271 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8272 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
8273 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8274 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
8275 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
8276 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
8277 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
8278 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
8279 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
8280 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8282 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
8284 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
8285 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8287 quad[0].position.z = tests[i].z;
8288 quad[1].position.z = tests[i].z;
8289 quad[2].position.z = tests[i].z;
8290 quad[3].position.z = tests[i].z;
8291 quad[0].position.w = tests[i].w;
8292 quad[1].position.w = tests[i].w;
8293 quad[2].position.w = tests[i].w;
8294 quad[3].position.w = tests[i].w;
8295 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, tests[i].z_test);
8296 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8298 hr = IDirect3DDevice7_BeginScene(device);
8299 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8300 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8301 D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad, 4, 0);
8302 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8303 hr = IDirect3DDevice7_EndScene(device);
8304 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8306 color = get_surface_color(rt, 0, 240);
8307 ok(compare_color(color, tests[i].color, 2),
8308 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color, tests[i].color, i);
8311 IDirectDrawSurface7_Release(rt);
8312 done:
8313 refcount = IDirect3DDevice7_Release(device);
8314 ok(!refcount, "Device has %u references left.\n", refcount);
8315 DestroyWindow(window);
8318 static void test_signed_formats(void)
8320 HRESULT hr;
8321 IDirect3DDevice7 *device;
8322 IDirect3D7 *d3d;
8323 IDirectDraw7 *ddraw;
8324 IDirectDrawSurface7 *surface, *rt;
8325 DDSURFACEDESC2 surface_desc;
8326 ULONG refcount;
8327 HWND window;
8328 D3DCOLOR color, expected_color;
8329 static struct
8331 struct vec3 position;
8332 struct vec2 texcoord;
8334 quad[] =
8336 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
8337 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
8338 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
8339 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
8341 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
8342 * of these values. */
8343 static const USHORT content_v8u8[4][4] =
8345 {0x0000, 0x7f7f, 0x8880, 0x0000},
8346 {0x0080, 0x8000, 0x7f00, 0x007f},
8347 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
8348 {0x4444, 0xc0c0, 0xa066, 0x22e0},
8350 static const DWORD content_x8l8v8u8[4][4] =
8352 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
8353 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
8354 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
8355 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
8357 static const USHORT content_l6v5u5[4][4] =
8359 {0x0000, 0xfdef, 0x0230, 0xfc00},
8360 {0x0010, 0x0200, 0x01e0, 0x000f},
8361 {0x4067, 0x53b9, 0x0421, 0xffff},
8362 {0x8108, 0x0318, 0xc28c, 0x909c},
8364 static const struct
8366 const char *name;
8367 const void *content;
8368 SIZE_T pixel_size;
8369 BOOL blue;
8370 unsigned int slop, slop_broken;
8371 DDPIXELFORMAT format;
8373 formats[] =
8376 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
8378 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
8379 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
8383 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
8385 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
8386 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
8390 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
8392 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
8393 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
8397 /* No V16U16 or Q8W8V8U8 support in ddraw. */
8399 static const D3DCOLOR expected_colors[4][4] =
8401 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
8402 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
8403 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
8404 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
8406 unsigned int i, width, x, y;
8407 D3DDEVICEDESC7 device_desc;
8409 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8410 0, 0, 640, 480, 0, 0, 0, 0);
8412 if (!(device = create_device(window, DDSCL_NORMAL)))
8414 skip("Failed to create a 3D device, skipping test.\n");
8415 DestroyWindow(window);
8416 return;
8419 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
8420 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8421 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
8423 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
8424 goto done;
8427 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
8428 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8429 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
8430 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
8431 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8432 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8434 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
8435 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8437 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
8438 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
8439 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8440 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
8441 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8442 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
8443 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8444 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
8445 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8447 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
8449 for (width = 1; width < 5; width += 3)
8451 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
8452 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
8454 memset(&surface_desc, 0, sizeof(surface_desc));
8455 surface_desc.dwSize = sizeof(surface_desc);
8456 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
8457 surface_desc.dwWidth = width;
8458 surface_desc.dwHeight = 4;
8459 U4(surface_desc).ddpfPixelFormat = formats[i].format;
8460 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
8461 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8462 if (FAILED(hr))
8464 skip("%s textures not supported, skipping.\n", formats[i].name);
8465 continue;
8467 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, format %s.\n", hr, formats[i].name);
8468 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
8469 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x, format %s.\n", hr, formats[i].name);
8471 memset(&surface_desc, 0, sizeof(surface_desc));
8472 surface_desc.dwSize = sizeof(surface_desc);
8473 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
8474 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, format %s.\n", hr, formats[i].name);
8475 for (y = 0; y < 4; y++)
8477 memcpy((char *)surface_desc.lpSurface + y * surface_desc.lPitch,
8478 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
8479 width * formats[i].pixel_size);
8481 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8482 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, format %s.\n", hr, formats[i].name);
8484 hr = IDirect3DDevice7_BeginScene(device);
8485 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8486 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8487 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
8488 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8489 hr = IDirect3DDevice7_EndScene(device);
8490 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8492 for (y = 0; y < 4; y++)
8494 for (x = 0; x < width; x++)
8496 expected_color = expected_colors[y][x];
8497 if (!formats[i].blue)
8498 expected_color |= 0x000000ff;
8500 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
8501 ok(compare_color(color, expected_color, formats[i].slop)
8502 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
8503 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
8504 expected_color, color, formats[i].name, x, y);
8508 IDirectDrawSurface7_Release(surface);
8513 IDirectDrawSurface7_Release(rt);
8514 IDirectDraw7_Release(ddraw);
8515 IDirect3D7_Release(d3d);
8517 done:
8518 refcount = IDirect3DDevice7_Release(device);
8519 ok(!refcount, "Device has %u references left.\n", refcount);
8520 DestroyWindow(window);
8523 static void test_color_fill(void)
8525 HRESULT hr;
8526 IDirect3DDevice7 *device;
8527 IDirect3D7 *d3d;
8528 IDirectDraw7 *ddraw;
8529 IDirectDrawSurface7 *surface, *surface2;
8530 DDSURFACEDESC2 surface_desc;
8531 DDPIXELFORMAT z_fmt;
8532 ULONG refcount;
8533 HWND window;
8534 unsigned int i;
8535 DDBLTFX fx;
8536 RECT rect = {5, 5, 7, 7};
8537 DWORD *color;
8538 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
8539 DDCAPS hal_caps;
8540 static const struct
8542 DWORD caps, caps2;
8543 HRESULT colorfill_hr, depthfill_hr;
8544 BOOL rop_success;
8545 const char *name;
8546 DWORD result;
8547 BOOL check_result;
8548 DDPIXELFORMAT format;
8550 tests[] =
8553 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
8554 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
8556 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
8557 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8561 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
8562 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
8564 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
8565 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8569 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
8570 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
8572 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
8573 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8577 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
8578 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
8580 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
8581 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8585 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
8586 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
8588 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
8589 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
8593 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
8594 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0, FALSE,
8595 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8598 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
8599 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0, FALSE,
8600 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
8603 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
8604 * different afterwards. DX9+ GPUs set one of the two luminance values
8605 * in each block, but AMD and Nvidia GPUs disagree on which luminance
8606 * value they set. r200 (dx8) just sets the entire block to the clear
8607 * value. */
8608 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
8609 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
8611 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
8612 {0}, {0}, {0}, {0}, {0}
8616 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
8617 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
8619 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8620 {0}, {0}, {0}, {0}, {0}
8624 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
8625 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
8627 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
8628 {0}, {0}, {0}, {0}, {0}
8632 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
8633 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
8635 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
8636 {0}, {0}, {0}, {0}, {0}
8640 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
8641 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
8643 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
8644 {0}, {0}, {0}, {0}, {0}
8648 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
8649 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
8651 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
8652 {0}, {0}, {0}, {0}, {0}
8656 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
8657 * surface works, presumably because it is handled by the runtime instead of
8658 * the driver. */
8659 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
8660 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
8662 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
8663 {8}, {0}, {0}, {0}, {0}
8667 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
8668 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
8670 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
8671 {8}, {0}, {0}, {0}, {0}
8675 static const struct
8677 DWORD rop;
8678 const char *name;
8679 HRESULT hr;
8681 rops[] =
8683 {SRCCOPY, "SRCCOPY", DD_OK},
8684 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
8685 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
8686 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
8687 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
8688 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
8689 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
8690 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
8691 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
8692 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
8693 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
8694 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
8695 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
8696 {BLACKNESS, "BLACKNESS", DD_OK},
8697 {WHITENESS, "WHITENESS", DD_OK},
8698 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
8701 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8702 0, 0, 640, 480, 0, 0, 0, 0);
8704 if (!(device = create_device(window, DDSCL_NORMAL)))
8706 skip("Failed to create a 3D device, skipping test.\n");
8707 DestroyWindow(window);
8708 return;
8711 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
8712 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8713 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
8714 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
8716 memset(&z_fmt, 0, sizeof(z_fmt));
8717 IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
8718 if (!z_fmt.dwSize)
8719 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
8721 IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
8722 if (!(supported_fmts & SUPPORT_DXT1))
8723 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
8725 IDirect3D7_Release(d3d);
8727 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
8728 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
8729 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
8730 num_fourcc_codes * sizeof(*fourcc_codes));
8731 if (!fourcc_codes)
8732 goto done;
8733 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
8734 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
8735 for (i = 0; i < num_fourcc_codes; i++)
8737 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
8738 supported_fmts |= SUPPORT_YUY2;
8739 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
8740 supported_fmts |= SUPPORT_UYVY;
8742 HeapFree(GetProcessHeap(), 0, fourcc_codes);
8744 memset(&hal_caps, 0, sizeof(hal_caps));
8745 hal_caps.dwSize = sizeof(hal_caps);
8746 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
8747 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8749 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
8750 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
8752 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
8754 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
8755 memset(&fx, 0, sizeof(fx));
8756 fx.dwSize = sizeof(fx);
8757 U5(fx).dwFillColor = 0xdeadbeef;
8759 memset(&surface_desc, 0, sizeof(surface_desc));
8760 surface_desc.dwSize = sizeof(surface_desc);
8761 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8762 surface_desc.dwWidth = 64;
8763 surface_desc.dwHeight = 64;
8764 U4(surface_desc).ddpfPixelFormat = tests[i].format;
8765 surface_desc.ddsCaps.dwCaps = tests[i].caps;
8766 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
8768 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
8769 continue;
8770 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
8771 continue;
8772 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
8773 continue;
8774 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
8775 continue;
8777 if (tests[i].caps & DDSCAPS_ZBUFFER)
8779 if (!z_fmt.dwSize)
8780 continue;
8782 U4(surface_desc).ddpfPixelFormat = z_fmt;
8785 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8786 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
8788 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8789 if (tests[i].format.dwFourCC)
8790 todo_wine ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
8791 hr, tests[i].colorfill_hr, tests[i].name);
8792 else
8793 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
8794 hr, tests[i].colorfill_hr, tests[i].name);
8796 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8797 if (tests[i].format.dwFourCC)
8798 todo_wine ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
8799 hr, tests[i].colorfill_hr, tests[i].name);
8800 else
8801 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
8802 hr, tests[i].colorfill_hr, tests[i].name);
8804 if (SUCCEEDED(hr) && tests[i].check_result)
8806 memset(&surface_desc, 0, sizeof(surface_desc));
8807 surface_desc.dwSize = sizeof(surface_desc);
8808 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
8809 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
8810 color = surface_desc.lpSurface;
8811 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
8812 *color, tests[i].result, tests[i].name);
8813 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8814 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
8817 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8818 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
8819 hr, tests[i].depthfill_hr, tests[i].name);
8820 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8821 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
8822 hr, tests[i].depthfill_hr, tests[i].name);
8824 U5(fx).dwFillColor = 0xdeadbeef;
8825 fx.dwROP = BLACKNESS;
8826 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
8827 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
8828 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
8829 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8830 U5(fx).dwFillColor, tests[i].name);
8832 if (SUCCEEDED(hr) && tests[i].check_result)
8834 memset(&surface_desc, 0, sizeof(surface_desc));
8835 surface_desc.dwSize = sizeof(surface_desc);
8836 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
8837 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
8838 color = surface_desc.lpSurface;
8839 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
8840 *color, tests[i].name);
8841 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8842 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
8845 fx.dwROP = WHITENESS;
8846 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
8847 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
8848 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
8849 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
8850 U5(fx).dwFillColor, tests[i].name);
8852 if (SUCCEEDED(hr) && tests[i].check_result)
8854 memset(&surface_desc, 0, sizeof(surface_desc));
8855 surface_desc.dwSize = sizeof(surface_desc);
8856 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
8857 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
8858 color = surface_desc.lpSurface;
8859 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
8860 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
8861 *color, tests[i].name);
8862 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8863 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
8866 IDirectDrawSurface7_Release(surface);
8869 memset(&fx, 0, sizeof(fx));
8870 fx.dwSize = sizeof(fx);
8871 U5(fx).dwFillColor = 0xdeadbeef;
8872 fx.dwROP = WHITENESS;
8874 memset(&surface_desc, 0, sizeof(surface_desc));
8875 surface_desc.dwSize = sizeof(surface_desc);
8876 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8877 surface_desc.dwWidth = 64;
8878 surface_desc.dwHeight = 64;
8879 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8880 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
8881 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8882 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8883 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8884 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8885 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
8886 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8887 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8888 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
8889 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8891 /* No DDBLTFX. */
8892 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
8893 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8894 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
8895 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8897 /* Unused source rectangle. */
8898 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8899 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8900 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
8901 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8903 /* Unused source surface. */
8904 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8905 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8906 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
8907 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8908 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8909 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8910 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
8911 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8913 /* Inverted destination or source rectangle. */
8914 SetRect(&rect, 5, 7, 7, 5);
8915 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8916 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8917 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8918 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8919 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8920 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8921 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8922 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8923 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
8924 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8926 /* Negative rectangle. */
8927 SetRect(&rect, -1, -1, 5, 5);
8928 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8929 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8930 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8931 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8932 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8933 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8934 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8935 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8936 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
8937 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8939 /* Out of bounds rectangle. */
8940 SetRect(&rect, 0, 0, 65, 65);
8941 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
8942 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8943 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
8944 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8946 /* Combine multiple flags. */
8947 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8948 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8949 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
8950 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8951 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
8952 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8954 for (i = 0; i < sizeof(rops) / sizeof(*rops); i++)
8956 fx.dwROP = rops[i].rop;
8957 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
8958 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
8961 IDirectDrawSurface7_Release(surface2);
8962 IDirectDrawSurface7_Release(surface);
8964 if (!z_fmt.dwSize)
8965 goto done;
8967 memset(&surface_desc, 0, sizeof(surface_desc));
8968 surface_desc.dwSize = sizeof(surface_desc);
8969 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8970 surface_desc.dwWidth = 64;
8971 surface_desc.dwHeight = 64;
8972 U4(surface_desc).ddpfPixelFormat = z_fmt;
8973 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
8974 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8975 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8976 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
8977 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8979 /* No DDBLTFX. */
8980 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
8981 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8983 /* Unused source rectangle. */
8984 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8985 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8987 /* Unused source surface. */
8988 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8989 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8990 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8991 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
8993 /* Inverted destination or source rectangle. */
8994 SetRect(&rect, 5, 7, 7, 5);
8995 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8996 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
8997 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
8998 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
8999 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9000 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9001 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9002 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9004 /* Negative rectangle. */
9005 SetRect(&rect, -1, -1, 5, 5);
9006 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9007 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9008 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9009 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9010 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9011 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9012 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9013 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9015 /* Out of bounds rectangle. */
9016 SetRect(&rect, 0, 0, 65, 65);
9017 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9018 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9020 /* Combine multiple flags. */
9021 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9022 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9024 IDirectDrawSurface7_Release(surface2);
9025 IDirectDrawSurface7_Release(surface);
9027 done:
9028 IDirectDraw7_Release(ddraw);
9029 refcount = IDirect3DDevice7_Release(device);
9030 ok(!refcount, "Device has %u references left.\n", refcount);
9031 DestroyWindow(window);
9034 START_TEST(ddraw7)
9036 HMODULE module = GetModuleHandleA("ddraw.dll");
9037 IDirectDraw7 *ddraw;
9038 DEVMODEW current_mode;
9040 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
9042 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
9043 return;
9046 if (!(ddraw = create_ddraw()))
9048 skip("Failed to create a ddraw object, skipping tests.\n");
9049 return;
9051 IDirectDraw7_Release(ddraw);
9053 memset(&current_mode, 0, sizeof(current_mode));
9054 current_mode.dmSize = sizeof(current_mode);
9055 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
9056 registry_mode.dmSize = sizeof(registry_mode);
9057 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
9058 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
9059 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
9061 skip("Current mode does not match registry mode, skipping test.\n");
9062 return;
9065 test_process_vertices();
9066 test_coop_level_create_device_window();
9067 test_clipper_blt();
9068 test_coop_level_d3d_state();
9069 test_surface_interface_mismatch();
9070 test_coop_level_threaded();
9071 test_depth_blit();
9072 test_texture_load_ckey();
9073 test_zenable();
9074 test_ck_rgba();
9075 test_ck_default();
9076 test_ck_complex();
9077 test_surface_qi();
9078 test_device_qi();
9079 test_wndproc();
9080 test_window_style();
9081 test_redundant_mode_set();
9082 test_coop_level_mode_set();
9083 test_coop_level_mode_set_multi();
9084 test_initialize();
9085 test_coop_level_surf_create();
9086 test_vb_discard();
9087 test_coop_level_multi_window();
9088 test_draw_strided();
9089 test_clear_rect_count();
9090 test_coop_level_versions();
9091 test_fog_special();
9092 test_lighting_interface_versions();
9093 test_coop_level_activateapp();
9094 test_texturemanage();
9095 test_block_formats_creation();
9096 test_unsupported_formats();
9097 test_rt_caps();
9098 test_primary_caps();
9099 test_surface_lock();
9100 test_surface_discard();
9101 test_flip();
9102 test_set_surface_desc();
9103 test_user_memory_getdc();
9104 test_sysmem_overlay();
9105 test_primary_palette();
9106 test_surface_attachment();
9107 test_private_data();
9108 test_pixel_format();
9109 test_create_surface_pitch();
9110 test_mipmap_lock();
9111 test_palette_complex();
9112 test_p8_rgb_blit();
9113 test_material();
9114 test_palette_gdi();
9115 test_palette_alpha();
9116 test_vb_writeonly();
9117 test_lost_device();
9118 test_resource_priority();
9119 test_surface_desc_lock();
9120 test_fog_interpolation();
9121 test_negative_fixedfunction_fog();
9122 test_table_fog_zw();
9123 test_signed_formats();
9124 test_color_fill();