ddraw: Mark surfaces as lost when the device window is deactivated.
[wine.git] / dlls / ddraw / tests / ddraw7.c
blob57cec093a9308492bcceef7a772164c37fb135ef
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 <math.h>
24 #include "d3d.h"
26 static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *guid, void **ddraw, REFIID iid, IUnknown *outer_unknown);
27 static BOOL is_ddraw64 = sizeof(DWORD) != sizeof(DWORD *);
28 static DEVMODEW registry_mode;
30 struct vec2
32 float x, y;
35 struct vec3
37 float x, y, z;
40 struct vec4
42 float x, y, z, w;
45 struct create_window_thread_param
47 HWND window;
48 HANDLE window_created;
49 HANDLE destroy_window;
50 HANDLE thread;
53 static BOOL compare_float(float f, float g, unsigned int ulps)
55 int x = *(int *)&f;
56 int y = *(int *)&g;
58 if (x < 0)
59 x = INT_MIN - x;
60 if (y < 0)
61 y = INT_MIN - y;
63 if (abs(x - y) > ulps)
64 return FALSE;
66 return TRUE;
69 static BOOL compare_vec3(struct vec3 *vec, float x, float y, float z, unsigned int ulps)
71 return compare_float(vec->x, x, ulps)
72 && compare_float(vec->y, y, ulps)
73 && compare_float(vec->z, z, ulps);
76 static BOOL compare_vec4(struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
78 return compare_float(vec->x, x, ulps)
79 && compare_float(vec->y, y, ulps)
80 && compare_float(vec->z, z, ulps)
81 && compare_float(vec->w, w, ulps);
84 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
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 c1 >>= 8; c2 >>= 8;
92 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
93 return TRUE;
96 static ULONG get_refcount(IUnknown *iface)
98 IUnknown_AddRef(iface);
99 return IUnknown_Release(iface);
102 static DWORD WINAPI create_window_thread_proc(void *param)
104 struct create_window_thread_param *p = param;
105 DWORD res;
106 BOOL ret;
108 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
109 0, 0, 640, 480, 0, 0, 0, 0);
110 ret = SetEvent(p->window_created);
111 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
113 for (;;)
115 MSG msg;
117 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
118 DispatchMessageA(&msg);
119 res = WaitForSingleObject(p->destroy_window, 100);
120 if (res == WAIT_OBJECT_0)
121 break;
122 if (res != WAIT_TIMEOUT)
124 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
125 break;
129 DestroyWindow(p->window);
131 return 0;
134 static void create_window_thread(struct create_window_thread_param *p)
136 DWORD res, tid;
138 p->window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
139 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
140 p->destroy_window = CreateEventA(NULL, FALSE, FALSE, NULL);
141 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
142 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
143 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
144 res = WaitForSingleObject(p->window_created, INFINITE);
145 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
148 static void destroy_window_thread(struct create_window_thread_param *p)
150 SetEvent(p->destroy_window);
151 WaitForSingleObject(p->thread, INFINITE);
152 CloseHandle(p->destroy_window);
153 CloseHandle(p->window_created);
154 CloseHandle(p->thread);
157 static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
159 IDirectDrawSurface7 *rt, *ret;
160 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, {0}};
161 HRESULT hr;
163 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
164 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
165 hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
166 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
167 IDirectDrawSurface7_Release(rt);
168 return ret;
171 static HRESULT set_display_mode(IDirectDraw7 *ddraw, DWORD width, DWORD height)
173 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
174 return DD_OK;
175 return IDirectDraw7_SetDisplayMode(ddraw, width, height, 24, 0, 0);
178 static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
180 RECT rect = {x, y, x + 1, y + 1};
181 DDSURFACEDESC2 surface_desc;
182 D3DCOLOR color;
183 HRESULT hr;
185 memset(&surface_desc, 0, sizeof(surface_desc));
186 surface_desc.dwSize = sizeof(surface_desc);
188 hr = IDirectDrawSurface7_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY, NULL);
189 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
190 if (FAILED(hr))
191 return 0xdeadbeef;
193 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
195 hr = IDirectDrawSurface7_Unlock(surface, &rect);
196 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
198 return color;
201 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
203 DDPIXELFORMAT *z_fmt = ctx;
205 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
206 *z_fmt = *format;
208 return DDENUMRET_OK;
211 static IDirectDraw7 *create_ddraw(void)
213 IDirectDraw7 *ddraw;
215 if (FAILED(pDirectDrawCreateEx(NULL, (void **)&ddraw, &IID_IDirectDraw7, NULL)))
216 return NULL;
218 return ddraw;
221 static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
223 BOOL *hal_ok = ctx;
224 if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DTnLHalDevice))
226 *hal_ok = TRUE;
227 return DDENUMRET_CANCEL;
229 return DDENUMRET_OK;
232 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
234 IDirectDrawSurface7 *surface, *ds;
235 IDirect3DDevice7 *device = NULL;
236 DDSURFACEDESC2 surface_desc;
237 DDPIXELFORMAT z_fmt;
238 IDirectDraw7 *ddraw;
239 IDirect3D7 *d3d7;
240 HRESULT hr;
241 BOOL hal_ok = FALSE;
242 const GUID *devtype = &IID_IDirect3DHALDevice;
244 if (!(ddraw = create_ddraw()))
245 return NULL;
247 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, coop_level);
248 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
250 memset(&surface_desc, 0, sizeof(surface_desc));
251 surface_desc.dwSize = sizeof(surface_desc);
252 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
253 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
254 surface_desc.dwWidth = 640;
255 surface_desc.dwHeight = 480;
257 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
258 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
260 if (coop_level & DDSCL_NORMAL)
262 IDirectDrawClipper *clipper;
264 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
265 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
266 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
267 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
268 hr = IDirectDrawSurface7_SetClipper(surface, clipper);
269 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
270 IDirectDrawClipper_Release(clipper);
273 hr = IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d7);
274 IDirectDraw7_Release(ddraw);
275 if (FAILED(hr))
277 IDirectDrawSurface7_Release(surface);
278 return NULL;
281 hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_cb, &hal_ok);
282 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
283 if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
285 memset(&z_fmt, 0, sizeof(z_fmt));
286 hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
287 if (FAILED(hr) || !z_fmt.dwSize)
289 IDirect3D7_Release(d3d7);
290 IDirectDrawSurface7_Release(surface);
291 return NULL;
294 memset(&surface_desc, 0, sizeof(surface_desc));
295 surface_desc.dwSize = sizeof(surface_desc);
296 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
297 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
298 U4(surface_desc).ddpfPixelFormat = z_fmt;
299 surface_desc.dwWidth = 640;
300 surface_desc.dwHeight = 480;
301 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
302 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
303 if (FAILED(hr))
305 IDirect3D7_Release(d3d7);
306 IDirectDrawSurface7_Release(surface);
307 return NULL;
310 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
311 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
312 IDirectDrawSurface7_Release(ds);
313 if (FAILED(hr))
315 IDirect3D7_Release(d3d7);
316 IDirectDrawSurface7_Release(surface);
317 return NULL;
320 hr = IDirect3D7_CreateDevice(d3d7, devtype, surface, &device);
321 IDirect3D7_Release(d3d7);
322 IDirectDrawSurface7_Release(surface);
323 if (FAILED(hr))
324 return NULL;
326 return device;
329 struct message
331 UINT message;
332 BOOL check_wparam;
333 WPARAM expect_wparam;
336 static const struct message *expect_messages;
338 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
340 if (expect_messages && message == expect_messages->message)
342 if (expect_messages->check_wparam)
343 ok (wparam == expect_messages->expect_wparam,
344 "Got unexpected wparam %lx for message %x, expected %lx.\n",
345 wparam, message, expect_messages->expect_wparam);
347 ++expect_messages;
350 return DefWindowProcA(hwnd, message, wparam, lparam);
353 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
354 * interface. This prevents subsequent SetCooperativeLevel() calls on a
355 * different window from failing with DDERR_HWNDALREADYSET. */
356 static void fix_wndproc(HWND window, LONG_PTR proc)
358 IDirectDraw7 *ddraw;
359 HRESULT hr;
361 if (!(ddraw = create_ddraw()))
362 return;
364 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
365 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
366 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
367 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
368 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
370 IDirectDraw7_Release(ddraw);
373 static void test_process_vertices(void)
375 IDirect3DVertexBuffer7 *src_vb, *dst_vb1, *dst_vb2;
376 D3DVERTEXBUFFERDESC vb_desc;
377 IDirect3DDevice7 *device;
378 struct vec4 *dst_data;
379 struct vec3 *dst_data2;
380 struct vec3 *src_data;
381 IDirect3D7 *d3d7;
382 D3DVIEWPORT7 vp;
383 HWND window;
384 HRESULT hr;
386 static D3DMATRIX world =
388 0.0f, 1.0f, 0.0f, 0.0f,
389 1.0f, 0.0f, 0.0f, 0.0f,
390 0.0f, 0.0f, 0.0f, 1.0f,
391 0.0f, 1.0f, 1.0f, 1.0f,
393 static D3DMATRIX view =
395 2.0f, 0.0f, 0.0f, 0.0f,
396 0.0f, -1.0f, 0.0f, 0.0f,
397 0.0f, 0.0f, 1.0f, 0.0f,
398 0.0f, 0.0f, 0.0f, 3.0f,
400 static D3DMATRIX proj =
402 1.0f, 0.0f, 0.0f, 1.0f,
403 0.0f, 1.0f, 1.0f, 0.0f,
404 0.0f, 1.0f, 1.0f, 0.0f,
405 1.0f, 0.0f, 0.0f, 1.0f,
408 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
409 0, 0, 640, 480, 0, 0, 0, 0);
410 if (!(device = create_device(window, DDSCL_NORMAL)))
412 skip("Failed to create a 3D device, skipping test.\n");
413 DestroyWindow(window);
414 return;
417 hr = IDirect3DDevice7_GetDirect3D(device, &d3d7);
418 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
420 memset(&vb_desc, 0, sizeof(vb_desc));
421 vb_desc.dwSize = sizeof(vb_desc);
422 vb_desc.dwFVF = D3DFVF_XYZ;
423 vb_desc.dwNumVertices = 4;
424 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &src_vb, 0);
425 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
427 hr = IDirect3DVertexBuffer7_Lock(src_vb, 0, (void **)&src_data, NULL);
428 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
429 src_data[0].x = 0.0f;
430 src_data[0].y = 0.0f;
431 src_data[0].z = 0.0f;
432 src_data[1].x = 1.0f;
433 src_data[1].y = 1.0f;
434 src_data[1].z = 1.0f;
435 src_data[2].x = -1.0f;
436 src_data[2].y = -1.0f;
437 src_data[2].z = 0.5f;
438 src_data[3].x = 0.5f;
439 src_data[3].y = -0.5f;
440 src_data[3].z = 0.25f;
441 hr = IDirect3DVertexBuffer7_Unlock(src_vb);
442 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
444 memset(&vb_desc, 0, sizeof(vb_desc));
445 vb_desc.dwSize = sizeof(vb_desc);
446 vb_desc.dwFVF = D3DFVF_XYZRHW;
447 vb_desc.dwNumVertices = 4;
448 /* MSDN says that the last parameter must be 0 - check that. */
449 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb1, 4);
450 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
452 memset(&vb_desc, 0, sizeof(vb_desc));
453 vb_desc.dwSize = sizeof(vb_desc);
454 vb_desc.dwFVF = D3DFVF_XYZ;
455 vb_desc.dwNumVertices = 5;
456 /* MSDN says that the last parameter must be 0 - check that. */
457 hr = IDirect3D7_CreateVertexBuffer(d3d7, &vb_desc, &dst_vb2, 12345678);
458 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
460 memset(&vp, 0, sizeof(vp));
461 vp.dwX = 64;
462 vp.dwY = 64;
463 vp.dwWidth = 128;
464 vp.dwHeight = 128;
465 vp.dvMinZ = 0.0f;
466 vp.dvMaxZ = 1.0f;
467 hr = IDirect3DDevice7_SetViewport(device, &vp);
468 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
470 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
471 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
472 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb2, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
473 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
475 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
476 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
477 ok(compare_vec4(&dst_data[0], +1.280e+2f, +1.280e+2f, +0.000e+0f, +1.000e+0f, 4096),
478 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
479 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
480 ok(compare_vec4(&dst_data[1], +1.920e+2f, +6.400e+1f, +1.000e+0f, +1.000e+0f, 4096),
481 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
482 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
483 ok(compare_vec4(&dst_data[2], +6.400e+1f, +1.920e+2f, +5.000e-1f, +1.000e+0f, 4096),
484 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
485 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
486 ok(compare_vec4(&dst_data[3], +1.600e+2f, +1.600e+2f, +2.500e-1f, +1.000e+0f, 4096),
487 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
488 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
489 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
490 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
492 hr = IDirect3DVertexBuffer7_Lock(dst_vb2, 0, (void **)&dst_data2, NULL);
493 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
494 /* Small thing without much practical meaning, but I stumbled upon it,
495 * so let's check for it: If the output vertex buffer has no RHW value,
496 * the RHW value of the last vertex is written into the next vertex. */
497 ok(compare_vec3(&dst_data2[4], +1.000e+0f, +0.000e+0f, +0.000e+0f, 4096),
498 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
499 dst_data2[4].x, dst_data2[4].y, dst_data2[4].z);
500 hr = IDirect3DVertexBuffer7_Unlock(dst_vb2);
501 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
503 /* Try a more complicated viewport, same vertices. */
504 memset(&vp, 0, sizeof(vp));
505 vp.dwX = 10;
506 vp.dwY = 5;
507 vp.dwWidth = 246;
508 vp.dwHeight = 130;
509 vp.dvMinZ = -2.0f;
510 vp.dvMaxZ = 4.0f;
511 hr = IDirect3DDevice7_SetViewport(device, &vp);
512 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
514 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
515 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
517 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
518 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
519 ok(compare_vec4(&dst_data[0], +1.330e+2f, +7.000e+1f, -2.000e+0f, +1.000e+0f, 4096),
520 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
521 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
522 ok(compare_vec4(&dst_data[1], +2.560e+2f, +5.000e+0f, +4.000e+0f, +1.000e+0f, 4096),
523 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
524 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
525 ok(compare_vec4(&dst_data[2], +1.000e+1f, +1.350e+2f, +1.000e+0f, +1.000e+0f, 4096),
526 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
527 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
528 ok(compare_vec4(&dst_data[3], +1.945e+2f, +1.025e+2f, -5.000e-1f, +1.000e+0f, 4096),
529 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
530 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
531 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
532 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
534 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &world);
535 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
536 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &view);
537 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
538 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &proj);
539 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
541 hr = IDirect3DVertexBuffer7_ProcessVertices(dst_vb1, D3DVOP_TRANSFORM, 0, 4, src_vb, 0, device, 0);
542 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
544 hr = IDirect3DVertexBuffer7_Lock(dst_vb1, 0, (void **)&dst_data, NULL);
545 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
546 ok(compare_vec4(&dst_data[0], +2.560e+2f, +7.000e+1f, -2.000e+0f, +3.333e-1f, 4096),
547 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
548 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
549 ok(compare_vec4(&dst_data[1], +2.560e+2f, +7.813e+1f, -2.750e+0f, +1.250e-1f, 4096),
550 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
551 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
552 ok(compare_vec4(&dst_data[2], +2.560e+2f, +4.400e+1f, +4.000e-1f, +4.000e-1f, 4096),
553 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
554 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
555 ok(compare_vec4(&dst_data[3], +2.560e+2f, +8.182e+1f, -3.091e+0f, +3.636e-1f, 4096),
556 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
557 dst_data[3].x, dst_data[3].y, dst_data[3].z, dst_data[3].w);
558 hr = IDirect3DVertexBuffer7_Unlock(dst_vb1);
559 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
561 IDirect3DVertexBuffer7_Release(dst_vb2);
562 IDirect3DVertexBuffer7_Release(dst_vb1);
563 IDirect3DVertexBuffer7_Release(src_vb);
564 IDirect3D7_Release(d3d7);
565 IDirect3DDevice7_Release(device);
566 DestroyWindow(window);
569 static void test_coop_level_create_device_window(void)
571 HWND focus_window, device_window;
572 IDirectDraw7 *ddraw;
573 HRESULT hr;
575 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
576 0, 0, 640, 480, 0, 0, 0, 0);
577 ddraw = create_ddraw();
578 ok(!!ddraw, "Failed to create a ddraw object.\n");
580 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
581 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
582 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
583 ok(!device_window, "Unexpected device window found.\n");
584 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
585 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
586 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
587 ok(!device_window, "Unexpected device window found.\n");
588 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
589 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
590 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
591 ok(!device_window, "Unexpected device window found.\n");
592 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
593 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
594 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
595 ok(!device_window, "Unexpected device window found.\n");
596 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
597 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
598 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
599 ok(!device_window, "Unexpected device window found.\n");
601 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
602 if (broken(hr == DDERR_INVALIDPARAMS))
604 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
605 IDirectDraw7_Release(ddraw);
606 DestroyWindow(focus_window);
607 return;
610 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
611 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
612 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
613 ok(!device_window, "Unexpected device window found.\n");
614 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
615 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
616 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
617 ok(!device_window, "Unexpected device window found.\n");
619 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
620 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
621 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
622 ok(!device_window, "Unexpected device window found.\n");
623 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
624 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
625 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
626 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
627 ok(!!device_window, "Device window not found.\n");
629 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
630 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
631 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
632 ok(!device_window, "Unexpected device window found.\n");
633 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
634 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
635 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
636 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!!device_window, "Device window not found.\n");
639 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
640 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
641 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
642 ok(!device_window, "Unexpected device window found.\n");
643 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
644 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
645 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
646 ok(!device_window, "Unexpected device window found.\n");
647 hr = IDirectDraw7_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
648 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
649 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
650 ok(!device_window, "Unexpected device window found.\n");
651 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
652 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
653 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
654 ok(!!device_window, "Device window not found.\n");
656 IDirectDraw7_Release(ddraw);
657 DestroyWindow(focus_window);
660 static void test_clipper_blt(void)
662 IDirectDrawSurface7 *src_surface, *dst_surface;
663 RECT client_rect, src_rect;
664 IDirectDrawClipper *clipper;
665 DDSURFACEDESC2 surface_desc;
666 unsigned int i, j, x, y;
667 IDirectDraw7 *ddraw;
668 RGNDATA *rgn_data;
669 D3DCOLOR color;
670 ULONG refcount;
671 HRGN r1, r2;
672 HWND window;
673 DDBLTFX fx;
674 HRESULT hr;
675 DWORD *ptr;
676 DWORD ret;
678 static const DWORD src_data[] =
680 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
681 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
682 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
684 static const D3DCOLOR expected1[] =
686 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
687 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
688 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
689 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
691 /* Nvidia on Windows seems to have an off-by-one error
692 * when processing source rectangles. Our left = 1 and
693 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
694 * read as well, but only for the edge pixels on the
695 * output image. The bug happens on the y axis as well,
696 * but we only read one row there, and all source rows
697 * contain the same data. This bug is not dependent on
698 * the presence of a clipper. */
699 static const D3DCOLOR expected1_broken[] =
701 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
702 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
703 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
704 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
706 static const D3DCOLOR expected2[] =
708 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
709 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
710 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
711 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
714 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
715 10, 10, 640, 480, 0, 0, 0, 0);
716 ShowWindow(window, SW_SHOW);
717 ddraw = create_ddraw();
718 ok(!!ddraw, "Failed to create a ddraw object.\n");
720 ret = GetClientRect(window, &client_rect);
721 ok(ret, "Failed to get client rect.\n");
722 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
723 ok(ret, "Failed to map client rect.\n");
725 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
726 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
728 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
729 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
730 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
731 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
732 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
733 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
734 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
735 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
736 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
737 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
738 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
739 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
740 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
741 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
742 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
743 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
744 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
745 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
746 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
747 HeapFree(GetProcessHeap(), 0, rgn_data);
749 r1 = CreateRectRgn(0, 0, 320, 240);
750 ok(!!r1, "Failed to create region.\n");
751 r2 = CreateRectRgn(320, 240, 640, 480);
752 ok(!!r2, "Failed to create region.\n");
753 CombineRgn(r1, r1, r2, RGN_OR);
754 ret = GetRegionData(r1, 0, NULL);
755 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
756 ret = GetRegionData(r1, ret, rgn_data);
757 ok(!!ret, "Failed to get region data.\n");
759 DeleteObject(r2);
760 DeleteObject(r1);
762 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
763 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
764 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
765 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
766 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
767 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
769 HeapFree(GetProcessHeap(), 0, rgn_data);
771 memset(&surface_desc, 0, sizeof(surface_desc));
772 surface_desc.dwSize = sizeof(surface_desc);
773 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
774 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
775 surface_desc.dwWidth = 640;
776 surface_desc.dwHeight = 480;
777 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
778 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
779 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
780 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
781 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
782 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
784 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
785 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
786 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
787 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
789 memset(&fx, 0, sizeof(fx));
790 fx.dwSize = sizeof(fx);
791 hr = IDirectDrawSurface7_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
792 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
793 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
794 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
796 hr = IDirectDrawSurface7_Lock(src_surface, NULL, &surface_desc, 0, NULL);
797 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
798 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
799 ptr = surface_desc.lpSurface;
800 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
801 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
802 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
803 hr = IDirectDrawSurface7_Unlock(src_surface, NULL);
804 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
806 hr = IDirectDrawSurface7_SetClipper(dst_surface, clipper);
807 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
809 SetRect(&src_rect, 1, 1, 5, 2);
810 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
811 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
812 for (i = 0; i < 4; ++i)
814 for (j = 0; j < 4; ++j)
816 x = 80 * ((2 * j) + 1);
817 y = 60 * ((2 * i) + 1);
818 color = get_surface_color(dst_surface, x, y);
819 ok(compare_color(color, expected1[i * 4 + j], 1)
820 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
821 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
825 U5(fx).dwFillColor = 0xff0000ff;
826 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
827 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
828 for (i = 0; i < 4; ++i)
830 for (j = 0; j < 4; ++j)
832 x = 80 * ((2 * j) + 1);
833 y = 60 * ((2 * i) + 1);
834 color = get_surface_color(dst_surface, x, y);
835 ok(compare_color(color, expected2[i * 4 + j], 1),
836 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
840 hr = IDirectDrawSurface7_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
841 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
843 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
844 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
845 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
846 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
847 DestroyWindow(window);
848 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
849 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
850 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
851 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
852 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
853 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
854 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
855 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
856 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
857 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
858 hr = IDirectDrawSurface7_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
859 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
861 IDirectDrawSurface7_Release(dst_surface);
862 IDirectDrawSurface7_Release(src_surface);
863 refcount = IDirectDrawClipper_Release(clipper);
864 ok(!refcount, "Clipper has %u references left.\n", refcount);
865 IDirectDraw7_Release(ddraw);
868 static void test_coop_level_d3d_state(void)
870 IDirectDrawSurface7 *rt, *surface;
871 IDirect3DDevice7 *device;
872 IDirectDraw7 *ddraw;
873 IDirect3D7 *d3d;
874 D3DCOLOR color;
875 DWORD value;
876 HWND window;
877 HRESULT hr;
879 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
880 0, 0, 640, 480, 0, 0, 0, 0);
881 if (!(device = create_device(window, DDSCL_NORMAL)))
883 skip("Failed to create a 3D device, skipping test.\n");
884 DestroyWindow(window);
885 return;
888 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
889 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
890 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
891 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
892 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
893 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
894 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
895 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
896 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
897 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
898 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
899 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
900 color = get_surface_color(rt, 320, 240);
901 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
903 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
904 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
905 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
906 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
907 IDirect3D7_Release(d3d);
908 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
909 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
910 hr = IDirectDrawSurface7_IsLost(rt);
911 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
912 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
913 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
914 IDirectDraw7_Release(ddraw);
916 hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
917 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
918 ok(surface == rt, "Got unexpected surface %p.\n", surface);
919 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
920 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
921 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
922 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
923 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
924 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
925 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
926 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
927 color = get_surface_color(rt, 320, 240);
928 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
930 IDirectDrawSurface7_Release(surface);
931 IDirectDrawSurface7_Release(rt);
932 IDirect3DDevice7_Release(device);
933 DestroyWindow(window);
936 static void test_surface_interface_mismatch(void)
938 IDirectDraw7 *ddraw = NULL;
939 IDirect3D7 *d3d = NULL;
940 IDirectDrawSurface7 *surface = NULL, *ds;
941 IDirectDrawSurface3 *surface3 = NULL;
942 IDirect3DDevice7 *device = NULL;
943 DDSURFACEDESC2 surface_desc;
944 DDPIXELFORMAT z_fmt;
945 ULONG refcount;
946 HRESULT hr;
947 D3DCOLOR color;
948 HWND window;
950 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
951 0, 0, 640, 480, 0, 0, 0, 0);
952 ddraw = create_ddraw();
953 ok(!!ddraw, "Failed to create a ddraw object.\n");
954 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
955 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
957 memset(&surface_desc, 0, sizeof(surface_desc));
958 surface_desc.dwSize = sizeof(surface_desc);
959 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
960 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
961 surface_desc.dwWidth = 640;
962 surface_desc.dwHeight = 480;
964 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
965 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
967 hr = IDirectDrawSurface7_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
968 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
970 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
972 skip("D3D interface is not available, skipping test.\n");
973 goto cleanup;
976 memset(&z_fmt, 0, sizeof(z_fmt));
977 hr = IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
978 if (FAILED(hr) || !z_fmt.dwSize)
980 skip("No depth buffer formats available, skipping test.\n");
981 goto cleanup;
984 memset(&surface_desc, 0, sizeof(surface_desc));
985 surface_desc.dwSize = sizeof(surface_desc);
986 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
987 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
988 U4(surface_desc).ddpfPixelFormat = z_fmt;
989 surface_desc.dwWidth = 640;
990 surface_desc.dwHeight = 480;
991 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
992 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
993 if (FAILED(hr))
994 goto cleanup;
996 /* Using a different surface interface version still works */
997 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
998 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
999 refcount = IDirectDrawSurface7_Release(ds);
1000 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1001 if (FAILED(hr))
1002 goto cleanup;
1004 /* Here too */
1005 hr = IDirect3D7_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface7 *)surface3, &device);
1006 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1007 if (FAILED(hr))
1008 goto cleanup;
1010 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1011 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1012 color = get_surface_color(surface, 320, 240);
1013 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1015 cleanup:
1016 if (surface3) IDirectDrawSurface3_Release(surface3);
1017 if (surface) IDirectDrawSurface7_Release(surface);
1018 if (device) IDirect3DDevice7_Release(device);
1019 if (d3d) IDirect3D7_Release(d3d);
1020 if (ddraw) IDirectDraw7_Release(ddraw);
1021 DestroyWindow(window);
1024 static void test_coop_level_threaded(void)
1026 struct create_window_thread_param p;
1027 IDirectDraw7 *ddraw;
1028 HRESULT hr;
1030 ddraw = create_ddraw();
1031 ok(!!ddraw, "Failed to create a ddraw object.\n");
1032 create_window_thread(&p);
1034 hr = IDirectDraw7_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1035 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1037 IDirectDraw7_Release(ddraw);
1038 destroy_window_thread(&p);
1041 static void test_depth_blit(void)
1043 IDirect3DDevice7 *device;
1044 static struct
1046 float x, y, z;
1047 DWORD color;
1049 quad1[] =
1051 { -1.0, 1.0, 0.50f, 0xff00ff00},
1052 { 1.0, 1.0, 0.50f, 0xff00ff00},
1053 { -1.0, -1.0, 0.50f, 0xff00ff00},
1054 { 1.0, -1.0, 0.50f, 0xff00ff00},
1056 static const D3DCOLOR expected_colors[4][4] =
1058 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1059 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1060 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1061 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1063 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1065 IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
1066 RECT src_rect, dst_rect;
1067 unsigned int i, j;
1068 D3DCOLOR color;
1069 HRESULT hr;
1070 IDirect3D7 *d3d;
1071 IDirectDraw7 *ddraw;
1072 DDBLTFX fx;
1073 HWND window;
1075 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1076 0, 0, 640, 480, 0, 0, 0, 0);
1077 if (!(device = create_device(window, DDSCL_NORMAL)))
1079 skip("Failed to create a 3D device, skipping test.\n");
1080 DestroyWindow(window);
1081 return;
1084 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1085 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1086 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1087 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1088 IDirect3D7_Release(d3d);
1090 ds1 = get_depth_stencil(device);
1092 memset(&ddsd_new, 0, sizeof(ddsd_new));
1093 ddsd_new.dwSize = sizeof(ddsd_new);
1094 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1095 ddsd_existing.dwSize = sizeof(ddsd_existing);
1096 hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
1097 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
1098 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1099 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1100 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1101 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1102 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1103 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1104 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1105 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1106 ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
1107 IDirectDraw7_Release(ddraw);
1109 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1110 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1111 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1112 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1113 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
1114 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
1116 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1117 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1119 /* Partial blit. */
1120 SetRect(&src_rect, 0, 0, 320, 240);
1121 SetRect(&dst_rect, 0, 0, 320, 240);
1122 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1123 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1124 /* Different locations. */
1125 SetRect(&src_rect, 0, 0, 320, 240);
1126 SetRect(&dst_rect, 320, 240, 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 /* Streched. */
1130 SetRect(&src_rect, 0, 0, 320, 240);
1131 SetRect(&dst_rect, 0, 0, 640, 480);
1132 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1133 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1134 /* Flipped. */
1135 SetRect(&src_rect, 0, 480, 640, 0);
1136 SetRect(&dst_rect, 0, 0, 640, 480);
1137 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1138 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1139 SetRect(&src_rect, 0, 0, 640, 480);
1140 SetRect(&dst_rect, 0, 480, 640, 0);
1141 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1142 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1143 /* Full, explicit. */
1144 SetRect(&src_rect, 0, 0, 640, 480);
1145 SetRect(&dst_rect, 0, 0, 640, 480);
1146 hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1147 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1148 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1150 /* Depth blit inside a BeginScene / EndScene pair */
1151 hr = IDirect3DDevice7_BeginScene(device);
1152 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1153 /* From the current depth stencil */
1154 hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1155 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1156 /* To the current depth stencil */
1157 hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1158 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1159 /* Between unbound surfaces */
1160 hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1161 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1162 hr = IDirect3DDevice7_EndScene(device);
1163 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1165 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1166 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1167 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1168 * a reliable result(z = 0.0) */
1169 memset(&fx, 0, sizeof(fx));
1170 fx.dwSize = sizeof(fx);
1171 hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1172 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1174 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1175 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1176 SetRect(&dst_rect, 0, 0, 320, 240);
1177 hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1178 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1179 IDirectDrawSurface7_Release(ds3);
1180 IDirectDrawSurface7_Release(ds2);
1181 IDirectDrawSurface7_Release(ds1);
1183 hr = IDirect3DDevice7_BeginScene(device);
1184 ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
1185 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1186 quad1, 4, 0);
1187 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1188 hr = IDirect3DDevice7_EndScene(device);
1189 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1191 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1192 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1193 for (i = 0; i < 4; ++i)
1195 for (j = 0; j < 4; ++j)
1197 unsigned int x = 80 * ((2 * j) + 1);
1198 unsigned int y = 60 * ((2 * i) + 1);
1199 color = get_surface_color(rt, x, y);
1200 ok(compare_color(color, expected_colors[i][j], 1),
1201 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1205 IDirectDrawSurface7_Release(rt);
1206 IDirect3DDevice7_Release(device);
1207 DestroyWindow(window);
1210 static void test_texture_load_ckey(void)
1212 HWND window;
1213 IDirect3DDevice7 *device;
1214 IDirectDraw7 *ddraw;
1215 IDirectDrawSurface7 *src;
1216 IDirectDrawSurface7 *dst;
1217 DDSURFACEDESC2 ddsd;
1218 HRESULT hr;
1219 DDCOLORKEY ckey;
1220 IDirect3D7 *d3d;
1222 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1223 0, 0, 640, 480, 0, 0, 0, 0);
1224 if (!(device = create_device(window, DDSCL_NORMAL)))
1226 skip("Failed to create a 3D device, skipping test.\n");
1227 DestroyWindow(window);
1228 return;
1231 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1232 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
1233 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1234 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
1235 IDirect3D7_Release(d3d);
1237 memset(&ddsd, 0, sizeof(ddsd));
1238 ddsd.dwSize = sizeof(ddsd);
1239 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1240 ddsd.dwHeight = 128;
1241 ddsd.dwWidth = 128;
1242 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1243 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &src, NULL);
1244 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1245 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1246 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &dst, NULL);
1247 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1249 /* No surface has a color key */
1250 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1251 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1252 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1253 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1254 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1255 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1256 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1258 /* Source surface has a color key */
1259 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1260 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1261 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1262 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1263 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1264 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1265 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1266 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1267 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1269 /* Both surfaces have a color key: Dest ckey is overwritten */
1270 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1271 hr = IDirectDrawSurface7_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1272 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1273 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1274 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1275 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1276 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1277 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1278 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1280 /* Only the destination has a color key: It is deleted. This behavior differs from
1281 * IDirect3DTexture(2)::Load */
1282 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1283 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1284 hr = IDirectDrawSurface7_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1285 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1286 hr = IDirect3DDevice7_Load(device, dst, NULL, src, NULL, 0);
1287 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1288 hr = IDirectDrawSurface7_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1289 todo_wine ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1291 IDirectDrawSurface7_Release(dst);
1292 IDirectDrawSurface7_Release(src);
1293 IDirectDraw7_Release(ddraw);
1294 IDirect3DDevice7_Release(device);
1295 DestroyWindow(window);
1298 static void test_zenable(void)
1300 static struct
1302 struct vec4 position;
1303 D3DCOLOR diffuse;
1305 tquad[] =
1307 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1308 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1309 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1310 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1312 IDirect3DDevice7 *device;
1313 IDirectDrawSurface7 *rt;
1314 D3DCOLOR color;
1315 HWND window;
1316 HRESULT hr;
1317 UINT x, y;
1318 UINT i, j;
1320 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1321 0, 0, 640, 480, 0, 0, 0, 0);
1322 if (!(device = create_device(window, DDSCL_NORMAL)))
1324 skip("Failed to create a 3D device, skipping test.\n");
1325 DestroyWindow(window);
1326 return;
1329 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1330 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1332 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1333 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1334 hr = IDirect3DDevice7_BeginScene(device);
1335 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1336 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1337 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1338 hr = IDirect3DDevice7_EndScene(device);
1339 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1341 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1342 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1343 for (i = 0; i < 4; ++i)
1345 for (j = 0; j < 4; ++j)
1347 x = 80 * ((2 * j) + 1);
1348 y = 60 * ((2 * i) + 1);
1349 color = get_surface_color(rt, x, y);
1350 ok(compare_color(color, 0x0000ff00, 1),
1351 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1354 IDirectDrawSurface7_Release(rt);
1356 IDirect3DDevice7_Release(device);
1357 DestroyWindow(window);
1360 static void test_ck_rgba(void)
1362 static struct
1364 struct vec4 position;
1365 struct vec2 texcoord;
1367 tquad[] =
1369 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1370 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1371 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1372 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1373 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1374 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1375 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1376 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1378 static const struct
1380 D3DCOLOR fill_color;
1381 BOOL color_key;
1382 BOOL blend;
1383 D3DCOLOR result1, result1_broken;
1384 D3DCOLOR result2, result2_broken;
1386 tests[] =
1388 /* r200 on Windows doesn't check the alpha component when applying the color
1389 * key, so the key matches on every texel. */
1390 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1391 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1392 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1393 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1394 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1395 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1396 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1397 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1400 IDirectDrawSurface7 *texture;
1401 DDSURFACEDESC2 surface_desc;
1402 IDirect3DDevice7 *device;
1403 IDirectDrawSurface7 *rt;
1404 IDirectDraw7 *ddraw;
1405 IDirect3D7 *d3d;
1406 D3DCOLOR color;
1407 HWND window;
1408 DDBLTFX fx;
1409 HRESULT hr;
1410 UINT i;
1412 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1413 0, 0, 640, 480, 0, 0, 0, 0);
1414 if (!(device = create_device(window, DDSCL_NORMAL)))
1416 skip("Failed to create a 3D device, skipping test.\n");
1417 DestroyWindow(window);
1418 return;
1421 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1422 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1423 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1424 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1425 IDirect3D7_Release(d3d);
1427 memset(&surface_desc, 0, sizeof(surface_desc));
1428 surface_desc.dwSize = sizeof(surface_desc);
1429 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1430 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1431 surface_desc.dwWidth = 256;
1432 surface_desc.dwHeight = 256;
1433 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1434 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1435 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1436 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1437 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1438 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1439 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1440 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1441 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1442 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
1443 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1445 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
1446 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1447 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1448 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1449 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1450 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1452 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1453 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1455 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1457 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1458 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1459 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1460 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1462 memset(&fx, 0, sizeof(fx));
1463 fx.dwSize = sizeof(fx);
1464 U5(fx).dwFillColor = tests[i].fill_color;
1465 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1466 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1468 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1469 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1470 hr = IDirect3DDevice7_BeginScene(device);
1471 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1472 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1473 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1474 hr = IDirect3DDevice7_EndScene(device);
1475 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1477 color = get_surface_color(rt, 320, 240);
1478 ok(compare_color(color, tests[i].result1, 1) || compare_color(color, tests[i].result1_broken, 1),
1479 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1480 tests[i].result1, i, color);
1482 U5(fx).dwFillColor = 0xff0000ff;
1483 hr = IDirectDrawSurface7_Blt(texture, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1484 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1486 hr = IDirect3DDevice7_BeginScene(device);
1487 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1488 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1489 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1490 hr = IDirect3DDevice7_EndScene(device);
1491 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1493 /* This tests that fragments that are masked out by the color key are
1494 * discarded, instead of just fully transparent. */
1495 color = get_surface_color(rt, 320, 240);
1496 ok(compare_color(color, tests[i].result2, 1) || compare_color(color, tests[i].result2_broken, 1),
1497 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1498 tests[i].result2, i, color);
1501 IDirectDrawSurface7_Release(rt);
1502 IDirectDrawSurface7_Release(texture);
1503 IDirectDraw7_Release(ddraw);
1504 IDirect3DDevice7_Release(device);
1505 DestroyWindow(window);
1508 static void test_ck_default(void)
1510 static struct
1512 struct vec4 position;
1513 struct vec2 texcoord;
1515 tquad[] =
1517 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1518 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1519 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1520 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1522 IDirectDrawSurface7 *surface, *rt;
1523 DDSURFACEDESC2 surface_desc;
1524 IDirect3DDevice7 *device;
1525 IDirectDraw7 *ddraw;
1526 IDirect3D7 *d3d;
1527 D3DCOLOR color;
1528 DWORD value;
1529 HWND window;
1530 DDBLTFX fx;
1531 HRESULT hr;
1533 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1534 0, 0, 640, 480, 0, 0, 0, 0);
1536 if (!(device = create_device(window, DDSCL_NORMAL)))
1538 skip("Failed to create a 3D device, skipping test.\n");
1539 DestroyWindow(window);
1540 return;
1543 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1544 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1545 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1546 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1547 IDirect3D7_Release(d3d);
1549 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
1550 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1552 memset(&surface_desc, 0, sizeof(surface_desc));
1553 surface_desc.dwSize = sizeof(surface_desc);
1554 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1555 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1556 surface_desc.dwWidth = 256;
1557 surface_desc.dwHeight = 256;
1558 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1559 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1560 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1561 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1562 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1563 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1564 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1565 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1566 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1567 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1568 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
1569 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1571 memset(&fx, 0, sizeof(fx));
1572 fx.dwSize = sizeof(fx);
1573 U5(fx).dwFillColor = 0x000000ff;
1574 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1575 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1577 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1578 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1579 hr = IDirect3DDevice7_BeginScene(device);
1580 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1581 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1582 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1583 ok(!value, "Got unexpected color keying state %#x.\n", value);
1584 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1585 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1586 hr = IDirect3DDevice7_EndScene(device);
1587 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1588 color = get_surface_color(rt, 320, 240);
1589 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1591 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1592 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
1593 hr = IDirect3DDevice7_BeginScene(device);
1594 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1595 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1596 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1597 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1598 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1599 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1600 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1601 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1602 hr = IDirect3DDevice7_EndScene(device);
1603 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1604 color = get_surface_color(rt, 320, 240);
1605 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1607 IDirectDrawSurface7_Release(surface);
1608 IDirectDrawSurface7_Release(rt);
1609 IDirect3DDevice7_Release(device);
1610 IDirectDraw7_Release(ddraw);
1611 DestroyWindow(window);
1614 static void test_ck_complex(void)
1616 IDirectDrawSurface7 *surface, *mipmap, *tmp;
1617 D3DDEVICEDESC7 device_desc;
1618 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
1619 DDSURFACEDESC2 surface_desc;
1620 IDirect3DDevice7 *device;
1621 DDCOLORKEY color_key;
1622 IDirectDraw7 *ddraw;
1623 IDirect3D7 *d3d;
1624 unsigned int i;
1625 ULONG refcount;
1626 HWND window;
1627 HRESULT hr;
1629 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1630 0, 0, 640, 480, 0, 0, 0, 0);
1631 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1633 skip("Failed to create a 3D device, skipping test.\n");
1634 DestroyWindow(window);
1635 return;
1637 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
1638 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1639 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
1640 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1641 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
1642 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1643 IDirect3D7_Release(d3d);
1645 memset(&surface_desc, 0, sizeof(surface_desc));
1646 surface_desc.dwSize = sizeof(surface_desc);
1647 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1648 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1649 surface_desc.dwWidth = 128;
1650 surface_desc.dwHeight = 128;
1651 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1652 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1654 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1655 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1656 color_key.dwColorSpaceLowValue = 0x0000ff00;
1657 color_key.dwColorSpaceHighValue = 0x0000ff00;
1658 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1659 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1660 memset(&color_key, 0, sizeof(color_key));
1661 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1662 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1663 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1664 color_key.dwColorSpaceLowValue);
1665 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1666 color_key.dwColorSpaceHighValue);
1668 mipmap = surface;
1669 IDirectDrawSurface_AddRef(mipmap);
1670 for (i = 0; i < 7; ++i)
1672 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1673 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1674 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1675 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1677 color_key.dwColorSpaceLowValue = 0x000000ff;
1678 color_key.dwColorSpaceHighValue = 0x000000ff;
1679 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1680 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1682 IDirectDrawSurface_Release(mipmap);
1683 mipmap = tmp;
1686 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1687 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1688 IDirectDrawSurface_Release(mipmap);
1689 refcount = IDirectDrawSurface7_Release(surface);
1690 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1692 memset(&surface_desc, 0, sizeof(surface_desc));
1693 surface_desc.dwSize = sizeof(surface_desc);
1694 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1695 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1696 U5(surface_desc).dwBackBufferCount = 1;
1697 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1698 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1700 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1701 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1702 color_key.dwColorSpaceLowValue = 0x0000ff00;
1703 color_key.dwColorSpaceHighValue = 0x0000ff00;
1704 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1705 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1706 memset(&color_key, 0, sizeof(color_key));
1707 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1708 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1709 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1710 color_key.dwColorSpaceLowValue);
1711 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1712 color_key.dwColorSpaceHighValue);
1714 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &tmp);
1715 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
1717 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1718 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1719 color_key.dwColorSpaceLowValue = 0x0000ff00;
1720 color_key.dwColorSpaceHighValue = 0x0000ff00;
1721 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1722 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1723 memset(&color_key, 0, sizeof(color_key));
1724 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1725 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1726 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1727 color_key.dwColorSpaceLowValue);
1728 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1729 color_key.dwColorSpaceHighValue);
1731 IDirectDrawSurface_Release(tmp);
1733 refcount = IDirectDrawSurface7_Release(surface);
1734 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1736 if (!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP))
1738 skip("Device does not support cubemaps.\n");
1739 goto cleanup;
1741 memset(&surface_desc, 0, sizeof(surface_desc));
1742 surface_desc.dwSize = sizeof(surface_desc);
1743 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1744 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1745 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES;
1746 surface_desc.dwWidth = 128;
1747 surface_desc.dwHeight = 128;
1748 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1749 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1751 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1752 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1753 color_key.dwColorSpaceLowValue = 0x0000ff00;
1754 color_key.dwColorSpaceHighValue = 0x0000ff00;
1755 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1756 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1758 caps.dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ;
1759 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
1760 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1762 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1763 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1764 color_key.dwColorSpaceLowValue = 0x000000ff;
1765 color_key.dwColorSpaceHighValue = 0x000000ff;
1766 hr = IDirectDrawSurface7_SetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1767 todo_wine ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1769 color_key.dwColorSpaceLowValue = 0;
1770 color_key.dwColorSpaceHighValue = 0;
1771 hr = IDirectDrawSurface7_GetColorKey(mipmap, DDCKEY_SRCBLT, &color_key);
1772 todo_wine ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1773 todo_wine ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1774 color_key.dwColorSpaceLowValue);
1775 todo_wine ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x.\n",
1776 color_key.dwColorSpaceHighValue);
1778 IDirectDrawSurface_AddRef(mipmap);
1779 for (i = 0; i < 7; ++i)
1781 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
1782 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1783 hr = IDirectDrawSurface7_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1784 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1786 color_key.dwColorSpaceLowValue = 0x000000ff;
1787 color_key.dwColorSpaceHighValue = 0x000000ff;
1788 hr = IDirectDrawSurface7_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1789 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
1791 IDirectDrawSurface_Release(mipmap);
1792 mipmap = tmp;
1795 IDirectDrawSurface7_Release(mipmap);
1797 refcount = IDirectDrawSurface7_Release(surface);
1798 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1800 cleanup:
1801 IDirectDraw7_Release(ddraw);
1802 refcount = IDirect3DDevice7_Release(device);
1803 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1804 DestroyWindow(window);
1807 struct qi_test
1809 REFIID iid;
1810 REFIID refcount_iid;
1811 HRESULT hr;
1814 static void test_qi(const char *test_name, IUnknown *base_iface,
1815 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1817 ULONG refcount, expected_refcount;
1818 IUnknown *iface1, *iface2;
1819 HRESULT hr;
1820 UINT i, j;
1822 for (i = 0; i < entry_count; ++i)
1824 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1825 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1826 if (SUCCEEDED(hr))
1828 for (j = 0; j < entry_count; ++j)
1830 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1831 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1832 if (SUCCEEDED(hr))
1834 expected_refcount = 0;
1835 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1836 ++expected_refcount;
1837 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1838 ++expected_refcount;
1839 refcount = IUnknown_Release(iface2);
1840 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1841 refcount, test_name, i, j, expected_refcount);
1845 expected_refcount = 0;
1846 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1847 ++expected_refcount;
1848 refcount = IUnknown_Release(iface1);
1849 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1850 refcount, test_name, i, expected_refcount);
1855 static void test_surface_qi(void)
1857 static const struct qi_test tests[] =
1859 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1860 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1861 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1862 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1863 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1864 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1865 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1866 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1867 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1868 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
1869 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1870 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1871 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1872 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1873 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1874 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1875 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1876 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1877 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1878 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1879 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1880 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1881 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1882 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1883 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1884 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1885 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1886 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1887 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1888 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1889 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1890 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1891 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1892 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1893 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1894 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1895 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1896 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1897 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1898 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1899 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1900 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1903 IDirectDrawSurface7 *surface;
1904 DDSURFACEDESC2 surface_desc;
1905 IDirect3DDevice7 *device;
1906 IDirectDraw7 *ddraw;
1907 HWND window;
1908 HRESULT hr;
1910 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1911 0, 0, 640, 480, 0, 0, 0, 0);
1912 /* Try to create a D3D device to see if the ddraw implementation supports
1913 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1914 * doesn't support e.g. the IDirect3DTexture interfaces. */
1915 if (!(device = create_device(window, DDSCL_NORMAL)))
1917 skip("Failed to create a 3D device, skipping test.\n");
1918 DestroyWindow(window);
1919 return;
1921 IDirect3DDevice_Release(device);
1922 ddraw = create_ddraw();
1923 ok(!!ddraw, "Failed to create a ddraw object.\n");
1924 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1925 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1927 memset(&surface_desc, 0, sizeof(surface_desc));
1928 surface_desc.dwSize = sizeof(surface_desc);
1929 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1930 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1931 surface_desc.dwWidth = 512;
1932 surface_desc.dwHeight = 512;
1933 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1934 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1936 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface7, tests, sizeof(tests) / sizeof(*tests));
1938 IDirectDrawSurface7_Release(surface);
1939 IDirectDraw7_Release(ddraw);
1940 DestroyWindow(window);
1943 static void test_device_qi(void)
1945 static const struct qi_test tests[] =
1947 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1948 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1949 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
1950 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1951 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
1952 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
1953 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
1954 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
1955 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
1956 {&IID_IDirect3DDevice7, &IID_IDirect3DDevice7, S_OK },
1957 {&IID_IDirect3DDevice3, NULL, E_NOINTERFACE},
1958 {&IID_IDirect3DDevice2, NULL, E_NOINTERFACE},
1959 {&IID_IDirect3DDevice, NULL, E_NOINTERFACE},
1960 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
1961 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
1962 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
1963 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
1964 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
1965 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
1966 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
1967 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
1968 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
1969 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
1970 {&IID_IDirect3D, NULL, E_NOINTERFACE},
1971 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
1972 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
1973 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
1974 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
1975 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
1976 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
1977 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
1978 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
1979 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
1980 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
1981 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
1982 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
1983 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
1984 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
1985 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
1986 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
1987 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
1988 {&IID_IUnknown, &IID_IDirect3DDevice7, S_OK },
1991 IDirect3DDevice7 *device;
1992 HWND window;
1994 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1995 0, 0, 640, 480, 0, 0, 0, 0);
1996 if (!(device = create_device(window, DDSCL_NORMAL)))
1998 skip("Failed to create a 3D device, skipping test.\n");
1999 DestroyWindow(window);
2000 return;
2003 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice7, tests, sizeof(tests) / sizeof(*tests));
2005 IDirect3DDevice7_Release(device);
2006 DestroyWindow(window);
2009 static void test_wndproc(void)
2011 LONG_PTR proc, ddraw_proc;
2012 IDirectDraw7 *ddraw;
2013 WNDCLASSA wc = {0};
2014 HWND window;
2015 HRESULT hr;
2016 ULONG ref;
2018 static struct message messages[] =
2020 {WM_WINDOWPOSCHANGING, FALSE, 0},
2021 {WM_MOVE, FALSE, 0},
2022 {WM_SIZE, FALSE, 0},
2023 {WM_WINDOWPOSCHANGING, FALSE, 0},
2024 {WM_ACTIVATE, FALSE, 0},
2025 {WM_SETFOCUS, FALSE, 0},
2026 {0, FALSE, 0},
2029 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2030 ddraw = create_ddraw();
2031 ok(!!ddraw, "Failed to create a ddraw object.\n");
2033 wc.lpfnWndProc = test_proc;
2034 wc.lpszClassName = "ddraw_test_wndproc_wc";
2035 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2037 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2038 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2040 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2041 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2042 (LONG_PTR)test_proc, proc);
2043 expect_messages = messages;
2044 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2045 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2046 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2047 expect_messages = NULL;
2048 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
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)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2055 (LONG_PTR)test_proc, proc);
2057 /* DDSCL_NORMAL doesn't. */
2058 ddraw = create_ddraw();
2059 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2060 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2061 (LONG_PTR)test_proc, proc);
2062 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2063 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2064 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2065 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2066 (LONG_PTR)test_proc, proc);
2067 ref = IDirectDraw7_Release(ddraw);
2068 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2069 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2070 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2071 (LONG_PTR)test_proc, proc);
2073 /* The original window proc is only restored by ddraw if the current
2074 * window proc matches the one ddraw set. This also affects switching
2075 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2076 ddraw = create_ddraw();
2077 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2078 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2079 (LONG_PTR)test_proc, proc);
2080 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2081 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2082 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2083 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2084 (LONG_PTR)test_proc, proc);
2085 ddraw_proc = proc;
2086 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2087 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2088 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2089 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2090 (LONG_PTR)test_proc, proc);
2091 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2092 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2093 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2094 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2095 (LONG_PTR)test_proc, proc);
2096 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2097 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2098 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2099 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2100 (LONG_PTR)DefWindowProcA, proc);
2101 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2102 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2103 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2104 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2105 (LONG_PTR)DefWindowProcA, proc);
2106 ref = IDirectDraw7_Release(ddraw);
2107 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2108 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2109 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2110 (LONG_PTR)test_proc, proc);
2112 ddraw = create_ddraw();
2113 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2114 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2115 (LONG_PTR)test_proc, proc);
2116 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2117 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2118 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2119 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2120 (LONG_PTR)test_proc, proc);
2121 ref = IDirectDraw7_Release(ddraw);
2122 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2123 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2124 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2125 (LONG_PTR)DefWindowProcA, proc);
2127 fix_wndproc(window, (LONG_PTR)test_proc);
2128 expect_messages = NULL;
2129 DestroyWindow(window);
2130 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2133 static void test_window_style(void)
2135 LONG style, exstyle, tmp, expected_style;
2136 RECT fullscreen_rect, r;
2137 IDirectDraw7 *ddraw;
2138 HWND window;
2139 HRESULT hr;
2140 ULONG ref;
2141 BOOL ret;
2143 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2144 0, 0, 100, 100, 0, 0, 0, 0);
2145 ddraw = create_ddraw();
2146 ok(!!ddraw, "Failed to create a ddraw object.\n");
2148 style = GetWindowLongA(window, GWL_STYLE);
2149 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2150 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2152 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2153 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2155 tmp = GetWindowLongA(window, GWL_STYLE);
2156 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2157 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2158 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2160 GetWindowRect(window, &r);
2161 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2162 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2163 r.left, r.top, r.right, r.bottom);
2164 GetClientRect(window, &r);
2165 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2167 ret = SetForegroundWindow(GetDesktopWindow());
2168 ok(ret, "Failed to set foreground window.\n");
2170 tmp = GetWindowLongA(window, GWL_STYLE);
2171 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2172 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2173 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2175 ret = SetForegroundWindow(window);
2176 ok(ret, "Failed to set foreground window.\n");
2177 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2178 * the next tests expect this. */
2179 ShowWindow(window, SW_HIDE);
2181 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2182 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2184 tmp = GetWindowLongA(window, GWL_STYLE);
2185 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2186 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2187 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2189 ShowWindow(window, SW_SHOW);
2190 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2191 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2193 tmp = GetWindowLongA(window, GWL_STYLE);
2194 expected_style = style | WS_VISIBLE;
2195 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2196 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2197 expected_style = exstyle | WS_EX_TOPMOST;
2198 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2200 ret = SetForegroundWindow(GetDesktopWindow());
2201 ok(ret, "Failed to set foreground window.\n");
2202 tmp = GetWindowLongA(window, GWL_STYLE);
2203 expected_style = style | WS_VISIBLE | WS_MINIMIZE;
2204 todo_wine ok(tmp == expected_style, "Expected window style %#x, got %#x.\n", expected_style, tmp);
2205 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2206 expected_style = exstyle | WS_EX_TOPMOST;
2207 todo_wine ok(tmp == expected_style, "Expected window extended style %#x, got %#x.\n", expected_style, tmp);
2209 ref = IDirectDraw7_Release(ddraw);
2210 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2212 DestroyWindow(window);
2215 static void test_redundant_mode_set(void)
2217 DDSURFACEDESC2 surface_desc = {0};
2218 IDirectDraw7 *ddraw;
2219 HWND window;
2220 HRESULT hr;
2221 RECT r, s;
2222 ULONG ref;
2224 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2225 0, 0, 100, 100, 0, 0, 0, 0);
2226 ddraw = create_ddraw();
2227 ok(!!ddraw, "Failed to create a ddraw object.\n");
2228 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2229 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2231 surface_desc.dwSize = sizeof(surface_desc);
2232 hr = IDirectDraw7_GetDisplayMode(ddraw, &surface_desc);
2233 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2235 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2236 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2237 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2239 GetWindowRect(window, &r);
2240 r.right /= 2;
2241 r.bottom /= 2;
2242 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2243 GetWindowRect(window, &s);
2244 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2245 r.left, r.top, r.right, r.bottom,
2246 s.left, s.top, s.right, s.bottom);
2248 hr = IDirectDraw7_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2249 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2250 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2252 GetWindowRect(window, &s);
2253 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2254 r.left, r.top, r.right, r.bottom,
2255 s.left, s.top, s.right, s.bottom);
2257 ref = IDirectDraw7_Release(ddraw);
2258 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2260 DestroyWindow(window);
2263 static SIZE screen_size, screen_size2;
2265 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2267 if (message == WM_SIZE)
2269 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2270 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2273 return test_proc(hwnd, message, wparam, lparam);
2276 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2278 if (message == WM_SIZE)
2280 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2281 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2284 return test_proc(hwnd, message, wparam, lparam);
2287 struct test_coop_level_mode_set_enum_param
2289 DWORD ddraw_width, ddraw_height, user32_width, user32_height;
2292 static HRESULT CALLBACK test_coop_level_mode_set_enum_cb(DDSURFACEDESC2 *surface_desc, void *context)
2294 struct test_coop_level_mode_set_enum_param *param = context;
2296 if (U1(U4(*surface_desc).ddpfPixelFormat).dwRGBBitCount != registry_mode.dmBitsPerPel)
2297 return DDENUMRET_OK;
2298 if (surface_desc->dwWidth == registry_mode.dmPelsWidth
2299 && surface_desc->dwHeight == registry_mode.dmPelsHeight)
2300 return DDENUMRET_OK;
2302 if (!param->ddraw_width)
2304 param->ddraw_width = surface_desc->dwWidth;
2305 param->ddraw_height = surface_desc->dwHeight;
2306 return DDENUMRET_OK;
2308 if (surface_desc->dwWidth == param->ddraw_width && surface_desc->dwHeight == param->ddraw_height)
2309 return DDENUMRET_OK;
2311 param->user32_width = surface_desc->dwWidth;
2312 param->user32_height = surface_desc->dwHeight;
2313 return DDENUMRET_CANCEL;
2316 static void test_coop_level_mode_set(void)
2318 IDirectDrawSurface7 *primary;
2319 RECT registry_rect, ddraw_rect, user32_rect, r;
2320 IDirectDraw7 *ddraw;
2321 DDSURFACEDESC2 ddsd;
2322 WNDCLASSA wc = {0};
2323 HWND window, window2;
2324 HRESULT hr;
2325 ULONG ref;
2326 MSG msg;
2327 struct test_coop_level_mode_set_enum_param param;
2328 DEVMODEW devmode;
2329 BOOL ret;
2330 LONG change_ret;
2332 static const struct message exclusive_messages[] =
2334 {WM_WINDOWPOSCHANGING, FALSE, 0},
2335 {WM_WINDOWPOSCHANGED, FALSE, 0},
2336 {WM_SIZE, FALSE, 0},
2337 {WM_DISPLAYCHANGE, FALSE, 0},
2338 {0, FALSE, 0},
2340 static const struct message exclusive_focus_loss_messages[] =
2342 {WM_ACTIVATE, TRUE, WA_INACTIVE},
2343 {WM_DISPLAYCHANGE, FALSE, 0},
2344 {WM_WINDOWPOSCHANGING, FALSE, 0},
2345 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2346 * SW_MINIMIZED, causing a recursive window activation that does not
2347 * produce the same result in Wine yet. Ignore the difference for now.
2348 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2349 {WM_WINDOWPOSCHANGED, FALSE, 0},
2350 {WM_MOVE, FALSE, 0},
2351 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2352 {WM_ACTIVATEAPP, TRUE, FALSE},
2353 {0, FALSE, 0},
2355 static const struct message exclusive_focus_restore_messages[] =
2357 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* From the ShowWindow(SW_RESTORE). */
2358 {WM_WINDOWPOSCHANGING, FALSE, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2359 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching previous message. */
2360 {WM_SIZE, FALSE, 0}, /* DefWindowProc. */
2361 {WM_DISPLAYCHANGE, FALSE, 0}, /* Ddraw restores mode. */
2362 /* Native redundantly sets the window size here. */
2363 {WM_ACTIVATEAPP, TRUE, TRUE}, /* End of ddraw's hooks. */
2364 {WM_WINDOWPOSCHANGED, FALSE, 0}, /* Matching the one from ShowWindow. */
2365 {WM_MOVE, FALSE, 0}, /* DefWindowProc. */
2366 {WM_SIZE, TRUE, SIZE_RESTORED}, /* DefWindowProc. */
2367 {0, FALSE, 0},
2369 static const struct message sc_restore_messages[] =
2371 {WM_SYSCOMMAND, TRUE, SC_RESTORE},
2372 {WM_WINDOWPOSCHANGING, FALSE, 0},
2373 {WM_WINDOWPOSCHANGED, FALSE, 0},
2374 {WM_SIZE, TRUE, SIZE_RESTORED},
2375 {0, FALSE, 0},
2377 static const struct message sc_minimize_messages[] =
2379 {WM_SYSCOMMAND, TRUE, SC_MINIMIZE},
2380 {WM_WINDOWPOSCHANGING, FALSE, 0},
2381 {WM_WINDOWPOSCHANGED, FALSE, 0},
2382 {WM_SIZE, TRUE, SIZE_MINIMIZED},
2383 {0, FALSE, 0},
2385 static const struct message sc_maximize_messages[] =
2387 {WM_SYSCOMMAND, TRUE, SC_MAXIMIZE},
2388 {WM_WINDOWPOSCHANGING, FALSE, 0},
2389 {WM_WINDOWPOSCHANGED, FALSE, 0},
2390 {WM_SIZE, TRUE, SIZE_MAXIMIZED},
2391 {0, FALSE, 0},
2394 static const struct message normal_messages[] =
2396 {WM_DISPLAYCHANGE, FALSE, 0},
2397 {0, FALSE, 0},
2400 ddraw = create_ddraw();
2401 ok(!!ddraw, "Failed to create a ddraw object.\n");
2403 memset(&param, 0, sizeof(param));
2404 hr = IDirectDraw7_EnumDisplayModes(ddraw, 0, NULL, &param, test_coop_level_mode_set_enum_cb);
2405 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2406 ref = IDirectDraw7_Release(ddraw);
2407 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2409 if (!param.user32_height)
2411 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2412 return;
2415 SetRect(&registry_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
2416 SetRect(&ddraw_rect, 0, 0, param.ddraw_width, param.ddraw_height);
2417 SetRect(&user32_rect, 0, 0, param.user32_width, param.user32_height);
2419 memset(&devmode, 0, sizeof(devmode));
2420 devmode.dmSize = sizeof(devmode);
2421 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2422 devmode.dmPelsWidth = param.user32_width;
2423 devmode.dmPelsHeight = param.user32_height;
2424 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2425 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2427 ddraw = create_ddraw();
2428 ok(!!ddraw, "Failed to create a ddraw object.\n");
2430 wc.lpfnWndProc = mode_set_proc;
2431 wc.lpszClassName = "ddraw_test_wndproc_wc";
2432 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2433 wc.lpfnWndProc = mode_set_proc2;
2434 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2435 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2437 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2438 0, 0, 100, 100, 0, 0, 0, 0);
2439 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2440 0, 0, 100, 100, 0, 0, 0, 0);
2442 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2443 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2445 GetWindowRect(window, &r);
2446 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2447 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2448 r.left, r.top, r.right, r.bottom);
2450 memset(&ddsd, 0, sizeof(ddsd));
2451 ddsd.dwSize = sizeof(ddsd);
2452 ddsd.dwFlags = DDSD_CAPS;
2453 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2455 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2456 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2457 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2458 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2459 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2460 param.user32_width, ddsd.dwWidth);
2461 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2462 param.user32_height, ddsd.dwHeight);
2464 GetWindowRect(window, &r);
2465 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2466 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2467 r.left, r.top, r.right, r.bottom);
2469 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2470 expect_messages = exclusive_messages;
2471 screen_size.cx = 0;
2472 screen_size.cy = 0;
2474 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2475 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2477 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2478 expect_messages = NULL;
2479 ok(screen_size.cx == param.ddraw_width && screen_size.cy == param.ddraw_height,
2480 "Expected screen size %ux%u, got %ux%u.\n",
2481 param.ddraw_width, param.ddraw_height, screen_size.cx, screen_size.cy);
2483 GetWindowRect(window, &r);
2484 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2485 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2486 r.left, r.top, r.right, r.bottom);
2488 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2489 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2490 ok(ddsd.dwWidth == param.user32_width, "Expected surface width %u, got %u.\n",
2491 param.user32_width, ddsd.dwWidth);
2492 ok(ddsd.dwHeight == param.user32_height, "Expected surface height %u, got %u.\n",
2493 param.user32_height, ddsd.dwHeight);
2494 IDirectDrawSurface7_Release(primary);
2496 memset(&ddsd, 0, sizeof(ddsd));
2497 ddsd.dwSize = sizeof(ddsd);
2498 ddsd.dwFlags = DDSD_CAPS;
2499 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2501 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2502 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2503 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2504 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2505 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2506 param.ddraw_width, ddsd.dwWidth);
2507 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2508 param.ddraw_height, ddsd.dwHeight);
2510 GetWindowRect(window, &r);
2511 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2512 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2513 r.left, r.top, r.right, r.bottom);
2515 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2516 expect_messages = exclusive_messages;
2517 screen_size.cx = 0;
2518 screen_size.cy = 0;
2520 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2521 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2523 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2524 expect_messages = NULL;
2525 ok(screen_size.cx == param.user32_width && screen_size.cy == param.user32_height,
2526 "Expected screen size %ux%u, got %ux%u.\n",
2527 param.user32_width, param.user32_height, screen_size.cx, screen_size.cy);
2529 GetWindowRect(window, &r);
2530 ok(EqualRect(&r, &user32_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2531 user32_rect.left, user32_rect.top, user32_rect.right, user32_rect.bottom,
2532 r.left, r.top, r.right, r.bottom);
2534 expect_messages = exclusive_focus_loss_messages;
2535 ret = SetForegroundWindow(GetDesktopWindow());
2536 ok(ret, "Failed to set foreground window.\n");
2537 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2538 memset(&devmode, 0, sizeof(devmode));
2539 devmode.dmSize = sizeof(devmode);
2540 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2541 ok(ret, "Failed to get display mode.\n");
2542 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2543 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2544 devmode.dmPelsWidth, devmode.dmPelsHeight);
2546 expect_messages = exclusive_focus_restore_messages;
2547 ShowWindow(window, SW_RESTORE);
2548 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2550 GetWindowRect(window, &r);
2551 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2552 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
2553 r.left, r.top, r.right, r.bottom);
2554 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2555 ok(ret, "Failed to get display mode.\n");
2556 ok(devmode.dmPelsWidth == param.ddraw_width
2557 && devmode.dmPelsHeight == param.ddraw_height, "Got unexpect screen size %ux%u.\n",
2558 devmode.dmPelsWidth, devmode.dmPelsHeight);
2560 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2561 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2562 /* Normally the primary should be restored here. Unfortunately this causes the
2563 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2564 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2565 * the point of the GetSurfaceDesc call. */
2567 expect_messages = sc_minimize_messages;
2568 SendMessageA(window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2569 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2570 expect_messages = NULL;
2572 expect_messages = sc_restore_messages;
2573 SendMessageA(window, WM_SYSCOMMAND, SC_RESTORE, 0);
2574 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2575 expect_messages = NULL;
2577 expect_messages = sc_maximize_messages;
2578 SendMessageA(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2579 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2580 expect_messages = NULL;
2582 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2583 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2585 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2586 expect_messages = exclusive_messages;
2587 screen_size.cx = 0;
2588 screen_size.cy = 0;
2590 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2591 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2593 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2594 expect_messages = NULL;
2595 ok(screen_size.cx == registry_mode.dmPelsWidth
2596 && screen_size.cy == registry_mode.dmPelsHeight,
2597 "Expected screen size %ux%u, got %ux%u.\n",
2598 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size.cx, screen_size.cy);
2600 GetWindowRect(window, &r);
2601 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2602 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2603 r.left, r.top, r.right, r.bottom);
2605 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2606 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2607 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2608 param.ddraw_width, ddsd.dwWidth);
2609 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2610 param.ddraw_height, ddsd.dwHeight);
2611 IDirectDrawSurface7_Release(primary);
2613 /* For Wine. */
2614 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2615 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2617 memset(&ddsd, 0, sizeof(ddsd));
2618 ddsd.dwSize = sizeof(ddsd);
2619 ddsd.dwFlags = DDSD_CAPS;
2620 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2622 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2623 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2624 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2625 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2626 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2627 registry_mode.dmPelsWidth, ddsd.dwWidth);
2628 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2629 registry_mode.dmPelsHeight, ddsd.dwHeight);
2631 GetWindowRect(window, &r);
2632 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2633 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2634 r.left, r.top, r.right, r.bottom);
2636 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2637 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2639 GetWindowRect(window, &r);
2640 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2641 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2642 r.left, r.top, r.right, r.bottom);
2644 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2645 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2646 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2647 registry_mode.dmPelsWidth, ddsd.dwWidth);
2648 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2649 registry_mode.dmPelsHeight, ddsd.dwHeight);
2650 IDirectDrawSurface7_Release(primary);
2652 memset(&ddsd, 0, sizeof(ddsd));
2653 ddsd.dwSize = sizeof(ddsd);
2654 ddsd.dwFlags = DDSD_CAPS;
2655 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2657 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2658 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2659 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2660 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2661 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2662 registry_mode.dmPelsWidth, ddsd.dwWidth);
2663 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2664 registry_mode.dmPelsHeight, ddsd.dwHeight);
2666 GetWindowRect(window, &r);
2667 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2668 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2669 r.left, r.top, r.right, r.bottom);
2671 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2672 expect_messages = normal_messages;
2673 screen_size.cx = 0;
2674 screen_size.cy = 0;
2676 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2677 devmode.dmPelsWidth = param.user32_width;
2678 devmode.dmPelsHeight = param.user32_height;
2679 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2680 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2682 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2683 expect_messages = NULL;
2684 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2686 GetWindowRect(window, &r);
2687 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2688 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2689 r.left, r.top, r.right, r.bottom);
2691 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2692 expect_messages = normal_messages;
2693 screen_size.cx = 0;
2694 screen_size.cy = 0;
2696 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2697 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2699 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2700 expect_messages = NULL;
2701 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2703 GetWindowRect(window, &r);
2704 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2705 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2706 r.left, r.top, r.right, r.bottom);
2708 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2709 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2710 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2711 registry_mode.dmPelsWidth, ddsd.dwWidth);
2712 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2713 registry_mode.dmPelsHeight, ddsd.dwHeight);
2714 IDirectDrawSurface7_Release(primary);
2716 memset(&ddsd, 0, sizeof(ddsd));
2717 ddsd.dwSize = sizeof(ddsd);
2718 ddsd.dwFlags = DDSD_CAPS;
2719 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2721 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2722 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2723 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2724 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2725 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2726 param.ddraw_width, ddsd.dwWidth);
2727 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2728 param.ddraw_height, ddsd.dwHeight);
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 = IDirectDraw_RestoreDisplayMode(ddraw);
2741 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, 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 == param.ddraw_width, "Expected surface width %u, got %u.\n",
2755 param.ddraw_width, ddsd.dwWidth);
2756 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2757 param.ddraw_height, ddsd.dwHeight);
2758 IDirectDrawSurface7_Release(primary);
2760 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2761 ok(ret, "Failed to get display mode.\n");
2762 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2763 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2764 "Expected resolution %ux%u, got %ux%u.\n",
2765 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2766 devmode.dmPelsWidth, devmode.dmPelsHeight);
2767 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2768 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2770 memset(&ddsd, 0, sizeof(ddsd));
2771 ddsd.dwSize = sizeof(ddsd);
2772 ddsd.dwFlags = DDSD_CAPS;
2773 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2775 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2776 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2777 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2778 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2779 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2780 registry_mode.dmPelsWidth, ddsd.dwWidth);
2781 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2782 registry_mode.dmPelsHeight, ddsd.dwHeight);
2784 GetWindowRect(window, &r);
2785 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2786 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2787 r.left, r.top, r.right, r.bottom);
2789 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2790 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2791 * not DDSCL_FULLSCREEN. */
2792 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2793 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2795 GetWindowRect(window, &r);
2796 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2797 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2798 r.left, r.top, r.right, r.bottom);
2800 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2801 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2802 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2803 registry_mode.dmPelsWidth, ddsd.dwWidth);
2804 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2805 registry_mode.dmPelsHeight, ddsd.dwHeight);
2806 IDirectDrawSurface7_Release(primary);
2808 memset(&ddsd, 0, sizeof(ddsd));
2809 ddsd.dwSize = sizeof(ddsd);
2810 ddsd.dwFlags = DDSD_CAPS;
2811 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2813 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2814 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2815 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2816 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2817 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2818 registry_mode.dmPelsWidth, ddsd.dwWidth);
2819 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2820 registry_mode.dmPelsHeight, ddsd.dwHeight);
2822 GetWindowRect(window, &r);
2823 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2824 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2825 r.left, r.top, r.right, r.bottom);
2827 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2828 expect_messages = normal_messages;
2829 screen_size.cx = 0;
2830 screen_size.cy = 0;
2832 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2833 devmode.dmPelsWidth = param.user32_width;
2834 devmode.dmPelsHeight = param.user32_height;
2835 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2836 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2838 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2839 expect_messages = NULL;
2840 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2842 GetWindowRect(window, &r);
2843 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2844 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2845 r.left, r.top, r.right, r.bottom);
2847 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2848 expect_messages = normal_messages;
2849 screen_size.cx = 0;
2850 screen_size.cy = 0;
2852 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2853 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2855 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2856 expect_messages = NULL;
2857 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2859 GetWindowRect(window, &r);
2860 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2861 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2862 r.left, r.top, r.right, r.bottom);
2864 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2865 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2866 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2867 registry_mode.dmPelsWidth, ddsd.dwWidth);
2868 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2869 registry_mode.dmPelsHeight, ddsd.dwHeight);
2870 IDirectDrawSurface7_Release(primary);
2872 memset(&ddsd, 0, sizeof(ddsd));
2873 ddsd.dwSize = sizeof(ddsd);
2874 ddsd.dwFlags = DDSD_CAPS;
2875 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2877 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2878 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2879 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2880 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2881 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2882 param.ddraw_width, ddsd.dwWidth);
2883 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2884 param.ddraw_height, ddsd.dwHeight);
2886 GetWindowRect(window, &r);
2887 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2888 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2889 r.left, r.top, r.right, r.bottom);
2891 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2892 expect_messages = normal_messages;
2893 screen_size.cx = 0;
2894 screen_size.cy = 0;
2896 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
2897 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2899 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2900 expect_messages = NULL;
2901 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2903 GetWindowRect(window, &r);
2904 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2905 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2906 r.left, r.top, r.right, r.bottom);
2908 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2909 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2910 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
2911 param.ddraw_width, ddsd.dwWidth);
2912 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
2913 param.ddraw_height, ddsd.dwHeight);
2914 IDirectDrawSurface7_Release(primary);
2916 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2917 ok(ret, "Failed to get display mode.\n");
2918 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2919 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
2920 "Expected resolution %ux%u, got %ux%u.\n",
2921 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2922 devmode.dmPelsWidth, devmode.dmPelsHeight);
2923 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2924 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2926 memset(&ddsd, 0, sizeof(ddsd));
2927 ddsd.dwSize = sizeof(ddsd);
2928 ddsd.dwFlags = DDSD_CAPS;
2929 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2931 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2932 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2933 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2934 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2935 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2936 registry_mode.dmPelsWidth, ddsd.dwWidth);
2937 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2938 registry_mode.dmPelsHeight, ddsd.dwHeight);
2939 IDirectDrawSurface7_Release(primary);
2941 GetWindowRect(window, &r);
2942 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2943 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2944 r.left, r.top, r.right, r.bottom);
2946 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2947 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2948 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2949 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2950 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2952 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2953 expect_messages = exclusive_messages;
2954 screen_size.cx = 0;
2955 screen_size.cy = 0;
2957 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2958 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2960 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
2961 expect_messages = NULL;
2962 ok(screen_size.cx == registry_mode.dmPelsWidth
2963 && screen_size.cy == registry_mode.dmPelsHeight,
2964 "Expected screen size %ux%u, got %ux%u.\n",
2965 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight,
2966 screen_size.cx, screen_size.cy);
2968 GetWindowRect(window, &r);
2969 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2970 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
2971 r.left, r.top, r.right, r.bottom);
2973 memset(&ddsd, 0, sizeof(ddsd));
2974 ddsd.dwSize = sizeof(ddsd);
2975 ddsd.dwFlags = DDSD_CAPS;
2976 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2978 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
2979 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2980 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
2981 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2982 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
2983 registry_mode.dmPelsWidth, ddsd.dwWidth);
2984 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
2985 registry_mode.dmPelsHeight, ddsd.dwHeight);
2986 IDirectDrawSurface7_Release(primary);
2988 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2989 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2990 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2991 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
2992 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2994 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2995 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2997 memset(&ddsd, 0, sizeof(ddsd));
2998 ddsd.dwSize = sizeof(ddsd);
2999 ddsd.dwFlags = DDSD_CAPS;
3000 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3002 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3003 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3004 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3005 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3006 ok(ddsd.dwWidth == param.ddraw_width, "Expected surface width %u, got %u.\n",
3007 param.ddraw_width, ddsd.dwWidth);
3008 ok(ddsd.dwHeight == param.ddraw_height, "Expected surface height %u, got %u.\n",
3009 param.ddraw_height, ddsd.dwHeight);
3010 IDirectDrawSurface7_Release(primary);
3012 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
3013 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3015 /* If the window is changed at the same time, messages are sent to the new window. */
3016 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3017 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3018 hr = set_display_mode(ddraw, param.ddraw_width, param.ddraw_height);
3019 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3021 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
3022 expect_messages = exclusive_messages;
3023 screen_size.cx = 0;
3024 screen_size.cy = 0;
3025 screen_size2.cx = 0;
3026 screen_size2.cy = 0;
3028 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3029 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3031 ok(!expect_messages->message, "Expected message %#x, but didn't receive it.\n", expect_messages->message);
3032 expect_messages = NULL;
3033 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
3034 screen_size.cx, screen_size.cy);
3035 ok(screen_size2.cx == registry_mode.dmPelsWidth && screen_size2.cy == registry_mode.dmPelsHeight,
3036 "Expected screen size 2 %ux%u, got %ux%u.\n",
3037 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, screen_size2.cx, screen_size2.cy);
3039 GetWindowRect(window, &r);
3040 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3041 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
3042 r.left, r.top, r.right, r.bottom);
3043 GetWindowRect(window2, &r);
3044 ok(EqualRect(&r, &registry_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3045 registry_rect.left, registry_rect.top, registry_rect.right, registry_rect.bottom,
3046 r.left, r.top, r.right, r.bottom);
3048 memset(&ddsd, 0, sizeof(ddsd));
3049 ddsd.dwSize = sizeof(ddsd);
3050 ddsd.dwFlags = DDSD_CAPS;
3051 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3053 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
3054 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3055 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &ddsd);
3056 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3057 ok(ddsd.dwWidth == registry_mode.dmPelsWidth, "Expected surface width %u, got %u.\n",
3058 registry_mode.dmPelsWidth, ddsd.dwWidth);
3059 ok(ddsd.dwHeight == registry_mode.dmPelsHeight, "Expected surface height %u, got %u.\n",
3060 registry_mode.dmPelsHeight, ddsd.dwHeight);
3061 IDirectDrawSurface7_Release(primary);
3063 ref = IDirectDraw7_Release(ddraw);
3064 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3066 GetWindowRect(window, &r);
3067 ok(EqualRect(&r, &ddraw_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3068 ddraw_rect.left, ddraw_rect.top, ddraw_rect.right, ddraw_rect.bottom,
3069 r.left, r.top, r.right, r.bottom);
3071 expect_messages = NULL;
3072 DestroyWindow(window);
3073 DestroyWindow(window2);
3074 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3075 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3078 static void test_coop_level_mode_set_multi(void)
3080 IDirectDraw7 *ddraw1, *ddraw2;
3081 UINT w, h;
3082 HWND window;
3083 HRESULT hr;
3084 ULONG ref;
3086 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3087 0, 0, 100, 100, 0, 0, 0, 0);
3088 ddraw1 = create_ddraw();
3089 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3091 /* With just a single ddraw object, the display mode is restored on
3092 * release. */
3093 hr = set_display_mode(ddraw1, 800, 600);
3094 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3095 w = GetSystemMetrics(SM_CXSCREEN);
3096 ok(w == 800, "Got unexpected screen width %u.\n", w);
3097 h = GetSystemMetrics(SM_CYSCREEN);
3098 ok(h == 600, "Got unexpected screen height %u.\n", h);
3100 ref = IDirectDraw7_Release(ddraw1);
3101 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3102 w = GetSystemMetrics(SM_CXSCREEN);
3103 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3104 h = GetSystemMetrics(SM_CYSCREEN);
3105 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3107 /* When there are multiple ddraw objects, the display mode is restored to
3108 * the initial mode, before the first SetDisplayMode() call. */
3109 ddraw1 = create_ddraw();
3110 hr = set_display_mode(ddraw1, 800, 600);
3111 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3112 w = GetSystemMetrics(SM_CXSCREEN);
3113 ok(w == 800, "Got unexpected screen width %u.\n", w);
3114 h = GetSystemMetrics(SM_CYSCREEN);
3115 ok(h == 600, "Got unexpected screen height %u.\n", h);
3117 ddraw2 = create_ddraw();
3118 hr = set_display_mode(ddraw2, 640, 480);
3119 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3120 w = GetSystemMetrics(SM_CXSCREEN);
3121 ok(w == 640, "Got unexpected screen width %u.\n", w);
3122 h = GetSystemMetrics(SM_CYSCREEN);
3123 ok(h == 480, "Got unexpected screen height %u.\n", h);
3125 ref = IDirectDraw7_Release(ddraw2);
3126 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3127 w = GetSystemMetrics(SM_CXSCREEN);
3128 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3129 h = GetSystemMetrics(SM_CYSCREEN);
3130 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3132 ref = IDirectDraw7_Release(ddraw1);
3133 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3134 w = GetSystemMetrics(SM_CXSCREEN);
3135 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3136 h = GetSystemMetrics(SM_CYSCREEN);
3137 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3139 /* Regardless of release ordering. */
3140 ddraw1 = create_ddraw();
3141 hr = set_display_mode(ddraw1, 800, 600);
3142 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3143 w = GetSystemMetrics(SM_CXSCREEN);
3144 ok(w == 800, "Got unexpected screen width %u.\n", w);
3145 h = GetSystemMetrics(SM_CYSCREEN);
3146 ok(h == 600, "Got unexpected screen height %u.\n", h);
3148 ddraw2 = create_ddraw();
3149 hr = set_display_mode(ddraw2, 640, 480);
3150 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3151 w = GetSystemMetrics(SM_CXSCREEN);
3152 ok(w == 640, "Got unexpected screen width %u.\n", w);
3153 h = GetSystemMetrics(SM_CYSCREEN);
3154 ok(h == 480, "Got unexpected screen height %u.\n", h);
3156 ref = IDirectDraw7_Release(ddraw1);
3157 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3158 w = GetSystemMetrics(SM_CXSCREEN);
3159 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3160 h = GetSystemMetrics(SM_CYSCREEN);
3161 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3163 ref = IDirectDraw7_Release(ddraw2);
3164 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3165 w = GetSystemMetrics(SM_CXSCREEN);
3166 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3167 h = GetSystemMetrics(SM_CYSCREEN);
3168 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3170 /* But only for ddraw objects that called SetDisplayMode(). */
3171 ddraw1 = create_ddraw();
3172 ddraw2 = create_ddraw();
3173 hr = set_display_mode(ddraw2, 640, 480);
3174 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3175 w = GetSystemMetrics(SM_CXSCREEN);
3176 ok(w == 640, "Got unexpected screen width %u.\n", w);
3177 h = GetSystemMetrics(SM_CYSCREEN);
3178 ok(h == 480, "Got unexpected screen height %u.\n", h);
3180 ref = IDirectDraw7_Release(ddraw1);
3181 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3182 w = GetSystemMetrics(SM_CXSCREEN);
3183 ok(w == 640, "Got unexpected screen width %u.\n", w);
3184 h = GetSystemMetrics(SM_CYSCREEN);
3185 ok(h == 480, "Got unexpected screen height %u.\n", h);
3187 ref = IDirectDraw7_Release(ddraw2);
3188 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3189 w = GetSystemMetrics(SM_CXSCREEN);
3190 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3191 h = GetSystemMetrics(SM_CYSCREEN);
3192 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3194 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3195 * restoring the display mode. */
3196 ddraw1 = create_ddraw();
3197 hr = set_display_mode(ddraw1, 800, 600);
3198 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3199 w = GetSystemMetrics(SM_CXSCREEN);
3200 ok(w == 800, "Got unexpected screen width %u.\n", w);
3201 h = GetSystemMetrics(SM_CYSCREEN);
3202 ok(h == 600, "Got unexpected screen height %u.\n", h);
3204 ddraw2 = create_ddraw();
3205 hr = set_display_mode(ddraw2, 640, 480);
3206 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3207 w = GetSystemMetrics(SM_CXSCREEN);
3208 ok(w == 640, "Got unexpected screen width %u.\n", w);
3209 h = GetSystemMetrics(SM_CYSCREEN);
3210 ok(h == 480, "Got unexpected screen height %u.\n", h);
3212 hr = IDirectDraw7_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3213 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3215 ref = IDirectDraw7_Release(ddraw1);
3216 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3217 w = GetSystemMetrics(SM_CXSCREEN);
3218 ok(w == 640, "Got unexpected screen width %u.\n", w);
3219 h = GetSystemMetrics(SM_CYSCREEN);
3220 ok(h == 480, "Got unexpected screen height %u.\n", h);
3222 ref = IDirectDraw7_Release(ddraw2);
3223 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3224 w = GetSystemMetrics(SM_CXSCREEN);
3225 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3226 h = GetSystemMetrics(SM_CYSCREEN);
3227 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3229 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3230 ddraw1 = create_ddraw();
3231 hr = set_display_mode(ddraw1, 800, 600);
3232 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3233 w = GetSystemMetrics(SM_CXSCREEN);
3234 ok(w == 800, "Got unexpected screen width %u.\n", w);
3235 h = GetSystemMetrics(SM_CYSCREEN);
3236 ok(h == 600, "Got unexpected screen height %u.\n", h);
3238 hr = IDirectDraw7_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3239 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3241 ddraw2 = create_ddraw();
3242 hr = set_display_mode(ddraw2, 640, 480);
3243 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3245 ref = IDirectDraw7_Release(ddraw1);
3246 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3247 w = GetSystemMetrics(SM_CXSCREEN);
3248 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3249 h = GetSystemMetrics(SM_CYSCREEN);
3250 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3252 ref = IDirectDraw7_Release(ddraw2);
3253 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3254 w = GetSystemMetrics(SM_CXSCREEN);
3255 ok(w == registry_mode.dmPelsWidth, "Got unexpected screen width %u.\n", w);
3256 h = GetSystemMetrics(SM_CYSCREEN);
3257 ok(h == registry_mode.dmPelsHeight, "Got unexpected screen height %u.\n", h);
3259 DestroyWindow(window);
3262 static void test_initialize(void)
3264 IDirectDraw7 *ddraw;
3265 HRESULT hr;
3267 ddraw = create_ddraw();
3268 ok(!!ddraw, "Failed to create a ddraw object.\n");
3270 hr = IDirectDraw7_Initialize(ddraw, NULL);
3271 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3272 IDirectDraw7_Release(ddraw);
3274 CoInitialize(NULL);
3275 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw7, (void **)&ddraw);
3276 ok(SUCCEEDED(hr), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr);
3277 hr = IDirectDraw7_Initialize(ddraw, NULL);
3278 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3279 hr = IDirectDraw7_Initialize(ddraw, NULL);
3280 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3281 IDirectDraw7_Release(ddraw);
3282 CoUninitialize();
3285 static void test_coop_level_surf_create(void)
3287 IDirectDrawSurface7 *surface;
3288 IDirectDraw7 *ddraw;
3289 DDSURFACEDESC2 ddsd;
3290 HRESULT hr;
3292 ddraw = create_ddraw();
3293 ok(!!ddraw, "Failed to create a ddraw object.\n");
3295 memset(&ddsd, 0, sizeof(ddsd));
3296 ddsd.dwSize = sizeof(ddsd);
3297 ddsd.dwFlags = DDSD_CAPS;
3298 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3299 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
3300 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3302 IDirectDraw7_Release(ddraw);
3305 static void test_vb_discard(void)
3307 static const struct vec4 quad[] =
3309 { 0.0f, 480.0f, 0.0f, 1.0f},
3310 { 0.0f, 0.0f, 0.0f, 1.0f},
3311 {640.0f, 480.0f, 0.0f, 1.0f},
3312 {640.0f, 0.0f, 0.0f, 1.0f},
3315 IDirect3DDevice7 *device;
3316 IDirect3D7 *d3d;
3317 IDirect3DVertexBuffer7 *buffer;
3318 HWND window;
3319 HRESULT hr;
3320 D3DVERTEXBUFFERDESC desc;
3321 BYTE *data;
3322 static const unsigned int vbsize = 16;
3323 unsigned int i;
3325 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3326 0, 0, 640, 480, 0, 0, 0, 0);
3328 if (!(device = create_device(window, DDSCL_NORMAL)))
3330 skip("Failed to create a 3D device, skipping test.\n");
3331 DestroyWindow(window);
3332 return;
3335 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
3336 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3338 memset(&desc, 0, sizeof(desc));
3339 desc.dwSize = sizeof(desc);
3340 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3341 desc.dwFVF = D3DFVF_XYZRHW;
3342 desc.dwNumVertices = vbsize;
3343 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
3344 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3346 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3347 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3348 memcpy(data, quad, sizeof(quad));
3349 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3350 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3352 hr = IDirect3DDevice7_BeginScene(device);
3353 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3354 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3355 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3356 hr = IDirect3DDevice7_EndScene(device);
3357 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3359 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3360 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3361 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3362 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3363 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3365 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3366 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3367 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3369 if (data[i] != 0xaa)
3371 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3372 break;
3375 hr = IDirect3DVertexBuffer7_Unlock(buffer);
3376 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3378 IDirect3DVertexBuffer7_Release(buffer);
3379 IDirect3D7_Release(d3d);
3380 IDirect3DDevice7_Release(device);
3381 DestroyWindow(window);
3384 static void test_coop_level_multi_window(void)
3386 HWND window1, window2;
3387 IDirectDraw7 *ddraw;
3388 HRESULT hr;
3390 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3391 0, 0, 640, 480, 0, 0, 0, 0);
3392 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3393 0, 0, 640, 480, 0, 0, 0, 0);
3394 ddraw = create_ddraw();
3395 ok(!!ddraw, "Failed to create a ddraw object.\n");
3397 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3398 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3399 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3400 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3401 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3402 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3404 IDirectDraw7_Release(ddraw);
3405 DestroyWindow(window2);
3406 DestroyWindow(window1);
3409 static void test_draw_strided(void)
3411 static struct vec3 position[] =
3413 {-1.0, -1.0, 0.0},
3414 {-1.0, 1.0, 0.0},
3415 { 1.0, 1.0, 0.0},
3416 { 1.0, -1.0, 0.0},
3418 static DWORD diffuse[] =
3420 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3422 static WORD indices[] =
3424 0, 1, 2, 2, 3, 0
3427 IDirectDrawSurface7 *rt;
3428 IDirect3DDevice7 *device;
3429 D3DCOLOR color;
3430 HWND window;
3431 HRESULT hr;
3432 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3434 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3435 0, 0, 640, 480, 0, 0, 0, 0);
3437 if (!(device = create_device(window, DDSCL_NORMAL)))
3439 skip("Failed to create a 3D device, skipping test.\n");
3440 DestroyWindow(window);
3441 return;
3444 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3445 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3447 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3448 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3449 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
3450 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3451 hr = IDirect3DDevice7_BeginScene(device);
3452 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3454 memset(&strided, 0x55, sizeof(strided));
3455 strided.position.lpvData = position;
3456 strided.position.dwStride = sizeof(*position);
3457 strided.diffuse.lpvData = diffuse;
3458 strided.diffuse.dwStride = sizeof(*diffuse);
3459 hr = IDirect3DDevice7_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3460 &strided, 4, indices, 6, 0);
3461 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3463 hr = IDirect3DDevice7_EndScene(device);
3464 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3466 color = get_surface_color(rt, 320, 240);
3467 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3469 IDirectDrawSurface7_Release(rt);
3470 IDirect3DDevice7_Release(device);
3471 DestroyWindow(window);
3474 static void test_lighting(void)
3476 static D3DMATRIX mat =
3478 1.0f, 0.0f, 0.0f, 0.0f,
3479 0.0f, 1.0f, 0.0f, 0.0f,
3480 0.0f, 0.0f, 1.0f, 0.0f,
3481 0.0f, 0.0f, 0.0f, 1.0f,
3483 mat_singular =
3485 1.0f, 0.0f, 1.0f, 0.0f,
3486 0.0f, 1.0f, 0.0f, 0.0f,
3487 1.0f, 0.0f, 1.0f, 0.0f,
3488 0.0f, 0.0f, 0.5f, 1.0f,
3490 mat_transf =
3492 0.0f, 0.0f, 1.0f, 0.0f,
3493 0.0f, 1.0f, 0.0f, 0.0f,
3494 -1.0f, 0.0f, 0.0f, 0.0f,
3495 10.f, 10.0f, 10.0f, 1.0f,
3497 mat_nonaffine =
3499 1.0f, 0.0f, 0.0f, 0.0f,
3500 0.0f, 1.0f, 0.0f, 0.0f,
3501 0.0f, 0.0f, 1.0f, -1.0f,
3502 10.f, 10.0f, 10.0f, 0.0f,
3504 static struct
3506 struct vec3 position;
3507 DWORD diffuse;
3509 unlitquad[] =
3511 {{-1.0f, -1.0f, 0.1f}, 0xffff0000},
3512 {{-1.0f, 0.0f, 0.1f}, 0xffff0000},
3513 {{ 0.0f, 0.0f, 0.1f}, 0xffff0000},
3514 {{ 0.0f, -1.0f, 0.1f}, 0xffff0000},
3516 litquad[] =
3518 {{-1.0f, 0.0f, 0.1f}, 0xff00ff00},
3519 {{-1.0f, 1.0f, 0.1f}, 0xff00ff00},
3520 {{ 0.0f, 1.0f, 0.1f}, 0xff00ff00},
3521 {{ 0.0f, 0.0f, 0.1f}, 0xff00ff00},
3523 static struct
3525 struct vec3 position;
3526 struct vec3 normal;
3527 DWORD diffuse;
3529 unlitnquad[] =
3531 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3532 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3533 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3534 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
3536 litnquad[] =
3538 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3539 {{0.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3540 {{1.0f, 1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3541 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xffffff00},
3543 nquad[] =
3545 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3546 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3547 {{ 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3548 {{ 1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3550 rotatedquad[] =
3552 {{-10.0f, -11.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3553 {{-10.0f, -9.0f, 11.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3554 {{-10.0f, -9.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3555 {{-10.0f, -11.0f, 9.0f}, {-1.0f, 0.0f, 0.0f}, 0xff0000ff},
3557 translatedquad[] =
3559 {{-11.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3560 {{-11.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3561 {{ -9.0f, -9.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3562 {{ -9.0f, -11.0f, -10.0f}, {0.0f, 0.0f, -1.0f}, 0xff0000ff},
3564 static WORD indices[] = {0, 1, 2, 2, 3, 0};
3565 static const struct
3567 D3DMATRIX *world_matrix;
3568 void *quad;
3569 DWORD expected;
3570 const char *message;
3572 tests[] =
3574 {&mat, nquad, 0x000000ff, "Lit quad with light"},
3575 {&mat_singular, nquad, 0x000000ff, "Lit quad with singular world matrix"},
3576 {&mat_transf, rotatedquad, 0x000000ff, "Lit quad with transformation matrix"},
3577 {&mat_nonaffine, translatedquad, 0x00000000, "Lit quad with non-affine matrix"},
3580 HWND window;
3581 IDirect3DDevice7 *device;
3582 IDirectDrawSurface7 *rt;
3583 HRESULT hr;
3584 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
3585 DWORD nfvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL;
3586 D3DCOLOR color;
3587 ULONG refcount;
3588 unsigned int i;
3590 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3591 0, 0, 640, 480, 0, 0, 0, 0);
3592 if (!(device = create_device(window, DDSCL_NORMAL)))
3594 skip("Failed to create a 3D device, skipping test.\n");
3595 DestroyWindow(window);
3596 return;
3599 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3600 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3602 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3603 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3605 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
3606 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3607 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
3608 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
3609 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
3610 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
3611 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3612 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
3613 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
3614 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
3615 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3616 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3617 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_STENCILENABLE, FALSE);
3618 ok(SUCCEEDED(hr), "Failed to disable stencil buffering, hr %#x.\n", hr);
3619 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
3620 ok(SUCCEEDED(hr), "Failed to disable culling, hr %#x.\n", hr);
3622 hr = IDirect3DDevice7_BeginScene(device);
3623 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3625 /* No lights are defined... That means, lit vertices should be entirely black. */
3626 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3627 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3628 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, unlitquad, 4,
3629 indices, 6, 0);
3630 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3632 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3633 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3634 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, litquad, 4,
3635 indices, 6, 0);
3636 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3638 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
3639 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
3640 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, unlitnquad, 4,
3641 indices, 6, 0);
3642 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3644 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, TRUE);
3645 ok(SUCCEEDED(hr), "Failed to enable lighting, hr %#x.\n", hr);
3646 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, litnquad, 4,
3647 indices, 6, 0);
3648 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3650 hr = IDirect3DDevice7_EndScene(device);
3651 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3653 color = get_surface_color(rt, 160, 360);
3654 ok(color == 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color);
3655 color = get_surface_color(rt, 160, 120);
3656 ok(color == 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color);
3657 color = get_surface_color(rt, 480, 360);
3658 ok(color == 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color);
3659 color = get_surface_color(rt, 480, 120);
3660 ok(color == 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color);
3662 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
3663 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
3665 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
3667 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, tests[i].world_matrix);
3668 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3670 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3671 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
3673 hr = IDirect3DDevice7_BeginScene(device);
3674 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3676 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, nfvf, tests[i].quad,
3677 4, indices, 6, 0);
3678 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3680 hr = IDirect3DDevice7_EndScene(device);
3681 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3683 color = get_surface_color(rt, 320, 240);
3684 ok(color == tests[i].expected, "%s has color 0x%08x.\n", tests[i].message, color);
3687 IDirectDrawSurface7_Release(rt);
3689 refcount = IDirect3DDevice7_Release(device);
3690 ok(!refcount, "Device has %u references left.\n", refcount);
3691 DestroyWindow(window);
3694 static void test_specular_lighting(void)
3696 static const unsigned int vertices_side = 5;
3697 const unsigned int indices_count = (vertices_side - 1) * (vertices_side - 1) * 2 * 3;
3698 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_NORMAL;
3699 static D3DMATRIX mat =
3701 1.0f, 0.0f, 0.0f, 0.0f,
3702 0.0f, 1.0f, 0.0f, 0.0f,
3703 0.0f, 0.0f, 1.0f, 0.0f,
3704 0.0f, 0.0f, 0.0f, 1.0f,
3706 static D3DLIGHT7 directional =
3708 D3DLIGHT_DIRECTIONAL,
3709 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3710 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3711 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3712 {{0.0f}, {0.0f}, {0.0f}},
3713 {{0.0f}, {0.0f}, {1.0f}},
3715 point =
3717 D3DLIGHT_POINT,
3718 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3719 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3720 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3721 {{0.0f}, {0.0f}, {0.0f}},
3722 {{0.0f}, {0.0f}, {0.0f}},
3723 100.0f,
3724 0.0f,
3725 0.0f, 0.0f, 1.0f,
3727 spot =
3729 D3DLIGHT_SPOT,
3730 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3731 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3732 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3733 {{0.0f}, {0.0f}, {0.0f}},
3734 {{0.0f}, {0.0f}, {1.0f}},
3735 100.0f,
3736 1.0f,
3737 0.0f, 0.0f, 1.0f,
3738 M_PI / 12.0f, M_PI / 3.0f
3740 /* The chosen range value makes the test fail when using a manhattan
3741 * distance metric vs the correct euclidean distance. */
3742 point_range =
3744 D3DLIGHT_POINT,
3745 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3746 {{1.0f}, {1.0f}, {1.0f}, {0.0f}},
3747 {{0.0f}, {0.0f}, {0.0f}, {0.0f}},
3748 {{0.0f}, {0.0f}, {0.0f}},
3749 {{0.0f}, {0.0f}, {0.0f}},
3750 1.2f,
3751 0.0f,
3752 0.0f, 0.0f, 1.0f,
3754 static const struct expected_color
3756 unsigned int x, y;
3757 D3DCOLOR color;
3759 expected_directional[] =
3761 {160, 120, 0x00ffffff},
3762 {320, 120, 0x00ffffff},
3763 {480, 120, 0x00ffffff},
3764 {160, 240, 0x00ffffff},
3765 {320, 240, 0x00ffffff},
3766 {480, 240, 0x00ffffff},
3767 {160, 360, 0x00ffffff},
3768 {320, 360, 0x00ffffff},
3769 {480, 360, 0x00ffffff},
3771 expected_directional_local[] =
3773 {160, 120, 0x003c3c3c},
3774 {320, 120, 0x00717171},
3775 {480, 120, 0x003c3c3c},
3776 {160, 240, 0x00717171},
3777 {320, 240, 0x00ffffff},
3778 {480, 240, 0x00717171},
3779 {160, 360, 0x003c3c3c},
3780 {320, 360, 0x00717171},
3781 {480, 360, 0x003c3c3c},
3783 expected_point[] =
3785 {160, 120, 0x00282828},
3786 {320, 120, 0x005a5a5a},
3787 {480, 120, 0x00282828},
3788 {160, 240, 0x005a5a5a},
3789 {320, 240, 0x00ffffff},
3790 {480, 240, 0x005a5a5a},
3791 {160, 360, 0x00282828},
3792 {320, 360, 0x005a5a5a},
3793 {480, 360, 0x00282828},
3795 expected_point_local[] =
3797 {160, 120, 0x00000000},
3798 {320, 120, 0x00070707},
3799 {480, 120, 0x00000000},
3800 {160, 240, 0x00070707},
3801 {320, 240, 0x00ffffff},
3802 {480, 240, 0x00070707},
3803 {160, 360, 0x00000000},
3804 {320, 360, 0x00070707},
3805 {480, 360, 0x00000000},
3807 expected_spot[] =
3809 {160, 120, 0x00000000},
3810 {320, 120, 0x00141414},
3811 {480, 120, 0x00000000},
3812 {160, 240, 0x00141414},
3813 {320, 240, 0x00ffffff},
3814 {480, 240, 0x00141414},
3815 {160, 360, 0x00000000},
3816 {320, 360, 0x00141414},
3817 {480, 360, 0x00000000},
3819 expected_spot_local[] =
3821 {160, 120, 0x00000000},
3822 {320, 120, 0x00020202},
3823 {480, 120, 0x00000000},
3824 {160, 240, 0x00020202},
3825 {320, 240, 0x00ffffff},
3826 {480, 240, 0x00020202},
3827 {160, 360, 0x00000000},
3828 {320, 360, 0x00020202},
3829 {480, 360, 0x00000000},
3831 expected_point_range[] =
3833 {160, 120, 0x00000000},
3834 {320, 120, 0x005a5a5a},
3835 {480, 120, 0x00000000},
3836 {160, 240, 0x005a5a5a},
3837 {320, 240, 0x00ffffff},
3838 {480, 240, 0x005a5a5a},
3839 {160, 360, 0x00000000},
3840 {320, 360, 0x005a5a5a},
3841 {480, 360, 0x00000000},
3843 static const struct
3845 D3DLIGHT7 *light;
3846 BOOL local_viewer;
3847 const struct expected_color *expected;
3848 unsigned int expected_count;
3850 tests[] =
3852 {&directional, FALSE, expected_directional,
3853 sizeof(expected_directional) / sizeof(expected_directional[0])},
3854 {&directional, TRUE, expected_directional_local,
3855 sizeof(expected_directional_local) / sizeof(expected_directional_local[0])},
3856 {&point, FALSE, expected_point,
3857 sizeof(expected_point) / sizeof(expected_point[0])},
3858 {&point, TRUE, expected_point_local,
3859 sizeof(expected_point_local) / sizeof(expected_point_local[0])},
3860 {&spot, FALSE, expected_spot,
3861 sizeof(expected_spot) / sizeof(expected_spot[0])},
3862 {&spot, TRUE, expected_spot_local,
3863 sizeof(expected_spot_local) / sizeof(expected_spot_local[0])},
3864 {&point_range, FALSE, expected_point_range,
3865 sizeof(expected_point_range) / sizeof(expected_point_range[0])},
3867 IDirect3DDevice7 *device;
3868 IDirectDrawSurface7 *rt;
3869 D3DMATERIAL7 material;
3870 D3DCOLOR color;
3871 ULONG refcount;
3872 HWND window;
3873 HRESULT hr;
3874 unsigned int i, j, x, y;
3875 struct
3877 struct vec3 position;
3878 struct vec3 normal;
3879 } *quad;
3880 WORD *indices;
3882 quad = HeapAlloc(GetProcessHeap(), 0, vertices_side * vertices_side * sizeof(*quad));
3883 indices = HeapAlloc(GetProcessHeap(), 0, indices_count * sizeof(*indices));
3884 for (i = 0, y = 0; y < vertices_side; ++y)
3886 for (x = 0; x < vertices_side; ++x)
3888 quad[i].position.x = x * 2.0f / (vertices_side - 1) - 1.0f;
3889 quad[i].position.y = y * 2.0f / (vertices_side - 1) - 1.0f;
3890 quad[i].position.z = 1.0f;
3891 quad[i].normal.x = 0.0f;
3892 quad[i].normal.y = 0.0f;
3893 quad[i++].normal.z = -1.0f;
3896 for (i = 0, y = 0; y < (vertices_side - 1); ++y)
3898 for (x = 0; x < (vertices_side - 1); ++x)
3900 indices[i++] = y * vertices_side + x + 1;
3901 indices[i++] = y * vertices_side + x;
3902 indices[i++] = (y + 1) * vertices_side + x;
3903 indices[i++] = y * vertices_side + x + 1;
3904 indices[i++] = (y + 1) * vertices_side + x;
3905 indices[i++] = (y + 1) * vertices_side + x + 1;
3909 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3910 0, 0, 640, 480, 0, 0, 0, 0);
3911 if (!(device = create_device(window, DDSCL_NORMAL)))
3913 skip("Failed to create a 3D device, skipping test.\n");
3914 DestroyWindow(window);
3915 return;
3918 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
3919 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3921 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
3922 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
3923 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
3924 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
3925 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
3926 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
3927 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
3928 ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr);
3929 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
3930 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
3931 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
3932 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
3934 memset(&material, 0, sizeof(material));
3935 U1(U2(material).specular).r = 1.0f;
3936 U2(U2(material).specular).g = 1.0f;
3937 U3(U2(material).specular).b = 1.0f;
3938 U4(U2(material).specular).a = 1.0f;
3939 U4(material).power = 30.0f;
3940 hr = IDirect3DDevice7_SetMaterial(device, &material);
3941 ok(SUCCEEDED(hr), "Failed to set material, hr %#x.\n", hr);
3943 hr = IDirect3DDevice7_LightEnable(device, 0, TRUE);
3944 ok(SUCCEEDED(hr), "Failed to enable light 0, hr %#x.\n", hr);
3945 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, TRUE);
3946 ok(SUCCEEDED(hr), "Failed to enable specular lighting, hr %#x.\n", hr);
3948 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
3950 hr = IDirect3DDevice7_SetLight(device, 0, tests[i].light);
3951 ok(SUCCEEDED(hr), "Failed to set light parameters, hr %#x.\n", hr);
3953 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LOCALVIEWER, tests[i].local_viewer);
3954 ok(SUCCEEDED(hr), "Failed to set local viewer state, hr %#x.\n", hr);
3956 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0, 0);
3957 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
3959 hr = IDirect3DDevice7_BeginScene(device);
3960 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3962 hr = IDirect3DDevice7_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, fvf, quad,
3963 vertices_side * vertices_side, indices, indices_count, 0);
3964 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3966 hr = IDirect3DDevice7_EndScene(device);
3967 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3969 for (j = 0; j < tests[i].expected_count; ++j)
3971 color = get_surface_color(rt, tests[i].expected[j].x, tests[i].expected[j].y);
3972 ok(compare_color(color, tests[i].expected[j].color, 1),
3973 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
3974 tests[i].expected[j].color, tests[i].expected[j].x,
3975 tests[i].expected[j].y, color, i);
3979 IDirectDrawSurface7_Release(rt);
3981 refcount = IDirect3DDevice7_Release(device);
3982 ok(!refcount, "Device has %u references left.\n", refcount);
3983 DestroyWindow(window);
3984 HeapFree(GetProcessHeap(), 0, indices);
3985 HeapFree(GetProcessHeap(), 0, quad);
3988 static void test_clear_rect_count(void)
3990 IDirectDrawSurface7 *rt;
3991 IDirect3DDevice7 *device;
3992 D3DCOLOR color;
3993 HWND window;
3994 HRESULT hr;
3995 D3DRECT rect = {{0}, {0}, {640}, {480}};
3997 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3998 0, 0, 640, 480, 0, 0, 0, 0);
3999 if (!(device = create_device(window, DDSCL_NORMAL)))
4001 skip("Failed to create a 3D device, skipping test.\n");
4002 DestroyWindow(window);
4003 return;
4006 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4007 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4009 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
4010 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4011 hr = IDirect3DDevice7_Clear(device, 0, &rect, D3DCLEAR_TARGET, 0x00ff0000, 1.0f, 0);
4012 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4014 color = get_surface_color(rt, 320, 240);
4015 ok(compare_color(color, 0x00ffffff, 1) || broken(compare_color(color, 0x00ff0000, 1)),
4016 "Clear with count = 0, rect != NULL has color %#08x.\n", color);
4018 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 1.0f, 0);
4019 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4020 hr = IDirect3DDevice7_Clear(device, 1, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
4021 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4023 color = get_surface_color(rt, 320, 240);
4024 ok(compare_color(color, 0x0000ff00, 1),
4025 "Clear with count = 1, rect = NULL has color %#08x.\n", color);
4027 IDirectDrawSurface7_Release(rt);
4028 IDirect3DDevice7_Release(device);
4029 DestroyWindow(window);
4032 static BOOL test_mode_restored(IDirectDraw7 *ddraw, HWND window)
4034 DDSURFACEDESC2 ddsd1, ddsd2;
4035 HRESULT hr;
4037 memset(&ddsd1, 0, sizeof(ddsd1));
4038 ddsd1.dwSize = sizeof(ddsd1);
4039 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd1);
4040 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4042 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4043 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4044 hr = set_display_mode(ddraw, 640, 480);
4045 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
4046 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4047 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4049 memset(&ddsd2, 0, sizeof(ddsd2));
4050 ddsd2.dwSize = sizeof(ddsd2);
4051 hr = IDirectDraw7_GetDisplayMode(ddraw, &ddsd2);
4052 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
4053 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
4054 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
4056 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
4059 static void test_coop_level_versions(void)
4061 HWND window;
4062 IDirectDraw *ddraw;
4063 HRESULT hr;
4064 BOOL restored;
4065 IDirectDrawSurface *surface;
4066 IDirectDraw7 *ddraw7;
4067 DDSURFACEDESC ddsd;
4069 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
4070 0, 0, 640, 480, 0, 0, 0, 0);
4072 ddraw7 = create_ddraw();
4073 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4074 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4075 restored = test_mode_restored(ddraw7, window);
4076 ok(restored, "Display mode not restored in new ddraw object\n");
4078 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4079 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4080 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4082 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4083 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4084 restored = test_mode_restored(ddraw7, window);
4085 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4087 /* A successful one does */
4088 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4089 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4090 restored = test_mode_restored(ddraw7, window);
4091 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4093 IDirectDraw_Release(ddraw);
4094 IDirectDraw7_Release(ddraw7);
4096 ddraw7 = create_ddraw();
4097 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4098 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4099 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4101 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
4102 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4103 restored = test_mode_restored(ddraw7, window);
4104 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4106 IDirectDraw_Release(ddraw);
4107 IDirectDraw7_Release(ddraw7);
4109 /* A failing call does not restore the ddraw2+ behavior */
4110 ddraw7 = create_ddraw();
4111 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4112 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4113 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4115 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4116 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4117 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4118 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
4119 restored = test_mode_restored(ddraw7, window);
4120 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4122 IDirectDraw_Release(ddraw);
4123 IDirectDraw7_Release(ddraw7);
4125 /* Neither does a sequence of successful calls with the new interface */
4126 ddraw7 = create_ddraw();
4127 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4128 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4129 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4131 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4132 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4133 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
4134 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4135 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
4136 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4138 restored = test_mode_restored(ddraw7, window);
4139 ok(!restored, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
4140 IDirectDraw_Release(ddraw);
4141 IDirectDraw7_Release(ddraw7);
4143 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4144 ddraw7 = create_ddraw();
4145 ok(!!ddraw7, "Failed to create a ddraw object.\n");
4146 hr = IDirectDraw7_QueryInterface(ddraw7, &IID_IDirectDraw, (void **)&ddraw);
4147 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
4149 hr = IDirectDraw7_SetCooperativeLevel(ddraw7, window, DDSCL_NORMAL);
4150 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
4152 memset(&ddsd, 0, sizeof(ddsd));
4153 ddsd.dwSize = sizeof(ddsd);
4154 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4155 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4156 ddsd.dwWidth = ddsd.dwHeight = 8;
4157 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
4158 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
4159 IDirectDrawSurface_Release(surface);
4160 restored = test_mode_restored(ddraw7, window);
4161 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
4163 IDirectDraw_Release(ddraw);
4164 IDirectDraw7_Release(ddraw7);
4165 DestroyWindow(window);
4168 static void test_fog_special(void)
4170 static struct
4172 struct vec3 position;
4173 D3DCOLOR diffuse;
4175 quad[] =
4177 {{ -1.0f, 1.0f, 0.0f}, 0xff00ff00},
4178 {{ 1.0f, 1.0f, 1.0f}, 0xff00ff00},
4179 {{ -1.0f, -1.0f, 0.0f}, 0xff00ff00},
4180 {{ 1.0f, -1.0f, 1.0f}, 0xff00ff00},
4182 static const struct
4184 DWORD vertexmode, tablemode;
4185 D3DCOLOR color_left, color_right;
4187 tests[] =
4189 {D3DFOG_LINEAR, D3DFOG_NONE, 0x00ff0000, 0x00ff0000},
4190 {D3DFOG_NONE, D3DFOG_LINEAR, 0x0000ff00, 0x00ff0000},
4192 union
4194 float f;
4195 DWORD d;
4196 } conv;
4197 D3DCOLOR color;
4198 HRESULT hr;
4199 unsigned int i;
4200 HWND window;
4201 IDirect3DDevice7 *device;
4202 IDirectDrawSurface7 *rt;
4204 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4205 0, 0, 640, 480, 0, 0, 0, 0);
4207 if (!(device = create_device(window, DDSCL_NORMAL)))
4209 skip("Failed to create a 3D device, skipping test.\n");
4210 DestroyWindow(window);
4211 return;
4214 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4215 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4217 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
4218 ok(SUCCEEDED(hr), "Failed to enable fog, hr %#x.\n", hr);
4219 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0xffff0000);
4220 ok(SUCCEEDED(hr), "Failed to set fog color, hr %#x.\n", hr);
4221 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
4222 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4223 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4224 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
4226 conv.f = 0.5f;
4227 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, conv.d);
4228 ok(SUCCEEDED(hr), "Failed to set fog start, hr %#x.\n", hr);
4229 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, conv.d);
4230 ok(SUCCEEDED(hr), "Failed to set fog end, hr %#x.\n", hr);
4232 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4234 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 1.0f, 0);
4235 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
4237 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vertexmode);
4238 ok(SUCCEEDED(hr), "Failed to set fogvertexmode, hr %#x.\n", hr);
4239 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tablemode);
4240 ok(SUCCEEDED(hr), "Failed to set fogtablemode, hr %#x.\n", hr);
4242 hr = IDirect3DDevice7_BeginScene(device);
4243 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4244 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, 4, 0);
4245 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4246 hr = IDirect3DDevice7_EndScene(device);
4247 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4249 color = get_surface_color(rt, 310, 240);
4250 ok(compare_color(color, tests[i].color_left, 1),
4251 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_left, color, i);
4252 color = get_surface_color(rt, 330, 240);
4253 ok(compare_color(color, tests[i].color_right, 1),
4254 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests[i].color_right, color, i);
4257 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
4258 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
4260 IDirectDrawSurface7_Release(rt);
4261 IDirect3DDevice7_Release(device);
4262 DestroyWindow(window);
4265 static void test_lighting_interface_versions(void)
4267 IDirect3DDevice7 *device;
4268 IDirectDrawSurface7 *rt;
4269 D3DCOLOR color;
4270 HWND window;
4271 HRESULT hr;
4272 DWORD rs;
4273 unsigned int i;
4274 ULONG ref;
4275 D3DMATERIAL7 material;
4276 static D3DVERTEX quad[] =
4278 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4279 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4280 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4281 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
4284 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4285 static struct
4287 struct vec3 position;
4288 struct vec3 normal;
4289 DWORD diffuse, specular;
4291 quad2[] =
4293 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4294 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4295 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4296 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
4299 static D3DLVERTEX lquad[] =
4301 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4302 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4303 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4304 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
4307 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4308 static struct
4310 struct vec3 position;
4311 DWORD diffuse, specular;
4312 struct vec2 texcoord;
4314 lquad2[] =
4316 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4317 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
4318 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4319 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
4322 static D3DTLVERTEX tlquad[] =
4324 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4325 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4326 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4327 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
4330 static const struct
4332 DWORD vertextype;
4333 void *data;
4334 DWORD d3drs_lighting, d3drs_specular;
4335 DWORD draw_flags;
4336 D3DCOLOR color;
4338 tests[] =
4340 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
4341 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
4342 * are not available
4344 * Note that the specular result is 0x00000000 when lighting is on even if the
4345 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
4346 * enabled */
4348 /* 0 */
4349 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x00ffffff},
4350 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
4351 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
4352 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4353 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x00ffffff},
4354 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
4355 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
4356 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4358 /* 8 */
4359 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x00ff0000},
4360 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
4361 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4362 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4363 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x00ff8080},
4364 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
4365 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4366 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4368 /* 16 */
4369 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
4370 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x0000ff00},
4371 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4372 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4373 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
4374 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x0000ff00},
4375 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4376 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4378 /* 24 */
4379 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
4380 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x0000ff00},
4381 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
4382 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x0000ff00},
4383 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
4384 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x0000ff00},
4385 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
4386 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x0000ff00},
4388 /* 32 */
4389 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
4390 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
4391 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4392 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
4393 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
4394 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
4395 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4396 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
4399 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4400 0, 0, 640, 480, 0, 0, 0, 0);
4402 if (!(device = create_device(window, DDSCL_NORMAL)))
4404 skip("Failed to create a 3D device, skipping test.\n");
4405 DestroyWindow(window);
4406 return;
4409 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
4410 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
4412 memset(&material, 0, sizeof(material));
4413 U2(U3(material).emissive).g = 1.0f;
4414 hr = IDirect3DDevice7_SetMaterial(device, &material);
4415 ok(SUCCEEDED(hr), "Failed set material, hr %#x.\n", hr);
4416 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
4417 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
4419 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
4420 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
4421 ok(rs == TRUE, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs);
4422 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
4423 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
4424 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
4426 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4428 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
4429 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
4431 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
4432 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
4433 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
4434 tests[i].d3drs_specular);
4435 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
4437 hr = IDirect3DDevice7_BeginScene(device);
4438 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
4439 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
4440 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
4441 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
4442 hr = IDirect3DDevice7_EndScene(device);
4443 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
4445 hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_LIGHTING, &rs);
4446 ok(SUCCEEDED(hr), "Failed to get lighting render state, hr %#x.\n", hr);
4447 ok(rs == tests[i].d3drs_lighting, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
4448 rs, tests[i].d3drs_lighting);
4450 color = get_surface_color(rt, 320, 240);
4451 ok(compare_color(color, tests[i].color, 1),
4452 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4453 color, tests[i].color, i);
4456 IDirectDrawSurface7_Release(rt);
4457 ref = IDirect3DDevice7_Release(device);
4458 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
4459 DestroyWindow(window);
4462 static struct
4464 BOOL received;
4465 IDirectDraw7 *ddraw;
4466 HWND window;
4467 DWORD coop_level;
4468 } activateapp_testdata;
4470 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
4472 if (message == WM_ACTIVATEAPP)
4474 if (activateapp_testdata.ddraw)
4476 HRESULT hr;
4477 activateapp_testdata.received = FALSE;
4478 hr = IDirectDraw7_SetCooperativeLevel(activateapp_testdata.ddraw,
4479 activateapp_testdata.window, activateapp_testdata.coop_level);
4480 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
4481 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4483 activateapp_testdata.received = TRUE;
4486 return DefWindowProcA(hwnd, message, wparam, lparam);
4489 static void test_coop_level_activateapp(void)
4491 IDirectDraw7 *ddraw;
4492 HRESULT hr;
4493 HWND window;
4494 WNDCLASSA wc = {0};
4495 DDSURFACEDESC2 ddsd;
4496 IDirectDrawSurface7 *surface;
4498 ddraw = create_ddraw();
4499 ok(!!ddraw, "Failed to create a ddraw object.\n");
4501 wc.lpfnWndProc = activateapp_test_proc;
4502 wc.lpszClassName = "ddraw_test_wndproc_wc";
4503 ok(RegisterClassA(&wc), "Failed to register window class.\n");
4505 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4506 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
4508 /* Exclusive with window already active. */
4509 SetForegroundWindow(window);
4510 activateapp_testdata.received = FALSE;
4511 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4512 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4513 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
4514 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4515 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4517 /* Exclusive with window not active. */
4518 SetForegroundWindow(GetDesktopWindow());
4519 activateapp_testdata.received = FALSE;
4520 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4521 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4522 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4523 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4524 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4526 /* Normal with window not active, then exclusive with the same window. */
4527 SetForegroundWindow(GetDesktopWindow());
4528 activateapp_testdata.received = FALSE;
4529 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4530 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4531 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4532 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4533 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4534 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4535 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4536 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4538 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4539 SetForegroundWindow(GetDesktopWindow());
4540 activateapp_testdata.received = FALSE;
4541 activateapp_testdata.ddraw = ddraw;
4542 activateapp_testdata.window = window;
4543 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
4544 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4545 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4546 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4547 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4548 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4550 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4551 * succeeding. Another switch to exclusive and back to normal is needed to release the
4552 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4553 * WM_ACTIVATEAPP messages. */
4554 activateapp_testdata.ddraw = NULL;
4555 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4556 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4557 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4558 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4560 /* Setting DDSCL_NORMAL with recursive invocation. */
4561 SetForegroundWindow(GetDesktopWindow());
4562 activateapp_testdata.received = FALSE;
4563 activateapp_testdata.ddraw = ddraw;
4564 activateapp_testdata.window = window;
4565 activateapp_testdata.coop_level = DDSCL_NORMAL;
4566 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4567 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4568 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4570 /* DDraw is in exlusive mode now. */
4571 memset(&ddsd, 0, sizeof(ddsd));
4572 ddsd.dwSize = sizeof(ddsd);
4573 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
4574 U5(ddsd).dwBackBufferCount = 1;
4575 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
4576 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4577 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4578 IDirectDrawSurface7_Release(surface);
4580 /* Recover again, just to be sure. */
4581 activateapp_testdata.ddraw = NULL;
4582 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
4583 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4584 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4585 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4587 DestroyWindow(window);
4588 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
4589 IDirectDraw7_Release(ddraw);
4592 static void test_texturemanage(void)
4594 IDirectDraw7 *ddraw;
4595 HRESULT hr;
4596 DDSURFACEDESC2 ddsd;
4597 IDirectDrawSurface7 *surface;
4598 unsigned int i;
4599 DDCAPS hal_caps, hel_caps;
4600 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
4601 static const struct
4603 DWORD caps_in, caps2_in;
4604 HRESULT hr;
4605 DWORD caps_out, caps2_out;
4607 tests[] =
4609 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4610 ~0U, ~0U},
4611 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4612 ~0U, ~0U},
4613 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4614 ~0U, ~0U},
4615 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4616 ~0U, ~0U},
4617 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
4618 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
4619 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
4620 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
4621 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4622 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
4623 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
4624 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
4626 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4627 ~0U, ~0U},
4628 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4629 ~0U, ~0U},
4630 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4631 ~0U, ~0U},
4632 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4633 ~0U, ~0U},
4634 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
4635 ~0U, ~0U},
4636 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
4637 ~0U, ~0U},
4638 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
4639 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
4640 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
4641 DDSCAPS_SYSTEMMEMORY, 0},
4644 ddraw = create_ddraw();
4645 ok(!!ddraw, "Failed to create a ddraw object.\n");
4646 hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4647 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4649 memset(&hal_caps, 0, sizeof(hal_caps));
4650 hal_caps.dwSize = sizeof(hal_caps);
4651 memset(&hel_caps, 0, sizeof(hel_caps));
4652 hel_caps.dwSize = sizeof(hel_caps);
4653 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, &hel_caps);
4654 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4655 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4657 skip("Managed textures not supported, skipping managed texture test.\n");
4658 IDirectDraw7_Release(ddraw);
4659 return;
4662 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4664 memset(&ddsd, 0, sizeof(ddsd));
4665 ddsd.dwSize = sizeof(ddsd);
4666 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4667 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4668 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4669 ddsd.dwWidth = 4;
4670 ddsd.dwHeight = 4;
4672 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4673 if (tests[i].hr == DD_OK && is_ddraw64 && (tests[i].caps_in & DDSCAPS_TEXTURE))
4674 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
4675 else
4676 ok(hr == tests[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, tests[i].hr);
4677 if (FAILED(hr))
4678 continue;
4680 memset(&ddsd, 0, sizeof(ddsd));
4681 ddsd.dwSize = sizeof(ddsd);
4682 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4683 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4685 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4686 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4687 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4688 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4689 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4690 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4692 IDirectDrawSurface7_Release(surface);
4695 IDirectDraw7_Release(ddraw);
4698 #define SUPPORT_DXT1 0x01
4699 #define SUPPORT_DXT2 0x02
4700 #define SUPPORT_DXT3 0x04
4701 #define SUPPORT_DXT4 0x08
4702 #define SUPPORT_DXT5 0x10
4703 #define SUPPORT_YUY2 0x20
4704 #define SUPPORT_UYVY 0x40
4706 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4708 DWORD *supported_fmts = ctx;
4710 if (!(fmt->dwFlags & DDPF_FOURCC))
4711 return DDENUMRET_OK;
4713 switch (fmt->dwFourCC)
4715 case MAKEFOURCC('D','X','T','1'):
4716 *supported_fmts |= SUPPORT_DXT1;
4717 break;
4718 case MAKEFOURCC('D','X','T','2'):
4719 *supported_fmts |= SUPPORT_DXT2;
4720 break;
4721 case MAKEFOURCC('D','X','T','3'):
4722 *supported_fmts |= SUPPORT_DXT3;
4723 break;
4724 case MAKEFOURCC('D','X','T','4'):
4725 *supported_fmts |= SUPPORT_DXT4;
4726 break;
4727 case MAKEFOURCC('D','X','T','5'):
4728 *supported_fmts |= SUPPORT_DXT5;
4729 break;
4730 case MAKEFOURCC('Y','U','Y','2'):
4731 *supported_fmts |= SUPPORT_YUY2;
4732 break;
4733 case MAKEFOURCC('U','Y','V','Y'):
4734 *supported_fmts |= SUPPORT_UYVY;
4735 break;
4736 default:
4737 break;
4740 return DDENUMRET_OK;
4743 static void test_block_formats_creation(void)
4745 HRESULT hr, expect_hr;
4746 unsigned int i, j, w, h;
4747 HWND window;
4748 IDirectDraw7 *ddraw;
4749 IDirect3D7 *d3d;
4750 IDirect3DDevice7 *device;
4751 IDirectDrawSurface7 *surface;
4752 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
4753 DWORD num_fourcc_codes = 0, *fourcc_codes;
4754 DDSURFACEDESC2 ddsd;
4755 DDCAPS hal_caps;
4756 void *mem;
4758 static const struct
4760 DWORD fourcc;
4761 const char *name;
4762 DWORD support_flag;
4763 unsigned int block_width;
4764 unsigned int block_height;
4765 unsigned int block_size;
4766 BOOL create_size_checked, overlay;
4768 formats[] =
4770 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
4771 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
4772 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
4773 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
4774 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
4775 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
4776 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
4778 static const struct
4780 DWORD caps, caps2;
4781 const char *name;
4782 BOOL overlay;
4784 types[] =
4786 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4787 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4789 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4790 * Other hw / drivers successfully create those surfaces. Ignore them, this
4791 * suggests that no game uses this, otherwise Nvidia would support it. */
4793 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4794 "videomemory texture", FALSE
4797 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4798 "videomemory overlay", TRUE
4801 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4802 "systemmemory texture", FALSE
4805 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4806 "managed texture", FALSE
4809 enum size_type
4811 SIZE_TYPE_ZERO,
4812 SIZE_TYPE_PITCH,
4813 SIZE_TYPE_SIZE,
4815 static const struct
4817 DWORD flags;
4818 enum size_type size_type;
4819 int rel_size;
4820 HRESULT hr;
4822 user_mem_tests[] =
4824 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
4825 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4826 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4827 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4828 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4829 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4830 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4831 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4832 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
4833 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
4834 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4835 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4836 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4837 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DDERR_INVALIDPARAMS},
4840 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4841 0, 0, 640, 480, 0, 0, 0, 0);
4843 if (!(device = create_device(window, DDSCL_NORMAL)))
4845 skip("Failed to create a 3D device, skipping test.\n");
4846 DestroyWindow(window);
4847 return;
4850 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
4851 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4852 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
4853 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4854 IDirect3D7_Release(d3d);
4856 hr = IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb,
4857 &supported_fmts);
4858 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4860 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4861 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4862 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4863 num_fourcc_codes * sizeof(*fourcc_codes));
4864 if (!fourcc_codes)
4865 goto cleanup;
4866 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
4867 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4868 for (i = 0; i < num_fourcc_codes; i++)
4870 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
4872 if (fourcc_codes[i] == formats[j].fourcc)
4873 supported_overlay_fmts |= formats[j].support_flag;
4876 HeapFree(GetProcessHeap(), 0, fourcc_codes);
4878 memset(&hal_caps, 0, sizeof(hal_caps));
4879 hal_caps.dwSize = sizeof(hal_caps);
4880 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
4881 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4883 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
4885 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4887 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
4889 BOOL support;
4891 if (formats[i].overlay != types[j].overlay
4892 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
4893 continue;
4895 if (formats[i].overlay)
4896 support = supported_overlay_fmts & formats[i].support_flag;
4897 else
4898 support = supported_fmts & formats[i].support_flag;
4900 for (w = 1; w <= 8; w++)
4902 for (h = 1; h <= 8; h++)
4904 BOOL block_aligned = TRUE;
4905 BOOL todo = FALSE;
4907 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
4908 block_aligned = FALSE;
4910 memset(&ddsd, 0, sizeof(ddsd));
4911 ddsd.dwSize = sizeof(ddsd);
4912 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4913 ddsd.ddsCaps.dwCaps = types[j].caps;
4914 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
4915 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4916 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4917 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4918 ddsd.dwWidth = w;
4919 ddsd.dwHeight = h;
4921 /* TODO: Handle power of two limitations. I cannot test the pow2
4922 * behavior on windows because I have no hardware that doesn't at
4923 * least support np2_conditional. There's probably no HW that
4924 * supports DXTN textures but no conditional np2 textures. */
4925 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
4926 expect_hr = DDERR_INVALIDPARAMS;
4927 else if (formats[i].create_size_checked && !block_aligned)
4929 expect_hr = DDERR_INVALIDPARAMS;
4930 if (!(types[j].caps & DDSCAPS_TEXTURE))
4931 todo = TRUE;
4933 else
4934 expect_hr = D3D_OK;
4936 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4937 if (todo)
4938 todo_wine ok(hr == expect_hr,
4939 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4940 hr, formats[i].name, types[j].name, w, h, expect_hr);
4941 else
4942 ok(hr == expect_hr,
4943 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4944 hr, formats[i].name, types[j].name, w, h, expect_hr);
4946 if (SUCCEEDED(hr))
4947 IDirectDrawSurface7_Release(surface);
4952 if (formats[i].overlay)
4953 continue;
4955 for (j = 0; j < sizeof(user_mem_tests) / sizeof(*user_mem_tests); ++j)
4957 memset(&ddsd, 0, sizeof(ddsd));
4958 ddsd.dwSize = sizeof(ddsd);
4959 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
4960 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
4962 switch (user_mem_tests[j].size_type)
4964 case SIZE_TYPE_ZERO:
4965 U1(ddsd).dwLinearSize = 0;
4966 break;
4968 case SIZE_TYPE_PITCH:
4969 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
4970 break;
4972 case SIZE_TYPE_SIZE:
4973 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
4974 break;
4976 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
4978 ddsd.lpSurface = mem;
4979 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4980 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4981 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4982 ddsd.dwWidth = 8;
4983 ddsd.dwHeight = 8;
4985 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
4986 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
4988 if (FAILED(hr))
4989 continue;
4991 memset(&ddsd, 0, sizeof(ddsd));
4992 ddsd.dwSize = sizeof(ddsd);
4993 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
4994 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
4995 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
4996 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
4997 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
4998 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
4999 j, U1(ddsd).dwLinearSize);
5000 else
5001 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
5002 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5003 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
5004 IDirectDrawSurface7_Release(surface);
5008 HeapFree(GetProcessHeap(), 0, mem);
5009 cleanup:
5010 IDirectDraw7_Release(ddraw);
5011 IDirect3DDevice7_Release(device);
5012 DestroyWindow(window);
5015 struct format_support_check
5017 const DDPIXELFORMAT *format;
5018 BOOL supported;
5021 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
5023 struct format_support_check *format = ctx;
5025 if (!memcmp(format->format, fmt, sizeof(*fmt)))
5027 format->supported = TRUE;
5028 return DDENUMRET_CANCEL;
5031 return DDENUMRET_OK;
5034 static void test_unsupported_formats(void)
5036 HRESULT hr;
5037 BOOL expect_success;
5038 HWND window;
5039 IDirectDraw7 *ddraw;
5040 IDirect3D7 *d3d;
5041 IDirect3DDevice7 *device;
5042 IDirectDrawSurface7 *surface;
5043 DDSURFACEDESC2 ddsd;
5044 unsigned int i, j;
5045 DWORD expected_caps;
5046 static const struct
5048 const char *name;
5049 DDPIXELFORMAT fmt;
5051 formats[] =
5054 "D3DFMT_A8R8G8B8",
5056 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
5057 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5061 "D3DFMT_P8",
5063 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5064 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5068 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
5070 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5071 0, 0, 640, 480, 0, 0, 0, 0);
5073 if (!(device = create_device(window, DDSCL_NORMAL)))
5075 skip("Failed to create a 3D device, skipping test.\n");
5076 DestroyWindow(window);
5077 return;
5080 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5081 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5082 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **) &ddraw);
5083 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5084 IDirect3D7_Release(d3d);
5086 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
5088 struct format_support_check check = {&formats[i].fmt, FALSE};
5089 hr = IDirect3DDevice7_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
5090 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
5092 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
5094 memset(&ddsd, 0, sizeof(ddsd));
5095 ddsd.dwSize = sizeof(ddsd);
5096 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5097 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
5098 ddsd.dwWidth = 4;
5099 ddsd.dwHeight = 4;
5100 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
5102 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
5103 expect_success = FALSE;
5104 else
5105 expect_success = TRUE;
5107 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5108 ok(SUCCEEDED(hr) == expect_success,
5109 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5110 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
5111 if (FAILED(hr))
5112 continue;
5114 memset(&ddsd, 0, sizeof(ddsd));
5115 ddsd.dwSize = sizeof(ddsd);
5116 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
5117 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5119 if (caps[j] & DDSCAPS_VIDEOMEMORY)
5120 expected_caps = DDSCAPS_VIDEOMEMORY;
5121 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
5122 expected_caps = DDSCAPS_SYSTEMMEMORY;
5123 else if (check.supported)
5124 expected_caps = DDSCAPS_VIDEOMEMORY;
5125 else
5126 expected_caps = DDSCAPS_SYSTEMMEMORY;
5128 ok(ddsd.ddsCaps.dwCaps & expected_caps,
5129 "Expected capability %#x, format %s, input cap %#x.\n",
5130 expected_caps, formats[i].name, caps[j]);
5132 IDirectDrawSurface7_Release(surface);
5136 IDirectDraw7_Release(ddraw);
5137 IDirect3DDevice7_Release(device);
5138 DestroyWindow(window);
5141 static void test_rt_caps(void)
5143 const GUID *devtype = &IID_IDirect3DHALDevice;
5144 PALETTEENTRY palette_entries[256];
5145 IDirectDrawPalette *palette;
5146 IDirectDraw7 *ddraw;
5147 BOOL hal_ok = FALSE;
5148 DDPIXELFORMAT z_fmt;
5149 IDirect3D7 *d3d;
5150 unsigned int i;
5151 ULONG refcount;
5152 HWND window;
5153 HRESULT hr;
5155 static const DDPIXELFORMAT p8_fmt =
5157 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
5158 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5161 const struct
5163 const DDPIXELFORMAT *pf;
5164 DWORD caps_in;
5165 DWORD caps_out;
5166 HRESULT create_device_hr;
5167 HRESULT set_rt_hr, alternative_set_rt_hr;
5169 test_data[] =
5172 NULL,
5173 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5174 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5175 D3D_OK,
5176 D3D_OK,
5177 D3D_OK,
5180 NULL,
5181 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5182 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5183 D3D_OK,
5184 D3D_OK,
5185 D3D_OK,
5188 NULL,
5189 DDSCAPS_OFFSCREENPLAIN,
5190 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5191 DDERR_INVALIDCAPS,
5192 DDERR_INVALIDCAPS,
5193 DDERR_INVALIDCAPS,
5196 NULL,
5197 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5198 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5199 D3DERR_SURFACENOTINVIDMEM,
5200 DDERR_INVALIDPARAMS,
5201 D3D_OK,
5204 NULL,
5205 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5206 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5207 DDERR_INVALIDCAPS,
5208 DDERR_INVALIDCAPS,
5209 DDERR_INVALIDCAPS,
5212 NULL,
5213 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
5214 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5215 D3D_OK,
5216 D3D_OK,
5217 D3D_OK,
5220 NULL,
5221 DDSCAPS_3DDEVICE,
5222 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5223 D3D_OK,
5224 D3D_OK,
5225 D3D_OK,
5228 NULL,
5230 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5231 DDERR_INVALIDCAPS,
5232 DDERR_INVALIDCAPS,
5233 DDERR_INVALIDCAPS,
5236 NULL,
5237 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5238 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5239 D3DERR_SURFACENOTINVIDMEM,
5240 DDERR_INVALIDPARAMS,
5241 D3D_OK,
5244 NULL,
5245 DDSCAPS_SYSTEMMEMORY,
5246 DDSCAPS_SYSTEMMEMORY,
5247 DDERR_INVALIDCAPS,
5248 DDERR_INVALIDCAPS,
5249 DDERR_INVALIDCAPS,
5252 &p8_fmt,
5254 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5255 DDERR_INVALIDCAPS,
5256 DDERR_INVALIDCAPS,
5257 DDERR_INVALIDCAPS,
5260 &p8_fmt,
5261 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5262 ~0U /* AMD r200 */,
5263 DDERR_NOPALETTEATTACHED,
5264 DDERR_INVALIDCAPS,
5265 DDERR_INVALIDCAPS,
5268 &p8_fmt,
5269 DDSCAPS_OFFSCREENPLAIN,
5270 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
5271 DDERR_INVALIDCAPS,
5272 DDERR_INVALIDCAPS,
5273 DDERR_INVALIDCAPS,
5276 &p8_fmt,
5277 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5278 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
5279 DDERR_NOPALETTEATTACHED,
5280 DDERR_INVALIDCAPS,
5281 DDERR_INVALIDCAPS,
5284 &p8_fmt,
5285 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5286 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5287 DDERR_INVALIDCAPS,
5288 DDERR_INVALIDCAPS,
5289 DDERR_INVALIDCAPS,
5292 &z_fmt,
5293 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
5294 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5295 DDERR_INVALIDCAPS,
5296 DDERR_INVALIDPIXELFORMAT,
5297 DDERR_INVALIDPIXELFORMAT,
5300 &z_fmt,
5301 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5302 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5303 DDERR_INVALIDCAPS,
5304 DDERR_INVALIDPIXELFORMAT,
5305 DDERR_INVALIDPIXELFORMAT,
5308 &z_fmt,
5309 DDSCAPS_ZBUFFER,
5310 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
5311 DDERR_INVALIDCAPS,
5312 DDERR_INVALIDCAPS,
5313 DDERR_INVALIDCAPS,
5316 &z_fmt,
5317 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5318 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
5319 DDERR_INVALIDCAPS,
5320 DDERR_INVALIDPARAMS,
5321 DDERR_INVALIDPIXELFORMAT,
5324 &z_fmt,
5325 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5326 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
5327 DDERR_INVALIDCAPS,
5328 DDERR_INVALIDCAPS,
5329 DDERR_INVALIDCAPS,
5333 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5334 0, 0, 640, 480, 0, 0, 0, 0);
5335 ddraw = create_ddraw();
5336 ok(!!ddraw, "Failed to create a ddraw object.\n");
5337 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5338 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5340 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5342 skip("D3D interface is not available, skipping test.\n");
5343 goto done;
5346 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5347 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5348 if (hal_ok)
5349 devtype = &IID_IDirect3DTnLHalDevice;
5351 memset(&z_fmt, 0, sizeof(z_fmt));
5352 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5353 if (FAILED(hr) || !z_fmt.dwSize)
5355 skip("No depth buffer formats available, skipping test.\n");
5356 IDirect3D7_Release(d3d);
5357 goto done;
5360 memset(palette_entries, 0, sizeof(palette_entries));
5361 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
5362 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5364 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5366 IDirectDrawSurface7 *surface, *rt, *expected_rt, *tmp;
5367 DDSURFACEDESC2 surface_desc;
5368 IDirect3DDevice7 *device;
5370 memset(&surface_desc, 0, sizeof(surface_desc));
5371 surface_desc.dwSize = sizeof(surface_desc);
5372 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5373 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5374 if (test_data[i].pf)
5376 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5377 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5379 surface_desc.dwWidth = 640;
5380 surface_desc.dwHeight = 480;
5381 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5382 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5383 i, test_data[i].caps_in, hr);
5385 memset(&surface_desc, 0, sizeof(surface_desc));
5386 surface_desc.dwSize = sizeof(surface_desc);
5387 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5388 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5389 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
5390 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5391 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5393 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5394 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5395 i, hr, test_data[i].create_device_hr);
5396 if (FAILED(hr))
5398 if (hr == DDERR_NOPALETTEATTACHED)
5400 hr = IDirectDrawSurface7_SetPalette(surface, palette);
5401 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
5402 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5403 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
5404 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
5405 else
5406 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
5408 IDirectDrawSurface7_Release(surface);
5410 memset(&surface_desc, 0, sizeof(surface_desc));
5411 surface_desc.dwSize = sizeof(surface_desc);
5412 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5413 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5414 surface_desc.dwWidth = 640;
5415 surface_desc.dwHeight = 480;
5416 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5417 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
5419 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5420 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
5423 memset(&surface_desc, 0, sizeof(surface_desc));
5424 surface_desc.dwSize = sizeof(surface_desc);
5425 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5426 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5427 if (test_data[i].pf)
5429 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
5430 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
5432 surface_desc.dwWidth = 640;
5433 surface_desc.dwHeight = 480;
5434 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &rt, NULL);
5435 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5436 i, test_data[i].caps_in, hr);
5438 hr = IDirect3DDevice7_SetRenderTarget(device, rt, 0);
5439 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
5440 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5441 i, hr, test_data[i].set_rt_hr);
5442 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
5443 expected_rt = rt;
5444 else
5445 expected_rt = surface;
5447 hr = IDirect3DDevice7_GetRenderTarget(device, &tmp);
5448 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
5449 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
5451 IDirectDrawSurface7_Release(tmp);
5452 IDirectDrawSurface7_Release(rt);
5453 refcount = IDirect3DDevice7_Release(device);
5454 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
5455 refcount = IDirectDrawSurface7_Release(surface);
5456 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
5459 IDirectDrawPalette_Release(palette);
5460 IDirect3D7_Release(d3d);
5462 done:
5463 refcount = IDirectDraw7_Release(ddraw);
5464 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5465 DestroyWindow(window);
5468 static void test_primary_caps(void)
5470 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5471 IDirectDrawSurface7 *surface;
5472 DDSURFACEDESC2 surface_desc;
5473 IDirectDraw7 *ddraw;
5474 unsigned int i;
5475 ULONG refcount;
5476 HWND window;
5477 HRESULT hr;
5479 static const struct
5481 DWORD coop_level;
5482 DWORD caps_in;
5483 DWORD back_buffer_count;
5484 HRESULT hr;
5485 DWORD caps_out;
5487 test_data[] =
5490 DDSCL_NORMAL,
5491 DDSCAPS_PRIMARYSURFACE,
5492 ~0u,
5493 DD_OK,
5494 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
5497 DDSCL_NORMAL,
5498 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
5499 ~0u,
5500 DDERR_INVALIDCAPS,
5501 ~0u,
5504 DDSCL_NORMAL,
5505 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
5506 ~0u,
5507 DDERR_INVALIDCAPS,
5508 ~0u,
5511 DDSCL_NORMAL,
5512 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
5513 ~0u,
5514 DDERR_INVALIDCAPS,
5515 ~0u,
5518 DDSCL_NORMAL,
5519 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
5520 ~0u,
5521 DDERR_INVALIDCAPS,
5522 ~0u,
5525 DDSCL_NORMAL,
5526 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
5527 ~0u,
5528 DDERR_INVALIDCAPS,
5529 ~0u,
5532 DDSCL_NORMAL,
5533 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5534 ~0u,
5535 DDERR_INVALIDCAPS,
5536 ~0u,
5539 DDSCL_NORMAL,
5540 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5542 DDERR_INVALIDCAPS,
5543 ~0u,
5546 DDSCL_NORMAL,
5547 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5549 DDERR_NOEXCLUSIVEMODE,
5550 ~0u,
5553 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5554 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5556 DDERR_INVALIDCAPS,
5557 ~0u,
5560 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5561 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
5563 DD_OK,
5564 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
5567 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5568 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
5570 DDERR_INVALIDCAPS,
5571 ~0u,
5574 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
5575 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
5577 DDERR_INVALIDCAPS,
5578 ~0u,
5582 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5583 0, 0, 640, 480, 0, 0, 0, 0);
5584 ddraw = create_ddraw();
5585 ok(!!ddraw, "Failed to create a ddraw object.\n");
5587 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
5589 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
5590 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5592 memset(&surface_desc, 0, sizeof(surface_desc));
5593 surface_desc.dwSize = sizeof(surface_desc);
5594 surface_desc.dwFlags = DDSD_CAPS;
5595 if (test_data[i].back_buffer_count != ~0u)
5596 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
5597 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
5598 U5(surface_desc).dwBackBufferCount = test_data[i].back_buffer_count;
5599 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5600 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
5601 if (FAILED(hr))
5602 continue;
5604 memset(&surface_desc, 0, sizeof(surface_desc));
5605 surface_desc.dwSize = sizeof(surface_desc);
5606 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
5607 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
5608 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
5609 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5610 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
5612 IDirectDrawSurface7_Release(surface);
5615 refcount = IDirectDraw7_Release(ddraw);
5616 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5617 DestroyWindow(window);
5620 static void test_surface_lock(void)
5622 IDirectDraw7 *ddraw;
5623 IDirect3D7 *d3d = NULL;
5624 IDirectDrawSurface7 *surface;
5625 IDirect3DDevice7 *device;
5626 HRESULT hr;
5627 HWND window;
5628 unsigned int i;
5629 DDSURFACEDESC2 ddsd;
5630 ULONG refcount;
5631 DDPIXELFORMAT z_fmt;
5632 BOOL hal_ok = FALSE;
5633 const GUID *devtype = &IID_IDirect3DHALDevice;
5634 D3DDEVICEDESC7 device_desc;
5635 BOOL cubemap_supported;
5636 static const struct
5638 DWORD caps;
5639 DWORD caps2;
5640 const char *name;
5642 tests[] =
5645 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
5647 "videomemory offscreenplain"
5650 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
5652 "systemmemory offscreenplain"
5655 DDSCAPS_PRIMARYSURFACE,
5657 "primary"
5660 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5662 "videomemory texture"
5665 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5666 DDSCAPS2_OPAQUE,
5667 "opaque videomemory texture"
5670 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5672 "systemmemory texture"
5675 DDSCAPS_TEXTURE,
5676 DDSCAPS2_TEXTUREMANAGE,
5677 "managed texture"
5680 DDSCAPS_TEXTURE,
5681 DDSCAPS2_D3DTEXTUREMANAGE,
5682 "managed texture"
5685 DDSCAPS_TEXTURE,
5686 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5687 "opaque managed texture"
5690 DDSCAPS_TEXTURE,
5691 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5692 "opaque managed texture"
5695 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5697 "render target"
5700 DDSCAPS_ZBUFFER,
5702 "Z buffer"
5705 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5706 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5707 "videomemory cube"
5710 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY,
5711 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5712 "opaque videomemory cube"
5715 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_SYSTEMMEMORY,
5716 DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5717 "systemmemory cube"
5720 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5721 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5722 "managed cube"
5725 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5726 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES,
5727 "managed cube"
5730 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5731 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5732 "opaque managed cube"
5735 DDSCAPS_TEXTURE | DDSCAPS_COMPLEX,
5736 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALLFACES | DDSCAPS2_OPAQUE,
5737 "opaque managed cube"
5741 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5742 0, 0, 640, 480, 0, 0, 0, 0);
5743 ddraw = create_ddraw();
5744 ok(!!ddraw, "Failed to create a ddraw object.\n");
5745 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5746 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5748 if (FAILED(IDirectDraw7_QueryInterface(ddraw, &IID_IDirect3D7, (void **)&d3d)))
5750 skip("D3D interface is not available, skipping test.\n");
5751 goto done;
5754 hr = IDirect3D7_EnumDevices(d3d, enum_devtype_cb, &hal_ok);
5755 ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
5756 if (hal_ok)
5757 devtype = &IID_IDirect3DTnLHalDevice;
5759 memset(&z_fmt, 0, sizeof(z_fmt));
5760 hr = IDirect3D7_EnumZBufferFormats(d3d, devtype, enum_z_fmt, &z_fmt);
5761 if (FAILED(hr) || !z_fmt.dwSize)
5763 skip("No depth buffer formats available, skipping test.\n");
5764 goto done;
5767 memset(&ddsd, 0, sizeof(ddsd));
5768 ddsd.dwSize = sizeof(ddsd);
5769 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5770 ddsd.dwWidth = 64;
5771 ddsd.dwHeight = 64;
5772 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5773 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5774 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5776 hr = IDirect3D7_CreateDevice(d3d, devtype, surface, &device);
5777 ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr);
5778 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
5779 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5780 cubemap_supported = !!(device_desc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP);
5781 IDirect3DDevice7_Release(device);
5783 IDirectDrawSurface7_Release(surface);
5785 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5787 if (!cubemap_supported && tests[i].caps2 & DDSCAPS2_CUBEMAP)
5788 continue;
5790 memset(&ddsd, 0, sizeof(ddsd));
5791 ddsd.dwSize = sizeof(ddsd);
5792 ddsd.dwFlags = DDSD_CAPS;
5793 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5795 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5796 ddsd.dwWidth = 64;
5797 ddsd.dwHeight = 64;
5799 if (tests[i].caps & DDSCAPS_ZBUFFER)
5801 ddsd.dwFlags |= DDSD_PIXELFORMAT;
5802 U4(ddsd).ddpfPixelFormat = z_fmt;
5804 ddsd.ddsCaps.dwCaps = tests[i].caps;
5805 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5807 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5808 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
5810 memset(&ddsd, 0, sizeof(ddsd));
5811 ddsd.dwSize = sizeof(ddsd);
5812 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5813 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
5814 if (SUCCEEDED(hr))
5816 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5817 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5820 IDirectDrawSurface7_Release(surface);
5823 done:
5824 if (d3d)
5825 IDirect3D7_Release(d3d);
5826 refcount = IDirectDraw7_Release(ddraw);
5827 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5828 DestroyWindow(window);
5831 static void test_surface_discard(void)
5833 IDirect3DDevice7 *device;
5834 IDirect3D7 *d3d;
5835 IDirectDraw7 *ddraw;
5836 HRESULT hr;
5837 HWND window;
5838 DDSURFACEDESC2 ddsd;
5839 IDirectDrawSurface7 *surface, *target;
5840 void *addr;
5841 static const struct
5843 DWORD caps, caps2;
5844 BOOL discard;
5846 tests[] =
5848 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5849 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5850 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5851 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5852 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
5853 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5854 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
5855 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5857 unsigned int i;
5859 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5860 0, 0, 640, 480, 0, 0, 0, 0);
5862 if (!(device = create_device(window, DDSCL_NORMAL)))
5864 skip("Failed to create a 3D device, skipping test.\n");
5865 DestroyWindow(window);
5866 return;
5868 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
5869 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5870 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
5871 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5872 hr = IDirect3DDevice7_GetRenderTarget(device, &target);
5873 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5875 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5877 BOOL discarded;
5879 memset(&ddsd, 0, sizeof(ddsd));
5880 ddsd.dwSize = sizeof(ddsd);
5881 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5882 ddsd.ddsCaps.dwCaps = tests[i].caps;
5883 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5884 ddsd.dwWidth = 64;
5885 ddsd.dwHeight = 64;
5886 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
5887 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
5889 memset(&ddsd, 0, sizeof(ddsd));
5890 ddsd.dwSize = sizeof(ddsd);
5891 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
5892 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5893 addr = ddsd.lpSurface;
5894 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5895 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5897 memset(&ddsd, 0, sizeof(ddsd));
5898 ddsd.dwSize = sizeof(ddsd);
5899 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5900 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5901 discarded = ddsd.lpSurface != addr;
5902 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5903 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5905 hr = IDirectDrawSurface7_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
5906 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
5908 memset(&ddsd, 0, sizeof(ddsd));
5909 ddsd.dwSize = sizeof(ddsd);
5910 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5911 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5912 discarded |= ddsd.lpSurface != addr;
5913 hr = IDirectDrawSurface7_Unlock(surface, NULL);
5914 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5916 IDirectDrawSurface7_Release(surface);
5918 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5919 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5920 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
5923 IDirectDrawSurface7_Release(target);
5924 IDirectDraw7_Release(ddraw);
5925 IDirect3D7_Release(d3d);
5926 IDirect3DDevice7_Release(device);
5927 DestroyWindow(window);
5930 static void test_flip(void)
5932 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5933 IDirectDrawSurface7 *primary, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
5934 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, {0}};
5935 DDSURFACEDESC2 surface_desc;
5936 BOOL sysmem_primary;
5937 IDirectDraw7 *ddraw;
5938 D3DCOLOR color;
5939 ULONG refcount;
5940 HWND window;
5941 DDBLTFX fx;
5942 HRESULT hr;
5944 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5945 0, 0, 640, 480, 0, 0, 0, 0);
5946 ddraw = create_ddraw();
5947 ok(!!ddraw, "Failed to create a ddraw object.\n");
5949 hr = set_display_mode(ddraw, 640, 480);
5950 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
5951 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5952 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5954 memset(&surface_desc, 0, sizeof(surface_desc));
5955 surface_desc.dwSize = sizeof(surface_desc);
5956 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5957 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5958 U5(surface_desc).dwBackBufferCount = 3;
5959 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5960 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5962 memset(&surface_desc, 0, sizeof(surface_desc));
5963 surface_desc.dwSize = sizeof(surface_desc);
5964 hr = IDirectDrawSurface7_GetSurfaceDesc(primary, &surface_desc);
5965 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5966 ok((surface_desc.ddsCaps.dwCaps & ~placement)
5967 == (DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5968 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5969 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
5971 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &backbuffer1);
5972 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5973 memset(&surface_desc, 0, sizeof(surface_desc));
5974 surface_desc.dwSize = sizeof(surface_desc);
5975 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer1, &surface_desc);
5976 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5977 ok(!U5(surface_desc).dwBackBufferCount, "Got unexpected back buffer count %u.\n", U5(surface_desc).dwBackBufferCount);
5978 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_BACKBUFFER),
5979 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5981 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
5982 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5983 memset(&surface_desc, 0, sizeof(surface_desc));
5984 surface_desc.dwSize = sizeof(surface_desc);
5985 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer2, &surface_desc);
5986 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5987 ok(!U5(surface_desc).dwBackBufferCount, "Got unexpected back buffer count %u.\n", U5(surface_desc).dwBackBufferCount);
5988 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5989 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5991 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
5992 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5993 memset(&surface_desc, 0, sizeof(surface_desc));
5994 surface_desc.dwSize = sizeof(surface_desc);
5995 hr = IDirectDrawSurface7_GetSurfaceDesc(backbuffer3, &surface_desc);
5996 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5997 ok(!U5(surface_desc).dwBackBufferCount, "Got unexpected back buffer count %u.\n", U5(surface_desc).dwBackBufferCount);
5998 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5999 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
6001 hr = IDirectDrawSurface7_GetAttachedSurface(backbuffer3, &caps, &surface);
6002 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6003 ok(surface == primary, "Got unexpected surface %p, expected %p.\n", surface, primary);
6004 IDirectDrawSurface7_Release(surface);
6006 memset(&surface_desc, 0, sizeof(surface_desc));
6007 surface_desc.dwSize = sizeof(surface_desc);
6008 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6009 surface_desc.ddsCaps.dwCaps = 0;
6010 surface_desc.dwWidth = 640;
6011 surface_desc.dwHeight = 480;
6012 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6013 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6014 hr = IDirectDrawSurface7_Flip(primary, surface, DDFLIP_WAIT);
6015 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
6016 IDirectDrawSurface7_Release(surface);
6018 hr = IDirectDrawSurface7_Flip(primary, primary, DDFLIP_WAIT);
6019 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
6020 hr = IDirectDrawSurface7_Flip(backbuffer1, NULL, DDFLIP_WAIT);
6021 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
6022 hr = IDirectDrawSurface7_Flip(backbuffer2, NULL, DDFLIP_WAIT);
6023 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
6024 hr = IDirectDrawSurface7_Flip(backbuffer3, NULL, DDFLIP_WAIT);
6025 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
6027 memset(&fx, 0, sizeof(fx));
6028 fx.dwSize = sizeof(fx);
6029 U5(fx).dwFillColor = 0xffff0000;
6030 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6031 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6032 U5(fx).dwFillColor = 0xff00ff00;
6033 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6034 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6035 U5(fx).dwFillColor = 0xff0000ff;
6036 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6037 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6039 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
6040 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
6041 color = get_surface_color(backbuffer1, 320, 240);
6042 /* The testbot seems to just copy the contents of one surface to all the
6043 * others, instead of properly flipping. */
6044 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6045 "Got unexpected color 0x%08x.\n", color);
6046 color = get_surface_color(backbuffer2, 320, 240);
6047 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
6048 U5(fx).dwFillColor = 0xffff0000;
6049 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6050 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6052 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
6053 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
6054 color = get_surface_color(backbuffer1, 320, 240);
6055 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6056 "Got unexpected color 0x%08x.\n", color);
6057 color = get_surface_color(backbuffer2, 320, 240);
6058 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
6059 U5(fx).dwFillColor = 0xff00ff00;
6060 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6061 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6063 hr = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
6064 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
6065 color = get_surface_color(backbuffer1, 320, 240);
6066 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6067 "Got unexpected color 0x%08x.\n", color);
6068 color = get_surface_color(backbuffer2, 320, 240);
6069 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
6070 U5(fx).dwFillColor = 0xff0000ff;
6071 hr = IDirectDrawSurface7_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6072 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6074 hr = IDirectDrawSurface7_Flip(primary, backbuffer1, DDFLIP_WAIT);
6075 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
6076 color = get_surface_color(backbuffer2, 320, 240);
6077 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
6078 "Got unexpected color 0x%08x.\n", color);
6079 color = get_surface_color(backbuffer3, 320, 240);
6080 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
6081 U5(fx).dwFillColor = 0xffff0000;
6082 hr = IDirectDrawSurface7_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6083 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6085 hr = IDirectDrawSurface7_Flip(primary, backbuffer2, DDFLIP_WAIT);
6086 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
6087 color = get_surface_color(backbuffer1, 320, 240);
6088 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
6089 color = get_surface_color(backbuffer3, 320, 240);
6090 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
6091 "Got unexpected color 0x%08x.\n", color);
6092 U5(fx).dwFillColor = 0xff00ff00;
6093 hr = IDirectDrawSurface7_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6094 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
6096 hr = IDirectDrawSurface7_Flip(primary, backbuffer3, DDFLIP_WAIT);
6097 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
6098 color = get_surface_color(backbuffer1, 320, 240);
6099 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
6100 "Got unexpected color 0x%08x.\n", color);
6101 color = get_surface_color(backbuffer2, 320, 240);
6102 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
6104 IDirectDrawSurface7_Release(backbuffer3);
6105 IDirectDrawSurface7_Release(backbuffer2);
6106 IDirectDrawSurface7_Release(backbuffer1);
6107 IDirectDrawSurface7_Release(primary);
6108 refcount = IDirectDraw7_Release(ddraw);
6109 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
6110 DestroyWindow(window);
6113 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
6115 memset(ddsd, 0, sizeof(*ddsd));
6116 ddsd->dwSize = sizeof(*ddsd);
6119 static void test_set_surface_desc(void)
6121 IDirectDraw7 *ddraw;
6122 HWND window;
6123 HRESULT hr;
6124 DDSURFACEDESC2 ddsd;
6125 IDirectDrawSurface7 *surface;
6126 BYTE data[16*16*4];
6127 ULONG ref;
6128 unsigned int i;
6129 static const struct
6131 DWORD caps, caps2;
6132 BOOL supported;
6133 const char *name;
6135 invalid_caps_tests[] =
6137 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
6138 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
6139 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
6140 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
6141 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
6144 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6145 0, 0, 640, 480, 0, 0, 0, 0);
6146 ddraw = create_ddraw();
6147 ok(!!ddraw, "Failed to create a ddraw object.\n");
6148 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6149 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6151 reset_ddsd(&ddsd);
6152 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6153 ddsd.dwWidth = 8;
6154 ddsd.dwHeight = 8;
6155 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6156 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6157 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6158 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6159 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6160 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6161 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6163 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6164 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6166 reset_ddsd(&ddsd);
6167 ddsd.dwFlags = DDSD_LPSURFACE;
6168 ddsd.lpSurface = data;
6169 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6170 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6172 /* Redundantly setting the same lpSurface is not an error. */
6173 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6174 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6176 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6177 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6178 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6179 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
6181 hr = IDirectDrawSurface7_Lock(surface, NULL, &ddsd, 0, NULL);
6182 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6183 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
6184 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
6185 hr = IDirectDrawSurface7_Unlock(surface, NULL);
6186 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6188 reset_ddsd(&ddsd);
6189 ddsd.dwFlags = DDSD_LPSURFACE;
6190 ddsd.lpSurface = data;
6191 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 1);
6192 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
6194 ddsd.lpSurface = NULL;
6195 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6196 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
6198 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, NULL, 0);
6199 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
6201 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6202 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6203 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6204 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6205 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6207 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6208 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6209 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
6211 ddsd.dwFlags = DDSD_CAPS;
6212 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6213 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
6215 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6216 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
6217 ddsd.lpSurface = data;
6218 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6219 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6220 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6221 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6222 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
6223 ddsd.ddsCaps.dwCaps = 0;
6224 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
6225 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6226 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6228 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6229 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6230 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
6231 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
6232 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
6234 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6235 reset_ddsd(&ddsd);
6236 ddsd.dwFlags = DDSD_HEIGHT;
6237 ddsd.dwHeight = 16;
6238 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6239 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
6241 ddsd.lpSurface = data;
6242 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
6243 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6244 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6246 ddsd.dwHeight = 0;
6247 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6248 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
6250 reset_ddsd(&ddsd);
6251 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6252 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
6253 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6254 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6256 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
6257 reset_ddsd(&ddsd);
6258 ddsd.dwFlags = DDSD_PITCH;
6259 U1(ddsd).lPitch = 8 * 4;
6260 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6261 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
6263 ddsd.dwFlags = DDSD_WIDTH;
6264 ddsd.dwWidth = 16;
6265 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6266 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
6268 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
6269 ddsd.lpSurface = data;
6270 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6271 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
6273 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
6274 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6275 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
6277 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6278 U1(ddsd).lPitch = 16 * 4;
6279 ddsd.dwWidth = 16;
6280 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6281 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6283 reset_ddsd(&ddsd);
6284 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
6285 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6286 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
6287 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
6288 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
6290 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6292 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6293 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6294 U1(ddsd).lPitch = 4 * 4;
6295 ddsd.lpSurface = data;
6296 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6297 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6299 U1(ddsd).lPitch = 4;
6300 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6301 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
6303 U1(ddsd).lPitch = 16 * 4 + 1;
6304 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6305 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6307 U1(ddsd).lPitch = 16 * 4 + 3;
6308 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6309 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
6311 U1(ddsd).lPitch = -4;
6312 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6313 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
6315 U1(ddsd).lPitch = 16 * 4;
6316 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6317 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6319 reset_ddsd(&ddsd);
6320 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6321 U1(ddsd).lPitch = 0;
6322 ddsd.dwWidth = 16;
6323 ddsd.lpSurface = data;
6324 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6325 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
6327 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
6328 U1(ddsd).lPitch = 16 * 4;
6329 ddsd.dwWidth = 0;
6330 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6331 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
6333 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6334 ddsd.dwFlags = DDSD_PIXELFORMAT;
6335 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6336 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6337 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6338 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6339 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6340 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6341 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6342 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
6344 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
6345 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6346 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6348 /* Can't set color keys. */
6349 reset_ddsd(&ddsd);
6350 ddsd.dwFlags = DDSD_CKSRCBLT;
6351 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
6352 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
6353 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6354 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6356 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
6357 ddsd.lpSurface = data;
6358 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6359 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
6361 IDirectDrawSurface7_Release(surface);
6363 /* SetSurfaceDesc needs systemmemory surfaces.
6365 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6366 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
6368 reset_ddsd(&ddsd);
6369 ddsd.dwFlags = DDSD_CAPS;
6370 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
6371 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
6372 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
6374 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6375 ddsd.dwWidth = 8;
6376 ddsd.dwHeight = 8;
6377 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6378 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6379 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6380 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6381 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6382 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6385 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6386 if (is_ddraw64 && (invalid_caps_tests[i].caps & DDSCAPS_TEXTURE))
6387 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Got unexpected hr %#x.\n", i, hr);
6388 else
6389 ok(hr == DD_OK || hr == DDERR_NODIRECTDRAWHW, "Test %u: Got unexpected hr %#x.\n", i, hr);
6390 if (FAILED(hr))
6391 continue;
6393 reset_ddsd(&ddsd);
6394 ddsd.dwFlags = DDSD_LPSURFACE;
6395 ddsd.lpSurface = data;
6396 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6397 if (invalid_caps_tests[i].supported)
6399 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6401 else
6403 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6404 invalid_caps_tests[i].name, hr);
6406 /* Check priority of error conditions. */
6407 ddsd.dwFlags = DDSD_WIDTH;
6408 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6409 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
6410 invalid_caps_tests[i].name, hr);
6413 IDirectDrawSurface7_Release(surface);
6416 ref = IDirectDraw7_Release(ddraw);
6417 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6418 DestroyWindow(window);
6421 static void test_user_memory_getdc(void)
6423 IDirectDraw7 *ddraw;
6424 HWND window;
6425 HRESULT hr;
6426 DDSURFACEDESC2 ddsd;
6427 IDirectDrawSurface7 *surface;
6428 DWORD data[16][16];
6429 ULONG ref;
6430 HDC dc;
6431 unsigned int x, y;
6433 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6434 0, 0, 640, 480, 0, 0, 0, 0);
6435 ddraw = create_ddraw();
6436 ok(!!ddraw, "Failed to create a ddraw object.\n");
6437 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6438 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6440 reset_ddsd(&ddsd);
6441 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
6442 ddsd.dwWidth = 16;
6443 ddsd.dwHeight = 16;
6444 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6445 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6446 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6447 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6448 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6449 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6450 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6451 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6452 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6454 memset(data, 0xaa, sizeof(data));
6455 reset_ddsd(&ddsd);
6456 ddsd.dwFlags = DDSD_LPSURFACE;
6457 ddsd.lpSurface = data;
6458 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6459 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6461 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6462 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6463 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
6464 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
6465 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6466 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6468 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
6469 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
6471 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
6472 ddsd.lpSurface = data;
6473 ddsd.dwWidth = 4;
6474 ddsd.dwHeight = 8;
6475 U1(ddsd).lPitch = sizeof(*data);
6476 hr = IDirectDrawSurface7_SetSurfaceDesc(surface, &ddsd, 0);
6477 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
6479 memset(data, 0xaa, sizeof(data));
6480 hr = IDirectDrawSurface7_GetDC(surface, &dc);
6481 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
6482 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
6483 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
6484 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
6485 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
6487 for (y = 0; y < 4; y++)
6489 for (x = 0; x < 4; x++)
6491 if ((x == 1 || x == 2) && (y == 1 || y == 2))
6492 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6493 x, y, data[y][x]);
6494 else
6495 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6496 x, y, data[y][x]);
6499 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6500 data[0][5]);
6501 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6502 data[7][3]);
6503 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6504 data[7][4]);
6505 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6506 data[8][0]);
6508 IDirectDrawSurface7_Release(surface);
6509 ref = IDirectDraw7_Release(ddraw);
6510 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6511 DestroyWindow(window);
6514 static void test_sysmem_overlay(void)
6516 IDirectDraw7 *ddraw;
6517 HWND window;
6518 HRESULT hr;
6519 DDSURFACEDESC2 ddsd;
6520 IDirectDrawSurface7 *surface;
6521 ULONG ref;
6523 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6524 0, 0, 640, 480, 0, 0, 0, 0);
6525 ddraw = create_ddraw();
6526 ok(!!ddraw, "Failed to create a ddraw object.\n");
6527 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6528 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6530 reset_ddsd(&ddsd);
6531 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
6532 ddsd.dwWidth = 16;
6533 ddsd.dwHeight = 16;
6534 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
6535 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
6536 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
6537 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
6538 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6539 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6540 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6541 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
6542 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
6544 ref = IDirectDraw7_Release(ddraw);
6545 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
6546 DestroyWindow(window);
6549 static void test_primary_palette(void)
6551 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, {0}};
6552 IDirectDrawSurface7 *primary, *backbuffer;
6553 PALETTEENTRY palette_entries[256];
6554 IDirectDrawPalette *palette, *tmp;
6555 DDSURFACEDESC2 surface_desc;
6556 IDirectDraw7 *ddraw;
6557 DWORD palette_caps;
6558 ULONG refcount;
6559 HWND window;
6560 HRESULT hr;
6562 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6563 0, 0, 640, 480, 0, 0, 0, 0);
6564 ddraw = create_ddraw();
6565 ok(!!ddraw, "Failed to create a ddraw object.\n");
6566 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
6568 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6569 IDirectDraw7_Release(ddraw);
6570 DestroyWindow(window);
6571 return;
6573 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6574 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6576 memset(&surface_desc, 0, sizeof(surface_desc));
6577 surface_desc.dwSize = sizeof(surface_desc);
6578 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
6579 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
6580 U5(surface_desc).dwBackBufferCount = 1;
6581 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
6582 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6583 hr = IDirectDrawSurface7_GetAttachedSurface(primary, &surface_caps, &backbuffer);
6584 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6586 memset(palette_entries, 0, sizeof(palette_entries));
6587 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
6588 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6589 refcount = get_refcount((IUnknown *)palette);
6590 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6592 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6593 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6594 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6596 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6597 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6599 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6600 * and is generally somewhat broken with respect to 8 bpp / palette
6601 * handling. */
6602 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer, &tmp)))
6604 win_skip("Broken palette handling detected, skipping tests.\n");
6605 IDirectDrawPalette_Release(tmp);
6606 IDirectDrawPalette_Release(palette);
6607 /* The Windows 8 testbot keeps extra references to the primary and
6608 * backbuffer while in 8 bpp mode. */
6609 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
6610 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
6611 goto done;
6614 refcount = get_refcount((IUnknown *)palette);
6615 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6617 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6618 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6619 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
6620 "Got unexpected palette caps %#x.\n", palette_caps);
6622 hr = IDirectDrawSurface7_SetPalette(primary, NULL);
6623 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6624 refcount = get_refcount((IUnknown *)palette);
6625 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6627 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
6628 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
6629 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
6631 hr = IDirectDrawSurface7_SetPalette(primary, palette);
6632 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6633 refcount = get_refcount((IUnknown *)palette);
6634 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6636 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6637 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6638 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
6639 IDirectDrawPalette_Release(tmp);
6640 hr = IDirectDrawSurface7_GetPalette(backbuffer, &tmp);
6641 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6643 refcount = IDirectDrawPalette_Release(palette);
6644 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6645 refcount = IDirectDrawPalette_Release(palette);
6646 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6648 /* Note that this only seems to work when the palette is attached to the
6649 * primary surface. When attached to a regular surface, attempting to get
6650 * the palette here will cause an access violation. */
6651 hr = IDirectDrawSurface7_GetPalette(primary, &tmp);
6652 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6654 done:
6655 refcount = IDirectDrawSurface7_Release(backbuffer);
6656 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6657 refcount = IDirectDrawSurface7_Release(primary);
6658 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6659 refcount = IDirectDraw7_Release(ddraw);
6660 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6661 DestroyWindow(window);
6664 static HRESULT WINAPI surface_counter(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *desc, void *context)
6666 UINT *surface_count = context;
6668 ++(*surface_count);
6669 IDirectDrawSurface_Release(surface);
6671 return DDENUMRET_OK;
6674 static void test_surface_attachment(void)
6676 IDirectDrawSurface7 *surface1, *surface2, *surface3, *surface4;
6677 IDirectDrawSurface *surface1v1, *surface2v1;
6678 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, {0}};
6679 DDSURFACEDESC2 surface_desc;
6680 IDirectDraw7 *ddraw;
6681 UINT surface_count;
6682 ULONG refcount;
6683 HWND window;
6684 HRESULT hr;
6686 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6687 0, 0, 640, 480, 0, 0, 0, 0);
6688 ddraw = create_ddraw();
6689 ok(!!ddraw, "Failed to create a ddraw object.\n");
6690 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6691 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6693 memset(&surface_desc, 0, sizeof(surface_desc));
6694 surface_desc.dwSize = sizeof(surface_desc);
6695 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6696 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6697 U2(surface_desc).dwMipMapCount = 3;
6698 surface_desc.dwWidth = 128;
6699 surface_desc.dwHeight = 128;
6700 if (FAILED(IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL)))
6702 skip("Failed to create a texture, skipping tests.\n");
6703 IDirectDraw7_Release(ddraw);
6704 DestroyWindow(window);
6705 return;
6708 hr = IDirectDrawSurface7_GetAttachedSurface(surface1, &caps, &surface2);
6709 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6710 hr = IDirectDrawSurface7_GetAttachedSurface(surface2, &caps, &surface3);
6711 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
6712 hr = IDirectDrawSurface7_GetAttachedSurface(surface3, &caps, &surface4);
6713 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6715 surface_count = 0;
6716 IDirectDrawSurface7_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
6717 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6718 surface_count = 0;
6719 IDirectDrawSurface7_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
6720 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6721 surface_count = 0;
6722 IDirectDrawSurface7_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
6723 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
6725 memset(&surface_desc, 0, sizeof(surface_desc));
6726 surface_desc.dwSize = sizeof(surface_desc);
6727 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6728 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6729 surface_desc.dwWidth = 16;
6730 surface_desc.dwHeight = 16;
6731 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6732 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6734 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6735 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6736 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6737 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6738 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
6739 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6740 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
6741 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6742 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
6743 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6744 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
6745 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6747 IDirectDrawSurface7_Release(surface4);
6749 memset(&surface_desc, 0, sizeof(surface_desc));
6750 surface_desc.dwSize = sizeof(surface_desc);
6751 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6752 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6753 surface_desc.dwWidth = 16;
6754 surface_desc.dwHeight = 16;
6755 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6756 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6758 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6759 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6760 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6761 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6762 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface4);
6763 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6764 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface3);
6765 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6766 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface4);
6767 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6768 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface2);
6769 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6771 IDirectDrawSurface7_Release(surface4);
6772 IDirectDrawSurface7_Release(surface3);
6773 IDirectDrawSurface7_Release(surface2);
6774 IDirectDrawSurface7_Release(surface1);
6776 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6777 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6779 /* Try a single primary and two offscreen plain surfaces. */
6780 memset(&surface_desc, 0, sizeof(surface_desc));
6781 surface_desc.dwSize = sizeof(surface_desc);
6782 surface_desc.dwFlags = DDSD_CAPS;
6783 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6784 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6785 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6787 memset(&surface_desc, 0, sizeof(surface_desc));
6788 surface_desc.dwSize = sizeof(surface_desc);
6789 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6790 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6791 surface_desc.dwWidth = registry_mode.dmPelsWidth;
6792 surface_desc.dwHeight = registry_mode.dmPelsHeight;
6793 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6794 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6796 memset(&surface_desc, 0, sizeof(surface_desc));
6797 surface_desc.dwSize = sizeof(surface_desc);
6798 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6799 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6800 surface_desc.dwWidth = registry_mode.dmPelsWidth;
6801 surface_desc.dwHeight = registry_mode.dmPelsHeight;
6802 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6803 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6805 /* This one has a different size. */
6806 memset(&surface_desc, 0, sizeof(surface_desc));
6807 surface_desc.dwSize = sizeof(surface_desc);
6808 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6809 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6810 surface_desc.dwWidth = 128;
6811 surface_desc.dwHeight = 128;
6812 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6813 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6815 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6816 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6817 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface1);
6818 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6819 hr = IDirectDrawSurface7_AddAttachedSurface(surface2, surface3);
6820 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6821 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface4);
6822 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6823 hr = IDirectDrawSurface7_AddAttachedSurface(surface4, surface1);
6824 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6826 IDirectDrawSurface7_Release(surface4);
6827 IDirectDrawSurface7_Release(surface3);
6828 IDirectDrawSurface7_Release(surface2);
6829 IDirectDrawSurface7_Release(surface1);
6831 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
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 = 64;
6836 surface_desc.dwHeight = 64;
6837 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
6838 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6839 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
6840 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
6841 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
6842 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
6843 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
6844 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6845 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6846 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6847 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6849 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
6850 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
6851 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
6852 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
6853 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6854 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6856 hr = IDirectDrawSurface7_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
6857 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6858 hr = IDirectDrawSurface7_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
6859 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6861 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6862 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6863 refcount = get_refcount((IUnknown *)surface2);
6864 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6865 refcount = get_refcount((IUnknown *)surface2v1);
6866 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6867 hr = IDirectDrawSurface7_AddAttachedSurface(surface1, surface2);
6868 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
6869 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6870 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6871 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6872 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6874 /* Attaching while already attached to other surface. */
6875 hr = IDirectDrawSurface7_AddAttachedSurface(surface3, surface2);
6876 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6877 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface3, 0, surface2);
6878 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6879 IDirectDrawSurface7_Release(surface3);
6881 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
6882 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6883 refcount = get_refcount((IUnknown *)surface2);
6884 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6885 refcount = get_refcount((IUnknown *)surface2v1);
6886 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6888 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6889 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6890 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6891 hr = IDirectDrawSurface7_DeleteAttachedSurface(surface1, 0, surface2);
6892 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6893 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6894 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6895 refcount = IDirectDrawSurface7_Release(surface2);
6896 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6897 refcount = IDirectDrawSurface7_Release(surface1);
6898 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6900 /* Automatic detachment on release. */
6901 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6902 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6903 refcount = get_refcount((IUnknown *)surface2v1);
6904 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6905 refcount = IDirectDrawSurface_Release(surface1v1);
6906 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6907 refcount = IDirectDrawSurface_Release(surface2v1);
6908 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6909 refcount = IDirectDraw7_Release(ddraw);
6910 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6911 DestroyWindow(window);
6914 static void test_private_data(void)
6916 IDirectDraw7 *ddraw;
6917 IDirectDrawSurface7 *surface, *surface2;
6918 DDSURFACEDESC2 surface_desc;
6919 ULONG refcount, refcount2, refcount3;
6920 IUnknown *ptr;
6921 DWORD size = sizeof(ptr);
6922 HRESULT hr;
6923 HWND window;
6924 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
6925 DWORD data[] = {1, 2, 3, 4};
6926 DDCAPS hal_caps;
6927 static const GUID ddraw_private_data_test_guid =
6929 0xfdb37466,
6930 0x428f,
6931 0x4edf,
6932 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6934 static const GUID ddraw_private_data_test_guid2 =
6936 0x2e5afac2,
6937 0x87b5,
6938 0x4c10,
6939 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6942 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6943 0, 0, 640, 480, 0, 0, 0, 0);
6944 ddraw = create_ddraw();
6945 ok(!!ddraw, "Failed to create a ddraw object.\n");
6946 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6947 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6949 reset_ddsd(&surface_desc);
6950 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
6951 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
6952 surface_desc.dwHeight = 4;
6953 surface_desc.dwWidth = 4;
6954 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6955 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6957 /* NULL pointers are not valid, but don't cause a crash. */
6958 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
6959 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
6960 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6961 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
6962 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6963 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
6964 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6966 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6967 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6968 0, DDSPD_IUNKNOWNPOINTER);
6969 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6970 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6971 5, DDSPD_IUNKNOWNPOINTER);
6972 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6973 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6974 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
6975 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6977 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6978 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6979 * erases the old content and returns an error. This behavior has
6980 * been fixed in d3d8 and d3d9. Unless an application is found
6981 * that depends on this we don't care about this behavior. */
6982 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6983 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6984 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6985 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6986 0, DDSPD_IUNKNOWNPOINTER);
6987 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6988 size = sizeof(ptr);
6989 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6990 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6991 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
6992 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6994 refcount = get_refcount((IUnknown *)ddraw);
6995 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6996 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6997 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6998 refcount2 = get_refcount((IUnknown *)ddraw);
6999 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7001 hr = IDirectDrawSurface7_FreePrivateData(surface, &ddraw_private_data_test_guid);
7002 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
7003 refcount2 = get_refcount((IUnknown *)ddraw);
7004 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7006 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7007 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7008 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7009 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
7010 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
7011 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7012 refcount2 = get_refcount((IUnknown *)ddraw);
7013 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
7015 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
7016 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
7017 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7018 size = 2 * sizeof(ptr);
7019 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7020 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
7021 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7022 refcount2 = get_refcount(ptr);
7023 /* Object is NOT addref'ed by the getter. */
7024 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
7025 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
7027 ptr = (IUnknown *)0xdeadbeef;
7028 size = 1;
7029 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7030 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7031 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7032 size = 2 * sizeof(ptr);
7033 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
7034 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7035 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
7036 size = 1;
7037 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
7038 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
7039 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
7040 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7041 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
7042 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7043 size = 0xdeadbabe;
7044 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
7045 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7046 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
7047 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
7048 hr = IDirectDrawSurface7_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
7049 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7051 refcount3 = IDirectDrawSurface7_Release(surface);
7052 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
7054 /* Destroying the surface frees the reference held on the private data. It also frees
7055 * the reference the surface is holding on its creating object. */
7056 refcount2 = get_refcount((IUnknown *)ddraw);
7057 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
7059 memset(&hal_caps, 0, sizeof(hal_caps));
7060 hal_caps.dwSize = sizeof(hal_caps);
7061 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7062 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7063 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7064 && !is_ddraw64)
7066 reset_ddsd(&surface_desc);
7067 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
7068 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7069 surface_desc.dwHeight = 4;
7070 surface_desc.dwWidth = 4;
7071 U2(surface_desc).dwMipMapCount = 2;
7072 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7073 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7074 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7075 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7077 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
7078 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
7079 hr = IDirectDrawSurface7_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
7080 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7082 IDirectDrawSurface7_Release(surface2);
7083 IDirectDrawSurface7_Release(surface);
7085 else
7086 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7088 refcount = IDirectDraw7_Release(ddraw);
7089 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7090 DestroyWindow(window);
7093 static void test_pixel_format(void)
7095 HWND window, window2 = NULL;
7096 HDC hdc, hdc2 = NULL;
7097 HMODULE gl = NULL;
7098 int format, test_format;
7099 PIXELFORMATDESCRIPTOR pfd;
7100 IDirectDraw7 *ddraw = NULL;
7101 IDirectDrawClipper *clipper = NULL;
7102 DDSURFACEDESC2 ddsd;
7103 IDirectDrawSurface7 *primary = NULL;
7104 DDBLTFX fx;
7105 HRESULT hr;
7107 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7108 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7109 if (!window)
7111 skip("Failed to create window\n");
7112 return;
7115 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
7116 100, 100, 160, 160, NULL, NULL, NULL, NULL);
7118 hdc = GetDC(window);
7119 if (!hdc)
7121 skip("Failed to get DC\n");
7122 goto cleanup;
7125 if (window2)
7126 hdc2 = GetDC(window2);
7128 gl = LoadLibraryA("opengl32.dll");
7129 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7131 format = GetPixelFormat(hdc);
7132 ok(format == 0, "new window has pixel format %d\n", format);
7134 ZeroMemory(&pfd, sizeof(pfd));
7135 pfd.nSize = sizeof(pfd);
7136 pfd.nVersion = 1;
7137 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7138 pfd.iPixelType = PFD_TYPE_RGBA;
7139 pfd.iLayerType = PFD_MAIN_PLANE;
7140 format = ChoosePixelFormat(hdc, &pfd);
7141 if (format <= 0)
7143 skip("no pixel format available\n");
7144 goto cleanup;
7147 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7149 skip("failed to set pixel format\n");
7150 goto cleanup;
7153 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7155 skip("failed to set pixel format on second window\n");
7156 if (hdc2)
7158 ReleaseDC(window2, hdc2);
7159 hdc2 = NULL;
7163 ddraw = create_ddraw();
7164 ok(!!ddraw, "Failed to create a ddraw object.\n");
7166 test_format = GetPixelFormat(hdc);
7167 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7169 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7170 if (FAILED(hr))
7172 skip("Failed to set cooperative level, hr %#x.\n", hr);
7173 goto cleanup;
7176 test_format = GetPixelFormat(hdc);
7177 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7179 if (hdc2)
7181 hr = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
7182 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
7183 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
7184 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
7186 test_format = GetPixelFormat(hdc);
7187 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7189 test_format = GetPixelFormat(hdc2);
7190 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7193 memset(&ddsd, 0, sizeof(ddsd));
7194 ddsd.dwSize = sizeof(ddsd);
7195 ddsd.dwFlags = DDSD_CAPS;
7196 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7198 hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &primary, NULL);
7199 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
7201 test_format = GetPixelFormat(hdc);
7202 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7204 if (hdc2)
7206 test_format = GetPixelFormat(hdc2);
7207 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7210 if (clipper)
7212 hr = IDirectDrawSurface7_SetClipper(primary, clipper);
7213 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
7215 test_format = GetPixelFormat(hdc);
7216 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7218 test_format = GetPixelFormat(hdc2);
7219 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7222 memset(&fx, 0, sizeof(fx));
7223 fx.dwSize = sizeof(fx);
7224 hr = IDirectDrawSurface7_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
7225 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
7227 test_format = GetPixelFormat(hdc);
7228 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7230 if (hdc2)
7232 test_format = GetPixelFormat(hdc2);
7233 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7236 cleanup:
7237 if (primary) IDirectDrawSurface7_Release(primary);
7238 if (clipper) IDirectDrawClipper_Release(clipper);
7239 if (ddraw) IDirectDraw7_Release(ddraw);
7240 if (gl) FreeLibrary(gl);
7241 if (hdc) ReleaseDC(window, hdc);
7242 if (hdc2) ReleaseDC(window2, hdc2);
7243 if (window) DestroyWindow(window);
7244 if (window2) DestroyWindow(window2);
7247 static void test_create_surface_pitch(void)
7249 IDirectDrawSurface7 *surface;
7250 DDSURFACEDESC2 surface_desc;
7251 IDirectDraw7 *ddraw;
7252 unsigned int i;
7253 ULONG refcount;
7254 HWND window;
7255 HRESULT hr;
7256 void *mem;
7258 static const struct
7260 DWORD placement;
7261 DWORD flags_in;
7262 DWORD pitch_in;
7263 HRESULT hr;
7264 DWORD flags_out;
7265 DWORD pitch_out32;
7266 DWORD pitch_out64;
7268 test_data[] =
7270 {DDSCAPS_VIDEOMEMORY, 0, 0, DD_OK,
7271 DDSD_PITCH, 0x100, 0x100},
7272 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x104, DD_OK,
7273 DDSD_PITCH, 0x100, 0x100},
7274 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
7275 DDSD_PITCH, 0x100, 0x100},
7276 {DDSCAPS_VIDEOMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
7277 0, 0, 0 },
7278 {DDSCAPS_SYSTEMMEMORY, 0, 0, DD_OK,
7279 DDSD_PITCH, 0x100, 0x0fc},
7280 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x104, DD_OK,
7281 DDSD_PITCH, 0x100, 0x0fc},
7282 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
7283 DDSD_PITCH, 0x100, 0x0fc},
7284 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
7285 DDSD_PITCH, 0x100, 0x0fc},
7286 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
7287 0, 0, 0 },
7288 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
7289 DDSD_PITCH, 0x100, 0x100},
7290 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
7291 0, 0, 0 },
7292 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
7293 DDSD_PITCH, 0x0fc, 0x0fc},
7294 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
7295 0, 0, 0 },
7296 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
7297 0, 0, 0 },
7298 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
7299 0, 0, 0 },
7300 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
7301 DDSD_PITCH, 0x100, 0x100},
7303 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
7305 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7306 0, 0, 640, 480, 0, 0, 0, 0);
7307 ddraw = create_ddraw();
7308 ok(!!ddraw, "Failed to create a ddraw object.\n");
7309 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7310 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7312 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
7314 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7316 memset(&surface_desc, 0, sizeof(surface_desc));
7317 surface_desc.dwSize = sizeof(surface_desc);
7318 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
7319 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | test_data[i].placement;
7320 surface_desc.dwWidth = 63;
7321 surface_desc.dwHeight = 63;
7322 U1(surface_desc).lPitch = test_data[i].pitch_in;
7323 surface_desc.lpSurface = mem;
7324 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7325 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7326 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7327 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7328 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7329 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7330 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7331 ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
7332 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
7333 if (FAILED(hr))
7334 continue;
7336 memset(&surface_desc, 0, sizeof(surface_desc));
7337 surface_desc.dwSize = sizeof(surface_desc);
7338 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
7339 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
7340 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
7341 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7342 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
7343 if (sizeof(void *) != sizeof(DWORD) && test_data[i].pitch_out32 != test_data[i].pitch_out64)
7344 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
7345 "Test %u: Got unexpected pitch %u, expected %u.\n",
7346 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
7347 else
7348 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
7349 "Test %u: Got unexpected pitch %u, expected %u.\n",
7350 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
7351 ok(!surface_desc.lpSurface, "Test %u: Got unexpected lpSurface %p.\n", i, surface_desc.lpSurface);
7353 IDirectDrawSurface7_Release(surface);
7356 HeapFree(GetProcessHeap(), 0, mem);
7357 refcount = IDirectDraw7_Release(ddraw);
7358 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7359 DestroyWindow(window);
7362 static void test_mipmap_lock(void)
7364 IDirectDrawSurface7 *surface, *surface2;
7365 DDSURFACEDESC2 surface_desc;
7366 IDirectDraw7 *ddraw;
7367 ULONG refcount;
7368 HWND window;
7369 HRESULT hr;
7370 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7371 DDCAPS hal_caps;
7373 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7374 0, 0, 640, 480, 0, 0, 0, 0);
7375 ddraw = create_ddraw();
7376 ok(!!ddraw, "Failed to create a ddraw object.\n");
7377 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7378 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7380 memset(&hal_caps, 0, sizeof(hal_caps));
7381 hal_caps.dwSize = sizeof(hal_caps);
7382 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7383 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7384 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7385 || is_ddraw64)
7387 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
7388 IDirectDraw7_Release(ddraw);
7389 DestroyWindow(window);
7390 return;
7393 memset(&surface_desc, 0, sizeof(surface_desc));
7394 surface_desc.dwSize = sizeof(surface_desc);
7395 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
7396 surface_desc.dwWidth = 4;
7397 surface_desc.dwHeight = 4;
7398 U2(surface_desc).dwMipMapCount = 2;
7399 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
7400 | DDSCAPS_SYSTEMMEMORY;
7401 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7402 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7403 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &surface2);
7404 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7406 memset(&surface_desc, 0, sizeof(surface_desc));
7407 surface_desc.dwSize = sizeof(surface_desc);
7408 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
7409 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7410 memset(&surface_desc, 0, sizeof(surface_desc));
7411 surface_desc.dwSize = sizeof(surface_desc);
7412 hr = IDirectDrawSurface7_Lock(surface2, NULL, &surface_desc, 0, NULL);
7413 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7414 IDirectDrawSurface7_Unlock(surface2, NULL);
7415 IDirectDrawSurface7_Unlock(surface, NULL);
7417 IDirectDrawSurface7_Release(surface2);
7418 IDirectDrawSurface7_Release(surface);
7419 refcount = IDirectDraw7_Release(ddraw);
7420 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7421 DestroyWindow(window);
7424 static void test_palette_complex(void)
7426 IDirectDrawSurface7 *surface, *mipmap, *tmp;
7427 DDSURFACEDESC2 surface_desc;
7428 IDirectDraw7 *ddraw;
7429 IDirectDrawPalette *palette, *palette2;
7430 ULONG refcount;
7431 HWND window;
7432 HRESULT hr;
7433 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
7434 DDCAPS hal_caps;
7435 PALETTEENTRY palette_entries[256];
7436 unsigned int i;
7438 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7439 0, 0, 640, 480, 0, 0, 0, 0);
7440 ddraw = create_ddraw();
7441 ok(!!ddraw, "Failed to create a ddraw object.\n");
7442 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7443 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7445 memset(&hal_caps, 0, sizeof(hal_caps));
7446 hal_caps.dwSize = sizeof(hal_caps);
7447 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
7448 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7449 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)
7450 || is_ddraw64)
7452 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7453 IDirectDraw7_Release(ddraw);
7454 DestroyWindow(window);
7455 return;
7458 memset(&surface_desc, 0, sizeof(surface_desc));
7459 surface_desc.dwSize = sizeof(surface_desc);
7460 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7461 surface_desc.dwWidth = 128;
7462 surface_desc.dwHeight = 128;
7463 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7464 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7465 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7466 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7467 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7468 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7470 memset(palette_entries, 0, sizeof(palette_entries));
7471 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7472 palette_entries, &palette, NULL);
7473 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7475 palette2 = (void *)0xdeadbeef;
7476 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7477 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
7478 ok(!palette2, "Got unexpected palette %p.\n", palette2);
7479 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7480 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7481 hr = IDirectDrawSurface7_GetPalette(surface, &palette2);
7482 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
7483 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
7484 IDirectDrawPalette_Release(palette2);
7486 mipmap = surface;
7487 IDirectDrawSurface7_AddRef(mipmap);
7488 for (i = 0; i < 7; ++i)
7490 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7491 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
7492 palette2 = (void *)0xdeadbeef;
7493 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7494 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7495 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7497 hr = IDirectDrawSurface7_SetPalette(tmp, palette);
7498 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x, i %u.\n", hr, i);
7500 hr = IDirectDrawSurface7_GetPalette(tmp, &palette2);
7501 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
7502 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
7504 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7505 * ddraw versions. Combined with the test results above this means no
7506 * palette is available. So depending on the driver either GetDC fails
7507 * or the DIB color table contains random data. */
7509 IDirectDrawSurface7_Release(mipmap);
7510 mipmap = tmp;
7513 hr = IDirectDrawSurface7_GetAttachedSurface(mipmap, &caps, &tmp);
7514 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
7515 IDirectDrawSurface7_Release(mipmap);
7516 refcount = IDirectDrawSurface7_Release(surface);
7517 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7519 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7520 memset(&surface_desc, 0, sizeof(surface_desc));
7521 surface_desc.dwSize = sizeof(surface_desc);
7522 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7523 surface_desc.dwWidth = 128;
7524 surface_desc.dwHeight = 128;
7525 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
7526 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7527 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7528 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7529 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7530 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7531 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7532 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7533 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7535 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
7536 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
7537 hr = IDirectDrawSurface7_SetPalette(mipmap, palette);
7538 ok(hr == DDERR_NOTONMIPMAPSUBLEVEL, "Got unexpected hr %#x.\n", hr);
7540 IDirectDrawSurface7_Release(mipmap);
7541 refcount = IDirectDrawSurface7_Release(surface);
7542 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7543 refcount = IDirectDrawPalette_Release(palette);
7544 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7546 refcount = IDirectDraw7_Release(ddraw);
7547 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7548 DestroyWindow(window);
7551 static void test_p8_rgb_blit(void)
7553 IDirectDrawSurface7 *src, *dst;
7554 DDSURFACEDESC2 surface_desc;
7555 IDirectDraw7 *ddraw;
7556 IDirectDrawPalette *palette;
7557 ULONG refcount;
7558 HWND window;
7559 HRESULT hr;
7560 PALETTEENTRY palette_entries[256];
7561 unsigned int x;
7562 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7563 static const D3DCOLOR expected[] =
7565 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7566 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7568 D3DCOLOR color;
7570 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7571 0, 0, 640, 480, 0, 0, 0, 0);
7572 ddraw = create_ddraw();
7573 ok(!!ddraw, "Failed to create a ddraw object.\n");
7574 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7575 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7577 memset(palette_entries, 0, sizeof(palette_entries));
7578 palette_entries[1].peGreen = 0xff;
7579 palette_entries[2].peBlue = 0xff;
7580 palette_entries[3].peFlags = 0xff;
7581 palette_entries[4].peRed = 0xff;
7582 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7583 palette_entries, &palette, NULL);
7584 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7586 memset(&surface_desc, 0, sizeof(surface_desc));
7587 surface_desc.dwSize = sizeof(surface_desc);
7588 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7589 surface_desc.dwWidth = 8;
7590 surface_desc.dwHeight = 1;
7591 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7592 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7593 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7594 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7595 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
7596 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7598 memset(&surface_desc, 0, sizeof(surface_desc));
7599 surface_desc.dwSize = sizeof(surface_desc);
7600 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7601 surface_desc.dwWidth = 8;
7602 surface_desc.dwHeight = 1;
7603 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7604 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7605 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
7606 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7607 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7608 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7609 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7610 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
7611 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
7612 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7614 memset(&surface_desc, 0, sizeof(surface_desc));
7615 surface_desc.dwSize = sizeof(surface_desc);
7616 hr = IDirectDrawSurface7_Lock(src, NULL, &surface_desc, 0, NULL);
7617 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
7618 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
7619 hr = IDirectDrawSurface7_Unlock(src, NULL);
7620 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
7622 hr = IDirectDrawSurface7_SetPalette(src, palette);
7623 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7624 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
7625 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7626 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7627 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
7628 "Failed to blit, hr %#x.\n", hr);
7630 if (SUCCEEDED(hr))
7632 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
7634 color = get_surface_color(dst, x, 0);
7635 todo_wine ok(compare_color(color, expected[x], 0),
7636 "Pixel %u: Got color %#x, expected %#x.\n",
7637 x, color, expected[x]);
7641 IDirectDrawSurface7_Release(src);
7642 IDirectDrawSurface7_Release(dst);
7643 IDirectDrawPalette_Release(palette);
7645 refcount = IDirectDraw7_Release(ddraw);
7646 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7647 DestroyWindow(window);
7650 static void test_material(void)
7652 static const D3DCOLORVALUE null_color;
7653 IDirect3DDevice7 *device;
7654 D3DMATERIAL7 material;
7655 ULONG refcount;
7656 HWND window;
7657 HRESULT hr;
7659 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7660 0, 0, 640, 480, 0, 0, 0, 0);
7661 if (!(device = create_device(window, DDSCL_NORMAL)))
7663 skip("Failed to create a 3D device, skipping test.\n");
7664 DestroyWindow(window);
7665 return;
7668 hr = IDirect3DDevice7_GetMaterial(device, &material);
7669 ok(SUCCEEDED(hr), "Failed to get material, hr %#x.\n", hr);
7670 ok(!memcmp(&U(material).diffuse, &null_color, sizeof(null_color)),
7671 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
7672 U1(U(material).diffuse).r, U2(U(material).diffuse).g,
7673 U3(U(material).diffuse).b, U4(U(material).diffuse).a);
7674 ok(!memcmp(&U1(material).ambient, &null_color, sizeof(null_color)),
7675 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
7676 U1(U1(material).ambient).r, U2(U1(material).ambient).g,
7677 U3(U1(material).ambient).b, U4(U1(material).ambient).a);
7678 ok(!memcmp(&U2(material).specular, &null_color, sizeof(null_color)),
7679 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
7680 U1(U2(material).specular).r, U2(U2(material).specular).g,
7681 U3(U2(material).specular).b, U4(U2(material).specular).a);
7682 ok(!memcmp(&U3(material).emissive, &null_color, sizeof(null_color)),
7683 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
7684 U1(U3(material).emissive).r, U2(U3(material).emissive).g,
7685 U3(U3(material).emissive).b, U4(U3(material).emissive).a);
7686 ok(U4(material).power == 0.0f, "Got unexpected power %.8e.\n", U4(material).power);
7688 refcount = IDirect3DDevice7_Release(device);
7689 ok(!refcount, "Device has %u references left.\n", refcount);
7690 DestroyWindow(window);
7693 static void test_palette_gdi(void)
7695 IDirectDrawSurface7 *surface, *primary;
7696 DDSURFACEDESC2 surface_desc;
7697 IDirectDraw7 *ddraw;
7698 IDirectDrawPalette *palette, *palette2;
7699 ULONG refcount;
7700 HWND window;
7701 HRESULT hr;
7702 PALETTEENTRY palette_entries[256];
7703 UINT i;
7704 HDC dc;
7705 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7706 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7707 * not the point of this test. */
7708 static const RGBQUAD expected1[] =
7710 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7711 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7713 static const RGBQUAD expected2[] =
7715 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7716 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7718 static const RGBQUAD expected3[] =
7720 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7721 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7723 HPALETTE ddraw_palette_handle;
7724 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7725 RGBQUAD rgbquad[255];
7726 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
7728 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7729 0, 0, 640, 480, 0, 0, 0, 0);
7730 ddraw = create_ddraw();
7731 ok(!!ddraw, "Failed to create a ddraw object.\n");
7732 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7733 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7735 memset(&surface_desc, 0, sizeof(surface_desc));
7736 surface_desc.dwSize = sizeof(surface_desc);
7737 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7738 surface_desc.dwWidth = 16;
7739 surface_desc.dwHeight = 16;
7740 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7741 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7742 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7743 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7744 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7745 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7747 /* Avoid colors from the Windows default palette. */
7748 memset(palette_entries, 0, sizeof(palette_entries));
7749 palette_entries[1].peRed = 0x01;
7750 palette_entries[2].peGreen = 0x02;
7751 palette_entries[3].peBlue = 0x03;
7752 palette_entries[4].peRed = 0x13;
7753 palette_entries[4].peGreen = 0x14;
7754 palette_entries[4].peBlue = 0x15;
7755 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7756 palette_entries, &palette, NULL);
7757 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7759 /* If there is no palette assigned and the display mode is not 8 bpp, some
7760 * drivers refuse to create a DC while others allow it. If a DC is created,
7761 * the DIB color table is uninitialized and contains random colors. No error
7762 * is generated when trying to read pixels and random garbage is returned.
7764 * The most likely explanation is that if the driver creates a DC, it (or
7765 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7766 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7767 * contains uninitialized garbage. See comments below for the P8 case. */
7769 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7770 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7771 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7772 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7773 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7774 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
7775 "Got unexpected palette %p, expected %p.\n",
7776 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7778 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7779 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7780 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
7782 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
7783 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7784 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7785 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
7787 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7789 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7790 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7791 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7794 /* Update the palette while the DC is in use. This does not modify the DC. */
7795 palette_entries[4].peRed = 0x23;
7796 palette_entries[4].peGreen = 0x24;
7797 palette_entries[4].peBlue = 0x25;
7798 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
7799 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
7801 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7802 ok(i == 1, "Expected count 1, got %u.\n", i);
7803 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7804 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7805 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7806 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7808 /* Neither does re-setting the palette. */
7809 hr = IDirectDrawSurface7_SetPalette(surface, NULL);
7810 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7811 hr = IDirectDrawSurface7_SetPalette(surface, palette);
7812 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7814 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7815 ok(i == 1, "Expected count 1, got %u.\n", i);
7816 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7817 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7818 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7819 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7821 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7822 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7824 /* Refresh the DC. This updates the palette. */
7825 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7826 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7827 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7828 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7829 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7831 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7832 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7833 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7834 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7836 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7838 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7839 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7840 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7842 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7843 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7845 refcount = IDirectDrawSurface7_Release(surface);
7846 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7848 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7850 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7851 IDirectDrawPalette_Release(palette);
7852 IDirectDraw7_Release(ddraw);
7853 DestroyWindow(window);
7854 return;
7856 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
7857 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
7858 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7860 memset(&surface_desc, 0, sizeof(surface_desc));
7861 surface_desc.dwSize = sizeof(surface_desc);
7862 surface_desc.dwFlags = DDSD_CAPS;
7863 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7864 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &primary, NULL);
7865 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7867 hr = IDirectDrawSurface7_SetPalette(primary, palette);
7868 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7869 hr = IDirectDrawSurface7_GetDC(primary, &dc);
7870 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7871 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7872 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7873 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE) || broken(TRUE),
7874 "Got unexpected palette %p, expected %p.\n",
7875 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7876 SelectPalette(dc, ddraw_palette_handle, FALSE);
7878 /* The primary uses the system palette. In exclusive mode, the system palette matches
7879 * the ddraw palette attached to the primary, so the result is what you would expect
7880 * from a regular surface. Tests for the interaction between the ddraw palette and
7881 * the system palette are not included pending an application that depends on this.
7882 * The relation between those causes problems on Windows Vista and newer for games
7883 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
7884 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7885 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7886 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7888 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7889 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7890 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7891 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7893 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7895 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7896 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7897 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7899 hr = IDirectDrawSurface7_ReleaseDC(primary, dc);
7900 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7902 memset(&surface_desc, 0, sizeof(surface_desc));
7903 surface_desc.dwSize = sizeof(surface_desc);
7904 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7905 surface_desc.dwWidth = 16;
7906 surface_desc.dwHeight = 16;
7907 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7908 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7909 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7911 /* Here the offscreen surface appears to use the primary's palette,
7912 * but in all likelihood it is actually the system palette. */
7913 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7914 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7915 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7916 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7917 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7919 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7920 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7921 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7922 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7924 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7926 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7927 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7928 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7930 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7931 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7933 /* On real hardware a change to the primary surface's palette applies immediately,
7934 * even on device contexts from offscreen surfaces that do not have their own
7935 * palette. On the testbot VMs this is not the case. Don't test this until we
7936 * know of an application that depends on this. */
7938 memset(palette_entries, 0, sizeof(palette_entries));
7939 palette_entries[1].peBlue = 0x40;
7940 palette_entries[2].peRed = 0x40;
7941 palette_entries[3].peGreen = 0x40;
7942 palette_entries[4].peRed = 0x12;
7943 palette_entries[4].peGreen = 0x34;
7944 palette_entries[4].peBlue = 0x56;
7945 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7946 palette_entries, &palette2, NULL);
7947 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7948 hr = IDirectDrawSurface7_SetPalette(surface, palette2);
7949 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7951 /* A palette assigned to the offscreen surface overrides the primary / system
7952 * palette. */
7953 hr = IDirectDrawSurface7_GetDC(surface, &dc);
7954 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7955 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7956 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7957 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
7959 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
7960 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7961 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7962 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
7964 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7966 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7967 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7968 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7970 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
7971 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7973 refcount = IDirectDrawSurface7_Release(surface);
7974 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7976 /* The Windows 8 testbot keeps extra references to the primary and
7977 * backbuffer while in 8 bpp mode. */
7978 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
7979 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7981 refcount = IDirectDrawSurface7_Release(primary);
7982 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7983 refcount = IDirectDrawPalette_Release(palette2);
7984 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7985 refcount = IDirectDrawPalette_Release(palette);
7986 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7987 refcount = IDirectDraw7_Release(ddraw);
7988 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7989 DestroyWindow(window);
7992 static void test_palette_alpha(void)
7994 IDirectDrawSurface7 *surface;
7995 DDSURFACEDESC2 surface_desc;
7996 IDirectDraw7 *ddraw;
7997 IDirectDrawPalette *palette;
7998 ULONG refcount;
7999 HWND window;
8000 HRESULT hr;
8001 PALETTEENTRY palette_entries[256];
8002 unsigned int i;
8003 static const struct
8005 DWORD caps, flags;
8006 BOOL attach_allowed;
8007 const char *name;
8009 test_data[] =
8011 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
8012 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
8013 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
8016 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8017 0, 0, 640, 480, 0, 0, 0, 0);
8018 ddraw = create_ddraw();
8019 ok(!!ddraw, "Failed to create a ddraw object.\n");
8020 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
8022 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8023 IDirectDraw7_Release(ddraw);
8024 DestroyWindow(window);
8025 return;
8027 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8028 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8030 memset(palette_entries, 0, sizeof(palette_entries));
8031 palette_entries[1].peFlags = 0x42;
8032 palette_entries[2].peFlags = 0xff;
8033 palette_entries[3].peFlags = 0x80;
8034 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
8035 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8037 memset(palette_entries, 0x66, sizeof(palette_entries));
8038 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8039 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8040 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8041 palette_entries[0].peFlags);
8042 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8043 palette_entries[1].peFlags);
8044 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8045 palette_entries[2].peFlags);
8046 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8047 palette_entries[3].peFlags);
8049 IDirectDrawPalette_Release(palette);
8051 memset(palette_entries, 0, sizeof(palette_entries));
8052 palette_entries[1].peFlags = 0x42;
8053 palette_entries[1].peRed = 0xff;
8054 palette_entries[2].peFlags = 0xff;
8055 palette_entries[3].peFlags = 0x80;
8056 hr = IDirectDraw7_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
8057 palette_entries, &palette, NULL);
8058 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
8060 memset(palette_entries, 0x66, sizeof(palette_entries));
8061 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
8062 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
8063 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8064 palette_entries[0].peFlags);
8065 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8066 palette_entries[1].peFlags);
8067 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8068 palette_entries[2].peFlags);
8069 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8070 palette_entries[3].peFlags);
8072 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
8074 memset(&surface_desc, 0, sizeof(surface_desc));
8075 surface_desc.dwSize = sizeof(surface_desc);
8076 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
8077 surface_desc.dwWidth = 128;
8078 surface_desc.dwHeight = 128;
8079 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8080 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8081 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
8083 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8084 if (test_data[i].attach_allowed)
8085 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
8086 else
8087 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
8089 if (SUCCEEDED(hr))
8091 HDC dc;
8092 RGBQUAD rgbquad;
8093 UINT retval;
8095 hr = IDirectDrawSurface7_GetDC(surface, &dc);
8096 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
8097 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
8098 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
8099 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8100 rgbquad.rgbRed, test_data[i].name);
8101 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8102 rgbquad.rgbGreen, test_data[i].name);
8103 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8104 rgbquad.rgbBlue, test_data[i].name);
8105 todo_wine ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8106 rgbquad.rgbReserved, test_data[i].name);
8107 hr = IDirectDrawSurface7_ReleaseDC(surface, dc);
8108 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
8110 IDirectDrawSurface7_Release(surface);
8113 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8114 memset(&surface_desc, 0, sizeof(surface_desc));
8115 surface_desc.dwSize = sizeof(surface_desc);
8116 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
8117 surface_desc.dwWidth = 128;
8118 surface_desc.dwHeight = 128;
8119 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8120 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
8121 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
8122 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
8123 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
8124 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
8125 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
8126 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8127 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8128 hr = IDirectDrawSurface7_SetPalette(surface, palette);
8129 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
8130 IDirectDrawSurface7_Release(surface);
8132 /* The Windows 8 testbot keeps extra references to the primary
8133 * while in 8 bpp mode. */
8134 hr = IDirectDraw7_RestoreDisplayMode(ddraw);
8135 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
8137 refcount = IDirectDrawPalette_Release(palette);
8138 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8139 refcount = IDirectDraw7_Release(ddraw);
8140 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8141 DestroyWindow(window);
8144 static void test_vb_writeonly(void)
8146 IDirect3DDevice7 *device;
8147 IDirect3D7 *d3d;
8148 IDirect3DVertexBuffer7 *buffer;
8149 HWND window;
8150 HRESULT hr;
8151 D3DVERTEXBUFFERDESC desc;
8152 void *ptr;
8153 static const struct vec4 quad[] =
8155 { 0.0f, 480.0f, 0.0f, 1.0f},
8156 { 0.0f, 0.0f, 0.0f, 1.0f},
8157 {640.0f, 480.0f, 0.0f, 1.0f},
8158 {640.0f, 0.0f, 0.0f, 1.0f},
8161 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8162 0, 0, 640, 480, 0, 0, 0, 0);
8164 if (!(device = create_device(window, DDSCL_NORMAL)))
8166 skip("Failed to create a 3D device, skipping test.\n");
8167 DestroyWindow(window);
8168 return;
8171 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
8172 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
8174 memset(&desc, 0, sizeof(desc));
8175 desc.dwSize = sizeof(desc);
8176 desc.dwCaps = D3DVBCAPS_WRITEONLY;
8177 desc.dwFVF = D3DFVF_XYZRHW;
8178 desc.dwNumVertices = sizeof(quad) / sizeof(*quad);
8179 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &buffer, 0);
8180 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
8182 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
8183 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8184 memcpy(ptr, quad, sizeof(quad));
8185 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8186 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8188 hr = IDirect3DDevice7_BeginScene(device);
8189 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8190 hr = IDirect3DDevice7_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
8191 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8192 hr = IDirect3DDevice7_EndScene(device);
8193 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8195 hr = IDirect3DVertexBuffer7_Lock(buffer, 0, &ptr, NULL);
8196 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8197 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8198 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8199 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8201 hr = IDirect3DVertexBuffer7_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
8202 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8203 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8204 hr = IDirect3DVertexBuffer7_Unlock(buffer);
8205 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8207 IDirect3DVertexBuffer7_Release(buffer);
8208 IDirect3D7_Release(d3d);
8209 IDirect3DDevice7_Release(device);
8210 DestroyWindow(window);
8213 static void test_lost_device(void)
8215 IDirectDrawSurface7 *surface;
8216 DDSURFACEDESC2 surface_desc;
8217 IDirectDraw7 *ddraw;
8218 ULONG refcount;
8219 HWND window;
8220 HRESULT hr;
8221 BOOL ret;
8223 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8224 0, 0, 640, 480, 0, 0, 0, 0);
8225 ddraw = create_ddraw();
8226 ok(!!ddraw, "Failed to create a ddraw object.\n");
8227 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8228 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8230 memset(&surface_desc, 0, sizeof(surface_desc));
8231 surface_desc.dwSize = sizeof(surface_desc);
8232 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
8233 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
8234 U5(surface_desc).dwBackBufferCount = 1;
8235 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8236 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8238 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8239 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8240 hr = IDirectDrawSurface7_IsLost(surface);
8241 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8242 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8243 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8245 ret = SetForegroundWindow(GetDesktopWindow());
8246 ok(ret, "Failed to set foreground window.\n");
8247 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8248 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
8249 hr = IDirectDrawSurface7_IsLost(surface);
8250 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8251 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8252 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8254 ret = SetForegroundWindow(window);
8255 ok(ret, "Failed to set foreground window.\n");
8256 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8257 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8258 hr = IDirectDrawSurface7_IsLost(surface);
8259 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8260 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8261 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8263 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8264 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8265 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8266 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8267 hr = IDirectDrawSurface7_IsLost(surface);
8268 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8269 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8270 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8272 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8273 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8274 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8275 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8276 hr = IDirectDrawSurface7_IsLost(surface);
8277 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8278 hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
8279 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8281 /* Trying to restore the primary will crash, probably because flippable
8282 * surfaces can't exist in DDSCL_NORMAL. */
8283 IDirectDrawSurface7_Release(surface);
8284 memset(&surface_desc, 0, sizeof(surface_desc));
8285 surface_desc.dwSize = sizeof(surface_desc);
8286 surface_desc.dwFlags = DDSD_CAPS;
8287 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
8288 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8289 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8291 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8292 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8293 hr = IDirectDrawSurface7_IsLost(surface);
8294 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8296 ret = SetForegroundWindow(GetDesktopWindow());
8297 ok(ret, "Failed to set foreground window.\n");
8298 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8299 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8300 hr = IDirectDrawSurface7_IsLost(surface);
8301 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8303 ret = SetForegroundWindow(window);
8304 ok(ret, "Failed to set foreground window.\n");
8305 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8306 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8307 hr = IDirectDrawSurface7_IsLost(surface);
8308 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8310 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
8311 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8312 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8313 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8314 hr = IDirectDrawSurface7_IsLost(surface);
8315 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
8317 hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
8318 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8319 hr = IDirectDraw7_TestCooperativeLevel(ddraw);
8320 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8321 hr = IDirectDrawSurface7_IsLost(surface);
8322 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
8324 IDirectDrawSurface7_Release(surface);
8325 refcount = IDirectDraw7_Release(ddraw);
8326 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8327 DestroyWindow(window);
8330 static void test_resource_priority(void)
8332 IDirectDrawSurface7 *surface, *mipmap;
8333 DDSURFACEDESC2 surface_desc;
8334 IDirectDraw7 *ddraw;
8335 ULONG refcount;
8336 HWND window;
8337 HRESULT hr;
8338 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, {0}};
8339 DDCAPS hal_caps;
8340 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_MIPMAP;
8341 unsigned int i;
8342 DWORD priority;
8343 static const struct
8345 DWORD caps, caps2;
8346 const char *name;
8347 HRESULT hr;
8348 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8349 BOOL crash;
8351 test_data[] =
8353 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, "vidmem texture", DDERR_INVALIDPARAMS, FALSE},
8354 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, "sysmem texture", DDERR_INVALIDPARAMS, FALSE},
8355 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8356 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, "managed texture", DD_OK, FALSE},
8357 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8358 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT, TRUE},
8361 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8362 0, 0, 640, 480, 0, 0, 0, 0);
8363 ddraw = create_ddraw();
8364 ok(!!ddraw, "Failed to create a ddraw object.\n");
8365 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8366 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8368 memset(&hal_caps, 0, sizeof(hal_caps));
8369 hal_caps.dwSize = sizeof(hal_caps);
8370 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
8371 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8372 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps
8373 || !(hal_caps.ddsCaps.dwCaps & DDSCAPS2_TEXTUREMANAGE))
8375 skip("Required surface types not supported, skipping test.\n");
8376 goto done;
8379 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
8381 memset(&surface_desc, 0, sizeof(surface_desc));
8382 surface_desc.dwSize = sizeof(surface_desc);
8383 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
8384 surface_desc.dwWidth = 32;
8385 surface_desc.dwHeight = 32;
8386 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
8387 surface_desc.ddsCaps.dwCaps2 = test_data[i].caps2;
8388 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8389 if (is_ddraw64 && (test_data[i].caps & DDSCAPS_TEXTURE))
8391 todo_wine ok(hr == E_NOINTERFACE, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8392 if (SUCCEEDED(hr))
8393 IDirectDrawSurface7_Release(surface);
8394 continue;
8396 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, test_data[i].name);
8398 /* Priority == NULL segfaults. */
8399 priority = 0xdeadbeef;
8400 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8401 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8402 if (SUCCEEDED(test_data[i].hr))
8403 ok(priority == 0, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8404 else
8405 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8407 if (!test_data[i].crash)
8409 hr = IDirectDrawSurface7_SetPriority(surface, 1);
8410 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8411 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8412 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8413 if (SUCCEEDED(test_data[i].hr))
8415 ok(priority == 1, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8416 hr = IDirectDrawSurface7_SetPriority(surface, 2);
8417 ok(hr == test_data[i].hr, "Got unexpected hr %#x, type %s.\n", hr, test_data[i].name);
8419 else
8420 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority, test_data[i].name);
8423 IDirectDrawSurface7_Release(surface);
8426 if (is_ddraw64)
8427 goto done;
8429 memset(&surface_desc, 0, sizeof(surface_desc));
8430 surface_desc.dwSize = sizeof(surface_desc);
8431 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_MIPMAPCOUNT;
8432 surface_desc.dwWidth = 32;
8433 surface_desc.dwHeight = 32;
8434 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
8435 surface_desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
8436 U2(surface_desc).dwMipMapCount = 2;
8437 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8438 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8439 hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &mipmap);
8440 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
8442 priority = 0xdeadbeef;
8443 hr = IDirectDrawSurface7_GetPriority(mipmap, &priority);
8444 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x, type managed mipmap.\n", hr);
8445 ok(priority == 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority);
8446 /* SetPriority on the mipmap surface crashes. */
8447 hr = IDirectDrawSurface7_GetPriority(surface, &priority);
8448 ok(SUCCEEDED(hr), "Failed to get priority, hr %#x.\n", hr);
8449 ok(priority == 0, "Got unexpected priority %u, type managed mipmap.\n", priority);
8451 IDirectDrawSurface7_Release(mipmap);
8452 refcount = IDirectDrawSurface7_Release(surface);
8453 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8455 done:
8456 refcount = IDirectDraw7_Release(ddraw);
8457 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8458 DestroyWindow(window);
8461 static void test_surface_desc_lock(void)
8463 IDirectDrawSurface7 *surface;
8464 DDSURFACEDESC2 surface_desc;
8465 IDirectDraw7 *ddraw;
8466 ULONG refcount;
8467 HWND window;
8468 HRESULT hr;
8470 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8471 0, 0, 640, 480, 0, 0, 0, 0);
8472 ddraw = create_ddraw();
8473 ok(!!ddraw, "Failed to create a ddraw object.\n");
8474 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
8475 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
8477 memset(&surface_desc, 0, sizeof(surface_desc));
8478 surface_desc.dwSize = sizeof(surface_desc);
8479 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
8480 surface_desc.dwWidth = 16;
8481 surface_desc.dwHeight = 16;
8482 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
8483 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
8484 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8486 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8487 surface_desc.dwSize = sizeof(surface_desc);
8488 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8489 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8490 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8492 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8493 surface_desc.dwSize = sizeof(surface_desc);
8494 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
8495 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8496 ok(surface_desc.lpSurface != NULL, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8497 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8498 surface_desc.dwSize = sizeof(surface_desc);
8499 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8500 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8501 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8502 hr = IDirectDrawSurface7_Unlock(surface, NULL);
8503 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8505 memset(&surface_desc, 0xaa, sizeof(surface_desc));
8506 surface_desc.dwSize = sizeof(surface_desc);
8507 hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &surface_desc);
8508 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
8509 ok(!surface_desc.lpSurface, "Got unexpected lpSurface %p.\n", surface_desc.lpSurface);
8511 IDirectDrawSurface7_Release(surface);
8512 refcount = IDirectDraw7_Release(ddraw);
8513 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
8514 DestroyWindow(window);
8517 static void test_fog_interpolation(void)
8519 HRESULT hr;
8520 IDirect3DDevice7 *device;
8521 IDirectDrawSurface7 *rt;
8522 ULONG refcount;
8523 HWND window;
8524 D3DCOLOR color;
8525 static struct
8527 struct vec3 position;
8528 D3DCOLOR diffuse;
8529 D3DCOLOR specular;
8531 quad[] =
8533 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff000000},
8534 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff000000},
8535 {{ 1.0f, -1.0f, 1.0f}, 0xffff0000, 0x00000000},
8536 {{ 1.0f, 1.0f, 1.0f}, 0xffff0000, 0x00000000},
8538 union
8540 DWORD d;
8541 float f;
8542 } conv;
8543 unsigned int i;
8544 static const struct
8546 D3DFOGMODE vfog, tfog;
8547 D3DSHADEMODE shade;
8548 D3DCOLOR middle_color;
8549 BOOL todo;
8551 tests[] =
8553 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, FALSE},
8554 {D3DFOG_NONE, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, FALSE},
8555 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_FLAT, 0x00007f80, TRUE},
8556 {D3DFOG_EXP, D3DFOG_NONE, D3DSHADE_GOURAUD, 0x00007f80, TRUE},
8557 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
8558 {D3DFOG_NONE, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
8559 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_FLAT, 0x0000ea15, FALSE},
8560 {D3DFOG_EXP, D3DFOG_EXP, D3DSHADE_GOURAUD, 0x0000ea15, FALSE},
8562 D3DDEVICEDESC7 caps;
8564 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8565 0, 0, 640, 480, 0, 0, 0, 0);
8567 if (!(device = create_device(window, DDSCL_NORMAL)))
8569 skip("Failed to create a 3D device, skipping test.\n");
8570 DestroyWindow(window);
8571 return;
8574 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8575 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8576 hr = IDirect3DDevice7_GetCaps(device, &caps);
8577 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8578 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
8579 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
8581 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
8582 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8583 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
8584 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8585 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
8586 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8587 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
8588 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8589 conv.f = 5.0;
8590 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGDENSITY, conv.d);
8591 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8593 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
8594 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8595 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
8596 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
8597 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x000000ff);
8598 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8600 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
8602 if(!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
8603 continue;
8605 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00808080, 0.0f, 0);
8606 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8608 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shade);
8609 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8610 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
8611 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8612 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
8613 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8614 hr = IDirect3DDevice7_BeginScene(device);
8615 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8616 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8617 D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_SPECULAR, quad, 4, 0);
8618 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8619 hr = IDirect3DDevice7_EndScene(device);
8620 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8622 color = get_surface_color(rt, 0, 240);
8623 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
8624 color = get_surface_color(rt, 320, 240);
8625 if (tests[i].todo)
8626 todo_wine ok(compare_color(color, tests[i].middle_color, 2),
8627 "Got unexpected color 0x%08x, case %u.\n", color, i);
8628 else
8629 ok(compare_color(color, tests[i].middle_color, 2),
8630 "Got unexpected color 0x%08x, case %u.\n", color, i);
8631 color = get_surface_color(rt, 639, 240);
8632 ok(compare_color(color, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color, i);
8635 IDirectDrawSurface7_Release(rt);
8636 refcount = IDirect3DDevice7_Release(device);
8637 ok(!refcount, "Device has %u references left.\n", refcount);
8638 DestroyWindow(window);
8641 static void test_negative_fixedfunction_fog(void)
8643 HRESULT hr;
8644 IDirect3DDevice7 *device;
8645 IDirectDrawSurface7 *rt;
8646 ULONG refcount;
8647 HWND window;
8648 D3DCOLOR color;
8649 static struct
8651 struct vec3 position;
8652 D3DCOLOR diffuse;
8654 quad[] =
8656 {{-1.0f, -1.0f, -0.5f}, 0xffff0000},
8657 {{-1.0f, 1.0f, -0.5f}, 0xffff0000},
8658 {{ 1.0f, -1.0f, -0.5f}, 0xffff0000},
8659 {{ 1.0f, 1.0f, -0.5f}, 0xffff0000},
8661 static struct
8663 struct vec4 position;
8664 D3DCOLOR diffuse;
8666 tquad[] =
8668 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
8669 {{640.0f, 0.0f, -0.5f, 1.0f}, 0xffff0000},
8670 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
8671 {{640.0f, 480.0f, -0.5f, 1.0f}, 0xffff0000},
8673 unsigned int i;
8674 static D3DMATRIX zero =
8676 1.0f, 0.0f, 0.0f, 0.0f,
8677 0.0f, 1.0f, 0.0f, 0.0f,
8678 0.0f, 0.0f, 0.0f, 0.0f,
8679 0.0f, 0.0f, 0.0f, 1.0f
8681 static D3DMATRIX identity =
8683 1.0f, 0.0f, 0.0f, 0.0f,
8684 0.0f, 1.0f, 0.0f, 0.0f,
8685 0.0f, 0.0f, 1.0f, 0.0f,
8686 0.0f, 0.0f, 0.0f, 1.0f
8688 static const struct
8690 DWORD pos_type;
8691 void *quad;
8692 D3DMATRIX *matrix;
8693 union
8695 float f;
8696 DWORD d;
8697 } start, end;
8698 D3DFOGMODE vfog, tfog;
8699 DWORD color, color_broken, color_broken2;
8701 tests[] =
8703 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
8705 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
8706 {D3DFVF_XYZRHW, tquad, &identity, { 0.0f}, {1.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
8707 0x00ff0000, 0x00808000, 0x00808000},
8708 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
8709 * parameters to 0.0 and 1.0 in the table fog case. */
8710 {D3DFVF_XYZRHW, tquad, &identity, {-1.0f}, {0.0f}, D3DFOG_NONE, D3DFOG_LINEAR,
8711 0x00808000, 0x00ff0000, 0x0000ff00},
8712 /* test_fog_interpolation shows that vertex fog evaluates the fog
8713 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
8714 * that the abs happens before the fog equation is evaluated.
8716 * Vertex fog abs() behavior is the same on all GPUs. */
8717 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
8718 0x00808000, 0x00808000, 0x00808000},
8719 {D3DFVF_XYZ, quad, &zero, {-1.0f}, {0.0f}, D3DFOG_LINEAR, D3DFOG_NONE,
8720 0x0000ff00, 0x0000ff00, 0x0000ff00},
8721 {D3DFVF_XYZ, quad, &zero, { 0.0f}, {1.0f}, D3DFOG_EXP, D3DFOG_NONE,
8722 0x009b6400, 0x009b6400, 0x009b6400},
8724 D3DDEVICEDESC7 caps;
8726 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8727 0, 0, 640, 480, 0, 0, 0, 0);
8729 if (!(device = create_device(window, DDSCL_NORMAL)))
8731 skip("Failed to create a 3D device, skipping test.\n");
8732 DestroyWindow(window);
8733 return;
8736 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8737 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8738 hr = IDirect3DDevice7_GetCaps(device, &caps);
8739 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8740 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
8741 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
8743 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
8744 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8745 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
8746 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8747 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
8748 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8749 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
8750 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8751 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
8752 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
8754 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
8756 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE) && tests[i].tfog)
8757 continue;
8759 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
8760 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8762 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, tests[i].matrix);
8763 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
8764 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGSTART, tests[i].start.d);
8765 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8766 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGEND, tests[i].end.d);
8767 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8768 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGVERTEXMODE, tests[i].vfog);
8769 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8770 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, tests[i].tfog);
8771 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8773 hr = IDirect3DDevice7_BeginScene(device);
8774 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8775 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8776 tests[i].pos_type | D3DFVF_DIFFUSE, tests[i].quad, 4, 0);
8777 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8778 hr = IDirect3DDevice7_EndScene(device);
8779 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8781 color = get_surface_color(rt, 0, 240);
8782 ok(compare_color(color, tests[i].color, 2) || broken(compare_color(color, tests[i].color_broken, 2))
8783 || broken(compare_color(color, tests[i].color_broken2, 2)),
8784 "Got unexpected color 0x%08x, case %u.\n", color, i);
8787 IDirectDrawSurface7_Release(rt);
8788 refcount = IDirect3DDevice7_Release(device);
8789 ok(!refcount, "Device has %u references left.\n", refcount);
8790 DestroyWindow(window);
8793 static void test_table_fog_zw(void)
8795 HRESULT hr;
8796 IDirect3DDevice7 *device;
8797 IDirectDrawSurface7 *rt;
8798 ULONG refcount;
8799 HWND window;
8800 D3DCOLOR color;
8801 static struct
8803 struct vec4 position;
8804 D3DCOLOR diffuse;
8806 quad[] =
8808 {{ 0.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
8809 {{640.0f, 0.0f, 0.0f, 0.0f}, 0xffff0000},
8810 {{ 0.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
8811 {{640.0f, 480.0f, 0.0f, 0.0f}, 0xffff0000},
8813 static D3DMATRIX identity =
8815 1.0f, 0.0f, 0.0f, 0.0f,
8816 0.0f, 1.0f, 0.0f, 0.0f,
8817 0.0f, 0.0f, 1.0f, 0.0f,
8818 0.0f, 0.0f, 0.0f, 1.0f
8820 D3DDEVICEDESC7 caps;
8821 static const struct
8823 float z, w;
8824 D3DZBUFFERTYPE z_test;
8825 D3DCOLOR color;
8827 tests[] =
8829 {0.7f, 0.0f, D3DZB_TRUE, 0x004cb200},
8830 {0.7f, 0.0f, D3DZB_FALSE, 0x004cb200},
8831 {0.7f, 0.3f, D3DZB_TRUE, 0x004cb200},
8832 {0.7f, 0.3f, D3DZB_FALSE, 0x004cb200},
8833 {0.7f, 3.0f, D3DZB_TRUE, 0x004cb200},
8834 {0.7f, 3.0f, D3DZB_FALSE, 0x004cb200},
8835 {0.3f, 0.0f, D3DZB_TRUE, 0x00b24c00},
8836 {0.3f, 0.0f, D3DZB_FALSE, 0x00b24c00},
8838 unsigned int i;
8840 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
8841 0, 0, 640, 480, 0, 0, 0, 0);
8843 if (!(device = create_device(window, DDSCL_NORMAL)))
8845 skip("Failed to create a 3D device, skipping test.\n");
8846 DestroyWindow(window);
8847 return;
8850 hr = IDirect3DDevice7_GetCaps(device, &caps);
8851 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8852 if (!(caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGTABLE))
8854 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
8855 goto done;
8857 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
8858 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8860 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
8861 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8862 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, TRUE);
8863 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8864 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGCOLOR, 0x0000ff00);
8865 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8866 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_CLIPPING, FALSE);
8867 ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
8868 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
8869 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
8870 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
8871 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_LINEAR);
8872 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8874 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
8876 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0);
8877 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8879 quad[0].position.z = tests[i].z;
8880 quad[1].position.z = tests[i].z;
8881 quad[2].position.z = tests[i].z;
8882 quad[3].position.z = tests[i].z;
8883 quad[0].position.w = tests[i].w;
8884 quad[1].position.w = tests[i].w;
8885 quad[2].position.w = tests[i].w;
8886 quad[3].position.w = tests[i].w;
8887 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, tests[i].z_test);
8888 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8890 hr = IDirect3DDevice7_BeginScene(device);
8891 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8892 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
8893 D3DFVF_XYZRHW | D3DFVF_DIFFUSE, quad, 4, 0);
8894 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8895 hr = IDirect3DDevice7_EndScene(device);
8896 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8898 color = get_surface_color(rt, 0, 240);
8899 ok(compare_color(color, tests[i].color, 2),
8900 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color, tests[i].color, i);
8903 IDirectDrawSurface7_Release(rt);
8904 done:
8905 refcount = IDirect3DDevice7_Release(device);
8906 ok(!refcount, "Device has %u references left.\n", refcount);
8907 DestroyWindow(window);
8910 static void test_signed_formats(void)
8912 HRESULT hr;
8913 IDirect3DDevice7 *device;
8914 IDirect3D7 *d3d;
8915 IDirectDraw7 *ddraw;
8916 IDirectDrawSurface7 *surface, *rt;
8917 DDSURFACEDESC2 surface_desc;
8918 ULONG refcount;
8919 HWND window;
8920 D3DCOLOR color, expected_color;
8921 static struct
8923 struct vec3 position;
8924 struct vec2 texcoord;
8926 quad[] =
8928 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
8929 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
8930 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
8931 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
8933 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
8934 * of these values. */
8935 static const USHORT content_v8u8[4][4] =
8937 {0x0000, 0x7f7f, 0x8880, 0x0000},
8938 {0x0080, 0x8000, 0x7f00, 0x007f},
8939 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
8940 {0x4444, 0xc0c0, 0xa066, 0x22e0},
8942 static const DWORD content_x8l8v8u8[4][4] =
8944 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
8945 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
8946 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
8947 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
8949 static const USHORT content_l6v5u5[4][4] =
8951 {0x0000, 0xfdef, 0x0230, 0xfc00},
8952 {0x0010, 0x0200, 0x01e0, 0x000f},
8953 {0x4067, 0x53b9, 0x0421, 0xffff},
8954 {0x8108, 0x0318, 0xc28c, 0x909c},
8956 static const struct
8958 const char *name;
8959 const void *content;
8960 SIZE_T pixel_size;
8961 BOOL blue;
8962 unsigned int slop, slop_broken;
8963 DDPIXELFORMAT format;
8965 formats[] =
8968 "D3DFMT_V8U8", content_v8u8, sizeof(WORD), FALSE, 1, 0,
8970 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV, 0,
8971 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
8975 "D3DFMT_X8L8V8U8", content_x8l8v8u8, sizeof(DWORD), TRUE, 1, 0,
8977 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
8978 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
8982 "D3DFMT_L6V5U5", content_l6v5u5, sizeof(WORD), TRUE, 4, 7,
8984 sizeof(DDPIXELFORMAT), DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE, 0,
8985 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
8989 /* No V16U16 or Q8W8V8U8 support in ddraw. */
8991 static const D3DCOLOR expected_colors[4][4] =
8993 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
8994 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
8995 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
8996 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
8998 unsigned int i, width, x, y;
8999 D3DDEVICEDESC7 device_desc;
9001 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9002 0, 0, 640, 480, 0, 0, 0, 0);
9004 if (!(device = create_device(window, DDSCL_NORMAL)))
9006 skip("Failed to create a 3D device, skipping test.\n");
9007 DestroyWindow(window);
9008 return;
9011 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
9012 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9013 if (!(device_desc.dwTextureOpCaps & D3DTEXOPCAPS_BLENDFACTORALPHA))
9015 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9016 goto done;
9019 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9020 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9021 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9022 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9023 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9024 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9026 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9027 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9029 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9030 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x80ffffff);
9031 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9032 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
9033 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9034 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9035 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9036 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
9037 ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr);
9039 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
9041 for (width = 1; width < 5; width += 3)
9043 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
9044 ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
9046 memset(&surface_desc, 0, sizeof(surface_desc));
9047 surface_desc.dwSize = sizeof(surface_desc);
9048 surface_desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
9049 surface_desc.dwWidth = width;
9050 surface_desc.dwHeight = 4;
9051 U4(surface_desc).ddpfPixelFormat = formats[i].format;
9052 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
9053 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9054 if (FAILED(hr))
9056 skip("%s textures not supported, skipping.\n", formats[i].name);
9057 continue;
9059 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, format %s.\n", hr, formats[i].name);
9060 hr = IDirect3DDevice7_SetTexture(device, 0, surface);
9061 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x, format %s.\n", hr, formats[i].name);
9063 memset(&surface_desc, 0, sizeof(surface_desc));
9064 surface_desc.dwSize = sizeof(surface_desc);
9065 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, 0, NULL);
9066 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, format %s.\n", hr, formats[i].name);
9067 for (y = 0; y < 4; y++)
9069 memcpy((char *)surface_desc.lpSurface + y * U1(surface_desc).lPitch,
9070 (char *)formats[i].content + y * 4 * formats[i].pixel_size,
9071 width * formats[i].pixel_size);
9073 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9074 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, format %s.\n", hr, formats[i].name);
9076 hr = IDirect3DDevice7_BeginScene(device);
9077 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9078 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
9079 D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
9080 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9081 hr = IDirect3DDevice7_EndScene(device);
9082 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9084 for (y = 0; y < 4; y++)
9086 for (x = 0; x < width; x++)
9088 expected_color = expected_colors[y][x];
9089 if (!formats[i].blue)
9090 expected_color |= 0x000000ff;
9092 color = get_surface_color(rt, 80 + 160 * x, 60 + 120 * y);
9093 ok(compare_color(color, expected_color, formats[i].slop)
9094 || broken(compare_color(color, expected_color, formats[i].slop_broken)),
9095 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9096 expected_color, color, formats[i].name, x, y);
9100 IDirectDrawSurface7_Release(surface);
9105 IDirectDrawSurface7_Release(rt);
9106 IDirectDraw7_Release(ddraw);
9107 IDirect3D7_Release(d3d);
9109 done:
9110 refcount = IDirect3DDevice7_Release(device);
9111 ok(!refcount, "Device has %u references left.\n", refcount);
9112 DestroyWindow(window);
9115 static void test_color_fill(void)
9117 HRESULT hr;
9118 IDirect3DDevice7 *device;
9119 IDirect3D7 *d3d;
9120 IDirectDraw7 *ddraw;
9121 IDirectDrawSurface7 *surface, *surface2;
9122 DDSURFACEDESC2 surface_desc;
9123 DDPIXELFORMAT z_fmt;
9124 ULONG refcount;
9125 HWND window;
9126 unsigned int i;
9127 DDBLTFX fx;
9128 RECT rect = {5, 5, 7, 7};
9129 DWORD *color;
9130 DWORD supported_fmts = 0, num_fourcc_codes, *fourcc_codes;
9131 DDCAPS hal_caps;
9132 static const struct
9134 DWORD caps, caps2;
9135 HRESULT colorfill_hr, depthfill_hr;
9136 BOOL rop_success;
9137 const char *name;
9138 DWORD result;
9139 BOOL check_result;
9140 DDPIXELFORMAT format;
9142 tests[] =
9145 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9146 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE,
9148 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9149 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9153 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9154 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE,
9156 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9157 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9161 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9162 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem texture RGB", 0xdeadbeef, TRUE,
9164 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9165 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9169 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9170 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem texture RGB", 0xdeadbeef, TRUE,
9172 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9173 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9177 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
9178 DD_OK, DDERR_INVALIDPARAMS, TRUE, "managed texture RGB", 0xdeadbeef, TRUE,
9180 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9181 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9185 DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY, 0,
9186 DDERR_INVALIDPARAMS, DD_OK, TRUE, "vidmem zbuffer", 0, FALSE,
9187 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9190 DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY, 0,
9191 DDERR_INVALIDPARAMS, DD_OK, TRUE, "sysmem zbuffer", 0, FALSE,
9192 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9195 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9196 * different afterwards. DX9+ GPUs set one of the two luminance values
9197 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9198 * value they set. r200 (dx8) just sets the entire block to the clear
9199 * value. */
9200 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9201 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain YUY2", 0, FALSE,
9203 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9204 {0}, {0}, {0}, {0}, {0}
9208 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9209 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem offscreenplain UYVY", 0, FALSE,
9211 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9212 {0}, {0}, {0}, {0}, {0}
9216 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9217 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay YUY2", 0, FALSE,
9219 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'),
9220 {0}, {0}, {0}, {0}, {0}
9224 DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY, 0,
9225 DD_OK, DDERR_INVALIDPARAMS, FALSE, "vidmem overlay UYVY", 0, FALSE,
9227 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9228 {0}, {0}, {0}, {0}, {0}
9232 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0,
9233 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "vidmem texture DXT1", 0, FALSE,
9235 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9236 {0}, {0}, {0}, {0}, {0}
9240 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0,
9241 E_NOTIMPL, DDERR_INVALIDPARAMS, FALSE, "sysmem texture DXT1", 0, FALSE,
9243 sizeof(DDPIXELFORMAT), DDPF_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'),
9244 {0}, {0}, {0}, {0}, {0}
9248 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9249 * surface works, presumably because it is handled by the runtime instead of
9250 * the driver. */
9251 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
9252 DD_OK, DDERR_INVALIDPARAMS, TRUE, "vidmem offscreenplain P8", 0xefefefef, FALSE,
9254 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9255 {8}, {0}, {0}, {0}, {0}
9259 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
9260 DD_OK, DDERR_INVALIDPARAMS, TRUE, "sysmem offscreenplain P8", 0xefefefef, TRUE,
9262 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_PALETTEINDEXED8, 0,
9263 {8}, {0}, {0}, {0}, {0}
9267 static const struct
9269 DWORD rop;
9270 const char *name;
9271 HRESULT hr;
9273 rops[] =
9275 {SRCCOPY, "SRCCOPY", DD_OK},
9276 {SRCPAINT, "SRCPAINT", DDERR_NORASTEROPHW},
9277 {SRCAND, "SRCAND", DDERR_NORASTEROPHW},
9278 {SRCINVERT, "SRCINVERT", DDERR_NORASTEROPHW},
9279 {SRCERASE, "SRCERASE", DDERR_NORASTEROPHW},
9280 {NOTSRCCOPY, "NOTSRCCOPY", DDERR_NORASTEROPHW},
9281 {NOTSRCERASE, "NOTSRCERASE", DDERR_NORASTEROPHW},
9282 {MERGECOPY, "MERGECOPY", DDERR_NORASTEROPHW},
9283 {MERGEPAINT, "MERGEPAINT", DDERR_NORASTEROPHW},
9284 {PATCOPY, "PATCOPY", DDERR_NORASTEROPHW},
9285 {PATPAINT, "PATPAINT", DDERR_NORASTEROPHW},
9286 {PATINVERT, "PATINVERT", DDERR_NORASTEROPHW},
9287 {DSTINVERT, "DSTINVERT", DDERR_NORASTEROPHW},
9288 {BLACKNESS, "BLACKNESS", DD_OK},
9289 {WHITENESS, "WHITENESS", DD_OK},
9290 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW} /* noop */
9293 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9294 0, 0, 640, 480, 0, 0, 0, 0);
9296 if (!(device = create_device(window, DDSCL_NORMAL)))
9298 skip("Failed to create a 3D device, skipping test.\n");
9299 DestroyWindow(window);
9300 return;
9303 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9304 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
9305 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9306 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
9308 memset(&z_fmt, 0, sizeof(z_fmt));
9309 IDirect3D7_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
9310 if (!z_fmt.dwSize)
9311 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9313 IDirect3DDevice7_EnumTextureFormats(device, test_block_formats_creation_cb, &supported_fmts);
9314 if (!(supported_fmts & SUPPORT_DXT1))
9315 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9317 IDirect3D7_Release(d3d);
9319 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
9320 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9321 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
9322 num_fourcc_codes * sizeof(*fourcc_codes));
9323 if (!fourcc_codes)
9324 goto done;
9325 hr = IDirectDraw7_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
9326 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
9327 for (i = 0; i < num_fourcc_codes; i++)
9329 if (fourcc_codes[i] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9330 supported_fmts |= SUPPORT_YUY2;
9331 else if (fourcc_codes[i] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9332 supported_fmts |= SUPPORT_UYVY;
9334 HeapFree(GetProcessHeap(), 0, fourcc_codes);
9336 memset(&hal_caps, 0, sizeof(hal_caps));
9337 hal_caps.dwSize = sizeof(hal_caps);
9338 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
9339 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
9341 if (!(supported_fmts & (SUPPORT_YUY2 | SUPPORT_UYVY)) || !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9342 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9344 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
9346 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9347 memset(&fx, 0, sizeof(fx));
9348 fx.dwSize = sizeof(fx);
9349 U5(fx).dwFillColor = 0xdeadbeef;
9351 memset(&surface_desc, 0, sizeof(surface_desc));
9352 surface_desc.dwSize = sizeof(surface_desc);
9353 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9354 surface_desc.dwWidth = 64;
9355 surface_desc.dwHeight = 64;
9356 U4(surface_desc).ddpfPixelFormat = tests[i].format;
9357 surface_desc.ddsCaps.dwCaps = tests[i].caps;
9358 surface_desc.ddsCaps.dwCaps2 = tests[i].caps2;
9360 if (tests[i].format.dwFourCC == MAKEFOURCC('D','X','T','1') && !(supported_fmts & SUPPORT_DXT1))
9361 continue;
9362 if (tests[i].format.dwFourCC == MAKEFOURCC('Y','U','Y','2') && !(supported_fmts & SUPPORT_YUY2))
9363 continue;
9364 if (tests[i].format.dwFourCC == MAKEFOURCC('U','Y','V','Y') && !(supported_fmts & SUPPORT_UYVY))
9365 continue;
9366 if (tests[i].caps & DDSCAPS_OVERLAY && !(hal_caps.dwCaps & DDCAPS_OVERLAY))
9367 continue;
9369 if (tests[i].caps & DDSCAPS_ZBUFFER)
9371 if (!z_fmt.dwSize)
9372 continue;
9374 U4(surface_desc).ddpfPixelFormat = z_fmt;
9377 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9378 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, surface %s.\n", hr, tests[i].name);
9380 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9381 if (tests[i].format.dwFourCC)
9382 todo_wine ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9383 hr, tests[i].colorfill_hr, tests[i].name);
9384 else
9385 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9386 hr, tests[i].colorfill_hr, tests[i].name);
9388 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9389 if (tests[i].format.dwFourCC)
9390 todo_wine ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9391 hr, tests[i].colorfill_hr, tests[i].name);
9392 else
9393 ok(hr == tests[i].colorfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9394 hr, tests[i].colorfill_hr, tests[i].name);
9396 if (SUCCEEDED(hr) && tests[i].check_result)
9398 memset(&surface_desc, 0, sizeof(surface_desc));
9399 surface_desc.dwSize = sizeof(surface_desc);
9400 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9401 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9402 color = surface_desc.lpSurface;
9403 ok(*color == tests[i].result, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9404 *color, tests[i].result, tests[i].name);
9405 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9406 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9409 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9410 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9411 hr, tests[i].depthfill_hr, tests[i].name);
9412 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9413 ok(hr == tests[i].depthfill_hr, "Blt returned %#x, expected %#x, surface %s.\n",
9414 hr, tests[i].depthfill_hr, tests[i].name);
9416 U5(fx).dwFillColor = 0xdeadbeef;
9417 fx.dwROP = BLACKNESS;
9418 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9419 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9420 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9421 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9422 U5(fx).dwFillColor, tests[i].name);
9424 if (SUCCEEDED(hr) && tests[i].check_result)
9426 memset(&surface_desc, 0, sizeof(surface_desc));
9427 surface_desc.dwSize = sizeof(surface_desc);
9428 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9429 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9430 color = surface_desc.lpSurface;
9431 ok(*color == 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9432 *color, tests[i].name);
9433 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9434 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9437 fx.dwROP = WHITENESS;
9438 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9439 ok(FAILED(hr) == !tests[i].rop_success, "Blt returned %#x, expected %s, surface %s.\n",
9440 hr, tests[i].rop_success ? "success" : "failure", tests[i].name);
9441 ok(U5(fx).dwFillColor == 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9442 U5(fx).dwFillColor, tests[i].name);
9444 if (SUCCEEDED(hr) && tests[i].check_result)
9446 memset(&surface_desc, 0, sizeof(surface_desc));
9447 surface_desc.dwSize = sizeof(surface_desc);
9448 hr = IDirectDrawSurface7_Lock(surface, NULL, &surface_desc, DDLOCK_READONLY, 0);
9449 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9450 color = surface_desc.lpSurface;
9451 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9452 ok((*color & 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9453 *color, tests[i].name);
9454 hr = IDirectDrawSurface7_Unlock(surface, NULL);
9455 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, surface %s.\n", hr, tests[i].name);
9458 IDirectDrawSurface7_Release(surface);
9461 memset(&fx, 0, sizeof(fx));
9462 fx.dwSize = sizeof(fx);
9463 U5(fx).dwFillColor = 0xdeadbeef;
9464 fx.dwROP = WHITENESS;
9466 memset(&surface_desc, 0, sizeof(surface_desc));
9467 surface_desc.dwSize = sizeof(surface_desc);
9468 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9469 surface_desc.dwWidth = 64;
9470 surface_desc.dwHeight = 64;
9471 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
9472 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
9473 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
9474 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
9475 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
9476 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
9477 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
9478 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9479 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9480 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9481 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9483 /* No DDBLTFX. */
9484 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, NULL);
9485 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9486 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, NULL);
9487 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9489 /* Unused source rectangle. */
9490 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9491 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9492 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9493 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9495 /* Unused source surface. */
9496 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9497 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9498 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9499 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9500 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9501 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9502 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9503 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9505 /* Inverted destination or source rectangle. */
9506 SetRect(&rect, 5, 7, 7, 5);
9507 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9508 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9509 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9510 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9511 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9512 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9513 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9514 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9515 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9516 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9518 /* Negative rectangle. */
9519 SetRect(&rect, -1, -1, 5, 5);
9520 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9521 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9522 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9523 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9524 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9525 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9526 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9527 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9528 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9529 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9531 /* Out of bounds rectangle. */
9532 SetRect(&rect, 0, 0, 65, 65);
9533 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9534 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9535 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_ROP | DDBLT_WAIT, &fx);
9536 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9538 /* Combine multiple flags. */
9539 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9540 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9541 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
9542 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9543 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_ROP | DDBLT_WAIT, &fx);
9544 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9546 for (i = 0; i < sizeof(rops) / sizeof(*rops); i++)
9548 fx.dwROP = rops[i].rop;
9549 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_ROP | DDBLT_WAIT, &fx);
9550 ok(hr == rops[i].hr, "Got unexpected hr %#x for rop %s.\n", hr, rops[i].name);
9553 IDirectDrawSurface7_Release(surface2);
9554 IDirectDrawSurface7_Release(surface);
9556 if (!z_fmt.dwSize)
9557 goto done;
9559 memset(&surface_desc, 0, sizeof(surface_desc));
9560 surface_desc.dwSize = sizeof(surface_desc);
9561 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9562 surface_desc.dwWidth = 64;
9563 surface_desc.dwHeight = 64;
9564 U4(surface_desc).ddpfPixelFormat = z_fmt;
9565 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
9566 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
9567 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9568 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
9569 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9571 /* No DDBLTFX. */
9572 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, NULL);
9573 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9575 /* Unused source rectangle. */
9576 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9577 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9579 /* Unused source surface. */
9580 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9581 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9582 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9583 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9585 /* Inverted destination or source rectangle. */
9586 SetRect(&rect, 5, 7, 7, 5);
9587 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9588 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9589 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9590 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9591 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9592 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9593 hr = IDirectDrawSurface7_Blt(surface, NULL, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9594 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9596 /* Negative rectangle. */
9597 SetRect(&rect, -1, -1, 5, 5);
9598 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9599 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9600 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9601 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
9602 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9603 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9604 hr = IDirectDrawSurface7_Blt(surface, &rect, surface2, &rect, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9605 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9607 /* Out of bounds rectangle. */
9608 SetRect(&rect, 0, 0, 65, 65);
9609 hr = IDirectDrawSurface7_Blt(surface, &rect, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9610 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
9612 /* Combine multiple flags. */
9613 hr = IDirectDrawSurface7_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
9614 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
9616 IDirectDrawSurface7_Release(surface2);
9617 IDirectDrawSurface7_Release(surface);
9619 done:
9620 IDirectDraw7_Release(ddraw);
9621 refcount = IDirect3DDevice7_Release(device);
9622 ok(!refcount, "Device has %u references left.\n", refcount);
9623 DestroyWindow(window);
9626 static void test_texcoordindex(void)
9628 static D3DMATRIX mat =
9630 1.0f, 0.0f, 0.0f, 0.0f,
9631 0.0f, 0.0f, 0.0f, 0.0f,
9632 0.0f, 0.0f, 0.0f, 0.0f,
9633 0.0f, 0.0f, 0.0f, 0.0f,
9635 static struct
9637 struct vec3 pos;
9638 struct vec2 texcoord1;
9639 struct vec2 texcoord2;
9640 struct vec2 texcoord3;
9642 quad[] =
9644 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f}},
9645 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 0.0f}},
9646 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}},
9647 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}},
9649 static const DWORD fvf = D3DFVF_XYZ | D3DFVF_TEX3;
9650 IDirect3DDevice7 *device;
9651 IDirect3D7 *d3d;
9652 IDirectDraw7 *ddraw;
9653 IDirectDrawSurface7 *rt;
9654 HWND window;
9655 HRESULT hr;
9656 IDirectDrawSurface7 *texture1, *texture2;
9657 DDSURFACEDESC2 surface_desc;
9658 ULONG refcount;
9659 D3DCOLOR color;
9660 DWORD *ptr;
9662 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9663 0, 0, 640, 480, 0, 0, 0, 0);
9664 if (!(device = create_device(window, DDSCL_NORMAL)))
9666 skip("Failed to create a 3D device, skipping test.\n");
9667 DestroyWindow(window);
9668 return;
9671 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9672 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
9673 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9674 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
9675 IDirect3D7_Release(d3d);
9677 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9678 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9680 memset(&surface_desc, 0, sizeof(surface_desc));
9681 surface_desc.dwSize = sizeof(surface_desc);
9682 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9683 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
9684 surface_desc.dwWidth = 2;
9685 surface_desc.dwHeight = 2;
9686 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
9687 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
9688 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
9689 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
9690 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
9691 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
9692 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
9693 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture1, NULL);
9694 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9695 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture2, NULL);
9696 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9698 memset(&surface_desc, 0, sizeof(surface_desc));
9699 surface_desc.dwSize = sizeof(surface_desc);
9700 hr = IDirectDrawSurface7_Lock(texture1, 0, &surface_desc, 0, NULL);
9701 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9702 ptr = surface_desc.lpSurface;
9703 ptr[0] = 0xff000000;
9704 ptr[1] = 0xff00ff00;
9705 ptr += surface_desc.lPitch / sizeof(*ptr);
9706 ptr[0] = 0xff0000ff;
9707 ptr[1] = 0xff00ffff;
9708 hr = IDirectDrawSurface7_Unlock(texture1, NULL);
9709 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9711 memset(&surface_desc, 0, sizeof(surface_desc));
9712 surface_desc.dwSize = sizeof(surface_desc);
9713 hr = IDirectDrawSurface7_Lock(texture2, 0, &surface_desc, 0, NULL);
9714 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9715 ptr = surface_desc.lpSurface;
9716 ptr[0] = 0xff000000;
9717 ptr[1] = 0xff0000ff;
9718 ptr += surface_desc.lPitch / sizeof(*ptr);
9719 ptr[0] = 0xffff0000;
9720 ptr[1] = 0xffff00ff;
9721 hr = IDirectDrawSurface7_Unlock(texture2, 0);
9722 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
9724 hr = IDirect3DDevice7_SetTexture(device, 0, texture1);
9725 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
9726 hr = IDirect3DDevice7_SetTexture(device, 1, texture2);
9727 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
9728 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9729 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
9730 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
9731 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9732 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9733 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9734 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
9735 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9736 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9737 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9738 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_CURRENT);
9739 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9740 hr = IDirect3DDevice7_SetTextureStageState(device, 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
9741 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9743 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_TEXCOORDINDEX, 1);
9744 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
9745 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 0);
9746 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
9748 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE);
9749 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
9751 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
9752 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9754 hr = IDirect3DDevice7_BeginScene(device);
9755 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9756 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
9757 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9758 hr = IDirect3DDevice7_EndScene(device);
9759 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9761 color = get_surface_color(rt, 160, 120);
9762 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
9763 color = get_surface_color(rt, 480, 120);
9764 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
9765 color = get_surface_color(rt, 160, 360);
9766 ok(compare_color(color, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color);
9767 color = get_surface_color(rt, 480, 360);
9768 ok(compare_color(color, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color);
9770 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
9771 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
9772 hr = IDirect3DDevice7_SetTransform(device, D3DTRANSFORMSTATE_TEXTURE1, &mat);
9773 ok(SUCCEEDED(hr), "Failed to set transformation matrix, hr %#x.\n", hr);
9775 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
9776 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9778 hr = IDirect3DDevice7_BeginScene(device);
9779 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9780 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
9781 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9782 hr = IDirect3DDevice7_EndScene(device);
9783 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9785 color = get_surface_color(rt, 160, 120);
9786 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
9787 color = get_surface_color(rt, 480, 120);
9788 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
9789 color = get_surface_color(rt, 160, 360);
9790 ok(compare_color(color, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color);
9791 color = get_surface_color(rt, 480, 360);
9792 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
9794 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
9795 ok(SUCCEEDED(hr), "Failed to set texture transform flags, hr %#x.\n", hr);
9796 hr = IDirect3DDevice7_SetTextureStageState(device, 1, D3DTSS_TEXCOORDINDEX, 2);
9797 ok(SUCCEEDED(hr), "Failed to set texcoord index, hr %#x.\n", hr);
9799 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0);
9800 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9802 hr = IDirect3DDevice7_BeginScene(device);
9803 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9804 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, fvf, quad, 4, 0);
9805 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
9806 hr = IDirect3DDevice7_EndScene(device);
9807 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9809 color = get_surface_color(rt, 160, 120);
9810 ok(compare_color(color, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color);
9811 color = get_surface_color(rt, 480, 120);
9812 ok(compare_color(color, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color);
9813 color = get_surface_color(rt, 160, 360);
9814 ok(compare_color(color, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color);
9815 color = get_surface_color(rt, 480, 360);
9816 ok(compare_color(color, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color);
9818 IDirectDrawSurface7_Release(texture1);
9819 IDirectDrawSurface7_Release(texture2);
9821 IDirectDrawSurface7_Release(rt);
9822 IDirectDraw_Release(ddraw);
9823 refcount = IDirect3DDevice7_Release(device);
9824 ok(!refcount, "Device has %u references left.\n", refcount);
9825 DestroyWindow(window);
9828 static void test_colorkey_precision(void)
9830 static struct
9832 struct vec3 pos;
9833 struct vec2 texcoord;
9835 quad[] =
9837 {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
9838 {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
9839 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
9840 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
9842 IDirect3DDevice7 *device;
9843 IDirect3D7 *d3d;
9844 IDirectDraw7 *ddraw;
9845 IDirectDrawSurface7 *rt;
9846 HWND window;
9847 HRESULT hr;
9848 IDirectDrawSurface7 *src, *dst, *texture;
9849 DDSURFACEDESC2 surface_desc, lock_desc;
9850 ULONG refcount;
9851 D3DCOLOR color;
9852 unsigned int t, c;
9853 DDCOLORKEY ckey;
9854 DDBLTFX fx;
9855 DWORD data[4] = {0}, color_mask;
9856 D3DDEVICEDESC7 device_desc;
9857 BOOL warp;
9858 static const struct
9860 unsigned int max, shift, bpp, clear;
9861 const char *name;
9862 DDPIXELFORMAT fmt;
9864 tests[] =
9867 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9869 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
9870 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9875 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9877 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
9878 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9883 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9885 sizeof(DDPIXELFORMAT), DDPF_RGB, 0,
9886 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9891 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9893 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
9894 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9900 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
9901 0, 0, 640, 480, 0, 0, 0, 0);
9902 if (!(device = create_device(window, DDSCL_NORMAL)))
9904 skip("Failed to create a 3D device, skipping test.\n");
9905 DestroyWindow(window);
9906 return;
9909 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9910 * (color key doesn't match although the values are equal), and a false
9911 * positive when the color key is 0 and the texture contains the value 1.
9912 * I don't want to mark this broken unconditionally since this would
9913 * essentially disable the test on Windows. Try to detect WARP (and I
9914 * guess mismatch other SW renderers) by its ability to texture from
9915 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
9916 hr = IDirect3DDevice7_GetCaps(device, &device_desc);
9917 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
9918 warp = !!(device_desc.dwDevCaps & D3DDEVCAPS_TEXTURESYSTEMMEMORY);
9920 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
9921 ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
9922 hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
9923 ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
9924 IDirect3D7_Release(d3d);
9925 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
9926 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
9928 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
9929 ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
9930 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
9931 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
9932 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
9933 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
9934 /* Multiply the texture read result with 0, that way the result color if the key doesn't
9935 * match is constant. In theory color keying works without reading the texture result
9936 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
9937 * to differ. */
9938 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
9939 ok(SUCCEEDED(hr), "Failed to set color op, hr %#x.\n", hr);
9940 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
9941 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9942 hr = IDirect3DDevice7_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
9943 ok(SUCCEEDED(hr), "Failed to set color arg, hr %#x.\n", hr);
9944 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_TEXTUREFACTOR, 0x00000000);
9945 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9947 memset(&fx, 0, sizeof(fx));
9948 fx.dwSize = sizeof(fx);
9949 memset(&lock_desc, 0, sizeof(lock_desc));
9950 lock_desc.dwSize = sizeof(lock_desc);
9952 for (t = 0; t < sizeof(tests) / sizeof(*tests); ++t)
9954 memset(&surface_desc, 0, sizeof(surface_desc));
9955 surface_desc.dwSize = sizeof(surface_desc);
9956 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
9957 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
9958 surface_desc.dwWidth = 4;
9959 surface_desc.dwHeight = 1;
9960 U4(surface_desc).ddpfPixelFormat = tests[t].fmt;
9961 /* Windows XP (at least with the r200 driver, other drivers untested) produces
9962 * garbage when doing color keyed texture->texture blits. */
9963 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &src, NULL);
9964 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9965 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &dst, NULL);
9966 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9968 fx.dwFillColor = tests[t].clear;
9969 /* On the w8 testbot (WARP driver) the blit result has different values in the
9970 * X channel. */
9971 color_mask = U2(tests[t].fmt).dwRBitMask
9972 | U3(tests[t].fmt).dwGBitMask
9973 | U4(tests[t].fmt).dwBBitMask;
9975 for (c = 0; c <= tests[t].max; ++c)
9977 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
9978 * texture after it has been set once... */
9979 surface_desc.dwFlags |= DDSD_CKSRCBLT;
9980 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
9981 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = c << tests[t].shift;
9982 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = c << tests[t].shift;
9983 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &texture, NULL);
9984 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
9985 hr = IDirect3DDevice7_SetTexture(device, 0, texture);
9986 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
9988 hr = IDirectDrawSurface7_Blt(dst, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
9989 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
9991 hr = IDirectDrawSurface7_Lock(src, NULL, &lock_desc, DDLOCK_WAIT, NULL);
9992 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
9993 switch (tests[t].bpp)
9995 case 4:
9996 ((DWORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
9997 ((DWORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
9998 ((DWORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
9999 ((DWORD *)lock_desc.lpSurface)[3] = 0xffffffff;
10000 break;
10002 case 2:
10003 ((WORD *)lock_desc.lpSurface)[0] = (c ? c - 1 : 0) << tests[t].shift;
10004 ((WORD *)lock_desc.lpSurface)[1] = c << tests[t].shift;
10005 ((WORD *)lock_desc.lpSurface)[2] = min(c + 1, tests[t].max) << tests[t].shift;
10006 ((WORD *)lock_desc.lpSurface)[3] = 0xffff;
10007 break;
10009 hr = IDirectDrawSurface7_Unlock(src, 0);
10010 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10011 hr = IDirectDrawSurface7_Blt(texture, NULL, src, NULL, DDBLT_WAIT, NULL);
10012 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10014 ckey.dwColorSpaceLowValue = c << tests[t].shift;
10015 ckey.dwColorSpaceHighValue = c << tests[t].shift;
10016 hr = IDirectDrawSurface7_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
10017 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10019 hr = IDirectDrawSurface7_Blt(dst, NULL, src, NULL, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
10020 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
10022 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10023 hr = IDirectDrawSurface7_Lock(dst, NULL, &lock_desc, DDLOCK_WAIT, NULL);
10024 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
10025 switch (tests[t].bpp)
10027 case 4:
10028 data[0] = ((DWORD *)lock_desc.lpSurface)[0] & color_mask;
10029 data[1] = ((DWORD *)lock_desc.lpSurface)[1] & color_mask;
10030 data[2] = ((DWORD *)lock_desc.lpSurface)[2] & color_mask;
10031 data[3] = ((DWORD *)lock_desc.lpSurface)[3] & color_mask;
10032 break;
10034 case 2:
10035 data[0] = ((WORD *)lock_desc.lpSurface)[0] & color_mask;
10036 data[1] = ((WORD *)lock_desc.lpSurface)[1] & color_mask;
10037 data[2] = ((WORD *)lock_desc.lpSurface)[2] & color_mask;
10038 data[3] = ((WORD *)lock_desc.lpSurface)[3] & color_mask;
10039 break;
10041 hr = IDirectDrawSurface7_Unlock(dst, 0);
10042 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
10044 if (!c)
10046 ok(data[0] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10047 tests[t].clear, data[0], tests[t].name, c);
10049 if (data[3] == tests[t].clear)
10051 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10052 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10053 * even when a different surface is used. The blit itself doesn't draw anything,
10054 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10055 * never be masked out by the key.
10057 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10058 * terrible on WARP. */
10059 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10060 IDirectDrawSurface7_Release(texture);
10061 IDirectDrawSurface7_Release(src);
10062 IDirectDrawSurface7_Release(dst);
10063 goto done;
10066 else
10067 ok(data[0] == (c - 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10068 (c - 1) << tests[t].shift, data[0], tests[t].name, c);
10070 ok(data[1] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10071 tests[t].clear, data[1], tests[t].name, c);
10073 if (c == tests[t].max)
10074 ok(data[2] == tests[t].clear, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10075 tests[t].clear, data[2], tests[t].name, c);
10076 else
10077 ok(data[2] == (c + 1) << tests[t].shift, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10078 (c + 1) << tests[t].shift, data[2], tests[t].name, c);
10080 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 1.0f, 0);
10081 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
10083 hr = IDirect3DDevice7_BeginScene(device);
10084 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10085 hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_TEX1, quad, 4, 0);
10086 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10087 hr = IDirect3DDevice7_EndScene(device);
10088 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10090 color = get_surface_color(rt, 80, 240);
10091 if (!c)
10092 ok(compare_color(color, 0x0000ff00, 1) || broken(warp && compare_color(color, 0x00000000, 1)),
10093 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10094 color, tests[t].name, c);
10095 else
10096 ok(compare_color(color, 0x00000000, 1) || broken(warp && compare_color(color, 0x0000ff00, 1)),
10097 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10098 color, tests[t].name, c);
10100 color = get_surface_color(rt, 240, 240);
10101 ok(compare_color(color, 0x0000ff00, 1) || broken(warp && compare_color(color, 0x00000000, 1)),
10102 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10103 color, tests[t].name, c);
10105 color = get_surface_color(rt, 400, 240);
10106 if (c == tests[t].max)
10107 ok(compare_color(color, 0x0000ff00, 1) || broken(warp && compare_color(color, 0x00000000, 1)),
10108 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10109 color, tests[t].name, c);
10110 else
10111 ok(compare_color(color, 0x00000000, 1) || broken(warp && compare_color(color, 0x0000ff00, 1)),
10112 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10113 color, tests[t].name, c);
10115 IDirectDrawSurface7_Release(texture);
10117 IDirectDrawSurface7_Release(src);
10118 IDirectDrawSurface7_Release(dst);
10120 done:
10122 IDirectDrawSurface7_Release(rt);
10123 IDirectDraw7_Release(ddraw);
10124 refcount = IDirect3DDevice7_Release(device);
10125 ok(!refcount, "Device has %u references left.\n", refcount);
10126 DestroyWindow(window);
10129 static void test_range_colorkey(void)
10131 IDirectDraw7 *ddraw;
10132 HWND window;
10133 HRESULT hr;
10134 IDirectDrawSurface7 *surface;
10135 DDSURFACEDESC2 surface_desc;
10136 ULONG refcount;
10137 DDCOLORKEY ckey;
10139 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10140 0, 0, 640, 480, 0, 0, 0, 0);
10141 ddraw = create_ddraw();
10142 ok(!!ddraw, "Failed to create a ddraw object.\n");
10143 hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
10144 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
10146 memset(&surface_desc, 0, sizeof(surface_desc));
10147 surface_desc.dwSize = sizeof(surface_desc);
10148 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
10149 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
10150 surface_desc.dwWidth = 1;
10151 surface_desc.dwHeight = 1;
10152 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
10153 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
10154 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
10155 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
10156 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
10157 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0x00000000;
10159 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10160 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10161 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10162 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10163 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10165 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10166 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10167 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10168 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10170 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10171 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
10172 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10173 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000001;
10174 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10175 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10177 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000001;
10178 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10179 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10180 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10182 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00000000;
10183 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00000000;
10184 hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
10185 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
10187 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10188 ckey.dwColorSpaceLowValue = 0x00000000;
10189 ckey.dwColorSpaceHighValue = 0x00000001;
10190 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10191 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10193 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10194 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10195 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10196 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10198 ckey.dwColorSpaceLowValue = 0x00000001;
10199 ckey.dwColorSpaceHighValue = 0x00000000;
10200 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10201 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10203 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10204 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10205 ok(ckey.dwColorSpaceLowValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10206 ok(ckey.dwColorSpaceHighValue == 0x00000001, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10208 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10209 ckey.dwColorSpaceLowValue = 0x00000000;
10210 ckey.dwColorSpaceHighValue = 0x00000000;
10211 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10212 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
10214 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10215 ckey.dwColorSpaceLowValue = 0x00000001;
10216 ckey.dwColorSpaceHighValue = 0x00000000;
10217 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10218 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10219 ckey.dwColorSpaceLowValue = 0x00000000;
10220 ckey.dwColorSpaceHighValue = 0x00000001;
10221 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10222 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10223 /* Range destination keys don't work either. */
10224 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_DESTBLT | DDCKEY_COLORSPACE, &ckey);
10225 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10227 /* Just to show it's not because of A, R, and G having equal values. */
10228 ckey.dwColorSpaceLowValue = 0x00000000;
10229 ckey.dwColorSpaceHighValue = 0x01010101;
10230 hr = IDirectDrawSurface7_SetColorKey(surface, DDCKEY_SRCBLT | DDCKEY_COLORSPACE, &ckey);
10231 ok(hr == DDERR_NOCOLORKEYHW, "Got unexpected hr %#x.\n", hr);
10233 /* None of these operations modified the key. */
10234 hr = IDirectDrawSurface7_GetColorKey(surface, DDCKEY_SRCBLT, &ckey);
10235 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
10236 ok(!ckey.dwColorSpaceLowValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceLowValue);
10237 ok(!ckey.dwColorSpaceHighValue, "Got unexpected value 0x%08x.\n", ckey.dwColorSpaceHighValue);
10239 IDirectDrawSurface7_Release(surface),
10240 refcount = IDirectDraw7_Release(ddraw);
10241 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
10242 DestroyWindow(window);
10245 static void test_shademode(void)
10247 IDirect3DVertexBuffer7 *vb_strip, *vb_list, *buffer;
10248 IDirect3DDevice7 *device;
10249 D3DVERTEXBUFFERDESC desc;
10250 IDirectDrawSurface7 *rt;
10251 DWORD color0, color1;
10252 void *data = NULL;
10253 IDirect3D7 *d3d;
10254 ULONG refcount;
10255 UINT i, count;
10256 HWND window;
10257 HRESULT hr;
10258 static const struct
10260 struct vec3 position;
10261 DWORD diffuse;
10263 quad_strip[] =
10265 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10266 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10267 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10268 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10270 quad_list[] =
10272 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10273 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10274 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10276 {{ 1.0f, -1.0f, 0.0f}, 0xff0000ff},
10277 {{-1.0f, 1.0f, 0.0f}, 0xff00ff00},
10278 {{ 1.0f, 1.0f, 0.0f}, 0xffffffff},
10280 static const struct
10282 DWORD primtype;
10283 DWORD shademode;
10284 DWORD color0, color1;
10286 tests[] =
10288 {D3DPT_TRIANGLESTRIP, D3DSHADE_FLAT, 0x00ff0000, 0x0000ff00},
10289 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10290 {D3DPT_TRIANGLESTRIP, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10291 {D3DPT_TRIANGLESTRIP, D3DSHADE_PHONG, 0x000dca28, 0x000d45c7},
10292 {D3DPT_TRIANGLELIST, D3DSHADE_FLAT, 0x00ff0000, 0x000000ff},
10293 {D3DPT_TRIANGLELIST, D3DSHADE_GOURAUD, 0x000dca28, 0x000d45c7},
10296 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
10297 0, 0, 640, 480, 0, 0, 0, 0);
10299 if (!(device = create_device(window, DDSCL_NORMAL)))
10301 skip("Failed to create a 3D device, skipping test.\n");
10302 DestroyWindow(window);
10303 return;
10306 hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
10307 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
10308 hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
10309 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
10311 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
10312 ok(hr == D3D_OK, "Failed to disable lighting, hr %#x.\n", hr);
10313 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_FOGENABLE, FALSE);
10314 ok(SUCCEEDED(hr), "Failed to disable fog, hr %#x.\n", hr);
10316 memset(&desc, 0, sizeof(desc));
10317 desc.dwSize = sizeof(desc);
10318 desc.dwCaps = D3DVBCAPS_WRITEONLY;
10319 desc.dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
10320 desc.dwNumVertices = sizeof(quad_strip) / sizeof(*quad_strip);
10321 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_strip, 0);
10322 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10323 hr = IDirect3DVertexBuffer7_Lock(vb_strip, 0, &data, NULL);
10324 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10325 memcpy(data, quad_strip, sizeof(quad_strip));
10326 hr = IDirect3DVertexBuffer7_Unlock(vb_strip);
10327 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10329 desc.dwNumVertices = sizeof(quad_list) / sizeof(*quad_list);
10330 hr = IDirect3D7_CreateVertexBuffer(d3d, &desc, &vb_list, 0);
10331 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
10332 hr = IDirect3DVertexBuffer7_Lock(vb_list, 0, &data, NULL);
10333 ok(hr == D3D_OK, "Failed to lock vertex buffer, hr %#x.\n", hr);
10334 memcpy(data, quad_list, sizeof(quad_list));
10335 hr = IDirect3DVertexBuffer7_Unlock(vb_list);
10336 ok(hr == D3D_OK, "Failed to unlock vertex buffer, hr %#x.\n", hr);
10338 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10339 * the color fixups we have to do for FLAT shading will be dependent on that. */
10341 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
10343 hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
10344 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
10346 hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_SHADEMODE, tests[i].shademode);
10347 ok(hr == D3D_OK, "Failed to set shade mode, hr %#x.\n", hr);
10349 hr = IDirect3DDevice7_BeginScene(device);
10350 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
10351 buffer = tests[i].primtype == D3DPT_TRIANGLESTRIP ? vb_strip : vb_list;
10352 count = tests[i].primtype == D3DPT_TRIANGLESTRIP ? 4 : 6;
10353 hr = IDirect3DDevice7_DrawPrimitiveVB(device, tests[i].primtype, buffer, 0, count, 0);
10354 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
10355 hr = IDirect3DDevice7_EndScene(device);
10356 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
10358 color0 = get_surface_color(rt, 100, 100); /* Inside first triangle */
10359 color1 = get_surface_color(rt, 500, 350); /* Inside second triangle */
10361 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10362 * each triangle. This requires EXT_provoking_vertex or similar
10363 * functionality being available. */
10364 /* PHONG should be the same as GOURAUD, since no hardware implements
10365 * this. */
10366 ok(color0 == tests[i].color0, "Test %u shading has color0 %08x, expected %08x.\n",
10367 i, color0, tests[i].color0);
10368 ok(color1 == tests[i].color1, "Test %u shading has color1 %08x, expected %08x.\n",
10369 i, color1, tests[i].color1);
10372 IDirect3DVertexBuffer7_Release(vb_strip);
10373 IDirect3DVertexBuffer7_Release(vb_list);
10374 IDirectDrawSurface7_Release(rt);
10375 IDirect3D7_Release(d3d);
10376 refcount = IDirect3DDevice7_Release(device);
10377 ok(!refcount, "Device has %u references left.\n", refcount);
10378 DestroyWindow(window);
10381 START_TEST(ddraw7)
10383 HMODULE module = GetModuleHandleA("ddraw.dll");
10384 IDirectDraw7 *ddraw;
10385 DEVMODEW current_mode;
10387 if (!(pDirectDrawCreateEx = (void *)GetProcAddress(module, "DirectDrawCreateEx")))
10389 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
10390 return;
10393 if (!(ddraw = create_ddraw()))
10395 skip("Failed to create a ddraw object, skipping tests.\n");
10396 return;
10398 IDirectDraw7_Release(ddraw);
10400 memset(&current_mode, 0, sizeof(current_mode));
10401 current_mode.dmSize = sizeof(current_mode);
10402 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
10403 registry_mode.dmSize = sizeof(registry_mode);
10404 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
10405 if (registry_mode.dmPelsWidth != current_mode.dmPelsWidth
10406 || registry_mode.dmPelsHeight != current_mode.dmPelsHeight)
10408 skip("Current mode does not match registry mode, skipping test.\n");
10409 return;
10412 test_process_vertices();
10413 test_coop_level_create_device_window();
10414 test_clipper_blt();
10415 test_coop_level_d3d_state();
10416 test_surface_interface_mismatch();
10417 test_coop_level_threaded();
10418 test_depth_blit();
10419 test_texture_load_ckey();
10420 test_zenable();
10421 test_ck_rgba();
10422 test_ck_default();
10423 test_ck_complex();
10424 test_surface_qi();
10425 test_device_qi();
10426 test_wndproc();
10427 test_window_style();
10428 test_redundant_mode_set();
10429 test_coop_level_mode_set();
10430 test_coop_level_mode_set_multi();
10431 test_initialize();
10432 test_coop_level_surf_create();
10433 test_vb_discard();
10434 test_coop_level_multi_window();
10435 test_draw_strided();
10436 test_lighting();
10437 test_specular_lighting();
10438 test_clear_rect_count();
10439 test_coop_level_versions();
10440 test_fog_special();
10441 test_lighting_interface_versions();
10442 test_coop_level_activateapp();
10443 test_texturemanage();
10444 test_block_formats_creation();
10445 test_unsupported_formats();
10446 test_rt_caps();
10447 test_primary_caps();
10448 test_surface_lock();
10449 test_surface_discard();
10450 test_flip();
10451 test_set_surface_desc();
10452 test_user_memory_getdc();
10453 test_sysmem_overlay();
10454 test_primary_palette();
10455 test_surface_attachment();
10456 test_private_data();
10457 test_pixel_format();
10458 test_create_surface_pitch();
10459 test_mipmap_lock();
10460 test_palette_complex();
10461 test_p8_rgb_blit();
10462 test_material();
10463 test_palette_gdi();
10464 test_palette_alpha();
10465 test_vb_writeonly();
10466 test_lost_device();
10467 test_resource_priority();
10468 test_surface_desc_lock();
10469 test_fog_interpolation();
10470 test_negative_fixedfunction_fog();
10471 test_table_fog_zw();
10472 test_signed_formats();
10473 test_color_fill();
10474 test_texcoordindex();
10475 test_colorkey_precision();
10476 test_range_colorkey();
10477 test_shademode();