wined3d: Vertex fog uses the absolute eye position z.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blob647ec828df1287e49ae42478b2ae8bb2ee6a6be7
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 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1094 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1095 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1096 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1097 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1098 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1099 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1100 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1101 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1102 IDirectDraw7_Release(ddraw);
1104 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1105 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1106 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1107 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1108 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1109 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1111 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1112 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1114 /* Partial blit. */
1115 SetRect(&src_rect, 0, 0, 320, 240);
1116 SetRect(&dst_rect, 0, 0, 320, 240);
1117 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1118 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1119 /* Different locations. */
1120 SetRect(&src_rect, 0, 0, 320, 240);
1121 SetRect(&dst_rect, 320, 240, 640, 480);
1122 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1123 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1124 /* Streched. */
1125 SetRect(&src_rect, 0, 0, 320, 240);
1126 SetRect(&dst_rect, 0, 0, 640, 480);
1127 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1128 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1129 /* Flipped. */
1130 SetRect(&src_rect, 0, 480, 640, 0);
1131 SetRect(&dst_rect, 0, 0, 640, 480);
1132 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1133 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1134 SetRect(&src_rect, 0, 0, 640, 480);
1135 SetRect(&dst_rect, 0, 480, 640, 0);
1136 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1137 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1138 /* Full, explicit. */
1139 SetRect(&src_rect, 0, 0, 640, 480);
1140 SetRect(&dst_rect, 0, 0, 640, 480);
1141 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1142 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1143 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1145 /* Depth blit inside a BeginScene / EndScene pair */
1146 hr = IDirect3DDevice7_BeginScene(device);
1147 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1148 /* From the current depth stencil */
1149 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1150 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1151 /* To the current depth stencil */
1152 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1153 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1154 /* Between unbound surfaces */
1155 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1156 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1157 hr = IDirect3DDevice7_EndScene(device);
1158 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1160 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1161 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1162 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1163 * a reliable result(z = 0.0) */
1164 memset(&fx, 0, sizeof(fx));
1165 fx.dwSize = sizeof(fx);
1166 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1167 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1169 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1170 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1171 SetRect(&dst_rect, 0, 0, 320, 240);
1172 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1173 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1174 IDirectDrawSurface7_Release(ds3);
1175 IDirectDrawSurface7_Release(ds2);
1176 IDirectDrawSurface7_Release(ds1);
1178 hr = IDirect3DDevice7_BeginScene(device);
1179 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1180 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1181 quad1, 4, 0);
1182 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1183 hr = IDirect3DDevice7_EndScene(device);
1184 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1186 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1187 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1188 for (i = 0; i < 4; ++i)
1190 for (j = 0; j < 4; ++j)
1192 unsigned int x = 80 * ((2 * j) + 1);
1193 unsigned int y = 60 * ((2 * i) + 1);
1194 color = get_surface_color(rt, x, y);
1195 ok(compare_color(color, expected_colors[i][j], 1),
1196 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1200 IDirectDrawSurface7_Release(rt);
1201 IDirect3DDevice7_Release(device);
1202 DestroyWindow(window);
1205 static void test_texture_load_ckey(void)
1207 HWND window;
1208 IDirect3DDevice7 *device;
1209 IDirectDraw7 *ddraw;
1210 IDirectDrawSurface7 *src;
1211 IDirectDrawSurface7 *dst;
1212 DDSURFACEDESC2 ddsd;
1213 HRESULT hr;
1214 DDCOLORKEY ckey;
1215 IDirect3D7 *d3d;
1217 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1218 0, 0, 640, 480, 0, 0, 0, 0);
1219 if (!(device = create_device(window, DDSCL_NORMAL)))
1221 skip("Failed to create a 3D device, skipping test.\n");
1222 DestroyWindow(window);
1223 return;
1226 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1227 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1228 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1229 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1230 IDirect3D7_Release(d3d);
1232 memset(&ddsd, 0, sizeof(ddsd));
1233 ddsd.dwSize = sizeof(ddsd);
1234 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1235 ddsd.dwHeight = 128;
1236 ddsd.dwWidth = 128;
1237 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1238 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1239 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1240 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1241 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1242 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1244 /* No surface has a color key */
1245 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1246 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1247 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1248 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1249 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1250 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1251 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1253 /* Source surface has a color key */
1254 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1255 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1256 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1257 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1258 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1259 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1260 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1261 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1262 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1264 /* Both surfaces have a color key: Dest ckey is overwritten */
1265 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1266 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1267 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1268 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1269 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1270 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1271 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1272 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1273 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1275 /* Only the destination has a color key: It is deleted. This behavior differs from
1276 * IDirect3DTexture(2)::Load */
1277 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1278 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1279 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1280 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1281 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1282 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1283 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1284 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1286 IDirectDrawSurface7_Release(dst);
1287 IDirectDrawSurface7_Release(src);
1288 IDirectDraw7_Release(ddraw);
1289 IDirect3DDevice7_Release(device);
1290 DestroyWindow(window);
1293 static void test_zenable(void)
1295 static struct
1297 struct vec4 position;
1298 D3DCOLOR diffuse;
1300 tquad[] =
1302 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1303 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1304 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1305 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1307 IDirect3DDevice7 *device;
1308 IDirectDrawSurface7 *rt;
1309 D3DCOLOR color;
1310 HWND window;
1311 HRESULT hr;
1312 UINT x, y;
1313 UINT i, j;
1315 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1316 0, 0, 640, 480, 0, 0, 0, 0);
1317 if (!(device = create_device(window, DDSCL_NORMAL)))
1319 skip("Failed to create a 3D device, skipping test.\n");
1320 DestroyWindow(window);
1321 return;
1324 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1325 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1327 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1328 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1329 hr = IDirect3DDevice7_BeginScene(device);
1330 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1331 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1332 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1333 hr = IDirect3DDevice7_EndScene(device);
1334 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1336 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1337 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1338 for (i = 0; i < 4; ++i)
1340 for (j = 0; j < 4; ++j)
1342 x = 80 * ((2 * j) + 1);
1343 y = 60 * ((2 * i) + 1);
1344 color = get_surface_color(rt, x, y);
1345 ok(compare_color(color, 0x0000ff00, 1),
1346 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1349 IDirectDrawSurface7_Release(rt);
1351 IDirect3DDevice7_Release(device);
1352 DestroyWindow(window);
1355 static void test_ck_rgba(void)
1357 static struct
1359 struct vec4 position;
1360 struct vec2 texcoord;
1362 tquad[] =
1364 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1365 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1366 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1367 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1368 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1369 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1370 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1371 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1373 static const struct
1375 D3DCOLOR fill_color;
1376 BOOL color_key;
1377 BOOL blend;
1378 D3DCOLOR result1;
1379 D3DCOLOR result2;
1381 tests[] =
1383 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x000000ff},
1384 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x000000ff},
1385 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00},
1386 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1387 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00807f00},
1388 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x0000ff00},
1389 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00},
1390 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1393 IDirectDrawSurface7 *texture;
1394 DDSURFACEDESC2 surface_desc;
1395 IDirect3DDevice7 *device;
1396 IDirectDrawSurface7 *rt;
1397 IDirectDraw7 *ddraw;
1398 IDirect3D7 *d3d;
1399 D3DCOLOR color;
1400 HWND window;
1401 DDBLTFX fx;
1402 HRESULT hr;
1403 UINT i;
1405 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1406 0, 0, 640, 480, 0, 0, 0, 0);
1407 if (!(device = create_device(window, DDSCL_NORMAL)))
1409 skip("Failed to create a 3D device, skipping test.\n");
1410 DestroyWindow(window);
1411 return;
1414 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1415 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1416 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1417 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1418 IDirect3D7_Release(d3d);
1420 memset(&surface_desc, 0, sizeof(surface_desc));
1421 surface_desc.dwSize = sizeof(surface_desc);
1422 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1423 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1424 surface_desc.dwWidth = 256;
1425 surface_desc.dwHeight = 256;
1426 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1427 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1428 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1429 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1430 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1431 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1432 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1433 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1434 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1435 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1436 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1438 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1439 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1440 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1441 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1442 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1443 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1445 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1446 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1448 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1450 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1451 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1452 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1453 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1455 memset(&fx, 0, sizeof(fx));
1456 fx.dwSize = sizeof(fx);
1457 U5(fx).dwFillColor = tests[i].fill_color;
1458 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1459 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1461 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1462 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1463 hr = IDirect3DDevice7_BeginScene(device);
1464 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1465 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1466 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1467 hr = IDirect3DDevice7_EndScene(device);
1468 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1470 color = get_surface_color(rt, 320, 240);
1471 if (i == 2)
1472 todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1473 tests[i].result1, i, color);
1474 else
1475 ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1476 tests[i].result1, i, color);
1478 U5(fx).dwFillColor = 0xff0000ff;
1479 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1480 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1482 hr = IDirect3DDevice7_BeginScene(device);
1483 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1484 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1485 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1486 hr = IDirect3DDevice7_EndScene(device);
1487 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1489 /* This tests that fragments that are masked out by the color key are
1490 * discarded, instead of just fully transparent. */
1491 color = get_surface_color(rt, 320, 240);
1492 if (i == 2)
1493 todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1494 tests[i].result2, i, color);
1495 else
1496 ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1497 tests[i].result2, i, color);
1500 IDirectDrawSurface7_Release(rt);
1501 IDirectDrawSurface7_Release(texture);
1502 IDirectDraw7_Release(ddraw);
1503 IDirect3DDevice7_Release(device);
1504 DestroyWindow(window);
1507 static void test_ck_default(void)
1509 static struct
1511 struct vec4 position;
1512 struct vec2 texcoord;
1514 tquad[] =
1516 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1517 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1518 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1519 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1521 IDirectDrawSurface7 *surface, *rt;
1522 DDSURFACEDESC2 surface_desc;
1523 IDirect3DDevice7 *device;
1524 IDirectDraw7 *ddraw;
1525 IDirect3D7 *d3d;
1526 D3DCOLOR color;
1527 DWORD value;
1528 HWND window;
1529 DDBLTFX fx;
1530 HRESULT hr;
1532 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1533 0, 0, 640, 480, 0, 0, 0, 0);
1535 if (!(device = create_device(window, DDSCL_NORMAL)))
1537 skip("Failed to create a 3D device, skipping test.\n");
1538 DestroyWindow(window);
1539 return;
1542 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1543 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1544 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1545 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1546 IDirect3D7_Release(d3d);
1548 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1549 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1551 memset(&surface_desc, 0, sizeof(surface_desc));
1552 surface_desc.dwSize = sizeof(surface_desc);
1553 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1554 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1555 surface_desc.dwWidth = 256;
1556 surface_desc.dwHeight = 256;
1557 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1558 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1559 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1560 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1561 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1562 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1563 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1564 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1565 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1566 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1567 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1568 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1570 memset(&fx, 0, sizeof(fx));
1571 fx.dwSize = sizeof(fx);
1572 U5(fx).dwFillColor = 0x000000ff;
1573 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1574 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1576 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1577 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1578 hr = IDirect3DDevice7_BeginScene(device);
1579 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1580 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1581 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1582 ok(!value, "Got unexpected color keying state %#x.\n", value);
1583 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1584 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1585 hr = IDirect3DDevice7_EndScene(device);
1586 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1587 color = get_surface_color(rt, 320, 240);
1588 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1590 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1591 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1592 hr = IDirect3DDevice7_BeginScene(device);
1593 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1594 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1595 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1596 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1597 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1598 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1599 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1600 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1601 hr = IDirect3DDevice7_EndScene(device);
1602 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1603 color = get_surface_color(rt, 320, 240);
1604 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1606 IDirectDrawSurface7_Release(surface);
1607 IDirectDrawSurface7_Release(rt);
1608 IDirect3DDevice7_Release(device);
1609 IDirectDraw7_Release(ddraw);
1610 DestroyWindow(window);
1613 static void test_ck_complex(void)
1615 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1616 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
1617 DDSURFACEDESC2 surface_desc;
1618 IDirect3DDevice7 *device;
1619 DDCOLORKEY color_key;
1620 IDirectDraw7 *ddraw;
1621 IDirect3D7 *d3d;
1622 unsigned int i;
1623 ULONG refcount;
1624 HWND window;
1625 HRESULT hr;
1627 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1628 0, 0, 640, 480, 0, 0, 0, 0);
1629 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1631 skip("Failed to create a 3D device, skipping test.\n");
1632 DestroyWindow(window);
1633 return;
1635 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1636 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1637 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1638 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1639 IDirect3D7_Release(d3d);
1641 memset(&surface_desc, 0, sizeof(surface_desc));
1642 surface_desc.dwSize = sizeof(surface_desc);
1643 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1644 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1645 surface_desc.dwWidth = 128;
1646 surface_desc.dwHeight = 128;
1647 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1648 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1650 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1651 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1652 color_key.dwColorSpaceLowValue = 0x0000ff00;
1653 color_key.dwColorSpaceHighValue = 0x0000ff00;
1654 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1655 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1656 memset(&color_key, 0, sizeof(color_key));
1657 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1658 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1659 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1660 color_key.dwColorSpaceLowValue);
1661 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1662 color_key.dwColorSpaceHighValue);
1664 mipmap = surface;
1665 IDirectDrawSurface_AddRef(mipmap);
1666 for (i = 0; i < 7; ++i)
1668 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1669 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1670 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1671 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1673 color_key.dwColorSpaceLowValue = 0x000000ff;
1674 color_key.dwColorSpaceHighValue = 0x000000ff;
1675 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1676 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1678 IDirectDrawSurface_Release(mipmap);
1679 mipmap = tmp;
1682 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1683 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1684 IDirectDrawSurface_Release(mipmap);
1685 refcount = IDirectDrawSurface7_Release(surface);
1686 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1688 memset(&surface_desc, 0, sizeof(surface_desc));
1689 surface_desc.dwSize = sizeof(surface_desc);
1690 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1691 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1692 surface_desc.dwBackBufferCount = 1;
1693 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1694 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1696 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1697 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1698 color_key.dwColorSpaceLowValue = 0x0000ff00;
1699 color_key.dwColorSpaceHighValue = 0x0000ff00;
1700 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1701 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1702 memset(&color_key, 0, sizeof(color_key));
1703 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1704 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1705 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1706 color_key.dwColorSpaceLowValue);
1707 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1708 color_key.dwColorSpaceHighValue);
1710 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1711 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1713 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1714 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1715 color_key.dwColorSpaceLowValue = 0x0000ff00;
1716 color_key.dwColorSpaceHighValue = 0x0000ff00;
1717 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1718 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1719 memset(&color_key, 0, sizeof(color_key));
1720 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1721 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1722 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1723 color_key.dwColorSpaceLowValue);
1724 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1725 color_key.dwColorSpaceHighValue);
1727 IDirectDrawSurface_Release(tmp);
1729 refcount = IDirectDrawSurface7_Release(surface);
1730 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1731 IDirectDraw7_Release(ddraw);
1732 refcount = IDirect3DDevice7_Release(device);
1733 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1734 DestroyWindow(window);
1737 struct qi_test
1739 REFIID iid;
1740 REFIID refcount_iid;
1741 HRESULT hr;
1744 static void test_qi(const char *test_name, IUnknown *base_iface,
1745 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1747 ULONG refcount, expected_refcount;
1748 IUnknown *iface1, *iface2;
1749 HRESULT hr;
1750 UINT i, j;
1752 for (i = 0; i < entry_count; ++i)
1754 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1755 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1756 if (SUCCEEDED(hr))
1758 for (j = 0; j < entry_count; ++j)
1760 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1761 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1762 if (SUCCEEDED(hr))
1764 expected_refcount = 0;
1765 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1766 ++expected_refcount;
1767 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1768 ++expected_refcount;
1769 refcount = IUnknown_Release(iface2);
1770 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1771 refcount, test_name, i, j, expected_refcount);
1775 expected_refcount = 0;
1776 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1777 ++expected_refcount;
1778 refcount = IUnknown_Release(iface1);
1779 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1780 refcount, test_name, i, expected_refcount);
1785 static void test_surface_qi(void)
1787 static const struct qi_test tests[] =
1789 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1790 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1791 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1792 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1793 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1794 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1795 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1796 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1797 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1798 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1799 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1800 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1801 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1802 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1803 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1804 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1805 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1806 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1807 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1808 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1809 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1810 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1811 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1812 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1813 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1814 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1815 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1816 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1817 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1818 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1819 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1820 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1821 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1822 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1823 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1824 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1825 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1826 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1827 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1828 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1829 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1830 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1833 IDirectDrawSurface7 *surface;
1834 DDSURFACEDESC2 surface_desc;
1835 IDirect3DDevice7 *device;
1836 IDirectDraw7 *ddraw;
1837 HWND window;
1838 HRESULT hr;
1840 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1841 0, 0, 640, 480, 0, 0, 0, 0);
1842 /* Try to create a D3D device to see if the ddraw implementation supports
1843 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1844 * doesn't support e.g. the IDirect3DTexture interfaces. */
1845 if (!(device = create_device(window, DDSCL_NORMAL)))
1847 skip("Failed to create a 3D device, skipping test.\n");
1848 DestroyWindow(window);
1849 return;
1851 IDirect3DDevice_Release(device);
1852 ddraw = create_ddraw();
1853 ok(!!ddraw, "Failed to create a ddraw object.\n");
1854 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1855 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1857 memset(&surface_desc, 0, sizeof(surface_desc));
1858 surface_desc.dwSize = sizeof(surface_desc);
1859 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1860 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1861 surface_desc.dwWidth = 512;
1862 surface_desc.dwHeight = 512;
1863 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1864 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1866 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, sizeof(tests) / sizeof(*tests));
1868 IDirectDrawSurface7_Release(surface);
1869 IDirectDraw7_Release(ddraw);
1870 DestroyWindow(window);
1873 static void test_device_qi(void)
1875 static const struct qi_test tests[] =
1877 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1878 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1879 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
1880 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1881 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
1882 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
1883 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
1884 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
1885 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
1886 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
1887 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1888 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1889 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1890 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1891 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1892 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1893 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1894 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1895 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1896 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1897 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1898 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1899 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1900 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1901 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1902 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1903 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1904 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1905 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1906 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1907 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1908 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1909 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1910 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1911 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1912 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1913 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1914 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1915 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1916 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1917 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1918 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
1921 IDirect3DDevice7 *device;
1922 HWND window;
1924 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1925 0, 0, 640, 480, 0, 0, 0, 0);
1926 if (!(device = create_device(window, DDSCL_NORMAL)))
1928 skip("Failed to create a 3D device, skipping test.\n");
1929 DestroyWindow(window);
1930 return;
1933 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, sizeof(tests) / sizeof(*tests));
1935 IDirect3DDevice7_Release(device);
1936 DestroyWindow(window);
1939 static void test_wndproc(void)
1941 LONG_PTR proc, ddraw_proc;
1942 IDirectDraw7 *ddraw;
1943 WNDCLASSA wc = {0};
1944 HWND window;
1945 HRESULT hr;
1946 ULONG ref;
1948 static struct message messages[] =
1950 {WM_WINDOWPOSCHANGING, FALSE, 0},
1951 {WM_MOVE, FALSE, 0},
1952 {WM_SIZE, FALSE, 0},
1953 {WM_WINDOWPOSCHANGING, FALSE, 0},
1954 {WM_ACTIVATE, FALSE, 0},
1955 {WM_SETFOCUS, FALSE, 0},
1956 {0, FALSE, 0},
1959 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1960 ddraw = create_ddraw();
1961 ok(!!ddraw, "Failed to create a ddraw object.\n");
1963 wc.lpfnWndProc = test_proc;
1964 wc.lpszClassName = "ddraw_test_wndproc_wc";
1965 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1967 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1968 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
1970 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1971 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1972 (LONG_PTR)test_proc, proc);
1973 expect_messages = messages;
1974 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1975 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1976 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
1977 expect_messages = NULL;
1978 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1979 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
1980 (LONG_PTR)test_proc, proc);
1981 ref = IDirectDraw7_Release(ddraw);
1982 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1983 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1984 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1985 (LONG_PTR)test_proc, proc);
1987 /* DDSCL_NORMAL doesn't. */
1988 ddraw = create_ddraw();
1989 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1990 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1991 (LONG_PTR)test_proc, proc);
1992 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
1993 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
1994 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
1995 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
1996 (LONG_PTR)test_proc, proc);
1997 ref = IDirectDraw7_Release(ddraw);
1998 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
1999 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2000 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2001 (LONG_PTR)test_proc, proc);
2003 /* The original window proc is only restored by ddraw if the current
2004 * window proc matches the one ddraw set. This also affects switching
2005 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2006 ddraw = create_ddraw();
2007 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2008 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2009 (LONG_PTR)test_proc, proc);
2010 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2011 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2012 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2013 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2014 (LONG_PTR)test_proc, proc);
2015 ddraw_proc = proc;
2016 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2017 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2018 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2019 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2020 (LONG_PTR)test_proc, proc);
2021 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2022 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2023 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2024 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2025 (LONG_PTR)test_proc, proc);
2026 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2027 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2028 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2029 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2030 (LONG_PTR)DefWindowProcA, proc);
2031 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2032 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2033 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2034 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2035 (LONG_PTR)DefWindowProcA, proc);
2036 ref = IDirectDraw7_Release(ddraw);
2037 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2038 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2039 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2040 (LONG_PTR)test_proc, proc);
2042 ddraw = create_ddraw();
2043 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2044 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2045 (LONG_PTR)test_proc, proc);
2046 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2047 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2048 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2049 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2050 (LONG_PTR)test_proc, proc);
2051 ref = IDirectDraw7_Release(ddraw);
2052 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2053 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2054 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2055 (LONG_PTR)DefWindowProcA, proc);
2057 fix_wndproc(window, (LONG_PTR)test_proc);
2058 expect_messages = NULL;
2059 DestroyWindow(window);
2060 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2063 static void test_window_style(void)
2065 LONG style, exstyle, tmp, expected_style;
2066 RECT fullscreen_rect, r;
2067 IDirectDraw7 *ddraw;
2068 HWND window;
2069 HRESULT hr;
2070 ULONG ref;
2071 BOOL ret;
2073 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2074 0, 0, 100, 100, 0, 0, 0, 0);
2075 ddraw = create_ddraw();
2076 ok(!!ddraw, "Failed to create a ddraw object.\n");
2078 style = GetWindowLongA(window, GWL_STYLE);
2079 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2080 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2082 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2083 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2085 tmp = GetWindowLongA(window, GWL_STYLE);
2086 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2087 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2088 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2090 GetWindowRect(window, &r);
2091 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2092 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2093 r.left, r.top, r.right, r.bottom);
2094 GetClientRect(window, &r);
2095 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2097 ret = SetForegroundWindow(GetDesktopWindow());
2098 ok(ret, "Failed to set foreground window.\n");
2100 tmp = GetWindowLongA(window, GWL_STYLE);
2101 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2102 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2103 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2105 ret = SetForegroundWindow(window);
2106 ok(ret, "Failed to set foreground window.\n");
2107 /* Windows 7 (but not Vista and XP) show the window when it receives focus. Hide it again,
2108 * the next tests expect this. */
2109 ShowWindow(window, SW_HIDE);
2111 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2112 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2114 tmp = GetWindowLongA(window, GWL_STYLE);
2115 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2116 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2117 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2119 ShowWindow(window, SW_SHOW);
2120 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2121 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2123 tmp = GetWindowLongA(window, GWL_STYLE);
2124 expected_style = style | WS_VISIBLE;
2125 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2126 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2127 expected_style = exstyle | WS_EX_TOPMOST;
2128 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2130 ret = SetForegroundWindow(GetDesktopWindow());
2131 ok(ret, "Failed to set foreground window.\n");
2132 tmp = GetWindowLongA(window, GWL_STYLE);
2133 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2134 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2135 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2136 expected_style = exstyle | WS_EX_TOPMOST;
2137 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2139 ref = IDirectDraw7_Release(ddraw);
2140 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2142 DestroyWindow(window);
2145 static void test_redundant_mode_set(void)
2147 DDSURFACEDESC2 surface_desc = {0};
2148 IDirectDraw7 *ddraw;
2149 HWND window;
2150 HRESULT hr;
2151 RECT r, s;
2152 ULONG ref;
2154 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2155 0, 0, 100, 100, 0, 0, 0, 0);
2156 ddraw = create_ddraw();
2157 ok(!!ddraw, "Failed to create a ddraw object.\n");
2158 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2159 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2161 surface_desc.dwSize = sizeof(surface_desc);
2162 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2163 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2165 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2166 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2167 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2169 GetWindowRect(window, &r);
2170 r.right /= 2;
2171 r.bottom /= 2;
2172 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2173 GetWindowRect(window, &s);
2174 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2175 r.left, r.top, r.right, r.bottom,
2176 s.left, s.top, s.right, s.bottom);
2178 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2179 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2180 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2182 GetWindowRect(window, &s);
2183 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2184 r.left, r.top, r.right, r.bottom,
2185 s.left, s.top, s.right, s.bottom);
2187 ref = IDirectDraw7_Release(ddraw);
2188 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2190 DestroyWindow(window);
2193 static SIZE screen_size, screen_size2;
2195 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2197 if (message == WM_SIZE)
2199 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2200 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2203 return test_proc(hwnd, message, wparam, lparam);
2206 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2208 if (message == WM_SIZE)
2210 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2211 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2214 return test_proc(hwnd, message, wparam, lparam);
2217 struct test_coop_level_mode_set_enum_param
2219 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2222 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2224 struct test_coop_level_mode_set_enum_param *param = context;
2226 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2227 return DDENUMRET_OK;
2228 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2229 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2230 return DDENUMRET_OK;
2232 if (!param->ddraw_width)
2234 param->ddraw_width = surface_desc->dwWidth;
2235 param->ddraw_height = surface_desc->dwHeight;
2236 return DDENUMRET_OK;
2238 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2239 return DDENUMRET_OK;
2241 param->user32_width = surface_desc->dwWidth;
2242 param->user32_height = surface_desc->dwHeight;
2243 return DDENUMRET_CANCEL;
2246 static void test_coop_level_mode_set(void)
2248 IDirectDrawSurface7 *primary;
2249 RECT registry_rect, ddraw_rect, user32_rect, r;
2250 IDirectDraw7 *ddraw;
2251 DDSURFACEDESC2 ddsd;
2252 WNDCLASSA wc = {0};
2253 HWND window, window2;
2254 HRESULT hr;
2255 ULONG ref;
2256 MSG msg;
2257 struct test_coop_level_mode_set_enum_param param;
2258 DEVMODEW devmode;
2259 BOOL ret;
2260 LONG change_ret;
2262 static const struct message exclusive_messages[] =
2264 {WM_WINDOWPOSCHANGING, FALSE, 0},
2265 {WM_WINDOWPOSCHANGED, FALSE, 0},
2266 {WM_SIZE, FALSE, 0},
2267 {WM_DISPLAYCHANGE, FALSE, 0},
2268 {0, FALSE, 0},
2270 static const struct message exclusive_focus_loss_messages[] =
2272 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2273 {WM_DISPLAYCHANGE, FALSE, 0},
2274 {WM_WINDOWPOSCHANGING, FALSE, 0},
2275 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2276 * SW_MINIMIZED, causing a recursive window activation that does not
2277 * produe the same result in Wine yet. Ignore the difference for now.
2278 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2279 {WM_WINDOWPOSCHANGED, FALSE, 0},
2280 {WM_MOVE, FALSE, 0},
2281 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2282 {WM_ACTIVATEAPP, TRUE, FALSE},
2283 {0, FALSE, 0},
2285 static const struct message exclusive_focus_restore_messages[] =
2287 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2288 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2289 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2290 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2291 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2292 /* Native redundantly sets the window size here. */
2293 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2294 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2295 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2296 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2297 {0, FALSE, 0},
2300 static const struct message normal_messages[] =
2302 {WM_DISPLAYCHANGE, FALSE, 0},
2303 {0, FALSE, 0},
2306 ddraw = create_ddraw();
2307 ok(!!ddraw, "Failed to create a ddraw object.\n");
2309 memset(&param, 0, sizeof(param));
2310 hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2311 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2312 ref = IDirectDraw7_Release(ddraw);
2313 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2315 if (!param.user32_height)
2317 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2318 return;
2321 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2322 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2323 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2325 memset(&devmode, 0, sizeof(devmode));
2326 devmode.dmSize = sizeof(devmode);
2327 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2328 devmode.dmPelsWidth = param.user32_width;
2329 devmode.dmPelsHeight = param.user32_height;
2330 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2331 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2333 ddraw = create_ddraw();
2334 ok(!!ddraw, "Failed to create a ddraw object.\n");
2336 wc.lpfnWndProc = mode_set_proc;
2337 wc.lpszClassName = "ddraw_test_wndproc_wc";
2338 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2339 wc.lpfnWndProc = mode_set_proc2;
2340 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2341 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2343 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2344 0, 0, 100, 100, 0, 0, 0, 0);
2345 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2346 0, 0, 100, 100, 0, 0, 0, 0);
2348 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2349 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2351 GetWindowRect(window, &r);
2352 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2353 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2354 r.left, r.top, r.right, r.bottom);
2356 memset(&ddsd, 0, sizeof(ddsd));
2357 ddsd.dwSize = sizeof(ddsd);
2358 ddsd.dwFlags = DDSD_CAPS;
2359 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2361 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2362 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2363 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2364 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2365 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2366 param.user32_width, ddsd.dwWidth);
2367 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2368 param.user32_height, ddsd.dwHeight);
2370 GetWindowRect(window, &r);
2371 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2372 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2373 r.left, r.top, r.right, r.bottom);
2375 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2376 expect_messages = exclusive_messages;
2377 screen_size.cx = 0;
2378 screen_size.cy = 0;
2380 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2381 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2383 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2384 expect_messages = NULL;
2385 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2386 "Expected screen size %ux%u, got %ux%u.\n",
2387 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2389 GetWindowRect(window, &r);
2390 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2391 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2392 r.left, r.top, r.right, r.bottom);
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);
2400 IDirectDrawSurface7_Release(primary);
2402 memset(&ddsd, 0, sizeof(ddsd));
2403 ddsd.dwSize = sizeof(ddsd);
2404 ddsd.dwFlags = DDSD_CAPS;
2405 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2407 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2408 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2409 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2410 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2411 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2412 param.ddraw_width, ddsd.dwWidth);
2413 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2414 param.ddraw_height, ddsd.dwHeight);
2416 GetWindowRect(window, &r);
2417 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2418 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2419 r.left, r.top, r.right, r.bottom);
2421 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2422 expect_messages = exclusive_messages;
2423 screen_size.cx = 0;
2424 screen_size.cy = 0;
2426 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2427 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2429 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2430 expect_messages = NULL;
2431 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2432 "Expected screen size %ux%u, got %ux%u.\n",
2433 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2435 GetWindowRect(window, &r);
2436 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2437 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2438 r.left, r.top, r.right, r.bottom);
2440 expect_messages = exclusive_focus_loss_messages;
2441 ret = SetForegroundWindow(GetDesktopWindow());
2442 ok(ret, "Failed to set foreground window.\n");
2443 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2444 memset(&devmode, 0, sizeof(devmode));
2445 devmode.dmSize = sizeof(devmode);
2446 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2447 ok(ret, "Failed to get display mode.\n");
2448 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2449 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2450 devmode.dmPelsWidth, devmode.dmPelsHeight);
2452 expect_messages = exclusive_focus_restore_messages;
2453 ShowWindow(window, SW_RESTORE);
2454 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2456 GetWindowRect(window, &r);
2457 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2458 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2459 r.left, r.top, r.right, r.bottom);
2460 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2461 ok(ret, "Failed to get display mode.\n");
2462 ok(devmode.dmPelsWidth == param.ddraw_width
2463 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2464 devmode.dmPelsWidth, devmode.dmPelsHeight);
2466 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2467 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2468 /* Normally the primary should be restored here. Unfortunately this causes the
2469 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2470 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2471 * the point of the GetSurfaceDesc call. */
2473 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2474 expect_messages = exclusive_messages;
2475 screen_size.cx = 0;
2476 screen_size.cy = 0;
2478 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2479 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2481 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2482 expect_messages = NULL;
2483 ok(screen_size.cx == registry_mode.dmPelsWidth
2484 && screen_size.cy == registry_mode.dmPelsHeight,
2485 "Expected screen size %ux%u, got %ux%u.\n",
2486 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2488 GetWindowRect(window, &r);
2489 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2490 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2491 r.left, r.top, r.right, r.bottom);
2493 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2494 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2495 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2496 param.ddraw_width, ddsd.dwWidth);
2497 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2498 param.ddraw_height, ddsd.dwHeight);
2499 IDirectDrawSurface7_Release(primary);
2501 /* For Wine. */
2502 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2503 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2505 memset(&ddsd, 0, sizeof(ddsd));
2506 ddsd.dwSize = sizeof(ddsd);
2507 ddsd.dwFlags = DDSD_CAPS;
2508 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2510 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2511 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2512 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2513 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2514 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2515 registry_mode.dmPelsWidth, ddsd.dwWidth);
2516 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2517 registry_mode.dmPelsHeight, ddsd.dwHeight);
2519 GetWindowRect(window, &r);
2520 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2521 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2522 r.left, r.top, r.right, r.bottom);
2524 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2525 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2527 GetWindowRect(window, &r);
2528 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2529 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2530 r.left, r.top, r.right, r.bottom);
2532 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2533 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2534 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2535 registry_mode.dmPelsWidth, ddsd.dwWidth);
2536 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2537 registry_mode.dmPelsHeight, ddsd.dwHeight);
2538 IDirectDrawSurface7_Release(primary);
2540 memset(&ddsd, 0, sizeof(ddsd));
2541 ddsd.dwSize = sizeof(ddsd);
2542 ddsd.dwFlags = DDSD_CAPS;
2543 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2545 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2546 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2547 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2548 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2549 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2550 registry_mode.dmPelsWidth, ddsd.dwWidth);
2551 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2552 registry_mode.dmPelsHeight, ddsd.dwHeight);
2554 GetWindowRect(window, &r);
2555 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2556 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2557 r.left, r.top, r.right, r.bottom);
2559 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2560 expect_messages = normal_messages;
2561 screen_size.cx = 0;
2562 screen_size.cy = 0;
2564 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2565 devmode.dmPelsWidth = param.user32_width;
2566 devmode.dmPelsHeight = param.user32_height;
2567 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2568 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2570 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2571 expect_messages = NULL;
2572 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2574 GetWindowRect(window, &r);
2575 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2576 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2577 r.left, r.top, r.right, r.bottom);
2579 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2580 expect_messages = normal_messages;
2581 screen_size.cx = 0;
2582 screen_size.cy = 0;
2584 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2585 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2587 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2588 expect_messages = NULL;
2589 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2591 GetWindowRect(window, &r);
2592 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2593 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2594 r.left, r.top, r.right, r.bottom);
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);
2602 IDirectDrawSurface7_Release(primary);
2604 memset(&ddsd, 0, sizeof(ddsd));
2605 ddsd.dwSize = sizeof(ddsd);
2606 ddsd.dwFlags = DDSD_CAPS;
2607 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2609 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2610 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2611 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2612 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2613 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2614 param.ddraw_width, ddsd.dwWidth);
2615 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2616 param.ddraw_height, ddsd.dwHeight);
2618 GetWindowRect(window, &r);
2619 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2620 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2621 r.left, r.top, r.right, r.bottom);
2623 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2624 expect_messages = normal_messages;
2625 screen_size.cx = 0;
2626 screen_size.cy = 0;
2628 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2629 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2631 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2632 expect_messages = NULL;
2633 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2635 GetWindowRect(window, &r);
2636 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2637 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2638 r.left, r.top, r.right, r.bottom);
2640 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2641 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2642 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2643 param.ddraw_width, ddsd.dwWidth);
2644 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2645 param.ddraw_height, ddsd.dwHeight);
2646 IDirectDrawSurface7_Release(primary);
2648 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2649 ok(ret, "Failed to get display mode.\n");
2650 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2651 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2652 "Expected resolution %ux%u, got %ux%u.\n",
2653 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2654 devmode.dmPelsWidth, devmode.dmPelsHeight);
2655 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2656 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2658 memset(&ddsd, 0, sizeof(ddsd));
2659 ddsd.dwSize = sizeof(ddsd);
2660 ddsd.dwFlags = DDSD_CAPS;
2661 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2663 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2664 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2665 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2666 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2667 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2668 registry_mode.dmPelsWidth, ddsd.dwWidth);
2669 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2670 registry_mode.dmPelsHeight, ddsd.dwHeight);
2672 GetWindowRect(window, &r);
2673 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2674 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2675 r.left, r.top, r.right, r.bottom);
2677 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2678 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2679 * not DDSCL_FULLSCREEN. */
2680 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2681 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2683 GetWindowRect(window, &r);
2684 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2685 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2686 r.left, r.top, r.right, r.bottom);
2688 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2689 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2690 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2691 registry_mode.dmPelsWidth, ddsd.dwWidth);
2692 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2693 registry_mode.dmPelsHeight, ddsd.dwHeight);
2694 IDirectDrawSurface7_Release(primary);
2696 memset(&ddsd, 0, sizeof(ddsd));
2697 ddsd.dwSize = sizeof(ddsd);
2698 ddsd.dwFlags = DDSD_CAPS;
2699 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2701 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2702 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2703 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2704 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2705 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2706 registry_mode.dmPelsWidth, ddsd.dwWidth);
2707 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2708 registry_mode.dmPelsHeight, ddsd.dwHeight);
2710 GetWindowRect(window, &r);
2711 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2712 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2713 r.left, r.top, r.right, r.bottom);
2715 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2716 expect_messages = normal_messages;
2717 screen_size.cx = 0;
2718 screen_size.cy = 0;
2720 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2721 devmode.dmPelsWidth = param.user32_width;
2722 devmode.dmPelsHeight = param.user32_height;
2723 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2724 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2726 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2727 expect_messages = NULL;
2728 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2730 GetWindowRect(window, &r);
2731 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2732 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2733 r.left, r.top, r.right, r.bottom);
2735 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2736 expect_messages = normal_messages;
2737 screen_size.cx = 0;
2738 screen_size.cy = 0;
2740 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2741 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2743 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2744 expect_messages = NULL;
2745 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2747 GetWindowRect(window, &r);
2748 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2749 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2750 r.left, r.top, r.right, r.bottom);
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);
2758 IDirectDrawSurface7_Release(primary);
2760 memset(&ddsd, 0, sizeof(ddsd));
2761 ddsd.dwSize = sizeof(ddsd);
2762 ddsd.dwFlags = DDSD_CAPS;
2763 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2765 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2766 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2767 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2768 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2769 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2770 param.ddraw_width, ddsd.dwWidth);
2771 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2772 param.ddraw_height, ddsd.dwHeight);
2774 GetWindowRect(window, &r);
2775 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2776 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2777 r.left, r.top, r.right, r.bottom);
2779 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2780 expect_messages = normal_messages;
2781 screen_size.cx = 0;
2782 screen_size.cy = 0;
2784 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2785 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2787 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2788 expect_messages = NULL;
2789 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2791 GetWindowRect(window, &r);
2792 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2793 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2794 r.left, r.top, r.right, r.bottom);
2796 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2797 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2798 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2799 param.ddraw_width, ddsd.dwWidth);
2800 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2801 param.ddraw_height, ddsd.dwHeight);
2802 IDirectDrawSurface7_Release(primary);
2804 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2805 ok(ret, "Failed to get display mode.\n");
2806 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2807 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2808 "Expected resolution %ux%u, got %ux%u.\n",
2809 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2810 devmode.dmPelsWidth, devmode.dmPelsHeight);
2811 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2812 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2814 memset(&ddsd, 0, sizeof(ddsd));
2815 ddsd.dwSize = sizeof(ddsd);
2816 ddsd.dwFlags = DDSD_CAPS;
2817 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2819 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2820 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2821 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2822 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2823 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2824 registry_mode.dmPelsWidth, ddsd.dwWidth);
2825 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2826 registry_mode.dmPelsHeight, ddsd.dwHeight);
2827 IDirectDrawSurface7_Release(primary);
2829 GetWindowRect(window, &r);
2830 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2831 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2832 r.left, r.top, r.right, r.bottom);
2834 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2835 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2836 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2837 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2838 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2840 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2841 expect_messages = exclusive_messages;
2842 screen_size.cx = 0;
2843 screen_size.cy = 0;
2845 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2846 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2848 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2849 expect_messages = NULL;
2850 ok(screen_size.cx == registry_mode.dmPelsWidth
2851 && screen_size.cy == registry_mode.dmPelsHeight,
2852 "Expected screen size %ux%u, got %ux%u.\n",
2853 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2854 screen_size.cx, screen_size.cy);
2856 GetWindowRect(window, &r);
2857 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2858 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2859 r.left, r.top, r.right, r.bottom);
2861 memset(&ddsd, 0, sizeof(ddsd));
2862 ddsd.dwSize = sizeof(ddsd);
2863 ddsd.dwFlags = DDSD_CAPS;
2864 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2866 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2867 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2868 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2869 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2870 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2871 registry_mode.dmPelsWidth, ddsd.dwWidth);
2872 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2873 registry_mode.dmPelsHeight, ddsd.dwHeight);
2874 IDirectDrawSurface7_Release(primary);
2876 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2877 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2878 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2879 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2880 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2882 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2883 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2885 memset(&ddsd, 0, sizeof(ddsd));
2886 ddsd.dwSize = sizeof(ddsd);
2887 ddsd.dwFlags = DDSD_CAPS;
2888 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2890 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2891 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2892 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2893 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2894 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2895 param.ddraw_width, ddsd.dwWidth);
2896 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2897 param.ddraw_height, ddsd.dwHeight);
2898 IDirectDrawSurface7_Release(primary);
2900 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2901 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2903 /* If the window is changed at the same time, messages are sent to the new window. */
2904 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2905 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2906 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2907 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2909 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2910 expect_messages = exclusive_messages;
2911 screen_size.cx = 0;
2912 screen_size.cy = 0;
2913 screen_size2.cx = 0;
2914 screen_size2.cy = 0;
2916 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
2917 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2919 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2920 expect_messages = NULL;
2921 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
2922 screen_size.cx, screen_size.cy);
2923 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
2924 "Expected screen size 2 %ux%u, got %ux%u.\n",
2925 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
2927 GetWindowRect(window, &r);
2928 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2929 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2930 r.left, r.top, r.right, r.bottom);
2931 GetWindowRect(window2, &r);
2932 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2933 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2934 r.left, r.top, r.right, r.bottom);
2936 memset(&ddsd, 0, sizeof(ddsd));
2937 ddsd.dwSize = sizeof(ddsd);
2938 ddsd.dwFlags = DDSD_CAPS;
2939 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2941 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2942 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2943 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2944 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2945 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2946 registry_mode.dmPelsWidth, ddsd.dwWidth);
2947 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2948 registry_mode.dmPelsHeight, ddsd.dwHeight);
2949 IDirectDrawSurface7_Release(primary);
2951 ref = IDirectDraw7_Release(ddraw);
2952 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2954 GetWindowRect(window, &r);
2955 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2956 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2957 r.left, r.top, r.right, r.bottom);
2959 expect_messages = NULL;
2960 DestroyWindow(window);
2961 DestroyWindow(window2);
2962 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2963 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
2966 static void test_coop_level_mode_set_multi(void)
2968 IDirectDraw7 *ddraw1, *ddraw2;
2969 UINT w, h;
2970 HWND window;
2971 HRESULT hr;
2972 ULONG ref;
2974 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2975 0, 0, 100, 100, 0, 0, 0, 0);
2976 ddraw1 = create_ddraw();
2977 ok(!!ddraw1, "Failed to create a ddraw object.\n");
2979 /* With just a single ddraw object, the display mode is restored on
2980 * release. */
2981 hr = set_display_mode(ddraw1, 800, 600);
2982 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2983 w = GetSystemMetrics(SM_CXSCREEN);
2984 ok(w == 800, "Got unexpected screen width %u.\n", w);
2985 h = GetSystemMetrics(SM_CYSCREEN);
2986 ok(h == 600, "Got unexpected screen height %u.\n", h);
2988 ref = IDirectDraw7_Release(ddraw1);
2989 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2990 w = GetSystemMetrics(SM_CXSCREEN);
2991 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
2992 h = GetSystemMetrics(SM_CYSCREEN);
2993 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
2995 /* When there are multiple ddraw objects, the display mode is restored to
2996 * the initial mode, before the first SetDisplayMode() call. */
2997 ddraw1 = create_ddraw();
2998 hr = set_display_mode(ddraw1, 800, 600);
2999 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3000 w = GetSystemMetrics(SM_CXSCREEN);
3001 ok(w == 800, "Got unexpected screen width %u.\n", w);
3002 h = GetSystemMetrics(SM_CYSCREEN);
3003 ok(h == 600, "Got unexpected screen height %u.\n", h);
3005 ddraw2 = create_ddraw();
3006 hr = set_display_mode(ddraw2, 640, 480);
3007 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3008 w = GetSystemMetrics(SM_CXSCREEN);
3009 ok(w == 640, "Got unexpected screen width %u.\n", w);
3010 h = GetSystemMetrics(SM_CYSCREEN);
3011 ok(h == 480, "Got unexpected screen height %u.\n", h);
3013 ref = IDirectDraw7_Release(ddraw2);
3014 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3015 w = GetSystemMetrics(SM_CXSCREEN);
3016 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3017 h = GetSystemMetrics(SM_CYSCREEN);
3018 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3020 ref = IDirectDraw7_Release(ddraw1);
3021 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3022 w = GetSystemMetrics(SM_CXSCREEN);
3023 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3024 h = GetSystemMetrics(SM_CYSCREEN);
3025 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3027 /* Regardless of release ordering. */
3028 ddraw1 = create_ddraw();
3029 hr = set_display_mode(ddraw1, 800, 600);
3030 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3031 w = GetSystemMetrics(SM_CXSCREEN);
3032 ok(w == 800, "Got unexpected screen width %u.\n", w);
3033 h = GetSystemMetrics(SM_CYSCREEN);
3034 ok(h == 600, "Got unexpected screen height %u.\n", h);
3036 ddraw2 = create_ddraw();
3037 hr = set_display_mode(ddraw2, 640, 480);
3038 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3039 w = GetSystemMetrics(SM_CXSCREEN);
3040 ok(w == 640, "Got unexpected screen width %u.\n", w);
3041 h = GetSystemMetrics(SM_CYSCREEN);
3042 ok(h == 480, "Got unexpected screen height %u.\n", h);
3044 ref = IDirectDraw7_Release(ddraw1);
3045 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3046 w = GetSystemMetrics(SM_CXSCREEN);
3047 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3048 h = GetSystemMetrics(SM_CYSCREEN);
3049 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3051 ref = IDirectDraw7_Release(ddraw2);
3052 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3053 w = GetSystemMetrics(SM_CXSCREEN);
3054 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3055 h = GetSystemMetrics(SM_CYSCREEN);
3056 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3058 /* But only for ddraw objects that called SetDisplayMode(). */
3059 ddraw1 = create_ddraw();
3060 ddraw2 = create_ddraw();
3061 hr = set_display_mode(ddraw2, 640, 480);
3062 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3063 w = GetSystemMetrics(SM_CXSCREEN);
3064 ok(w == 640, "Got unexpected screen width %u.\n", w);
3065 h = GetSystemMetrics(SM_CYSCREEN);
3066 ok(h == 480, "Got unexpected screen height %u.\n", h);
3068 ref = IDirectDraw7_Release(ddraw1);
3069 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3070 w = GetSystemMetrics(SM_CXSCREEN);
3071 ok(w == 640, "Got unexpected screen width %u.\n", w);
3072 h = GetSystemMetrics(SM_CYSCREEN);
3073 ok(h == 480, "Got unexpected screen height %u.\n", h);
3075 ref = IDirectDraw7_Release(ddraw2);
3076 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3077 w = GetSystemMetrics(SM_CXSCREEN);
3078 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3079 h = GetSystemMetrics(SM_CYSCREEN);
3080 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3082 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3083 * restoring the display mode. */
3084 ddraw1 = create_ddraw();
3085 hr = set_display_mode(ddraw1, 800, 600);
3086 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3087 w = GetSystemMetrics(SM_CXSCREEN);
3088 ok(w == 800, "Got unexpected screen width %u.\n", w);
3089 h = GetSystemMetrics(SM_CYSCREEN);
3090 ok(h == 600, "Got unexpected screen height %u.\n", h);
3092 ddraw2 = create_ddraw();
3093 hr = set_display_mode(ddraw2, 640, 480);
3094 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3095 w = GetSystemMetrics(SM_CXSCREEN);
3096 ok(w == 640, "Got unexpected screen width %u.\n", w);
3097 h = GetSystemMetrics(SM_CYSCREEN);
3098 ok(h == 480, "Got unexpected screen height %u.\n", h);
3100 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3101 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3103 ref = IDirectDraw7_Release(ddraw1);
3104 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3105 w = GetSystemMetrics(SM_CXSCREEN);
3106 ok(w == 640, "Got unexpected screen width %u.\n", w);
3107 h = GetSystemMetrics(SM_CYSCREEN);
3108 ok(h == 480, "Got unexpected screen height %u.\n", h);
3110 ref = IDirectDraw7_Release(ddraw2);
3111 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3112 w = GetSystemMetrics(SM_CXSCREEN);
3113 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3114 h = GetSystemMetrics(SM_CYSCREEN);
3115 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3117 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3118 ddraw1 = create_ddraw();
3119 hr = set_display_mode(ddraw1, 800, 600);
3120 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3121 w = GetSystemMetrics(SM_CXSCREEN);
3122 ok(w == 800, "Got unexpected screen width %u.\n", w);
3123 h = GetSystemMetrics(SM_CYSCREEN);
3124 ok(h == 600, "Got unexpected screen height %u.\n", h);
3126 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3127 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3129 ddraw2 = create_ddraw();
3130 hr = set_display_mode(ddraw2, 640, 480);
3131 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3133 ref = IDirectDraw7_Release(ddraw1);
3134 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3135 w = GetSystemMetrics(SM_CXSCREEN);
3136 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3137 h = GetSystemMetrics(SM_CYSCREEN);
3138 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3140 ref = IDirectDraw7_Release(ddraw2);
3141 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3142 w = GetSystemMetrics(SM_CXSCREEN);
3143 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3144 h = GetSystemMetrics(SM_CYSCREEN);
3145 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3147 DestroyWindow(window);
3150 static void test_initialize(void)
3152 IDirectDraw7 *ddraw;
3153 HRESULT hr;
3155 ddraw = create_ddraw();
3156 ok(!!ddraw, "Failed to create a ddraw object.\n");
3158 hr = IDirectDraw7_Initialize(ddraw, NULL);
3159 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3160 IDirectDraw7_Release(ddraw);
3162 CoInitialize(NULL);
3163 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
3164 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
3165 hr = IDirectDraw7_Initialize(ddraw, NULL);
3166 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3167 hr = IDirectDraw7_Initialize(ddraw, NULL);
3168 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3169 IDirectDraw7_Release(ddraw);
3170 CoUninitialize();
3173 static void test_coop_level_surf_create(void)
3175 IDirectDrawSurface7 *surface;
3176 IDirectDraw7 *ddraw;
3177 DDSURFACEDESC2 ddsd;
3178 HRESULT hr;
3180 ddraw = create_ddraw();
3181 ok(!!ddraw, "Failed to create a ddraw object.\n");
3183 memset(&ddsd, 0, sizeof(ddsd));
3184 ddsd.dwSize = sizeof(ddsd);
3185 ddsd.dwFlags = DDSD_CAPS;
3186 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3187 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3188 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3190 IDirectDraw7_Release(ddraw);
3193 static void test_vb_discard(void)
3195 static const struct vec4 quad[] =
3197 { 0.0f, 480.0f, 0.0f, 1.0f},
3198 { 0.0f, 0.0f, 0.0f, 1.0f},
3199 {640.0f, 480.0f, 0.0f, 1.0f},
3200 {640.0f, 0.0f, 0.0f, 1.0f},
3203 IDirect3DDevice7 *device;
3204 IDirect3D7 *d3d;
3205 IDirect3DVertexBuffer7 *buffer;
3206 HWND window;
3207 HRESULT hr;
3208 D3DVERTEXBUFFERDESC desc;
3209 BYTE *data;
3210 static const unsigned int vbsize = 16;
3211 unsigned int i;
3213 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3214 0, 0, 640, 480, 0, 0, 0, 0);
3216 if (!(device = create_device(window, DDSCL_NORMAL)))
3218 skip("Failed to create a 3D device, skipping test.\n");
3219 DestroyWindow(window);
3220 return;
3223 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3224 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3226 memset(&desc, 0, sizeof(desc));
3227 desc.dwSize = sizeof(desc);
3228 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3229 desc.dwFVF = D3DFVF_XYZRHW;
3230 desc.dwNumVertices = vbsize;
3231 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
3232 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3234 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3235 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3236 memcpy(data, quad, sizeof(quad));
3237 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3238 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3240 hr = IDirect3DDevice7_BeginScene(device);
3241 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3242 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3243 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3244 hr = IDirect3DDevice7_EndScene(device);
3245 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3247 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3248 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3249 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3250 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3251 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3253 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3254 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3255 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3257 if (data[i] != 0xaa)
3259 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3260 break;
3263 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3264 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3266 IDirect3DVertexBuffer7_Release(buffer);
3267 IDirect3D7_Release(d3d);
3268 IDirect3DDevice7_Release(device);
3269 DestroyWindow(window);
3272 static void test_coop_level_multi_window(void)
3274 HWND window1, window2;
3275 IDirectDraw7 *ddraw;
3276 HRESULT hr;
3278 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3279 0, 0, 640, 480, 0, 0, 0, 0);
3280 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3281 0, 0, 640, 480, 0, 0, 0, 0);
3282 ddraw = create_ddraw();
3283 ok(!!ddraw, "Failed to create a ddraw object.\n");
3285 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3286 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3287 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3288 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3289 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3290 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3292 IDirectDraw7_Release(ddraw);
3293 DestroyWindow(window2);
3294 DestroyWindow(window1);
3297 static void test_draw_strided(void)
3299 static struct vec3 position[] =
3301 {-1.0, -1.0, 0.0},
3302 {-1.0, 1.0, 0.0},
3303 { 1.0, 1.0, 0.0},
3304 { 1.0, -1.0, 0.0},
3306 static DWORD diffuse[] =
3308 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3310 static WORD indices[] =
3312 0, 1, 2, 2, 3, 0
3315 IDirectDrawSurface7 *rt;
3316 IDirect3DDevice7 *device;
3317 D3DCOLOR color;
3318 HWND window;
3319 HRESULT hr;
3320 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3322 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3323 0, 0, 640, 480, 0, 0, 0, 0);
3325 if (!(device = create_device(window, DDSCL_NORMAL)))
3327 skip("Failed to create a 3D device, skipping test.\n");
3328 DestroyWindow(window);
3329 return;
3332 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3333 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3335 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3336 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3337 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3338 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3339 hr = IDirect3DDevice7_BeginScene(device);
3340 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3342 memset(&strided, 0x55, sizeof(strided));
3343 strided.position.lpvData = position;
3344 strided.position.dwStride = sizeof(*position);
3345 strided.diffuse.lpvData = diffuse;
3346 strided.diffuse.dwStride = sizeof(*diffuse);
3347 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3348 &strided, 4, indices, 6, 0);
3349 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3351 hr = IDirect3DDevice7_EndScene(device);
3352 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3354 color = get_surface_color(rt, 320, 240);
3355 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3357 IDirectDrawSurface7_Release(rt);
3358 IDirect3DDevice7_Release(device);
3359 DestroyWindow(window);
3362 static void test_clear_rect_count(void)
3364 IDirectDrawSurface7 *rt;
3365 IDirect3DDevice7 *device;
3366 D3DCOLOR color;
3367 HWND window;
3368 HRESULT hr;
3369 D3DRECT rect = {{0}, {0}, {640}, {480}};
3371 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3372 0, 0, 640, 480, 0, 0, 0, 0);
3373 if (!(device = create_device(window, DDSCL_NORMAL)))
3375 skip("Failed to create a 3D device, skipping test.\n");
3376 DestroyWindow(window);
3377 return;
3380 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3381 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3383 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
3384 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3385 hr = IDirect3DDevice7_Clear(device, 0, &rect, D3DCLEAR_TARGET, 0x00ff0000, 1.0f, 0);
3386 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3388 color = get_surface_color(rt, 320, 240);
3389 ok(compare_color(color, 0x00ffffff, 1),
3390 "Clear with count = 0, rect != NULL has color %#08x.\n", color);
3392 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
3393 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3394 hr = IDirect3DDevice7_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
3395 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3397 color = get_surface_color(rt, 320, 240);
3398 ok(compare_color(color, 0x0000ff00, 1),
3399 "Clear with count = 1, rect = NULL has color %#08x.\n", color);
3401 IDirectDrawSurface7_Release(rt);
3402 IDirect3DDevice7_Release(device);
3403 DestroyWindow(window);
3406 static BOOL test_mode_restored(IDirectDraw7 *ddraw, HWND window)
3408 DDSURFACEDESC2 ddsd1, ddsd2;
3409 HRESULT hr;
3411 memset(&ddsd1, 0, sizeof(ddsd1));
3412 ddsd1.dwSize = sizeof(ddsd1);
3413 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd1);
3414 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3416 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3417 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3418 hr = set_display_mode(ddraw, 640, 480);
3419 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3420 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3421 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3423 memset(&ddsd2, 0, sizeof(ddsd2));
3424 ddsd2.dwSize = sizeof(ddsd2);
3425 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd2);
3426 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3427 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3428 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3430 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
3433 static void test_coop_level_versions(void)
3435 HWND window;
3436 IDirectDraw *ddraw;
3437 HRESULT hr;
3438 BOOL restored;
3439 IDirectDrawSurface *surface;
3440 IDirectDraw7 *ddraw7;
3441 DDSURFACEDESC ddsd;
3443 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3444 0, 0, 640, 480, 0, 0, 0, 0);
3446 ddraw7 = create_ddraw();
3447 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3448 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3449 restored = test_mode_restored(ddraw7, window);
3450 ok(restored, "Display mode not restored in new ddraw object\n");
3452 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3453 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3454 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3456 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3457 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3458 restored = test_mode_restored(ddraw7, window);
3459 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3461 /* A successful one does */
3462 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3463 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3464 restored = test_mode_restored(ddraw7, window);
3465 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3467 IDirectDraw_Release(ddraw);
3468 IDirectDraw7_Release(ddraw7);
3470 ddraw7 = create_ddraw();
3471 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3472 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3473 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3475 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
3476 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3477 restored = test_mode_restored(ddraw7, window);
3478 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3480 IDirectDraw_Release(ddraw);
3481 IDirectDraw7_Release(ddraw7);
3483 /* A failing call does not restore the ddraw2+ behavior */
3484 ddraw7 = create_ddraw();
3485 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3486 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3487 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3489 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3490 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3491 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3492 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3493 restored = test_mode_restored(ddraw7, window);
3494 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3496 IDirectDraw_Release(ddraw);
3497 IDirectDraw7_Release(ddraw7);
3499 /* Neither does a sequence of successful calls with the new interface */
3500 ddraw7 = create_ddraw();
3501 ok(!!ddraw7, "Failed to create a ddraw object.\n");
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_NORMAL);
3506 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3507 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3508 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3509 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
3510 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3512 restored = test_mode_restored(ddraw7, window);
3513 ok(!restored, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
3514 IDirectDraw_Release(ddraw);
3515 IDirectDraw7_Release(ddraw7);
3517 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3518 ddraw7 = create_ddraw();
3519 ok(!!ddraw7, "Failed to create a ddraw object.\n");
3520 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
3521 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3523 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
3524 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3526 memset(&ddsd, 0, sizeof(ddsd));
3527 ddsd.dwSize = sizeof(ddsd);
3528 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3529 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3530 ddsd.dwWidth = ddsd.dwHeight = 8;
3531 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3532 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
3533 IDirectDrawSurface_Release(surface);
3534 restored = test_mode_restored(ddraw7, window);
3535 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
3537 IDirectDraw_Release(ddraw);
3538 IDirectDraw7_Release(ddraw7);
3539 DestroyWindow(window);
3542 static void test_fog_special(void)
3544 static struct
3546 struct vec3 position;
3547 D3DCOLOR diffuse;
3549 quad[] =
3551 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
3552 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00},
3553 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
3554 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
3556 static const struct
3558 DWORD vertexmode, tablemode;
3559 D3DCOLOR color_left, color_right;
3561 tests[] =
3563 {D3DFOG_LINEAR, D3DFOG_NONE, 0x00ff0000, 0x00ff0000},
3564 {D3DFOG_NONE, D3DFOG_LINEAR, 0x0000ff00, 0x00ff0000},
3566 union
3568 float f;
3569 DWORD d;
3570 } conv;
3571 D3DCOLOR color;
3572 HRESULT hr;
3573 unsigned int i;
3574 HWND window;
3575 IDirect3DDevice7 *device;
3576 IDirectDrawSurface7 *rt;
3578 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3579 0, 0, 640, 480, 0, 0, 0, 0);
3581 if (!(device = create_device(window, DDSCL_NORMAL)))
3583 skip("Failed to create a 3D device, skipping test.\n");
3584 DestroyWindow(window);
3585 return;
3588 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3589 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3591 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
3592 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
3593 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xffff0000);
3594 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
3595 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3596 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3597 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3598 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3600 conv.f = 0.5f;
3601 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, conv.d);
3602 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
3603 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, conv.d);
3604 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
3606 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3608 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0);
3609 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3611 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vertexmode);
3612 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
3613 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tablemode);
3614 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
3616 hr = IDirect3DDevice7_BeginScene(device);
3617 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3618 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
3619 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3620 hr = IDirect3DDevice7_EndScene(device);
3621 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3623 color = get_surface_color(rt, 310, 240);
3624 ok(compare_color(color, tests[i].color_left, 1),
3625 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
3626 color = get_surface_color(rt, 330, 240);
3627 ok(compare_color(color, tests[i].color_right, 1),
3628 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
3631 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3632 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3634 IDirectDrawSurface7_Release(rt);
3635 IDirect3DDevice7_Release(device);
3636 DestroyWindow(window);
3639 static void test_lighting_interface_versions(void)
3641 IDirect3DDevice7 *device;
3642 IDirectDrawSurface7 *rt;
3643 D3DCOLOR color;
3644 HWND window;
3645 HRESULT hr;
3646 DWORD rs;
3647 unsigned int i;
3648 ULONG ref;
3649 D3DMATERIAL7 material;
3650 static D3DVERTEX quad[] =
3652 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3653 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3654 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3655 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3658 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3659 static struct
3661 struct vec3 position;
3662 struct vec3 normal;
3663 DWORD diffuse, specular;
3665 quad2[] =
3667 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3668 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3669 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3670 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3673 static D3DLVERTEX lquad[] =
3675 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3676 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3677 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3678 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3681 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3682 static struct
3684 struct vec3 position;
3685 DWORD diffuse, specular;
3686 struct vec2 texcoord;
3688 lquad2[] =
3690 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3691 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3692 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3693 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3696 static D3DTLVERTEX tlquad[] =
3698 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3699 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3700 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3701 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3704 static const struct
3706 DWORD vertextype;
3707 void *data;
3708 DWORD d3drs_lighting, d3drs_specular;
3709 DWORD draw_flags;
3710 D3DCOLOR color;
3712 tests[] =
3714 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
3715 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
3716 * are not available
3718 * Note that the specular result is 0x00000000 when lighting is on even if the
3719 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
3720 * enabled */
3722 /* 0 */
3723 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x00ffffff},
3724 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
3725 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3726 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3727 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x00ffffff},
3728 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
3729 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3730 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3732 /* 8 */
3733 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x00ff0000},
3734 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
3735 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3736 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3737 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x00ff8080},
3738 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
3739 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3740 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3742 /* 16 */
3743 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
3744 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x0000ff00},
3745 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3746 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3747 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
3748 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x0000ff00},
3749 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3750 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3752 /* 24 */
3753 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
3754 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x0000ff00},
3755 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3756 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
3757 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
3758 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x0000ff00},
3759 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3760 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
3762 /* 32 */
3763 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
3764 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
3765 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3766 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3767 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
3768 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
3769 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3770 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3773 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3774 0, 0, 640, 480, 0, 0, 0, 0);
3776 if (!(device = create_device(window, DDSCL_NORMAL)))
3778 skip("Failed to create a 3D device, skipping test.\n");
3779 DestroyWindow(window);
3780 return;
3783 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3784 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3786 memset(&material, 0, sizeof(material));
3787 U2(U3(material).emissive).g = 1.0f;
3788 hr = IDirect3DDevice7_SetMaterial(device, &material);
3789 ok(SUCCEEDED(hr), "Failed set material, hr %#x.\n", hr);
3790 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3791 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
3793 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
3794 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
3795 ok(rs == TRUE, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs);
3796 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
3797 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
3798 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
3800 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3802 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
3803 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3805 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
3806 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
3807 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
3808 tests[i].d3drs_specular);
3809 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
3811 hr = IDirect3DDevice7_BeginScene(device);
3812 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3813 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
3814 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
3815 hr = IDirect3DDevice7_EndScene(device);
3816 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3818 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
3819 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
3820 ok(rs == tests[i].d3drs_lighting, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
3821 rs, tests[i].d3drs_lighting);
3823 color = get_surface_color(rt, 320, 240);
3824 ok(compare_color(color, tests[i].color, 1),
3825 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3826 color, tests[i].color, i);
3829 IDirectDrawSurface7_Release(rt);
3830 ref = IDirect3DDevice7_Release(device);
3831 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
3832 DestroyWindow(window);
3835 static struct
3837 BOOL received;
3838 IDirectDraw7 *ddraw;
3839 HWND window;
3840 DWORD coop_level;
3841 } activateapp_testdata;
3843 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3845 if (message == WM_ACTIVATEAPP)
3847 if (activateapp_testdata.ddraw)
3849 HRESULT hr;
3850 activateapp_testdata.received = FALSE;
3851 hr = IDirectDraw7_SetCooperativeLevel(activateapp_testdata.ddraw,
3852 activateapp_testdata.window, activateapp_testdata.coop_level);
3853 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3854 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3856 activateapp_testdata.received = TRUE;
3859 return DefWindowProcA(hwnd, message, wparam, lparam);
3862 static void test_coop_level_activateapp(void)
3864 IDirectDraw7 *ddraw;
3865 HRESULT hr;
3866 HWND window;
3867 WNDCLASSA wc = {0};
3868 DDSURFACEDESC2 ddsd;
3869 IDirectDrawSurface7 *surface;
3871 ddraw = create_ddraw();
3872 ok(!!ddraw, "Failed to create a ddraw object.\n");
3874 wc.lpfnWndProc = activateapp_test_proc;
3875 wc.lpszClassName = "ddraw_test_wndproc_wc";
3876 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3878 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3879 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3881 /* Exclusive with window already active. */
3882 SetActiveWindow(window);
3883 activateapp_testdata.received = FALSE;
3884 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3885 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3886 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3887 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3888 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3890 /* Exclusive with window not active. */
3891 SetActiveWindow(NULL);
3892 activateapp_testdata.received = FALSE;
3893 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3894 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3895 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3896 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3897 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3899 /* Normal with window not active, then exclusive with the same window. */
3900 SetActiveWindow(NULL);
3901 activateapp_testdata.received = FALSE;
3902 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3903 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3904 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3905 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3906 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3907 /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
3908 * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken. */
3909 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3910 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3911 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3912 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3914 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3915 SetActiveWindow(NULL);
3916 activateapp_testdata.received = FALSE;
3917 activateapp_testdata.ddraw = ddraw;
3918 activateapp_testdata.window = window;
3919 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3920 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3921 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3922 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3923 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3924 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3925 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3927 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3928 * succeeding. Another switch to exclusive and back to normal is needed to release the
3929 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3930 * WM_ACTIVATEAPP messages. */
3931 activateapp_testdata.ddraw = NULL;
3932 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3933 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3934 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3935 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3937 /* Setting DDSCL_NORMAL with recursive invocation. */
3938 SetActiveWindow(NULL);
3939 activateapp_testdata.received = FALSE;
3940 activateapp_testdata.ddraw = ddraw;
3941 activateapp_testdata.window = window;
3942 activateapp_testdata.coop_level = DDSCL_NORMAL;
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 || broken(!activateapp_testdata.received),
3946 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3948 /* DDraw is in exlusive mode now. */
3949 memset(&ddsd, 0, sizeof(ddsd));
3950 ddsd.dwSize = sizeof(ddsd);
3951 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3952 ddsd.dwBackBufferCount = 1;
3953 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3954 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3955 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3956 IDirectDrawSurface7_Release(surface);
3958 /* Recover again, just to be sure. */
3959 activateapp_testdata.ddraw = NULL;
3960 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3961 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3962 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3963 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3965 DestroyWindow(window);
3966 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3967 IDirectDraw7_Release(ddraw);
3970 static void test_texturemanage(void)
3972 IDirectDraw7 *ddraw;
3973 HRESULT hr;
3974 DDSURFACEDESC2 ddsd;
3975 IDirectDrawSurface7 *surface;
3976 unsigned int i;
3977 DDCAPS hal_caps, hel_caps;
3978 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
3979 static const struct
3981 DWORD caps_in, caps2_in;
3982 HRESULT hr;
3983 DWORD caps_out, caps2_out;
3985 tests[] =
3987 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3988 ~0U, ~0U},
3989 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3990 ~0U, ~0U},
3991 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3992 ~0U, ~0U},
3993 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3994 ~0U, ~0U},
3995 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
3996 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
3997 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
3998 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
3999 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4000 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
4001 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4002 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
4004 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4005 ~0U, ~0U},
4006 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4007 ~0U, ~0U},
4008 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4009 ~0U, ~0U},
4010 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4011 ~0U, ~0U},
4012 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4013 ~0U, ~0U},
4014 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4015 ~0U, ~0U},
4016 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
4017 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
4018 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
4019 DDSCAPS_SYSTEMMEMORY, 0},
4022 ddraw = create_ddraw();
4023 ok(!!ddraw, "Failed to create a ddraw object.\n");
4024 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4025 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4027 memset(&hal_caps, 0, sizeof(hal_caps));
4028 hal_caps.dwSize = sizeof(hal_caps);
4029 memset(&hel_caps, 0, sizeof(hel_caps));
4030 hel_caps.dwSize = sizeof(hel_caps);
4031 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, &hel_caps);
4032 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4033 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4035 skip("Managed textures not supported, skipping managed texture test.\n");
4036 IDirectDraw7_Release(ddraw);
4037 return;
4040 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4042 memset(&ddsd, 0, sizeof(ddsd));
4043 ddsd.dwSize = sizeof(ddsd);
4044 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4045 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4046 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4047 ddsd.dwWidth = 4;
4048 ddsd.dwHeight = 4;
4050 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4051 ok(hr == tests[i].hr, "Got unexpected, hr %#x, case %u.\n", hr, i);
4052 if (FAILED(hr))
4053 continue;
4055 memset(&ddsd, 0, sizeof(ddsd));
4056 ddsd.dwSize = sizeof(ddsd);
4057 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4058 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4060 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4061 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4062 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4063 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4064 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4065 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4067 IDirectDrawSurface7_Release(surface);
4070 IDirectDraw7_Release(ddraw);
4073 #define SUPPORT_DXT1 0x01
4074 #define SUPPORT_DXT2 0x02
4075 #define SUPPORT_DXT3 0x04
4076 #define SUPPORT_DXT4 0x08
4077 #define SUPPORT_DXT5 0x10
4078 #define SUPPORT_YUY2 0x20
4079 #define SUPPORT_UYVY 0x40
4081 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4083 DWORD *supported_fmts = ctx;
4085 if (!(fmt->dwFlags & DDPF_FOURCC))
4086 return DDENUMRET_OK;
4088 switch (fmt->dwFourCC)
4090 case MAKEFOURCC('D','X','T','1'):
4091 *supported_fmts |= SUPPORT_DXT1;
4092 break;
4093 case MAKEFOURCC('D','X','T','2'):
4094 *supported_fmts |= SUPPORT_DXT2;
4095 break;
4096 case MAKEFOURCC('D','X','T','3'):
4097 *supported_fmts |= SUPPORT_DXT3;
4098 break;
4099 case MAKEFOURCC('D','X','T','4'):
4100 *supported_fmts |= SUPPORT_DXT4;
4101 break;
4102 case MAKEFOURCC('D','X','T','5'):
4103 *supported_fmts |= SUPPORT_DXT5;
4104 break;
4105 case MAKEFOURCC('Y','U','Y','2'):
4106 *supported_fmts |= SUPPORT_YUY2;
4107 break;
4108 case MAKEFOURCC('U','Y','V','Y'):
4109 *supported_fmts |= SUPPORT_UYVY;
4110 break;
4111 default:
4112 break;
4115 return DDENUMRET_OK;
4118 static void test_block_formats_creation(void)
4120 HRESULT hr, expect_hr;
4121 unsigned int i, j, w, h;
4122 HWND window;
4123 IDirectDraw7 *ddraw;
4124 IDirect3D7 *d3d;
4125 IDirect3DDevice7 *device;
4126 IDirectDrawSurface7 *surface;
4127 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
4128 DWORD num_fourcc_codes = 0, *fourcc_codes;
4129 DDSURFACEDESC2 ddsd;
4130 DDCAPS hal_caps;
4131 void *mem;
4133 static const struct
4135 DWORD fourcc;
4136 const char *name;
4137 DWORD support_flag;
4138 unsigned int block_width;
4139 unsigned int block_height;
4140 unsigned int block_size;
4141 BOOL create_size_checked, overlay;
4143 formats[] =
4145 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
4146 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
4147 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
4148 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
4149 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
4150 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
4151 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
4153 static const struct
4155 DWORD caps, caps2;
4156 const char *name;
4157 BOOL overlay;
4159 types[] =
4161 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4162 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4164 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4165 * Other hw / drivers successfully create those surfaces. Ignore them, this
4166 * suggests that no game uses this, otherwise Nvidia would support it. */
4168 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4169 "videomemory texture", FALSE
4172 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4173 "videomemory overlay", TRUE
4176 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4177 "systemmemory texture", FALSE
4180 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4181 "managed texture", FALSE
4184 enum size_type
4186 SIZE_TYPE_ZERO,
4187 SIZE_TYPE_PITCH,
4188 SIZE_TYPE_SIZE,
4190 static const struct
4192 DWORD flags;
4193 enum size_type size_type;
4194 int rel_size;
4195 HRESULT hr;
4197 user_mem_tests[] =
4199 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
4200 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4201 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4202 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4203 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4204 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4205 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4206 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4207 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
4208 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
4209 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4210 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4211 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4212 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4215 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4216 0, 0, 640, 480, 0, 0, 0, 0);
4218 if (!(device = create_device(window, DDSCL_NORMAL)))
4220 skip("Failed to create a 3D device, skipping test.\n");
4221 DestroyWindow(window);
4222 return;
4225 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4226 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4227 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4228 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4229 IDirect3D7_Release(d3d);
4231 hr = IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb,
4232 &supported_fmts);
4233 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4235 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4236 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4237 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4238 num_fourcc_codes * sizeof(*fourcc_codes));
4239 if (!fourcc_codes)
4240 goto cleanup;
4241 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
4242 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4243 for (i = 0; i < num_fourcc_codes; i++)
4245 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
4247 if (fourcc_codes[i] == formats[j].fourcc)
4248 supported_overlay_fmts |= formats[j].support_flag;
4251 HeapFree(GetProcessHeap(), 0, fourcc_codes);
4253 memset(&hal_caps, 0, sizeof(hal_caps));
4254 hal_caps.dwSize = sizeof(hal_caps);
4255 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
4256 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4258 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
4260 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4262 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
4264 BOOL support;
4266 if (formats[i].overlay != types[j].overlay
4267 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
4268 continue;
4270 if (formats[i].overlay)
4271 support = supported_overlay_fmts & formats[i].support_flag;
4272 else
4273 support = supported_fmts & formats[i].support_flag;
4275 for (w = 1; w <= 8; w++)
4277 for (h = 1; h <= 8; h++)
4279 BOOL block_aligned = TRUE;
4280 BOOL todo = FALSE;
4282 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
4283 block_aligned = FALSE;
4285 memset(&ddsd, 0, sizeof(ddsd));
4286 ddsd.dwSize = sizeof(ddsd);
4287 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4288 ddsd.ddsCaps.dwCaps = types[j].caps;
4289 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
4290 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4291 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4292 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4293 ddsd.dwWidth = w;
4294 ddsd.dwHeight = h;
4296 /* TODO: Handle power of two limitations. I cannot test the pow2
4297 * behavior on windows because I have no hardware that doesn't at
4298 * least support np2_conditional. There's probably no HW that
4299 * supports DXTN textures but no conditional np2 textures. */
4300 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
4301 expect_hr = DDERR_INVALIDPARAMS;
4302 else if (formats[i].create_size_checked && !block_aligned)
4304 expect_hr = DDERR_INVALIDPARAMS;
4305 if (!(types[j].caps & DDSCAPS_TEXTURE))
4306 todo = TRUE;
4308 else
4309 expect_hr = D3D_OK;
4311 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4312 if (todo)
4313 todo_wine ok(hr == expect_hr,
4314 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4315 hr, formats[i].name, types[j].name, w, h, expect_hr);
4316 else
4317 ok(hr == expect_hr,
4318 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4319 hr, formats[i].name, types[j].name, w, h, expect_hr);
4321 if (SUCCEEDED(hr))
4322 IDirectDrawSurface7_Release(surface);
4327 if (formats[i].overlay)
4328 continue;
4330 for (j = 0; j < sizeof(user_mem_tests) / sizeof(*user_mem_tests); ++j)
4332 memset(&ddsd, 0, sizeof(ddsd));
4333 ddsd.dwSize = sizeof(ddsd);
4334 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
4335 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
4337 switch (user_mem_tests[j].size_type)
4339 case SIZE_TYPE_ZERO:
4340 U1(ddsd).dwLinearSize = 0;
4341 break;
4343 case SIZE_TYPE_PITCH:
4344 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
4345 break;
4347 case SIZE_TYPE_SIZE:
4348 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
4349 break;
4351 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
4353 ddsd.lpSurface = mem;
4354 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4355 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4356 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4357 ddsd.dwWidth = 8;
4358 ddsd.dwHeight = 8;
4360 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4361 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
4363 if (FAILED(hr))
4364 continue;
4366 memset(&ddsd, 0, sizeof(ddsd));
4367 ddsd.dwSize = sizeof(ddsd);
4368 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4369 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
4370 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
4371 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
4372 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
4373 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
4374 j, U1(ddsd).dwLinearSize);
4375 else
4376 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
4377 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
4378 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
4379 IDirectDrawSurface7_Release(surface);
4383 HeapFree(GetProcessHeap(), 0, mem);
4384 cleanup:
4385 IDirectDraw7_Release(ddraw);
4386 IDirect3DDevice7_Release(device);
4387 DestroyWindow(window);
4390 struct format_support_check
4392 const DDPIXELFORMAT *format;
4393 BOOL supported;
4396 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
4398 struct format_support_check *format = ctx;
4400 if (!memcmp(format->format, fmt, sizeof(*fmt)))
4402 format->supported = TRUE;
4403 return DDENUMRET_CANCEL;
4406 return DDENUMRET_OK;
4409 static void test_unsupported_formats(void)
4411 HRESULT hr;
4412 BOOL expect_success;
4413 HWND window;
4414 IDirectDraw7 *ddraw;
4415 IDirect3D7 *d3d;
4416 IDirect3DDevice7 *device;
4417 IDirectDrawSurface7 *surface;
4418 DDSURFACEDESC2 ddsd;
4419 unsigned int i, j;
4420 DWORD expected_caps;
4421 static const struct
4423 const char *name;
4424 DDPIXELFORMAT fmt;
4426 formats[] =
4429 "D3DFMT_A8R8G8B8",
4431 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
4432 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4436 "D3DFMT_P8",
4438 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4439 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4443 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
4445 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4446 0, 0, 640, 480, 0, 0, 0, 0);
4448 if (!(device = create_device(window, DDSCL_NORMAL)))
4450 skip("Failed to create a 3D device, skipping test.\n");
4451 DestroyWindow(window);
4452 return;
4455 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4456 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4457 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4458 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4459 IDirect3D7_Release(d3d);
4461 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4463 struct format_support_check check = {&formats[i].fmt, FALSE};
4464 hr = IDirect3DDevice7_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
4465 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4467 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
4469 memset(&ddsd, 0, sizeof(ddsd));
4470 ddsd.dwSize = sizeof(ddsd);
4471 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4472 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
4473 ddsd.dwWidth = 4;
4474 ddsd.dwHeight = 4;
4475 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
4477 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
4478 expect_success = FALSE;
4479 else
4480 expect_success = TRUE;
4482 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4483 ok(SUCCEEDED(hr) == expect_success,
4484 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4485 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
4486 if (FAILED(hr))
4487 continue;
4489 memset(&ddsd, 0, sizeof(ddsd));
4490 ddsd.dwSize = sizeof(ddsd);
4491 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4492 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4494 if (caps[j] & DDSCAPS_VIDEOMEMORY)
4495 expected_caps = DDSCAPS_VIDEOMEMORY;
4496 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
4497 expected_caps = DDSCAPS_SYSTEMMEMORY;
4498 else if (check.supported)
4499 expected_caps = DDSCAPS_VIDEOMEMORY;
4500 else
4501 expected_caps = DDSCAPS_SYSTEMMEMORY;
4503 ok(ddsd.ddsCaps.dwCaps & expected_caps,
4504 "Expected capability %#x, format %s, input cap %#x.\n",
4505 expected_caps, formats[i].name, caps[j]);
4507 IDirectDrawSurface7_Release(surface);
4511 IDirectDraw7_Release(ddraw);
4512 IDirect3DDevice7_Release(device);
4513 DestroyWindow(window);
4516 static void test_rt_caps(void)
4518 const GUID *devtype = &IID_IDirect3DHALDevice;
4519 PALETTEENTRY palette_entries[256];
4520 IDirectDrawPalette *palette;
4521 IDirectDraw7 *ddraw;
4522 BOOL hal_ok = FALSE;
4523 DDPIXELFORMAT z_fmt;
4524 IDirect3D7 *d3d;
4525 unsigned int i;
4526 ULONG refcount;
4527 HWND window;
4528 HRESULT hr;
4530 static const DDPIXELFORMAT p8_fmt =
4532 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4533 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4536 const struct
4538 const DDPIXELFORMAT *pf;
4539 DWORD caps_in;
4540 DWORD caps_out;
4541 HRESULT create_device_hr;
4542 HRESULT set_rt_hr, alternative_set_rt_hr;
4544 test_data[] =
4547 NULL,
4548 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4549 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4550 D3D_OK,
4551 D3D_OK,
4552 D3D_OK,
4555 NULL,
4556 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4557 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4558 D3D_OK,
4559 D3D_OK,
4560 D3D_OK,
4563 NULL,
4564 DDSCAPS_OFFSCREENPLAIN,
4565 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4566 DDERR_INVALIDCAPS,
4567 DDERR_INVALIDCAPS,
4568 DDERR_INVALIDCAPS,
4571 NULL,
4572 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4573 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4574 D3DERR_SURFACENOTINVIDMEM,
4575 DDERR_INVALIDPARAMS,
4576 D3D_OK,
4579 NULL,
4580 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4581 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4582 DDERR_INVALIDCAPS,
4583 DDERR_INVALIDCAPS,
4584 DDERR_INVALIDCAPS,
4587 NULL,
4588 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4589 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4590 D3D_OK,
4591 D3D_OK,
4592 D3D_OK,
4595 NULL,
4596 DDSCAPS_3DDEVICE,
4597 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4598 D3D_OK,
4599 D3D_OK,
4600 D3D_OK,
4603 NULL,
4605 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4606 DDERR_INVALIDCAPS,
4607 DDERR_INVALIDCAPS,
4608 DDERR_INVALIDCAPS,
4611 NULL,
4612 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4613 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4614 D3DERR_SURFACENOTINVIDMEM,
4615 DDERR_INVALIDPARAMS,
4616 D3D_OK,
4619 NULL,
4620 DDSCAPS_SYSTEMMEMORY,
4621 DDSCAPS_SYSTEMMEMORY,
4622 DDERR_INVALIDCAPS,
4623 DDERR_INVALIDCAPS,
4624 DDERR_INVALIDCAPS,
4627 &p8_fmt,
4629 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4630 DDERR_INVALIDCAPS,
4631 DDERR_INVALIDCAPS,
4632 DDERR_INVALIDCAPS,
4635 &p8_fmt,
4636 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4637 ~0U /* AMD r200 */,
4638 DDERR_NOPALETTEATTACHED,
4639 DDERR_INVALIDCAPS,
4640 DDERR_INVALIDCAPS,
4643 &p8_fmt,
4644 DDSCAPS_OFFSCREENPLAIN,
4645 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4646 DDERR_INVALIDCAPS,
4647 DDERR_INVALIDCAPS,
4648 DDERR_INVALIDCAPS,
4651 &p8_fmt,
4652 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4653 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4654 DDERR_NOPALETTEATTACHED,
4655 DDERR_INVALIDCAPS,
4656 DDERR_INVALIDCAPS,
4659 &p8_fmt,
4660 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4661 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4662 DDERR_INVALIDCAPS,
4663 DDERR_INVALIDCAPS,
4664 DDERR_INVALIDCAPS,
4667 &z_fmt,
4668 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
4669 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4670 DDERR_INVALIDCAPS,
4671 DDERR_INVALIDPIXELFORMAT,
4672 DDERR_INVALIDPIXELFORMAT,
4675 &z_fmt,
4676 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4677 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4678 DDERR_INVALIDCAPS,
4679 DDERR_INVALIDPIXELFORMAT,
4680 DDERR_INVALIDPIXELFORMAT,
4683 &z_fmt,
4684 DDSCAPS_ZBUFFER,
4685 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4686 DDERR_INVALIDCAPS,
4687 DDERR_INVALIDCAPS,
4688 DDERR_INVALIDCAPS,
4691 &z_fmt,
4692 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4693 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4694 DDERR_INVALIDCAPS,
4695 DDERR_INVALIDPARAMS,
4696 DDERR_INVALIDPIXELFORMAT,
4699 &z_fmt,
4700 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4701 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4702 DDERR_INVALIDCAPS,
4703 DDERR_INVALIDCAPS,
4704 DDERR_INVALIDCAPS,
4708 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4709 0, 0, 640, 480, 0, 0, 0, 0);
4710 ddraw = create_ddraw();
4711 ok(!!ddraw, "Failed to create a ddraw object.\n");
4712 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4713 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4715 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
4717 skip("D3D interface is not available, skipping test.\n");
4718 goto done;
4721 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
4722 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
4723 if (hal_ok)
4724 devtype = &IID_IDirect3DTnLHalDevice;
4726 memset(&z_fmt, 0, sizeof(z_fmt));
4727 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
4728 if (FAILED(hr) || !z_fmt.dwSize)
4730 skip("No depth buffer formats available, skipping test.\n");
4731 IDirect3D7_Release(d3d);
4732 goto done;
4735 memset(palette_entries, 0, sizeof(palette_entries));
4736 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
4737 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
4739 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4741 IDirectDrawSurface7 *surface, *rt, *expected_rt, *tmp;
4742 DDSURFACEDESC2 surface_desc;
4743 IDirect3DDevice7 *device;
4745 memset(&surface_desc, 0, sizeof(surface_desc));
4746 surface_desc.dwSize = sizeof(surface_desc);
4747 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4748 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4749 if (test_data[i].pf)
4751 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4752 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4754 surface_desc.dwWidth = 640;
4755 surface_desc.dwHeight = 480;
4756 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4757 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4758 i, test_data[i].caps_in, hr);
4760 memset(&surface_desc, 0, sizeof(surface_desc));
4761 surface_desc.dwSize = sizeof(surface_desc);
4762 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
4763 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4764 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
4765 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4766 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4768 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4769 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4770 i, hr, test_data[i].create_device_hr);
4771 if (FAILED(hr))
4773 if (hr == DDERR_NOPALETTEATTACHED)
4775 hr = IDirectDrawSurface7_SetPalette(surface, palette);
4776 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
4777 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4778 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
4779 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
4780 else
4781 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
4783 IDirectDrawSurface7_Release(surface);
4785 memset(&surface_desc, 0, sizeof(surface_desc));
4786 surface_desc.dwSize = sizeof(surface_desc);
4787 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4788 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4789 surface_desc.dwWidth = 640;
4790 surface_desc.dwHeight = 480;
4791 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4792 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
4794 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
4795 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
4798 memset(&surface_desc, 0, sizeof(surface_desc));
4799 surface_desc.dwSize = sizeof(surface_desc);
4800 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4801 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4802 if (test_data[i].pf)
4804 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4805 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4807 surface_desc.dwWidth = 640;
4808 surface_desc.dwHeight = 480;
4809 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
4810 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4811 i, test_data[i].caps_in, hr);
4813 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
4814 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
4815 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4816 i, hr, test_data[i].set_rt_hr);
4817 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
4818 expected_rt = rt;
4819 else
4820 expected_rt = surface;
4822 hr = IDirect3DDevice7_GetRenderTarget(device, &tmp);
4823 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
4824 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
4826 IDirectDrawSurface7_Release(tmp);
4827 IDirectDrawSurface7_Release(rt);
4828 refcount = IDirect3DDevice7_Release(device);
4829 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
4830 refcount = IDirectDrawSurface7_Release(surface);
4831 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
4834 IDirectDrawPalette_Release(palette);
4835 IDirect3D7_Release(d3d);
4837 done:
4838 refcount = IDirectDraw7_Release(ddraw);
4839 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4840 DestroyWindow(window);
4843 static void test_primary_caps(void)
4845 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4846 IDirectDrawSurface7 *surface;
4847 DDSURFACEDESC2 surface_desc;
4848 IDirectDraw7 *ddraw;
4849 unsigned int i;
4850 ULONG refcount;
4851 HWND window;
4852 HRESULT hr;
4854 static const struct
4856 DWORD coop_level;
4857 DWORD caps_in;
4858 DWORD back_buffer_count;
4859 HRESULT hr;
4860 DWORD caps_out;
4862 test_data[] =
4865 DDSCL_NORMAL,
4866 DDSCAPS_PRIMARYSURFACE,
4867 ~0u,
4868 DD_OK,
4869 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
4872 DDSCL_NORMAL,
4873 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
4874 ~0u,
4875 DDERR_INVALIDCAPS,
4876 ~0u,
4879 DDSCL_NORMAL,
4880 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
4881 ~0u,
4882 DDERR_INVALIDCAPS,
4883 ~0u,
4886 DDSCL_NORMAL,
4887 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
4888 ~0u,
4889 DDERR_INVALIDCAPS,
4890 ~0u,
4893 DDSCL_NORMAL,
4894 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
4895 ~0u,
4896 DDERR_INVALIDCAPS,
4897 ~0u,
4900 DDSCL_NORMAL,
4901 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
4902 ~0u,
4903 DDERR_INVALIDCAPS,
4904 ~0u,
4907 DDSCL_NORMAL,
4908 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4909 ~0u,
4910 DDERR_INVALIDCAPS,
4911 ~0u,
4914 DDSCL_NORMAL,
4915 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4917 DDERR_INVALIDCAPS,
4918 ~0u,
4921 DDSCL_NORMAL,
4922 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4924 DDERR_NOEXCLUSIVEMODE,
4925 ~0u,
4928 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4929 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4931 DDERR_INVALIDCAPS,
4932 ~0u,
4935 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4936 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4938 DD_OK,
4939 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
4942 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4943 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
4945 DDERR_INVALIDCAPS,
4946 ~0u,
4949 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4950 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
4952 DDERR_INVALIDCAPS,
4953 ~0u,
4957 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4958 0, 0, 640, 480, 0, 0, 0, 0);
4959 ddraw = create_ddraw();
4960 ok(!!ddraw, "Failed to create a ddraw object.\n");
4962 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4964 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
4965 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4967 memset(&surface_desc, 0, sizeof(surface_desc));
4968 surface_desc.dwSize = sizeof(surface_desc);
4969 surface_desc.dwFlags = DDSD_CAPS;
4970 if (test_data[i].back_buffer_count != ~0u)
4971 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
4972 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4973 surface_desc.dwBackBufferCount = test_data[i].back_buffer_count;
4974 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4975 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
4976 if (FAILED(hr))
4977 continue;
4979 memset(&surface_desc, 0, sizeof(surface_desc));
4980 surface_desc.dwSize = sizeof(surface_desc);
4981 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
4982 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4983 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
4984 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4985 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4987 IDirectDrawSurface7_Release(surface);
4990 refcount = IDirectDraw7_Release(ddraw);
4991 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4992 DestroyWindow(window);
4995 static void test_surface_lock(void)
4997 IDirectDraw7 *ddraw;
4998 IDirect3D7 *d3d = NULL;
4999 IDirectDrawSurface7 *surface;
5000 IDirect3DDevice7 *device;
5001 HRESULT hr;
5002 HWND window;
5003 unsigned int i;
5004 DDSURFACEDESC2 ddsd;
5005 ULONG refcount;
5006 DDPIXELFORMAT z_fmt;
5007 BOOL hal_ok = FALSE;
5008 const GUID *devtype = &IID_IDirect3DHALDevice;
5009 D3DDEVICEDESC7 device_desc;
5010 BOOL cubemap_supported;
5011 static const struct
5013 DWORD caps;
5014 DWORD caps2;
5015 const char *name;
5017 tests[] =
5020 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
5022 "videomemory offscreenplain"
5025 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5027 "systemmemory offscreenplain"
5030 DDSCAPS_PRIMARYSURFACE,
5032 "primary"
5035 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5037 "videomemory texture"
5040 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5041 DDSCAPS2_OPAQUE,
5042 "opaque videomemory texture"
5045 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5047 "systemmemory texture"
5050 DDSCAPS_TEXTURE,
5051 DDSCAPS2_TEXTUREMANAGE,
5052 "managed texture"
5055 DDSCAPS_TEXTURE,
5056 DDSCAPS2_D3DTEXTUREMANAGE,
5057 "managed texture"
5060 DDSCAPS_TEXTURE,
5061 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5062 "opaque managed texture"
5065 DDSCAPS_TEXTURE,
5066 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5067 "opaque managed texture"
5070 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5072 "render target"
5075 DDSCAPS_ZBUFFER,
5077 "Z buffer"
5080 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5081 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5082 "videomemory cube"
5085 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5086 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5087 "opaque videomemory cube"
5090 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY,
5091 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5092 "systemmemory cube"
5095 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5096 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5097 "managed cube"
5100 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5101 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5102 "managed cube"
5105 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5106 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5107 "opaque managed cube"
5110 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5111 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5112 "opaque managed cube"
5116 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5117 0, 0, 640, 480, 0, 0, 0, 0);
5118 ddraw = create_ddraw();
5119 ok(!!ddraw, "Failed to create a ddraw object.\n");
5120 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5121 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5123 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5125 skip("D3D interface is not available, skipping test.\n");
5126 goto done;
5129 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5130 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5131 if (hal_ok)
5132 devtype = &IID_IDirect3DTnLHalDevice;
5134 memset(&z_fmt, 0, sizeof(z_fmt));
5135 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5136 if (FAILED(hr) || !z_fmt.dwSize)
5138 skip("No depth buffer formats available, skipping test.\n");
5139 goto done;
5142 memset(&ddsd, 0, sizeof(ddsd));
5143 ddsd.dwSize = sizeof(ddsd);
5144 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5145 ddsd.dwWidth = 64;
5146 ddsd.dwHeight = 64;
5147 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5148 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5149 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5151 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5152 ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr);
5153 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
5154 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5155 cubemap_supported = !!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP);
5156 IDirect3DDevice7_Release(device);
5158 IDirectDrawSurface7_Release(surface);
5160 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5162 if (!cubemap_supported && tests[i].caps2 & DDSCAPS2_CUBEMAP)
5163 continue;
5165 memset(&ddsd, 0, sizeof(ddsd));
5166 ddsd.dwSize = sizeof(ddsd);
5167 ddsd.dwFlags = DDSD_CAPS;
5168 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5170 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5171 ddsd.dwWidth = 64;
5172 ddsd.dwHeight = 64;
5174 if (tests[i].caps & DDSCAPS_ZBUFFER)
5176 ddsd.dwFlags |= DDSD_PIXELFORMAT;
5177 U4(ddsd).ddpfPixelFormat = z_fmt;
5179 ddsd.ddsCaps.dwCaps = tests[i].caps;
5180 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5182 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5183 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
5185 memset(&ddsd, 0, sizeof(ddsd));
5186 ddsd.dwSize = sizeof(ddsd);
5187 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5188 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
5189 if (SUCCEEDED(hr))
5191 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5192 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5195 IDirectDrawSurface7_Release(surface);
5198 done:
5199 if (d3d)
5200 IDirect3D7_Release(d3d);
5201 refcount = IDirectDraw7_Release(ddraw);
5202 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5203 DestroyWindow(window);
5206 static void test_surface_discard(void)
5208 IDirect3DDevice7 *device;
5209 IDirect3D7 *d3d;
5210 IDirectDraw7 *ddraw;
5211 HRESULT hr;
5212 HWND window;
5213 DDSURFACEDESC2 ddsd;
5214 IDirectDrawSurface7 *surface, *target;
5215 void *addr;
5216 static const struct
5218 DWORD caps, caps2;
5219 BOOL discard;
5221 tests[] =
5223 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5224 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5225 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5226 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5227 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
5228 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5229 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
5230 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5232 unsigned int i;
5234 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5235 0, 0, 640, 480, 0, 0, 0, 0);
5237 if (!(device = create_device(window, DDSCL_NORMAL)))
5239 skip("Failed to create a 3D device, skipping test.\n");
5240 DestroyWindow(window);
5241 return;
5243 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5244 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5245 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
5246 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5247 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
5248 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5250 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5252 BOOL discarded;
5254 memset(&ddsd, 0, sizeof(ddsd));
5255 ddsd.dwSize = sizeof(ddsd);
5256 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5257 ddsd.ddsCaps.dwCaps = tests[i].caps;
5258 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5259 ddsd.dwWidth = 64;
5260 ddsd.dwHeight = 64;
5261 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5262 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
5264 memset(&ddsd, 0, sizeof(ddsd));
5265 ddsd.dwSize = sizeof(ddsd);
5266 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5267 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5268 addr = ddsd.lpSurface;
5269 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5270 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5272 memset(&ddsd, 0, sizeof(ddsd));
5273 ddsd.dwSize = sizeof(ddsd);
5274 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5275 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5276 discarded = ddsd.lpSurface != addr;
5277 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5278 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5280 hr = IDirectDrawSurface7_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
5281 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
5283 memset(&ddsd, 0, sizeof(ddsd));
5284 ddsd.dwSize = sizeof(ddsd);
5285 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5286 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5287 discarded |= ddsd.lpSurface != addr;
5288 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5289 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5291 IDirectDrawSurface7_Release(surface);
5293 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5294 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5295 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
5298 IDirectDrawSurface7_Release(target);
5299 IDirectDraw7_Release(ddraw);
5300 IDirect3D7_Release(d3d);
5301 IDirect3DDevice7_Release(device);
5302 DestroyWindow(window);
5305 static void test_flip(void)
5307 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5308 IDirectDrawSurface7 *primary, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
5309 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, 0};
5310 DDSURFACEDESC2 surface_desc;
5311 BOOL sysmem_primary;
5312 IDirectDraw7 *ddraw;
5313 D3DCOLOR color;
5314 ULONG refcount;
5315 HWND window;
5316 DDBLTFX fx;
5317 HRESULT hr;
5319 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5320 0, 0, 640, 480, 0, 0, 0, 0);
5321 ddraw = create_ddraw();
5322 ok(!!ddraw, "Failed to create a ddraw object.\n");
5324 hr = set_display_mode(ddraw, 640, 480);
5325 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
5326 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5327 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5329 memset(&surface_desc, 0, sizeof(surface_desc));
5330 surface_desc.dwSize = sizeof(surface_desc);
5331 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5332 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5333 surface_desc.dwBackBufferCount = 3;
5334 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5335 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5337 memset(&surface_desc, 0, sizeof(surface_desc));
5338 surface_desc.dwSize = sizeof(surface_desc);
5339 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
5340 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5341 ok((surface_desc.ddsCaps.dwCaps & ~placement)
5342 == (DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5343 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5344 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
5346 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &backbuffer1);
5347 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5348 memset(&surface_desc, 0, sizeof(surface_desc));
5349 surface_desc.dwSize = sizeof(surface_desc);
5350 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer1, &surface_desc);
5351 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5352 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5353 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_BACKBUFFER),
5354 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5356 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
5357 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5358 memset(&surface_desc, 0, sizeof(surface_desc));
5359 surface_desc.dwSize = sizeof(surface_desc);
5360 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer2, &surface_desc);
5361 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5362 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5363 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5364 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5366 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
5367 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5368 memset(&surface_desc, 0, sizeof(surface_desc));
5369 surface_desc.dwSize = sizeof(surface_desc);
5370 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer3, &surface_desc);
5371 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5372 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5373 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5374 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5376 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer3, &caps, &surface);
5377 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5378 ok(surface == primary, "Got unexpected surface %p, expected %p.\n", surface, primary);
5379 IDirectDrawSurface7_Release(surface);
5381 memset(&surface_desc, 0, sizeof(surface_desc));
5382 surface_desc.dwSize = sizeof(surface_desc);
5383 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5384 surface_desc.ddsCaps.dwCaps = 0;
5385 surface_desc.dwWidth = 640;
5386 surface_desc.dwHeight = 480;
5387 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5388 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5389 hr = IDirectDrawSurface7_Flip(primary, surface, DDFLIP_WAIT);
5390 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5391 IDirectDrawSurface7_Release(surface);
5393 hr = IDirectDrawSurface7_Flip(primary, primary, DDFLIP_WAIT);
5394 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5395 hr = IDirectDrawSurface7_Flip(backbuffer1, NULL, DDFLIP_WAIT);
5396 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5397 hr = IDirectDrawSurface7_Flip(backbuffer2, NULL, DDFLIP_WAIT);
5398 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5399 hr = IDirectDrawSurface7_Flip(backbuffer3, NULL, DDFLIP_WAIT);
5400 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5402 memset(&fx, 0, sizeof(fx));
5403 fx.dwSize = sizeof(fx);
5404 U5(fx).dwFillColor = 0xffff0000;
5405 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5406 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5407 U5(fx).dwFillColor = 0xff00ff00;
5408 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5409 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5410 U5(fx).dwFillColor = 0xff0000ff;
5411 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5412 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5414 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5415 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5416 color = get_surface_color(backbuffer1, 320, 240);
5417 /* The testbot seems to just copy the contents of one surface to all the
5418 * others, instead of properly flipping. */
5419 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5420 "Got unexpected color 0x%08x.\n", color);
5421 color = get_surface_color(backbuffer2, 320, 240);
5422 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5423 U5(fx).dwFillColor = 0xffff0000;
5424 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5425 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5427 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5428 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5429 color = get_surface_color(backbuffer1, 320, 240);
5430 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5431 "Got unexpected color 0x%08x.\n", color);
5432 color = get_surface_color(backbuffer2, 320, 240);
5433 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5434 U5(fx).dwFillColor = 0xff00ff00;
5435 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5436 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5438 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
5439 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5440 color = get_surface_color(backbuffer1, 320, 240);
5441 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5442 "Got unexpected color 0x%08x.\n", color);
5443 color = get_surface_color(backbuffer2, 320, 240);
5444 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5445 U5(fx).dwFillColor = 0xff0000ff;
5446 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5447 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5449 hr = IDirectDrawSurface7_Flip(primary, backbuffer1, DDFLIP_WAIT);
5450 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5451 color = get_surface_color(backbuffer2, 320, 240);
5452 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5453 "Got unexpected color 0x%08x.\n", color);
5454 color = get_surface_color(backbuffer3, 320, 240);
5455 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5456 U5(fx).dwFillColor = 0xffff0000;
5457 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5458 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5460 hr = IDirectDrawSurface7_Flip(primary, backbuffer2, DDFLIP_WAIT);
5461 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5462 color = get_surface_color(backbuffer1, 320, 240);
5463 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5464 color = get_surface_color(backbuffer3, 320, 240);
5465 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5466 "Got unexpected color 0x%08x.\n", color);
5467 U5(fx).dwFillColor = 0xff00ff00;
5468 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5469 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5471 hr = IDirectDrawSurface7_Flip(primary, backbuffer3, DDFLIP_WAIT);
5472 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5473 color = get_surface_color(backbuffer1, 320, 240);
5474 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5475 "Got unexpected color 0x%08x.\n", color);
5476 color = get_surface_color(backbuffer2, 320, 240);
5477 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5479 IDirectDrawSurface7_Release(backbuffer3);
5480 IDirectDrawSurface7_Release(backbuffer2);
5481 IDirectDrawSurface7_Release(backbuffer1);
5482 IDirectDrawSurface7_Release(primary);
5483 refcount = IDirectDraw7_Release(ddraw);
5484 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5485 DestroyWindow(window);
5488 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
5490 memset(ddsd, 0, sizeof(*ddsd));
5491 ddsd->dwSize = sizeof(*ddsd);
5494 static void test_set_surface_desc(void)
5496 IDirectDraw7 *ddraw;
5497 HWND window;
5498 HRESULT hr;
5499 DDSURFACEDESC2 ddsd;
5500 IDirectDrawSurface7 *surface;
5501 BYTE data[16*16*4];
5502 ULONG ref;
5503 unsigned int i;
5504 static const struct
5506 DWORD caps, caps2;
5507 BOOL supported;
5508 const char *name;
5510 invalid_caps_tests[] =
5512 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
5513 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
5514 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
5515 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
5516 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
5519 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5520 0, 0, 640, 480, 0, 0, 0, 0);
5521 ddraw = create_ddraw();
5522 ok(!!ddraw, "Failed to create a ddraw object.\n");
5523 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5524 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5526 reset_ddsd(&ddsd);
5527 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5528 ddsd.dwWidth = 8;
5529 ddsd.dwHeight = 8;
5530 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5531 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5532 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5533 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5534 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5535 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5536 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5538 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5539 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5541 reset_ddsd(&ddsd);
5542 ddsd.dwFlags = DDSD_LPSURFACE;
5543 ddsd.lpSurface = data;
5544 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5545 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5547 /* Redundantly setting the same lpSurface is not an error. */
5548 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5549 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5551 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5552 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5553 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5554 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
5556 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5557 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5558 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5559 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
5560 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5561 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5563 reset_ddsd(&ddsd);
5564 ddsd.dwFlags = DDSD_LPSURFACE;
5565 ddsd.lpSurface = data;
5566 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 1);
5567 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
5569 ddsd.lpSurface = NULL;
5570 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5571 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
5573 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, NULL, 0);
5574 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
5576 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5577 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5578 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5579 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5580 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5582 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5583 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5584 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
5586 ddsd.dwFlags = DDSD_CAPS;
5587 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5588 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
5590 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
5591 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
5592 ddsd.lpSurface = data;
5593 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5594 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5595 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5596 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5597 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5598 ddsd.ddsCaps.dwCaps = 0;
5599 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
5600 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5601 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5603 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5604 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5605 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5606 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5607 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5609 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5610 reset_ddsd(&ddsd);
5611 ddsd.dwFlags = DDSD_HEIGHT;
5612 ddsd.dwHeight = 16;
5613 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5614 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
5616 ddsd.lpSurface = data;
5617 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
5618 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5619 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5621 ddsd.dwHeight = 0;
5622 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5623 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
5625 reset_ddsd(&ddsd);
5626 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5627 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
5628 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5629 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5631 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5632 reset_ddsd(&ddsd);
5633 ddsd.dwFlags = DDSD_PITCH;
5634 U1(ddsd).lPitch = 8 * 4;
5635 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5636 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
5638 ddsd.dwFlags = DDSD_WIDTH;
5639 ddsd.dwWidth = 16;
5640 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5641 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
5643 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
5644 ddsd.lpSurface = data;
5645 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5646 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
5648 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
5649 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5650 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
5652 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5653 U1(ddsd).lPitch = 16 * 4;
5654 ddsd.dwWidth = 16;
5655 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5656 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5658 reset_ddsd(&ddsd);
5659 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5660 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5661 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5662 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5663 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
5665 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5667 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5668 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5669 U1(ddsd).lPitch = 4 * 4;
5670 ddsd.lpSurface = data;
5671 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5672 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5674 U1(ddsd).lPitch = 4;
5675 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5676 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5678 U1(ddsd).lPitch = 16 * 4 + 1;
5679 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5680 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5682 U1(ddsd).lPitch = 16 * 4 + 3;
5683 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5684 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5686 U1(ddsd).lPitch = -4;
5687 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5688 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
5690 U1(ddsd).lPitch = 16 * 4;
5691 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5692 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5694 reset_ddsd(&ddsd);
5695 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5696 U1(ddsd).lPitch = 0;
5697 ddsd.dwWidth = 16;
5698 ddsd.lpSurface = data;
5699 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5700 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
5702 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5703 U1(ddsd).lPitch = 16 * 4;
5704 ddsd.dwWidth = 0;
5705 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5706 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
5708 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5709 ddsd.dwFlags = DDSD_PIXELFORMAT;
5710 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5711 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5712 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5713 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5714 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5715 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5716 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5717 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
5719 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
5720 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5721 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5723 /* Can't set color keys. */
5724 reset_ddsd(&ddsd);
5725 ddsd.dwFlags = DDSD_CKSRCBLT;
5726 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
5727 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
5728 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5729 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5731 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
5732 ddsd.lpSurface = data;
5733 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5734 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5736 IDirectDrawSurface7_Release(surface);
5738 /* SetSurfaceDesc needs systemmemory surfaces.
5740 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5741 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
5743 reset_ddsd(&ddsd);
5744 ddsd.dwFlags = DDSD_CAPS;
5745 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
5746 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
5747 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5749 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5750 ddsd.dwWidth = 8;
5751 ddsd.dwHeight = 8;
5752 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5753 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5754 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5755 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5756 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5757 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5760 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5761 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW, "Failed to create surface, hr %#x.\n", hr);
5762 if (FAILED(hr))
5764 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5765 invalid_caps_tests[i].name);
5766 goto done;
5769 reset_ddsd(&ddsd);
5770 ddsd.dwFlags = DDSD_LPSURFACE;
5771 ddsd.lpSurface = data;
5772 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5773 if (invalid_caps_tests[i].supported)
5775 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5777 else
5779 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5780 invalid_caps_tests[i].name, hr);
5782 /* Check priority of error conditions. */
5783 ddsd.dwFlags = DDSD_WIDTH;
5784 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5785 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5786 invalid_caps_tests[i].name, hr);
5789 IDirectDrawSurface7_Release(surface);
5792 done:
5793 ref = IDirectDraw7_Release(ddraw);
5794 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5795 DestroyWindow(window);
5798 static void test_user_memory_getdc(void)
5800 IDirectDraw7 *ddraw;
5801 HWND window;
5802 HRESULT hr;
5803 DDSURFACEDESC2 ddsd;
5804 IDirectDrawSurface7 *surface;
5805 DWORD data[16][16];
5806 ULONG ref;
5807 HDC dc;
5808 unsigned int x, y;
5810 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5811 0, 0, 640, 480, 0, 0, 0, 0);
5812 ddraw = create_ddraw();
5813 ok(!!ddraw, "Failed to create a ddraw object.\n");
5814 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5815 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5817 reset_ddsd(&ddsd);
5818 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5819 ddsd.dwWidth = 16;
5820 ddsd.dwHeight = 16;
5821 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5822 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5823 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5824 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5825 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5826 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5827 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5828 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5829 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5831 memset(data, 0xaa, sizeof(data));
5832 reset_ddsd(&ddsd);
5833 ddsd.dwFlags = DDSD_LPSURFACE;
5834 ddsd.lpSurface = data;
5835 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5836 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5838 hr = IDirectDrawSurface7_GetDC(surface, &dc);
5839 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5840 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
5841 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
5842 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
5843 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5845 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
5846 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
5848 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
5849 ddsd.lpSurface = data;
5850 ddsd.dwWidth = 4;
5851 ddsd.dwHeight = 8;
5852 U1(ddsd).lPitch = sizeof(*data);
5853 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
5854 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5856 memset(data, 0xaa, sizeof(data));
5857 hr = IDirectDrawSurface7_GetDC(surface, &dc);
5858 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5859 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
5860 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
5861 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
5862 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5864 for (y = 0; y < 4; y++)
5866 for (x = 0; x < 4; x++)
5868 if ((x == 1 || x == 2) && (y == 1 || y == 2))
5869 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5870 x, y, data[y][x]);
5871 else
5872 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
5873 x, y, data[y][x]);
5876 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5877 data[0][5]);
5878 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5879 data[7][3]);
5880 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5881 data[7][4]);
5882 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5883 data[8][0]);
5885 IDirectDrawSurface7_Release(surface);
5886 ref = IDirectDraw7_Release(ddraw);
5887 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5888 DestroyWindow(window);
5891 static void test_sysmem_overlay(void)
5893 IDirectDraw7 *ddraw;
5894 HWND window;
5895 HRESULT hr;
5896 DDSURFACEDESC2 ddsd;
5897 IDirectDrawSurface7 *surface;
5898 ULONG ref;
5900 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5901 0, 0, 640, 480, 0, 0, 0, 0);
5902 ddraw = create_ddraw();
5903 ok(!!ddraw, "Failed to create a ddraw object.\n");
5904 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5905 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5907 reset_ddsd(&ddsd);
5908 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
5909 ddsd.dwWidth = 16;
5910 ddsd.dwHeight = 16;
5911 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
5912 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5913 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5914 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5915 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5916 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5917 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5918 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5919 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
5921 ref = IDirectDraw7_Release(ddraw);
5922 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5923 DestroyWindow(window);
5926 static void test_primary_palette(void)
5928 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, 0};
5929 IDirectDrawSurface7 *primary, *backbuffer;
5930 PALETTEENTRY palette_entries[256];
5931 IDirectDrawPalette *palette, *tmp;
5932 DDSURFACEDESC2 surface_desc;
5933 IDirectDraw7 *ddraw;
5934 DWORD palette_caps;
5935 ULONG refcount;
5936 HWND window;
5937 HRESULT hr;
5939 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5940 0, 0, 640, 480, 0, 0, 0, 0);
5941 ddraw = create_ddraw();
5942 ok(!!ddraw, "Failed to create a ddraw object.\n");
5943 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
5945 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5946 IDirectDraw7_Release(ddraw);
5947 DestroyWindow(window);
5948 return;
5950 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5951 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5953 memset(&surface_desc, 0, sizeof(surface_desc));
5954 surface_desc.dwSize = sizeof(surface_desc);
5955 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5956 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5957 surface_desc.dwBackBufferCount = 1;
5958 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5959 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5960 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
5961 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5963 memset(palette_entries, 0, sizeof(palette_entries));
5964 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
5965 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5966 refcount = get_refcount((IUnknown *)palette);
5967 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5969 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5970 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5971 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
5973 hr = IDirectDrawSurface7_SetPalette(primary, palette);
5974 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5976 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5977 * and is generally somewhat broken with respect to 8 bpp / palette
5978 * handling. */
5979 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer, &tmp)))
5981 win_skip("Broken palette handling detected, skipping tests.\n");
5982 IDirectDrawPalette_Release(tmp);
5983 IDirectDrawPalette_Release(palette);
5984 /* The Windows 8 testbot keeps extra references to the primary and
5985 * backbuffer while in 8 bpp mode. */
5986 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
5987 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
5988 goto done;
5991 refcount = get_refcount((IUnknown *)palette);
5992 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5994 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5995 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5996 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
5997 "Got unexpected palette caps %#x.\n", palette_caps);
5999 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
6000 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6001 refcount = get_refcount((IUnknown *)palette);
6002 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6004 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6005 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6006 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6008 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6009 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6010 refcount = get_refcount((IUnknown *)palette);
6011 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6013 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6014 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6015 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6016 IDirectDrawPalette_Release(tmp);
6017 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
6018 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6020 refcount = IDirectDrawPalette_Release(palette);
6021 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6022 refcount = IDirectDrawPalette_Release(palette);
6023 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6025 /* Note that this only seems to work when the palette is attached to the
6026 * primary surface. When attached to a regular surface, attempting to get
6027 * the palette here will cause an access violation. */
6028 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6029 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6031 done:
6032 refcount = IDirectDrawSurface7_Release(backbuffer);
6033 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6034 refcount = IDirectDrawSurface7_Release(primary);
6035 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6036 refcount = IDirectDraw7_Release(ddraw);
6037 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6038 DestroyWindow(window);
6041 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
6043 UINT *surface_count = context;
6045 ++(*surface_count);
6046 IDirectDrawSurface_Release(surface);
6048 return DDENUMRET_OK;
6051 static void test_surface_attachment(void)
6053 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
6054 IDirectDrawSurface *surface1v1, *surface2v1;
6055 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0};
6056 DDSURFACEDESC2 surface_desc;
6057 IDirectDraw7 *ddraw;
6058 UINT surface_count;
6059 ULONG refcount;
6060 HWND window;
6061 HRESULT hr;
6063 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6064 0, 0, 640, 480, 0, 0, 0, 0);
6065 ddraw = create_ddraw();
6066 ok(!!ddraw, "Failed to create a ddraw object.\n");
6067 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6068 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6070 memset(&surface_desc, 0, sizeof(surface_desc));
6071 surface_desc.dwSize = sizeof(surface_desc);
6072 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6073 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6074 U2(surface_desc).dwMipMapCount = 3;
6075 surface_desc.dwWidth = 128;
6076 surface_desc.dwHeight = 128;
6077 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
6079 skip("Failed to create a texture, skipping tests.\n");
6080 IDirectDraw7_Release(ddraw);
6081 DestroyWindow(window);
6082 return;
6085 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
6086 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6087 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
6088 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6089 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
6090 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6092 surface_count = 0;
6093 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
6094 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6095 surface_count = 0;
6096 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
6097 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6098 surface_count = 0;
6099 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
6100 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
6102 memset(&surface_desc, 0, sizeof(surface_desc));
6103 surface_desc.dwSize = sizeof(surface_desc);
6104 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6105 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6106 surface_desc.dwWidth = 16;
6107 surface_desc.dwHeight = 16;
6108 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6109 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6111 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6112 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6113 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6114 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6115 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
6116 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6117 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
6118 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6119 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
6120 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6121 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
6122 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6124 IDirectDrawSurface7_Release(surface4);
6126 memset(&surface_desc, 0, sizeof(surface_desc));
6127 surface_desc.dwSize = sizeof(surface_desc);
6128 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6129 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6130 surface_desc.dwWidth = 16;
6131 surface_desc.dwHeight = 16;
6132 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6133 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6135 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6136 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6137 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6138 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6139 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
6140 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6141 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
6142 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6143 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
6144 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6145 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
6146 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6148 IDirectDrawSurface7_Release(surface4);
6149 IDirectDrawSurface7_Release(surface3);
6150 IDirectDrawSurface7_Release(surface2);
6151 IDirectDrawSurface7_Release(surface1);
6153 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6154 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6156 /* Try a single primary and two offscreen plain surfaces. */
6157 memset(&surface_desc, 0, sizeof(surface_desc));
6158 surface_desc.dwSize = sizeof(surface_desc);
6159 surface_desc.dwFlags = DDSD_CAPS;
6160 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6161 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6162 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6164 memset(&surface_desc, 0, sizeof(surface_desc));
6165 surface_desc.dwSize = sizeof(surface_desc);
6166 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6167 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6168 surface_desc.dwWidth = registry_mode.dmPelsWidth;
6169 surface_desc.dwHeight = registry_mode.dmPelsHeight;
6170 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6171 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6173 memset(&surface_desc, 0, sizeof(surface_desc));
6174 surface_desc.dwSize = sizeof(surface_desc);
6175 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6176 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6177 surface_desc.dwWidth = registry_mode.dmPelsWidth;
6178 surface_desc.dwHeight = registry_mode.dmPelsHeight;
6179 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6180 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6182 /* This one has a different size. */
6183 memset(&surface_desc, 0, sizeof(surface_desc));
6184 surface_desc.dwSize = sizeof(surface_desc);
6185 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6186 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6187 surface_desc.dwWidth = 128;
6188 surface_desc.dwHeight = 128;
6189 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6190 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6192 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6193 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6194 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
6195 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6196 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
6197 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6198 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6199 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6200 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6201 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6203 IDirectDrawSurface7_Release(surface4);
6204 IDirectDrawSurface7_Release(surface3);
6205 IDirectDrawSurface7_Release(surface2);
6206 IDirectDrawSurface7_Release(surface1);
6208 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
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 | DDSD_PIXELFORMAT;
6212 surface_desc.dwWidth = 64;
6213 surface_desc.dwHeight = 64;
6214 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
6215 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6216 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
6217 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
6218 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
6219 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
6220 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
6221 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6222 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6223 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6224 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6226 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
6227 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
6228 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
6229 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
6230 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6231 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6233 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
6234 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6235 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
6236 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6238 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6239 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6240 refcount = get_refcount((IUnknown *)surface2);
6241 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6242 refcount = get_refcount((IUnknown *)surface2v1);
6243 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6244 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6245 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
6246 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6247 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6248 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6249 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6251 /* Attaching while already attached to other surface. */
6252 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
6253 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6254 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
6255 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6256 IDirectDrawSurface7_Release(surface3);
6258 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
6259 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6260 refcount = get_refcount((IUnknown *)surface2);
6261 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6262 refcount = get_refcount((IUnknown *)surface2v1);
6263 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6265 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6266 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6267 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6268 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
6269 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6270 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6271 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6272 refcount = IDirectDrawSurface7_Release(surface2);
6273 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6274 refcount = IDirectDrawSurface7_Release(surface1);
6275 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6277 /* Automatic detachment on release. */
6278 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6279 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6280 refcount = get_refcount((IUnknown *)surface2v1);
6281 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6282 refcount = IDirectDrawSurface_Release(surface1v1);
6283 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6284 refcount = IDirectDrawSurface_Release(surface2v1);
6285 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6286 refcount = IDirectDraw7_Release(ddraw);
6287 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6288 DestroyWindow(window);
6291 static void test_private_data(void)
6293 IDirectDraw7 *ddraw;
6294 IDirectDrawSurface7 *surface, *surface2;
6295 DDSURFACEDESC2 surface_desc;
6296 ULONG refcount, refcount2, refcount3;
6297 IUnknown *ptr;
6298 DWORD size = sizeof(ptr);
6299 HRESULT hr;
6300 HWND window;
6301 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6302 DWORD data[] = {1, 2, 3, 4};
6303 DDCAPS hal_caps;
6304 static const GUID ddraw_private_data_test_guid =
6306 0xfdb37466,
6307 0x428f,
6308 0x4edf,
6309 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6311 static const GUID ddraw_private_data_test_guid2 =
6313 0x2e5afac2,
6314 0x87b5,
6315 0x4c10,
6316 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6319 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6320 0, 0, 640, 480, 0, 0, 0, 0);
6321 ddraw = create_ddraw();
6322 ok(!!ddraw, "Failed to create a ddraw object.\n");
6323 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6324 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6326 reset_ddsd(&surface_desc);
6327 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
6328 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
6329 surface_desc.dwHeight = 4;
6330 surface_desc.dwWidth = 4;
6331 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6332 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6334 /* NULL pointers are not valid, but don't cause a crash. */
6335 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
6336 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
6337 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6338 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
6339 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6340 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
6341 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6343 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6344 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6345 0, DDSPD_IUNKNOWNPOINTER);
6346 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6347 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6348 5, DDSPD_IUNKNOWNPOINTER);
6349 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6350 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6351 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
6352 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6354 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6355 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6356 * erases the old content and returns an error. This behavior has
6357 * been fixed in d3d8 and d3d9. Unless an application is found
6358 * that depends on this we don't care about this behavior. */
6359 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6360 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6361 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6362 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6363 0, DDSPD_IUNKNOWNPOINTER);
6364 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6365 size = sizeof(ptr);
6366 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6367 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6368 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
6369 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6371 refcount = get_refcount((IUnknown *)ddraw);
6372 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6373 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6374 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6375 refcount2 = get_refcount((IUnknown *)ddraw);
6376 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6378 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
6379 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6380 refcount2 = get_refcount((IUnknown *)ddraw);
6381 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6383 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6384 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6385 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6386 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
6387 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
6388 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6389 refcount2 = get_refcount((IUnknown *)ddraw);
6390 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6392 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6393 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6394 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6395 size = 2 * sizeof(ptr);
6396 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6397 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6398 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6399 refcount2 = get_refcount(ptr);
6400 /* Object is NOT addref'ed by the getter. */
6401 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
6402 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6404 ptr = (IUnknown *)0xdeadbeef;
6405 size = 1;
6406 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6407 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6408 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6409 size = 2 * sizeof(ptr);
6410 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6411 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6412 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
6413 size = 1;
6414 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6415 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6416 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6417 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6418 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
6419 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6420 size = 0xdeadbabe;
6421 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
6422 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6423 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6424 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
6425 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
6426 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6428 refcount3 = IDirectDrawSurface7_Release(surface);
6429 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
6431 /* Destroying the surface frees the reference held on the private data. It also frees
6432 * the reference the surface is holding on its creating object. */
6433 refcount2 = get_refcount((IUnknown *)ddraw);
6434 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
6436 memset(&hal_caps, 0, sizeof(hal_caps));
6437 hal_caps.dwSize = sizeof(hal_caps);
6438 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6439 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6440 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6442 reset_ddsd(&surface_desc);
6443 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
6444 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6445 surface_desc.dwHeight = 4;
6446 surface_desc.dwWidth = 4;
6447 U2(surface_desc).dwMipMapCount = 2;
6448 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6449 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6450 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
6451 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6453 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
6454 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6455 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
6456 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6458 IDirectDrawSurface7_Release(surface2);
6459 IDirectDrawSurface7_Release(surface);
6461 else
6462 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
6464 refcount = IDirectDraw7_Release(ddraw);
6465 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6466 DestroyWindow(window);
6469 static void test_pixel_format(void)
6471 HWND window, window2 = NULL;
6472 HDC hdc, hdc2 = NULL;
6473 HMODULE gl = NULL;
6474 int format, test_format;
6475 PIXELFORMATDESCRIPTOR pfd;
6476 IDirectDraw7 *ddraw = NULL;
6477 IDirectDrawClipper *clipper = NULL;
6478 DDSURFACEDESC2 ddsd;
6479 IDirectDrawSurface7 *primary = NULL;
6480 DDBLTFX fx;
6481 HRESULT hr;
6483 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6484 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6485 if (!window)
6487 skip("Failed to create window\n");
6488 return;
6491 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6492 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6494 hdc = GetDC(window);
6495 if (!hdc)
6497 skip("Failed to get DC\n");
6498 goto cleanup;
6501 if (window2)
6502 hdc2 = GetDC(window2);
6504 gl = LoadLibraryA("opengl32.dll");
6505 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6507 format = GetPixelFormat(hdc);
6508 ok(format == 0, "new window has pixel format %d\n", format);
6510 ZeroMemory(&pfd, sizeof(pfd));
6511 pfd.nSize = sizeof(pfd);
6512 pfd.nVersion = 1;
6513 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
6514 pfd.iPixelType = PFD_TYPE_RGBA;
6515 pfd.iLayerType = PFD_MAIN_PLANE;
6516 format = ChoosePixelFormat(hdc, &pfd);
6517 if (format <= 0)
6519 skip("no pixel format available\n");
6520 goto cleanup;
6523 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
6525 skip("failed to set pixel format\n");
6526 goto cleanup;
6529 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
6531 skip("failed to set pixel format on second window\n");
6532 if (hdc2)
6534 ReleaseDC(window2, hdc2);
6535 hdc2 = NULL;
6539 ddraw = create_ddraw();
6540 ok(!!ddraw, "Failed to create a ddraw object.\n");
6542 test_format = GetPixelFormat(hdc);
6543 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6545 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6546 if (FAILED(hr))
6548 skip("Failed to set cooperative level, hr %#x.\n", hr);
6549 goto cleanup;
6552 test_format = GetPixelFormat(hdc);
6553 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6555 if (hdc2)
6557 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
6558 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
6559 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
6560 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
6562 test_format = GetPixelFormat(hdc);
6563 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6565 test_format = GetPixelFormat(hdc2);
6566 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6569 memset(&ddsd, 0, sizeof(ddsd));
6570 ddsd.dwSize = sizeof(ddsd);
6571 ddsd.dwFlags = DDSD_CAPS;
6572 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6574 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
6575 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
6577 test_format = GetPixelFormat(hdc);
6578 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6580 if (hdc2)
6582 test_format = GetPixelFormat(hdc2);
6583 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6586 if (clipper)
6588 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
6589 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
6591 test_format = GetPixelFormat(hdc);
6592 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6594 test_format = GetPixelFormat(hdc2);
6595 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6598 memset(&fx, 0, sizeof(fx));
6599 fx.dwSize = sizeof(fx);
6600 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6601 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
6603 test_format = GetPixelFormat(hdc);
6604 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6606 if (hdc2)
6608 test_format = GetPixelFormat(hdc2);
6609 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6612 cleanup:
6613 if (primary) IDirectDrawSurface7_Release(primary);
6614 if (clipper) IDirectDrawClipper_Release(clipper);
6615 if (ddraw) IDirectDraw7_Release(ddraw);
6616 if (gl) FreeLibrary(gl);
6617 if (hdc) ReleaseDC(window, hdc);
6618 if (hdc2) ReleaseDC(window2, hdc2);
6619 if (window) DestroyWindow(window);
6620 if (window2) DestroyWindow(window2);
6623 static void test_create_surface_pitch(void)
6625 IDirectDrawSurface7 *surface;
6626 DDSURFACEDESC2 surface_desc;
6627 IDirectDraw7 *ddraw;
6628 unsigned int i;
6629 ULONG refcount;
6630 HWND window;
6631 HRESULT hr;
6632 void *mem;
6634 static const struct
6636 DWORD placement;
6637 DWORD flags_in;
6638 DWORD pitch_in;
6639 HRESULT hr;
6640 DWORD flags_out;
6641 DWORD pitch_out32;
6642 DWORD pitch_out64;
6644 test_data[] =
6646 {DDSCAPS_VIDEOMEMORY, 0, 0, DD_OK,
6647 DDSD_PITCH, 0x100, 0x100},
6648 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x104, DD_OK,
6649 DDSD_PITCH, 0x100, 0x100},
6650 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
6651 DDSD_PITCH, 0x100, 0x100},
6652 {DDSCAPS_VIDEOMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
6653 0, 0, 0 },
6654 {DDSCAPS_SYSTEMMEMORY, 0, 0, DD_OK,
6655 DDSD_PITCH, 0x100, 0x0fc},
6656 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x104, DD_OK,
6657 DDSD_PITCH, 0x100, 0x0fc},
6658 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
6659 DDSD_PITCH, 0x100, 0x0fc},
6660 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
6661 DDSD_PITCH, 0x100, 0x0fc},
6662 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
6663 0, 0, 0 },
6664 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
6665 DDSD_PITCH, 0x100, 0x100},
6666 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
6667 0, 0, 0 },
6668 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
6669 DDSD_PITCH, 0x0fc, 0x0fc},
6670 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
6671 0, 0, 0 },
6672 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
6673 0, 0, 0 },
6674 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
6675 0, 0, 0 },
6676 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
6677 DDSD_PITCH, 0x100, 0x100},
6679 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
6681 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6682 0, 0, 640, 480, 0, 0, 0, 0);
6683 ddraw = create_ddraw();
6684 ok(!!ddraw, "Failed to create a ddraw object.\n");
6685 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6686 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6688 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
6690 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
6692 memset(&surface_desc, 0, sizeof(surface_desc));
6693 surface_desc.dwSize = sizeof(surface_desc);
6694 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
6695 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | test_data[i].placement;
6696 surface_desc.dwWidth = 63;
6697 surface_desc.dwHeight = 63;
6698 U1(surface_desc).lPitch = test_data[i].pitch_in;
6699 surface_desc.lpSurface = mem;
6700 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6701 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
6702 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6703 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6704 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6705 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6706 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6707 ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
6708 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
6709 if (FAILED(hr))
6710 continue;
6712 memset(&surface_desc, 0, sizeof(surface_desc));
6713 surface_desc.dwSize = sizeof(surface_desc);
6714 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
6715 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
6716 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
6717 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6718 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
6719 if (sizeof(void *) != sizeof(DWORD) && test_data[i].pitch_out32 != test_data[i].pitch_out64)
6720 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
6721 "Test %u: Got unexpected pitch %u, expected %u.\n",
6722 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
6723 else
6724 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
6725 "Test %u: Got unexpected pitch %u, expected %u.\n",
6726 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
6727 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
6729 IDirectDrawSurface7_Release(surface);
6732 HeapFree(GetProcessHeap(), 0, mem);
6733 refcount = IDirectDraw7_Release(ddraw);
6734 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6735 DestroyWindow(window);
6738 static void test_mipmap_lock(void)
6740 IDirectDrawSurface7 *surface, *surface2;
6741 DDSURFACEDESC2 surface_desc;
6742 IDirectDraw7 *ddraw;
6743 ULONG refcount;
6744 HWND window;
6745 HRESULT hr;
6746 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6747 DDCAPS hal_caps;
6749 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6750 0, 0, 640, 480, 0, 0, 0, 0);
6751 ddraw = create_ddraw();
6752 ok(!!ddraw, "Failed to create a ddraw object.\n");
6753 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6754 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6756 memset(&hal_caps, 0, sizeof(hal_caps));
6757 hal_caps.dwSize = sizeof(hal_caps);
6758 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6759 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6760 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6762 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6763 IDirectDraw7_Release(ddraw);
6764 DestroyWindow(window);
6765 return;
6768 memset(&surface_desc, 0, sizeof(surface_desc));
6769 surface_desc.dwSize = sizeof(surface_desc);
6770 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6771 surface_desc.dwWidth = 4;
6772 surface_desc.dwHeight = 4;
6773 U2(surface_desc).dwMipMapCount = 2;
6774 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
6775 | DDSCAPS_SYSTEMMEMORY;
6776 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6777 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6778 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
6779 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6781 memset(&surface_desc, 0, sizeof(surface_desc));
6782 surface_desc.dwSize = sizeof(surface_desc);
6783 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
6784 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6785 memset(&surface_desc, 0, sizeof(surface_desc));
6786 surface_desc.dwSize = sizeof(surface_desc);
6787 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
6788 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6789 IDirectDrawSurface7_Unlock(surface2, NULL);
6790 IDirectDrawSurface7_Unlock(surface, NULL);
6792 IDirectDrawSurface7_Release(surface2);
6793 IDirectDrawSurface7_Release(surface);
6794 refcount = IDirectDraw7_Release(ddraw);
6795 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6796 DestroyWindow(window);
6799 static void test_palette_complex(void)
6801 IDirectDrawSurface7 *surface, *mipmap, *tmp;
6802 DDSURFACEDESC2 surface_desc;
6803 IDirectDraw7 *ddraw;
6804 IDirectDrawPalette *palette, *palette2;
6805 ULONG refcount;
6806 HWND window;
6807 HRESULT hr;
6808 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6809 DDCAPS hal_caps;
6810 PALETTEENTRY palette_entries[256];
6811 unsigned int i;
6813 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6814 0, 0, 640, 480, 0, 0, 0, 0);
6815 ddraw = create_ddraw();
6816 ok(!!ddraw, "Failed to create a ddraw object.\n");
6817 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6818 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6820 memset(&hal_caps, 0, sizeof(hal_caps));
6821 hal_caps.dwSize = sizeof(hal_caps);
6822 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6823 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6824 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6826 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6827 IDirectDraw7_Release(ddraw);
6828 DestroyWindow(window);
6829 return;
6832 memset(&surface_desc, 0, sizeof(surface_desc));
6833 surface_desc.dwSize = sizeof(surface_desc);
6834 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6835 surface_desc.dwWidth = 128;
6836 surface_desc.dwHeight = 128;
6837 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6838 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6839 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
6840 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
6841 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6842 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6844 memset(palette_entries, 0, sizeof(palette_entries));
6845 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6846 palette_entries, &palette, NULL);
6847 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6849 palette2 = (void *)0xdeadbeef;
6850 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
6851 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6852 ok(!palette2, "Got unexpected palette %p.\n", palette2);
6853 hr = IDirectDrawSurface7_SetPalette(surface, palette);
6854 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6855 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
6856 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6857 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
6858 IDirectDrawPalette_Release(palette2);
6860 mipmap = surface;
6861 IDirectDrawSurface7_AddRef(mipmap);
6862 for (i = 0; i < 7; ++i)
6864 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
6865 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
6866 palette2 = (void *)0xdeadbeef;
6867 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
6868 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
6869 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
6871 hr = IDirectDrawSurface7_SetPalette(tmp, palette);
6872 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
6874 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
6875 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
6876 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
6878 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
6879 * ddraw versions. Combined with the test results above this means no
6880 * palette is available. So depending on the driver either GetDC fails
6881 * or the DIB color table contains random data. */
6883 IDirectDrawSurface7_Release(mipmap);
6884 mipmap = tmp;
6887 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
6888 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6889 IDirectDrawSurface7_Release(mipmap);
6890 refcount = IDirectDrawSurface7_Release(surface);
6891 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6893 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
6894 memset(&surface_desc, 0, sizeof(surface_desc));
6895 surface_desc.dwSize = sizeof(surface_desc);
6896 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6897 surface_desc.dwWidth = 128;
6898 surface_desc.dwHeight = 128;
6899 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6900 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6901 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
6902 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6903 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6904 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6905 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6906 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6907 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6909 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
6910 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6911 hr = IDirectDrawSurface7_SetPalette(mipmap, palette);
6912 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x.\n", hr);
6914 IDirectDrawSurface7_Release(mipmap);
6915 refcount = IDirectDrawSurface7_Release(surface);
6916 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6917 refcount = IDirectDrawPalette_Release(palette);
6918 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6920 refcount = IDirectDraw7_Release(ddraw);
6921 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6922 DestroyWindow(window);
6925 static void test_p8_rgb_blit(void)
6927 IDirectDrawSurface7 *src, *dst;
6928 DDSURFACEDESC2 surface_desc;
6929 IDirectDraw7 *ddraw;
6930 IDirectDrawPalette *palette;
6931 ULONG refcount;
6932 HWND window;
6933 HRESULT hr;
6934 PALETTEENTRY palette_entries[256];
6935 unsigned int x;
6936 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6937 static const D3DCOLOR expected[] =
6939 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6940 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6942 D3DCOLOR color;
6944 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6945 0, 0, 640, 480, 0, 0, 0, 0);
6946 ddraw = create_ddraw();
6947 ok(!!ddraw, "Failed to create a ddraw object.\n");
6948 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6949 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6951 memset(palette_entries, 0, sizeof(palette_entries));
6952 palette_entries[1].peGreen = 0xff;
6953 palette_entries[2].peBlue = 0xff;
6954 palette_entries[3].peFlags = 0xff;
6955 palette_entries[4].peRed = 0xff;
6956 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6957 palette_entries, &palette, NULL);
6958 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6960 memset(&surface_desc, 0, sizeof(surface_desc));
6961 surface_desc.dwSize = sizeof(surface_desc);
6962 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6963 surface_desc.dwWidth = 8;
6964 surface_desc.dwHeight = 1;
6965 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6966 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6967 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
6968 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
6969 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
6970 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6972 memset(&surface_desc, 0, sizeof(surface_desc));
6973 surface_desc.dwSize = sizeof(surface_desc);
6974 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6975 surface_desc.dwWidth = 8;
6976 surface_desc.dwHeight = 1;
6977 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6978 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6979 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
6980 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6981 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6982 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6983 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6984 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
6985 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
6986 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6988 memset(&surface_desc, 0, sizeof(surface_desc));
6989 surface_desc.dwSize = sizeof(surface_desc);
6990 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, 0, NULL);
6991 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
6992 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
6993 hr = IDirectDrawSurface7_Unlock(src, NULL);
6994 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
6996 hr = IDirectDrawSurface7_SetPalette(src, palette);
6997 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6998 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
6999 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7000 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7001 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
7002 "Failed to blit, hr %#x.\n", hr);
7004 if (SUCCEEDED(hr))
7006 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
7008 color = get_surface_color(dst, x, 0);
7009 todo_wine ok(compare_color(color, expected[x], 0),
7010 "Pixel %u: Got color %#x, expected %#x.\n",
7011 x, color, expected[x]);
7015 IDirectDrawSurface7_Release(src);
7016 IDirectDrawSurface7_Release(dst);
7017 IDirectDrawPalette_Release(palette);
7019 refcount = IDirectDraw7_Release(ddraw);
7020 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7021 DestroyWindow(window);
7024 static void test_material(void)
7026 static const D3DCOLORVALUE null_color;
7027 IDirect3DDevice7 *device;
7028 D3DMATERIAL7 material;
7029 ULONG refcount;
7030 HWND window;
7031 HRESULT hr;
7033 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7034 0, 0, 640, 480, 0, 0, 0, 0);
7035 if (!(device = create_device(window, DDSCL_NORMAL)))
7037 skip("Failed to create a 3D device, skipping test.\n");
7038 DestroyWindow(window);
7039 return;
7042 hr = IDirect3DDevice7_GetMaterial(device, &material);
7043 ok(SUCCEEDED(hr), "Failed to get material, hr %#x.\n", hr);
7044 ok(!memcmp(&U(material).diffuse, &null_color, sizeof(null_color)),
7045 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
7046 U1(U(material).diffuse).r, U2(U(material).diffuse).g,
7047 U3(U(material).diffuse).b, U4(U(material).diffuse).a);
7048 ok(!memcmp(&U1(material).ambient, &null_color, sizeof(null_color)),
7049 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
7050 U1(U1(material).ambient).r, U2(U1(material).ambient).g,
7051 U3(U1(material).ambient).b, U4(U1(material).ambient).a);
7052 ok(!memcmp(&U2(material).specular, &null_color, sizeof(null_color)),
7053 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
7054 U1(U2(material).specular).r, U2(U2(material).specular).g,
7055 U3(U2(material).specular).b, U4(U2(material).specular).a);
7056 ok(!memcmp(&U3(material).emissive, &null_color, sizeof(null_color)),
7057 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
7058 U1(U3(material).emissive).r, U2(U3(material).emissive).g,
7059 U3(U3(material).emissive).b, U4(U3(material).emissive).a);
7060 ok(U4(material).power == 0.0f, "Got unexpected power %.8e.\n", U4(material).power);
7062 refcount = IDirect3DDevice7_Release(device);
7063 ok(!refcount, "Device has %u references left.\n", refcount);
7064 DestroyWindow(window);
7067 static void test_palette_gdi(void)
7069 IDirectDrawSurface7 *surface, *primary;
7070 DDSURFACEDESC2 surface_desc;
7071 IDirectDraw7 *ddraw;
7072 IDirectDrawPalette *palette, *palette2;
7073 ULONG refcount;
7074 HWND window;
7075 HRESULT hr;
7076 PALETTEENTRY palette_entries[256];
7077 UINT i;
7078 HDC dc;
7079 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7080 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7081 * not the point of this test. */
7082 static const RGBQUAD expected1[] =
7084 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7085 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7087 static const RGBQUAD expected2[] =
7089 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7090 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7092 static const RGBQUAD expected3[] =
7094 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7095 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7097 HPALETTE ddraw_palette_handle;
7098 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7099 RGBQUAD rgbquad[255];
7100 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
7102 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7103 0, 0, 640, 480, 0, 0, 0, 0);
7104 ddraw = create_ddraw();
7105 ok(!!ddraw, "Failed to create a ddraw object.\n");
7106 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7107 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7109 memset(&surface_desc, 0, sizeof(surface_desc));
7110 surface_desc.dwSize = sizeof(surface_desc);
7111 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7112 surface_desc.dwWidth = 16;
7113 surface_desc.dwHeight = 16;
7114 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7115 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7116 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7117 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7118 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7119 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7121 /* Avoid colors from the Windows default palette. */
7122 memset(palette_entries, 0, sizeof(palette_entries));
7123 palette_entries[1].peRed = 0x01;
7124 palette_entries[2].peGreen = 0x02;
7125 palette_entries[3].peBlue = 0x03;
7126 palette_entries[4].peRed = 0x13;
7127 palette_entries[4].peGreen = 0x14;
7128 palette_entries[4].peBlue = 0x15;
7129 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7130 palette_entries, &palette, NULL);
7131 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7133 /* If there is no palette assigned and the display mode is not 8 bpp, some
7134 * drivers refuse to create a DC while others allow it. If a DC is created,
7135 * the DIB color table is uninitialized and contains random colors. No error
7136 * is generated when trying to read pixels and random garbage is returned.
7138 * The most likely explanation is that if the driver creates a DC, it (or
7139 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7140 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7141 * contains uninitialized garbage. See comments below for the P8 case. */
7143 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7144 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7145 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7146 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7147 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7148 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
7149 "Got unexpected palette %p, expected %p.\n",
7150 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7152 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7153 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7154 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
7156 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
7157 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7158 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7159 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
7161 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7163 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7164 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7165 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7168 /* Update the palette while the DC is in use. This does not modify the DC. */
7169 palette_entries[4].peRed = 0x23;
7170 palette_entries[4].peGreen = 0x24;
7171 palette_entries[4].peBlue = 0x25;
7172 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
7173 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
7175 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7176 ok(i == 1, "Expected count 1, got %u.\n", i);
7177 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7178 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7179 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7180 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7182 /* Neither does re-setting the palette. */
7183 hr = IDirectDrawSurface7_SetPalette(surface, NULL);
7184 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7185 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7186 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7188 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7189 ok(i == 1, "Expected count 1, got %u.\n", i);
7190 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7191 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7192 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7193 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7195 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7196 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7198 /* Refresh the DC. This updates the palette. */
7199 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7200 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7201 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7202 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7203 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7205 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7206 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7207 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7208 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7210 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7212 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7213 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7214 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7216 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7217 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7219 refcount = IDirectDrawSurface7_Release(surface);
7220 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7222 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7224 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7225 IDirectDrawPalette_Release(palette);
7226 IDirectDraw7_Release(ddraw);
7227 DestroyWindow(window);
7228 return;
7230 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
7231 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
7232 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7234 memset(&surface_desc, 0, sizeof(surface_desc));
7235 surface_desc.dwSize = sizeof(surface_desc);
7236 surface_desc.dwFlags = DDSD_CAPS;
7237 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7238 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
7239 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7241 hr = IDirectDrawSurface7_SetPalette(primary, palette);
7242 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7243 hr = IDirectDrawSurface7_GetDC(primary, &dc);
7244 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7245 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7246 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7247 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE) || broken(TRUE),
7248 "Got unexpected palette %p, expected %p.\n",
7249 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7250 SelectPalette(dc, ddraw_palette_handle, FALSE);
7252 /* The primary uses the system palette. In exclusive mode, the system palette matches
7253 * the ddraw palette attached to the primary, so the result is what you would expect
7254 * from a regular surface. Tests for the interaction between the ddraw palette and
7255 * the system palette are not included pending an application that depends on this.
7256 * The relation between those causes problems on Windows Vista and newer for games
7257 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
7258 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7259 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7260 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7262 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7263 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7264 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7265 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7267 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7269 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7270 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7271 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7273 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
7274 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7276 memset(&surface_desc, 0, sizeof(surface_desc));
7277 surface_desc.dwSize = sizeof(surface_desc);
7278 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7279 surface_desc.dwWidth = 16;
7280 surface_desc.dwHeight = 16;
7281 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7282 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7283 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7285 /* Here the offscreen surface appears to use the primary's palette,
7286 * but in all likelihood it is actually the system palette. */
7287 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7288 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7289 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7290 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7291 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7293 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7294 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7295 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7296 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7298 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7300 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7301 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7302 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7304 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7305 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7307 /* On real hardware a change to the primary surface's palette applies immediately,
7308 * even on device contexts from offscreen surfaces that do not have their own
7309 * palette. On the testbot VMs this is not the case. Don't test this until we
7310 * know of an application that depends on this. */
7312 memset(palette_entries, 0, sizeof(palette_entries));
7313 palette_entries[1].peBlue = 0x40;
7314 palette_entries[2].peRed = 0x40;
7315 palette_entries[3].peGreen = 0x40;
7316 palette_entries[4].peRed = 0x12;
7317 palette_entries[4].peGreen = 0x34;
7318 palette_entries[4].peBlue = 0x56;
7319 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7320 palette_entries, &palette2, NULL);
7321 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7322 hr = IDirectDrawSurface7_SetPalette(surface, palette2);
7323 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7325 /* A palette assigned to the offscreen surface overrides the primary / system
7326 * palette. */
7327 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7328 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7329 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7330 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7331 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
7333 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
7334 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7335 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7336 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
7338 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7340 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7341 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7342 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7344 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7345 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7347 refcount = IDirectDrawSurface7_Release(surface);
7348 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7350 /* The Windows 8 testbot keeps extra references to the primary and
7351 * backbuffer while in 8 bpp mode. */
7352 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
7353 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7355 refcount = IDirectDrawSurface7_Release(primary);
7356 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7357 refcount = IDirectDrawPalette_Release(palette2);
7358 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7359 refcount = IDirectDrawPalette_Release(palette);
7360 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7361 refcount = IDirectDraw7_Release(ddraw);
7362 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7363 DestroyWindow(window);
7366 static void test_palette_alpha(void)
7368 IDirectDrawSurface7 *surface;
7369 DDSURFACEDESC2 surface_desc;
7370 IDirectDraw7 *ddraw;
7371 IDirectDrawPalette *palette;
7372 ULONG refcount;
7373 HWND window;
7374 HRESULT hr;
7375 PALETTEENTRY palette_entries[256];
7376 unsigned int i;
7377 static const struct
7379 DWORD caps, flags;
7380 BOOL attach_allowed;
7381 const char *name;
7383 test_data[] =
7385 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
7386 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
7387 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
7390 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7391 0, 0, 640, 480, 0, 0, 0, 0);
7392 ddraw = create_ddraw();
7393 ok(!!ddraw, "Failed to create a ddraw object.\n");
7394 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7396 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7397 IDirectDraw7_Release(ddraw);
7398 DestroyWindow(window);
7399 return;
7401 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7402 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7404 memset(palette_entries, 0, sizeof(palette_entries));
7405 palette_entries[1].peFlags = 0x42;
7406 palette_entries[2].peFlags = 0xff;
7407 palette_entries[3].peFlags = 0x80;
7408 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
7409 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7411 memset(palette_entries, 0x66, sizeof(palette_entries));
7412 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
7413 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
7414 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7415 palette_entries[0].peFlags);
7416 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7417 palette_entries[1].peFlags);
7418 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7419 palette_entries[2].peFlags);
7420 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7421 palette_entries[3].peFlags);
7423 IDirectDrawPalette_Release(palette);
7425 memset(palette_entries, 0, sizeof(palette_entries));
7426 palette_entries[1].peFlags = 0x42;
7427 palette_entries[1].peRed = 0xff;
7428 palette_entries[2].peFlags = 0xff;
7429 palette_entries[3].peFlags = 0x80;
7430 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
7431 palette_entries, &palette, NULL);
7432 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7434 memset(palette_entries, 0x66, sizeof(palette_entries));
7435 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
7436 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
7437 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7438 palette_entries[0].peFlags);
7439 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7440 palette_entries[1].peFlags);
7441 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7442 palette_entries[2].peFlags);
7443 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7444 palette_entries[3].peFlags);
7446 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7448 memset(&surface_desc, 0, sizeof(surface_desc));
7449 surface_desc.dwSize = sizeof(surface_desc);
7450 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
7451 surface_desc.dwWidth = 128;
7452 surface_desc.dwHeight = 128;
7453 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7454 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7455 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
7457 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7458 if (test_data[i].attach_allowed)
7459 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
7460 else
7461 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
7463 if (SUCCEEDED(hr))
7465 HDC dc;
7466 RGBQUAD rgbquad;
7467 UINT retval;
7469 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7470 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
7471 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
7472 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
7473 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7474 rgbquad.rgbRed, test_data[i].name);
7475 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7476 rgbquad.rgbGreen, test_data[i].name);
7477 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7478 rgbquad.rgbBlue, test_data[i].name);
7479 todo_wine ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7480 rgbquad.rgbReserved, test_data[i].name);
7481 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7482 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7484 IDirectDrawSurface7_Release(surface);
7487 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7488 memset(&surface_desc, 0, sizeof(surface_desc));
7489 surface_desc.dwSize = sizeof(surface_desc);
7490 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7491 surface_desc.dwWidth = 128;
7492 surface_desc.dwHeight = 128;
7493 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7494 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7495 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7496 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7497 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7498 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7499 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7500 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7501 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7502 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7503 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
7504 IDirectDrawSurface7_Release(surface);
7506 /* The Windows 8 testbot keeps extra references to the primary
7507 * while in 8 bpp mode. */
7508 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
7509 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7511 refcount = IDirectDrawPalette_Release(palette);
7512 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7513 refcount = IDirectDraw7_Release(ddraw);
7514 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7515 DestroyWindow(window);
7518 static void test_vb_writeonly(void)
7520 IDirect3DDevice7 *device;
7521 IDirect3D7 *d3d;
7522 IDirect3DVertexBuffer7 *buffer;
7523 HWND window;
7524 HRESULT hr;
7525 D3DVERTEXBUFFERDESC desc;
7526 void *ptr;
7527 static const struct vec4 quad[] =
7529 { 0.0f, 480.0f, 0.0f, 1.0f},
7530 { 0.0f, 0.0f, 0.0f, 1.0f},
7531 {640.0f, 480.0f, 0.0f, 1.0f},
7532 {640.0f, 0.0f, 0.0f, 1.0f},
7535 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7536 0, 0, 640, 480, 0, 0, 0, 0);
7538 if (!(device = create_device(window, DDSCL_NORMAL)))
7540 skip("Failed to create a 3D device, skipping test.\n");
7541 DestroyWindow(window);
7542 return;
7545 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
7546 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
7548 memset(&desc, 0, sizeof(desc));
7549 desc.dwSize = sizeof(desc);
7550 desc.dwCaps = D3DVBCAPS_WRITEONLY;
7551 desc.dwFVF = D3DFVF_XYZRHW;
7552 desc.dwNumVertices = sizeof(quad) / sizeof(*quad);
7553 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
7554 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
7556 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
7557 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7558 memcpy(ptr, quad, sizeof(quad));
7559 hr = IDirect3DVertexBuffer7_Unlock(buffer);
7560 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7562 hr = IDirect3DDevice7_BeginScene(device);
7563 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7564 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
7565 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7566 hr = IDirect3DDevice7_EndScene(device);
7567 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7569 hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL);
7570 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7571 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7572 hr = IDirect3DVertexBuffer7_Unlock(buffer);
7573 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7575 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
7576 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7577 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7578 hr = IDirect3DVertexBuffer7_Unlock(buffer);
7579 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7581 IDirect3DVertexBuffer7_Release(buffer);
7582 IDirect3D7_Release(d3d);
7583 IDirect3DDevice7_Release(device);
7584 DestroyWindow(window);
7587 static void test_lost_device(void)
7589 IDirectDrawSurface7 *surface;
7590 DDSURFACEDESC2 surface_desc;
7591 IDirectDraw7 *ddraw;
7592 ULONG refcount;
7593 HWND window;
7594 HRESULT hr;
7595 BOOL ret;
7597 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7598 0, 0, 640, 480, 0, 0, 0, 0);
7599 ddraw = create_ddraw();
7600 ok(!!ddraw, "Failed to create a ddraw object.\n");
7601 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7602 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7604 memset(&surface_desc, 0, sizeof(surface_desc));
7605 surface_desc.dwSize = sizeof(surface_desc);
7606 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
7607 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
7608 surface_desc.dwBackBufferCount = 1;
7609 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7610 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7612 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7613 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7614 hr = IDirectDrawSurface7_IsLost(surface);
7615 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7616 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7617 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7619 ret = SetForegroundWindow(GetDesktopWindow());
7620 ok(ret, "Failed to set foreground window.\n");
7621 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7622 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
7623 hr = IDirectDrawSurface7_IsLost(surface);
7624 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7625 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7626 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7628 ret = SetForegroundWindow(window);
7629 ok(ret, "Failed to set foreground window.\n");
7630 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7631 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7632 hr = IDirectDrawSurface7_IsLost(surface);
7633 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7634 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7635 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7637 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
7638 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7639 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7640 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7641 hr = IDirectDrawSurface7_IsLost(surface);
7642 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7643 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7644 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7646 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7647 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7648 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7649 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7650 hr = IDirectDrawSurface7_IsLost(surface);
7651 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7652 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
7653 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7655 /* Trying to restore the primary will crash, probably because flippable
7656 * surfaces can't exist in DDSCL_NORMAL. */
7657 IDirectDrawSurface7_Release(surface);
7658 memset(&surface_desc, 0, sizeof(surface_desc));
7659 surface_desc.dwSize = sizeof(surface_desc);
7660 surface_desc.dwFlags = DDSD_CAPS;
7661 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7662 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7663 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7665 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7666 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7667 hr = IDirectDrawSurface7_IsLost(surface);
7668 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7670 ret = SetForegroundWindow(GetDesktopWindow());
7671 ok(ret, "Failed to set foreground window.\n");
7672 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7673 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7674 hr = IDirectDrawSurface7_IsLost(surface);
7675 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7677 ret = SetForegroundWindow(window);
7678 ok(ret, "Failed to set foreground window.\n");
7679 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7680 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7681 hr = IDirectDrawSurface7_IsLost(surface);
7682 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7684 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7685 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7686 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
7687 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7688 hr = IDirectDrawSurface7_IsLost(surface);
7689 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7691 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
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 == DD_OK, "Got unexpected hr %#x.\n", hr);
7698 IDirectDrawSurface7_Release(surface);
7699 refcount = IDirectDraw7_Release(ddraw);
7700 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7701 DestroyWindow(window);
7704 static void test_resource_priority(void)
7706 IDirectDrawSurface7 *surface, *mipmap;
7707 DDSURFACEDESC2 surface_desc;
7708 IDirectDraw7 *ddraw;
7709 ULONG refcount;
7710 HWND window;
7711 HRESULT hr;
7712 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
7713 DDCAPS hal_caps;
7714 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_MIPMAP;
7715 unsigned int i;
7716 DWORD priority;
7717 static const struct
7719 DWORD caps, caps2;
7720 const char *name;
7721 HRESULT hr;
7722 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
7723 BOOL crash;
7725 test_data[] =
7727 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS, FALSE},
7728 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS, FALSE},
7729 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK, FALSE},
7730 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, "managed texture", DD_OK, FALSE},
7731 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
7732 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
7735 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7736 0, 0, 640, 480, 0, 0, 0, 0);
7737 ddraw = create_ddraw();
7738 ok(!!ddraw, "Failed to create a ddraw object.\n");
7739 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7740 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7742 memset(&hal_caps, 0, sizeof(hal_caps));
7743 hal_caps.dwSize = sizeof(hal_caps);
7744 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7745 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7746 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
7747 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
7749 skip("Required surface types not supported, skipping test.\n");
7750 goto done;
7753 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7755 memset(&surface_desc, 0, sizeof(surface_desc));
7756 surface_desc.dwSize = sizeof(surface_desc);
7757 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
7758 surface_desc.dwWidth = 32;
7759 surface_desc.dwHeight = 32;
7760 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7761 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2;
7762 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7763 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, test_data[i].name);
7765 /* Priority == NULL segfaults. */
7766 priority = 0xdeadbeef;
7767 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
7768 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7769 if (SUCCEEDED(test_data[i].hr))
7770 ok(priority == 0, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7771 else
7772 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7774 if (!test_data[i].crash)
7776 hr = IDirectDrawSurface7_SetPriority(surface, 1);
7777 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7778 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
7779 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7780 if (SUCCEEDED(test_data[i].hr))
7782 ok(priority == 1, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7783 hr = IDirectDrawSurface7_SetPriority(surface, 2);
7784 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
7786 else
7787 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
7790 IDirectDrawSurface7_Release(surface);
7793 memset(&surface_desc, 0, sizeof(surface_desc));
7794 surface_desc.dwSize = sizeof(surface_desc);
7795 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
7796 surface_desc.dwWidth = 32;
7797 surface_desc.dwHeight = 32;
7798 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7799 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
7800 U2(surface_desc).dwMipMapCount = 2;
7801 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7802 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7803 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
7804 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7806 priority = 0xdeadbeef;
7807 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
7808 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type managed mipmap.\n", hr);
7809 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority);
7810 /* SetPriority on the mipmap surface crashes. */
7811 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
7812 ok(SUCCEEDED(hr), "Failed to get priority, hr %#x.\n", hr);
7813 ok(priority == 0, "Got unexpected priority %u, type managed mipmap.\n", priority);
7815 IDirectDrawSurface7_Release(mipmap);
7816 refcount = IDirectDrawSurface7_Release(surface);
7817 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7819 done:
7820 refcount = IDirectDraw7_Release(ddraw);
7821 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7822 DestroyWindow(window);
7825 static void test_surface_desc_lock(void)
7827 IDirectDrawSurface7 *surface;
7828 DDSURFACEDESC2 surface_desc;
7829 IDirectDraw7 *ddraw;
7830 ULONG refcount;
7831 HWND window;
7832 HRESULT hr;
7834 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7835 0, 0, 640, 480, 0, 0, 0, 0);
7836 ddraw = create_ddraw();
7837 ok(!!ddraw, "Failed to create a ddraw object.\n");
7838 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7839 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7841 memset(&surface_desc, 0, sizeof(surface_desc));
7842 surface_desc.dwSize = sizeof(surface_desc);
7843 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7844 surface_desc.dwWidth = 16;
7845 surface_desc.dwHeight = 16;
7846 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7847 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7848 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7850 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7851 surface_desc.dwSize = sizeof(surface_desc);
7852 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7853 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
7854 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7856 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7857 surface_desc.dwSize = sizeof(surface_desc);
7858 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
7859 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7860 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7861 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7862 surface_desc.dwSize = sizeof(surface_desc);
7863 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7864 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
7865 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7866 hr = IDirectDrawSurface7_Unlock(surface, NULL);
7867 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7869 memset(&surface_desc, 0xaa, sizeof(surface_desc));
7870 surface_desc.dwSize = sizeof(surface_desc);
7871 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7872 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
7873 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
7875 IDirectDrawSurface7_Release(surface);
7876 refcount = IDirectDraw7_Release(ddraw);
7877 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7878 DestroyWindow(window);
7881 static void fog_interpolation_test(void)
7883 HRESULT hr;
7884 IDirect3DDevice7 *device;
7885 IDirectDrawSurface7 *rt;
7886 ULONG refcount;
7887 HWND window;
7888 D3DCOLOR color;
7889 static struct
7891 struct vec3 position;
7892 D3DCOLOR diffuse;
7893 D3DCOLOR specular;
7895 quad[] =
7897 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
7898 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
7899 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
7900 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
7902 union
7904 DWORD d;
7905 float f;
7906 } conv;
7907 unsigned int i;
7908 static const struct
7910 D3DFOGMODE vfog, tfog;
7911 D3DSHADEMODE shade;
7912 D3DCOLOR middle_color;
7913 BOOL todo;
7915 tests[] =
7917 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
7918 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
7919 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
7920 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
7921 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
7922 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
7923 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
7924 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
7926 D3DDEVICEDESC7 caps;
7928 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7929 0, 0, 640, 480, 0, 0, 0, 0);
7931 if (!(device = create_device(window, DDSCL_NORMAL)))
7933 skip("Failed to create a 3D device, skipping test.\n");
7934 DestroyWindow(window);
7935 return;
7938 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
7939 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7940 hr = IDirect3DDevice7_GetCaps(device, &caps);
7941 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7942 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
7943 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
7945 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
7946 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7947 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
7948 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7949 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
7950 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7951 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
7952 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7953 conv.f = 5.0;
7954 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGDENSITY, conv.d);
7955 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7957 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
7958 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
7959 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
7960 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
7961 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x000000ff);
7962 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7964 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
7966 if(!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
7967 continue;
7969 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
7970 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
7972 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shade);
7973 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7974 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
7975 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7976 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
7977 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
7978 hr = IDirect3DDevice7_BeginScene(device);
7979 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7980 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
7981 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, quad, 4, 0);
7982 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7983 hr = IDirect3DDevice7_EndScene(device);
7984 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7986 color = get_surface_color(rt, 0, 240);
7987 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
7988 color = get_surface_color(rt, 320, 240);
7989 if (tests[i].todo)
7990 todo_wine ok(compare_color(color, tests[i].middle_color, 2),
7991 "Got unexpected color 0x%08x, case %u.\n", color, i);
7992 else
7993 ok(compare_color(color, tests[i].middle_color, 2),
7994 "Got unexpected color 0x%08x, case %u.\n", color, i);
7995 color = get_surface_color(rt, 639, 240);
7996 ok(compare_color(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
7999 IDirectDrawSurface7_Release(rt);
8000 refcount = IDirect3DDevice7_Release(device);
8001 ok(!refcount, "Device has %u references left.\n", refcount);
8002 DestroyWindow(window);
8005 static void test_negative_fixedfunction_fog(void)
8007 HRESULT hr;
8008 IDirect3DDevice7 *device;
8009 IDirectDrawSurface7 *rt;
8010 ULONG refcount;
8011 HWND window;
8012 D3DCOLOR color;
8013 static struct
8015 struct vec3 position;
8016 D3DCOLOR diffuse;
8018 quad[] =
8020 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
8021 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
8022 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
8023 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
8025 unsigned int i;
8026 static const struct
8028 union
8030 float f;
8031 DWORD d;
8032 } start, end;
8033 DWORD color;
8035 tests[] =
8037 /* fog_interpolation_test shows that vertex fog evaluates the fog
8038 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
8039 * that the abs happens before the fog equation is evaluated. */
8040 {{ 0.0f}, {1.0f}, 0x00808000},
8041 {{-1.0f}, {0.0f}, 0x0000ff00},
8043 static D3DMATRIX proj_mat =
8045 1.0f, 0.0f, 0.0f, 0.0f,
8046 0.0f, 1.0f, 0.0f, 0.0f,
8047 0.0f, 0.0f, 0.0f, 0.0f,
8048 0.0f, 0.0f, 0.0f, 1.0f
8051 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8052 0, 0, 640, 480, 0, 0, 0, 0);
8054 if (!(device = create_device(window, DDSCL_NORMAL)))
8056 skip("Failed to create a 3D device, skipping test.\n");
8057 DestroyWindow(window);
8058 return;
8061 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8062 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8064 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
8065 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8066 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
8067 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8068 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
8069 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8070 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
8071 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8072 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, D3DFOG_LINEAR);
8073 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8074 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj_mat);
8075 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
8077 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
8079 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
8080 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8082 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, tests[i].start.d);
8083 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8084 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, tests[i].end.d);
8085 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8086 hr = IDirect3DDevice7_BeginScene(device);
8087 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8088 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8089 D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
8090 hr = IDirect3DDevice7_EndScene(device);
8091 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8093 color = get_surface_color(rt, 0, 240);
8094 ok(compare_color(color, tests[i].color, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
8097 IDirectDrawSurface7_Release(rt);
8098 refcount = IDirect3DDevice7_Release(device);
8099 ok(!refcount, "Device has %u references left.\n", refcount);
8100 DestroyWindow(window);
8103 START_TEST(ddraw7)
8105 HMODULE module = GetModuleHandleA("ddraw.dll");
8106 IDirectDraw7 *ddraw;
8107 DEVMODEW current_mode;
8109 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
8111 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
8112 return;
8115 if (!(ddraw = create_ddraw()))
8117 skip("Failed to create a ddraw object, skipping tests.\n");
8118 return;
8120 IDirectDraw7_Release(ddraw);
8122 memset(&current_mode, 0, sizeof(current_mode));
8123 current_mode.dmSize = sizeof(current_mode);
8124 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
8125 registry_mode.dmSize = sizeof(registry_mode);
8126 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
8127 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
8128 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
8130 skip("Current mode does not match registry mode, skipping test.\n");
8131 return;
8134 test_process_vertices();
8135 test_coop_level_create_device_window();
8136 test_clipper_blt();
8137 test_coop_level_d3d_state();
8138 test_surface_interface_mismatch();
8139 test_coop_level_threaded();
8140 test_depth_blit();
8141 test_texture_load_ckey();
8142 test_zenable();
8143 test_ck_rgba();
8144 test_ck_default();
8145 test_ck_complex();
8146 test_surface_qi();
8147 test_device_qi();
8148 test_wndproc();
8149 test_window_style();
8150 test_redundant_mode_set();
8151 test_coop_level_mode_set();
8152 test_coop_level_mode_set_multi();
8153 test_initialize();
8154 test_coop_level_surf_create();
8155 test_vb_discard();
8156 test_coop_level_multi_window();
8157 test_draw_strided();
8158 test_clear_rect_count();
8159 test_coop_level_versions();
8160 test_fog_special();
8161 test_lighting_interface_versions();
8162 test_coop_level_activateapp();
8163 test_texturemanage();
8164 test_block_formats_creation();
8165 test_unsupported_formats();
8166 test_rt_caps();
8167 test_primary_caps();
8168 test_surface_lock();
8169 test_surface_discard();
8170 test_flip();
8171 test_set_surface_desc();
8172 test_user_memory_getdc();
8173 test_sysmem_overlay();
8174 test_primary_palette();
8175 test_surface_attachment();
8176 test_private_data();
8177 test_pixel_format();
8178 test_create_surface_pitch();
8179 test_mipmap_lock();
8180 test_palette_complex();
8181 test_p8_rgb_blit();
8182 test_material();
8183 test_palette_gdi();
8184 test_palette_alpha();
8185 test_vb_writeonly();
8186 test_lost_device();
8187 test_resource_priority();
8188 test_surface_desc_lock();
8189 fog_interpolation_test();
8190 test_negative_fixedfunction_fog();