ddraw/tests: Test unsupported texture formats.
[wine.git] / dlls / ddraw / tests / ddraw4.c
blob485633f92c2539e25c63d7cf6ce97bddff36484f
1 /*
2 * Copyright 2011-2012 Henri Verbeet for CodeWeavers
3 * Copyright 2012-2013 Stefan Dösinger for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "wine/test.h"
22 #include <limits.h>
23 #include "d3d.h"
25 struct vec2
27 float x, y;
30 struct vec3
32 float x, y, z;
35 struct vec4
37 float x, y, z, w;
40 struct create_window_thread_param
42 HWND window;
43 HANDLE window_created;
44 HANDLE destroy_window;
45 HANDLE thread;
48 static BOOL compare_float(float f, float g, unsigned int ulps)
50 int x = *(int *)&f;
51 int y = *(int *)&g;
53 if (x < 0)
54 x = INT_MIN - x;
55 if (y < 0)
56 y = INT_MIN - y;
58 if (abs(x - y) > ulps)
59 return FALSE;
61 return TRUE;
64 static BOOL compare_vec4(struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
66 return compare_float(vec->x, x, ulps)
67 && compare_float(vec->y, y, ulps)
68 && compare_float(vec->z, z, ulps)
69 && compare_float(vec->w, w, ulps);
72 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
74 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
75 c1 >>= 8; c2 >>= 8;
76 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
77 c1 >>= 8; c2 >>= 8;
78 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
79 c1 >>= 8; c2 >>= 8;
80 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
81 return TRUE;
84 static DWORD WINAPI create_window_thread_proc(void *param)
86 struct create_window_thread_param *p = param;
87 DWORD res;
88 BOOL ret;
90 p->window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
91 0, 0, 640, 480, 0, 0, 0, 0);
92 ret = SetEvent(p->window_created);
93 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
95 for (;;)
97 MSG msg;
99 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
100 DispatchMessage(&msg);
101 res = WaitForSingleObject(p->destroy_window, 100);
102 if (res == WAIT_OBJECT_0)
103 break;
104 if (res != WAIT_TIMEOUT)
106 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
107 break;
111 DestroyWindow(p->window);
113 return 0;
116 static void create_window_thread(struct create_window_thread_param *p)
118 DWORD res, tid;
120 p->window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
121 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
122 p->destroy_window = CreateEvent(NULL, FALSE, FALSE, NULL);
123 ok(!!p->destroy_window, "CreateEvent failed, last error %#x.\n", GetLastError());
124 p->thread = CreateThread(NULL, 0, create_window_thread_proc, p, 0, &tid);
125 ok(!!p->thread, "Failed to create thread, last error %#x.\n", GetLastError());
126 res = WaitForSingleObject(p->window_created, INFINITE);
127 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
130 static void destroy_window_thread(struct create_window_thread_param *p)
132 SetEvent(p->destroy_window);
133 WaitForSingleObject(p->thread, INFINITE);
134 CloseHandle(p->destroy_window);
135 CloseHandle(p->window_created);
136 CloseHandle(p->thread);
139 static IDirectDrawSurface4 *get_depth_stencil(IDirect3DDevice3 *device)
141 IDirectDrawSurface4 *rt, *ret;
142 DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, 0};
143 HRESULT hr;
145 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
146 ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
147 hr = IDirectDrawSurface4_GetAttachedSurface(rt, &caps, &ret);
148 ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
149 IDirectDrawSurface4_Release(rt);
150 return ret;
153 static D3DCOLOR get_surface_color(IDirectDrawSurface4 *surface, UINT x, UINT y)
155 RECT rect = {x, y, x + 1, y + 1};
156 DDSURFACEDESC2 surface_desc;
157 D3DCOLOR color;
158 HRESULT hr;
160 memset(&surface_desc, 0, sizeof(surface_desc));
161 surface_desc.dwSize = sizeof(surface_desc);
163 hr = IDirectDrawSurface4_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
164 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
165 if (FAILED(hr))
166 return 0xdeadbeef;
168 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
170 hr = IDirectDrawSurface4_Unlock(surface, &rect);
171 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
173 return color;
176 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
178 DDPIXELFORMAT *z_fmt = ctx;
180 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
181 *z_fmt = *format;
183 return DDENUMRET_OK;
186 static IDirectDraw4 *create_ddraw(void)
188 IDirectDraw4 *ddraw4;
189 IDirectDraw *ddraw1;
190 HRESULT hr;
192 if (FAILED(DirectDrawCreate(NULL, &ddraw1, NULL)))
193 return NULL;
195 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw4);
196 IDirectDraw_Release(ddraw1);
197 if (FAILED(hr))
198 return NULL;
200 return ddraw4;
203 static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
205 IDirectDrawSurface4 *surface, *ds;
206 IDirect3DDevice3 *device = NULL;
207 DDSURFACEDESC2 surface_desc;
208 IDirectDraw4 *ddraw4;
209 DDPIXELFORMAT z_fmt;
210 IDirect3D3 *d3d3;
211 HRESULT hr;
213 if (!(ddraw4 = create_ddraw()))
214 return NULL;
216 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, coop_level);
217 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
219 memset(&surface_desc, 0, sizeof(surface_desc));
220 surface_desc.dwSize = sizeof(surface_desc);
221 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
222 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
223 surface_desc.dwWidth = 640;
224 surface_desc.dwHeight = 480;
226 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &surface, NULL);
227 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
229 if (coop_level & DDSCL_NORMAL)
231 IDirectDrawClipper *clipper;
233 hr = IDirectDraw4_CreateClipper(ddraw4, 0, &clipper, NULL);
234 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
235 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
236 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
237 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
238 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
239 IDirectDrawClipper_Release(clipper);
242 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirect3D3, (void **)&d3d3);
243 IDirectDraw4_Release(ddraw4);
244 if (FAILED(hr))
246 IDirectDrawSurface4_Release(surface);
247 return NULL;
250 memset(&z_fmt, 0, sizeof(z_fmt));
251 hr = IDirect3D3_EnumZBufferFormats(d3d3, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
252 if (FAILED(hr) || !z_fmt.dwSize)
254 IDirect3D3_Release(d3d3);
255 IDirectDrawSurface4_Release(surface);
256 return NULL;
259 memset(&surface_desc, 0, sizeof(surface_desc));
260 surface_desc.dwSize = sizeof(surface_desc);
261 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
262 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
263 U4(surface_desc).ddpfPixelFormat = z_fmt;
264 surface_desc.dwWidth = 640;
265 surface_desc.dwHeight = 480;
266 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &ds, NULL);
267 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
268 if (FAILED(hr))
270 IDirect3D3_Release(d3d3);
271 IDirectDrawSurface4_Release(surface);
272 return NULL;
275 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
276 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
277 IDirectDrawSurface4_Release(ds);
278 if (FAILED(hr))
280 IDirect3D3_Release(d3d3);
281 IDirectDrawSurface4_Release(surface);
282 return NULL;
285 hr = IDirect3D3_CreateDevice(d3d3, &IID_IDirect3DHALDevice, surface, &device, NULL);
286 IDirect3D3_Release(d3d3);
287 IDirectDrawSurface4_Release(surface);
288 if (FAILED(hr))
289 return NULL;
291 return device;
294 static IDirect3DViewport3 *create_viewport(IDirect3DDevice3 *device, UINT x, UINT y, UINT w, UINT h)
296 IDirect3DViewport3 *viewport;
297 D3DVIEWPORT2 vp;
298 IDirect3D3 *d3d;
299 HRESULT hr;
301 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
302 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
303 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
304 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
305 hr = IDirect3DDevice3_AddViewport(device, viewport);
306 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
307 memset(&vp, 0, sizeof(vp));
308 vp.dwSize = sizeof(vp);
309 vp.dwX = x;
310 vp.dwY = y;
311 vp.dwWidth = w;
312 vp.dwHeight = h;
313 vp.dvClipX = -1.0f;
314 vp.dvClipY = 1.0f;
315 vp.dvClipWidth = 2.0f;
316 vp.dvClipHeight = 2.0f;
317 vp.dvMinZ = 0.0f;
318 vp.dvMaxZ = 1.0f;
319 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
320 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
321 IDirect3D3_Release(d3d);
323 return viewport;
326 static void destroy_viewport(IDirect3DDevice3 *device, IDirect3DViewport3 *viewport)
328 HRESULT hr;
330 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
331 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
332 IDirect3DViewport3_Release(viewport);
335 static const UINT *expect_messages;
337 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
339 if (expect_messages && message == *expect_messages)
340 ++expect_messages;
342 return DefWindowProcA(hwnd, message, wparam, lparam);
345 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
346 * interface. This prevents subsequent SetCooperativeLevel() calls on a
347 * different window from failing with DDERR_HWNDALREADYSET. */
348 static void fix_wndproc(HWND window, LONG_PTR proc)
350 IDirectDraw4 *ddraw;
351 HRESULT hr;
353 if (!(ddraw = create_ddraw()))
354 return;
356 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
357 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
358 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
359 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
360 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
362 IDirectDraw4_Release(ddraw);
365 static void test_process_vertices(void)
367 IDirect3DVertexBuffer *src_vb, *dst_vb;
368 IDirect3DViewport3 *viewport;
369 D3DVERTEXBUFFERDESC vb_desc;
370 IDirect3DDevice3 *device;
371 struct vec3 *src_data;
372 struct vec4 *dst_data;
373 IDirect3D3 *d3d3;
374 D3DVIEWPORT2 vp2;
375 D3DVIEWPORT vp1;
376 HWND window;
377 HRESULT hr;
379 static D3DMATRIX identity =
381 1.0f, 0.0f, 0.0f, 0.0f,
382 0.0f, 1.0f, 0.0f, 0.0f,
383 0.0f, 0.0f, 1.0f, 0.0f,
384 0.0f, 0.0f, 0.0f, 1.0f,
386 static D3DMATRIX projection =
388 1.0f, 0.0f, 0.0f, 0.0f,
389 0.0f, 1.0f, 0.0f, 0.0f,
390 0.0f, 0.0f, 1.0f, 0.0f,
391 6.0f, 7.0f, 8.0f, 1.0f,
394 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
395 0, 0, 640, 480, 0, 0, 0, 0);
396 if (!(device = create_device(window, DDSCL_NORMAL)))
398 skip("Failed to create a 3D device, skipping test.\n");
399 DestroyWindow(window);
400 return;
403 hr = IDirect3DDevice3_GetDirect3D(device, &d3d3);
404 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
406 memset(&vb_desc, 0, sizeof(vb_desc));
407 vb_desc.dwSize = sizeof(vb_desc);
408 vb_desc.dwFVF = D3DFVF_XYZ;
409 vb_desc.dwNumVertices = 3;
410 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &src_vb, 0, NULL);
411 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
413 hr = IDirect3DVertexBuffer_Lock(src_vb, DDLOCK_WRITEONLY, (void **)&src_data, NULL);
414 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
415 src_data[0].x = -1.0f;
416 src_data[0].y = -1.0f;
417 src_data[0].z = -1.0f;
418 src_data[1].x = 0.0f;
419 src_data[1].y = 0.0f;
420 src_data[1].z = 0.0f;
421 src_data[2].x = 1.0f;
422 src_data[2].y = 1.0f;
423 src_data[2].z = 1.0f;
424 hr = IDirect3DVertexBuffer_Unlock(src_vb);
425 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
427 memset(&vb_desc, 0, sizeof(vb_desc));
428 vb_desc.dwSize = sizeof(vb_desc);
429 vb_desc.dwFVF = D3DFVF_XYZRHW;
430 vb_desc.dwNumVertices = 3;
431 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &dst_vb, 0, NULL);
432 ok(SUCCEEDED(hr), "Failed to create destination vertex buffer, hr %#x.\n", hr);
434 hr = IDirect3D3_CreateViewport(d3d3, &viewport, NULL);
435 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
436 hr = IDirect3DDevice3_AddViewport(device, viewport);
437 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
438 vp2.dwSize = sizeof(vp2);
439 vp2.dwX = 10;
440 vp2.dwY = 20;
441 vp2.dwWidth = 100;
442 vp2.dwHeight = 200;
443 vp2.dvClipX = 2.0f;
444 vp2.dvClipY = 3.0f;
445 vp2.dvClipWidth = 4.0f;
446 vp2.dvClipHeight = 5.0f;
447 vp2.dvMinZ = -2.0f;
448 vp2.dvMaxZ = 3.0f;
449 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
450 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
451 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
452 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
454 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
455 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#x.\n", hr);
456 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &identity);
457 ok(SUCCEEDED(hr), "Failed to set view transformation, hr %#x.\n", hr);
458 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
459 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
461 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
462 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
464 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
465 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
466 ok(compare_vec4(&dst_data[0], -6.500e+1f, +1.800e+2f, +2.000e-1f, +1.000e+0f, 4096),
467 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
468 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
469 ok(compare_vec4(&dst_data[1], -4.000e+1f, +1.400e+2f, +4.000e-1f, +1.000e+0f, 4096),
470 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
471 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
472 ok(compare_vec4(&dst_data[2], -1.500e+1f, +1.000e+2f, +6.000e-1f, +1.000e+0f, 4096),
473 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
474 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
475 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
476 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
478 hr = IDirect3DDevice3_MultiplyTransform(device, D3DTRANSFORMSTATE_PROJECTION, &projection);
479 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
481 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
482 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
484 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
485 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
486 ok(compare_vec4(&dst_data[0], +8.500e+1f, -1.000e+2f, +1.800e+0f, +1.000e+0f, 4096),
487 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
488 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
489 ok(compare_vec4(&dst_data[1], +1.100e+2f, -1.400e+2f, +2.000e+0f, +1.000e+0f, 4096),
490 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
491 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
492 ok(compare_vec4(&dst_data[2], +1.350e+2f, -1.800e+2f, +2.200e+0f, +1.000e+0f, 4096),
493 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
494 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
495 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
496 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
498 vp2.dwSize = sizeof(vp2);
499 vp2.dwX = 30;
500 vp2.dwY = 40;
501 vp2.dwWidth = 90;
502 vp2.dwHeight = 80;
503 vp2.dvClipX = 4.0f;
504 vp2.dvClipY = 6.0f;
505 vp2.dvClipWidth = 2.0f;
506 vp2.dvClipHeight = 4.0f;
507 vp2.dvMinZ = 3.0f;
508 vp2.dvMaxZ = -2.0f;
509 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
510 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
512 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
513 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
515 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
516 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
517 ok(compare_vec4(&dst_data[0], +7.500e+1f, +4.000e+1f, -8.000e-1f, +1.000e+0f, 4096),
518 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
519 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
520 ok(compare_vec4(&dst_data[1], +1.200e+2f, +2.000e+1f, -1.000e+0f, +1.000e+0f, 4096),
521 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
522 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
523 ok(compare_vec4(&dst_data[2], +1.650e+2f, +0.000e+0f, -1.200e+0f, +1.000e+0f, 4096),
524 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
525 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
526 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
527 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
529 vp1.dwSize = sizeof(vp1);
530 vp1.dwX = 30;
531 vp1.dwY = 40;
532 vp1.dwWidth = 90;
533 vp1.dwHeight = 80;
534 vp1.dvScaleX = 7.0f;
535 vp1.dvScaleY = 2.0f;
536 vp1.dvMaxX = 6.0f;
537 vp1.dvMaxY = 10.0f;
538 vp1.dvMinZ = -2.0f;
539 vp1.dvMaxZ = 3.0f;
540 hr = IDirect3DViewport3_SetViewport(viewport, &vp1);
541 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
543 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
544 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
546 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
547 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
548 ok(compare_vec4(&dst_data[0], +1.100e+2f, +6.800e+1f, +7.000e+0f, +1.000e+0f, 4096),
549 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
550 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
551 ok(compare_vec4(&dst_data[1], +1.170e+2f, +6.600e+1f, +8.000e+0f, +1.000e+0f, 4096),
552 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
553 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
554 ok(compare_vec4(&dst_data[2], +1.240e+2f, +6.400e+1f, +9.000e+0f, +1.000e+0f, 4096),
555 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
556 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
557 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
558 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
560 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
561 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
563 IDirect3DVertexBuffer_Release(dst_vb);
564 IDirect3DVertexBuffer_Release(src_vb);
565 IDirect3DViewport3_Release(viewport);
566 IDirect3D3_Release(d3d3);
567 IDirect3DDevice3_Release(device);
568 DestroyWindow(window);
571 static void test_coop_level_create_device_window(void)
573 HWND focus_window, device_window;
574 IDirectDraw4 *ddraw;
575 HRESULT hr;
577 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
578 0, 0, 640, 480, 0, 0, 0, 0);
579 if (!(ddraw = create_ddraw()))
581 skip("Failed to create a ddraw object, skipping test.\n");
582 DestroyWindow(focus_window);
583 return;
586 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
587 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
588 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
589 ok(!device_window, "Unexpected device window found.\n");
590 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
591 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
592 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
593 ok(!device_window, "Unexpected device window found.\n");
594 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
595 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
596 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
597 ok(!device_window, "Unexpected device window found.\n");
598 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
599 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
600 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
601 ok(!device_window, "Unexpected device window found.\n");
602 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
603 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
604 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
605 ok(!device_window, "Unexpected device window found.\n");
607 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
608 if (broken(hr == DDERR_INVALIDPARAMS))
610 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
611 IDirectDraw4_Release(ddraw);
612 DestroyWindow(focus_window);
613 return;
616 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
617 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
618 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
619 ok(!device_window, "Unexpected device window found.\n");
620 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
621 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
622 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
623 ok(!device_window, "Unexpected device window found.\n");
625 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
626 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
627 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
628 ok(!device_window, "Unexpected device window found.\n");
629 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
630 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
631 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
632 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
633 ok(!!device_window, "Device window not found.\n");
635 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
636 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
637 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
638 ok(!device_window, "Unexpected device window found.\n");
639 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
640 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
641 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
642 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
643 ok(!!device_window, "Device window not found.\n");
645 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
646 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
647 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
648 ok(!device_window, "Unexpected device window found.\n");
649 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
650 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
651 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
652 ok(!device_window, "Unexpected device window found.\n");
653 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
654 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
655 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
656 ok(!device_window, "Unexpected device window found.\n");
657 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
658 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
659 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
660 ok(!!device_window, "Device window not found.\n");
662 IDirectDraw4_Release(ddraw);
663 DestroyWindow(focus_window);
666 static void test_clipper_blt(void)
668 IDirectDrawSurface4 *src_surface, *dst_surface;
669 RECT client_rect, src_rect;
670 IDirectDrawClipper *clipper;
671 DDSURFACEDESC2 surface_desc;
672 unsigned int i, j, x, y;
673 IDirectDraw4 *ddraw;
674 RGNDATA *rgn_data;
675 D3DCOLOR color;
676 HRGN r1, r2;
677 HWND window;
678 DDBLTFX fx;
679 HRESULT hr;
680 DWORD *ptr;
681 DWORD ret;
683 static const DWORD src_data[] =
685 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
686 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
687 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
689 static const D3DCOLOR expected1[] =
691 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
692 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
693 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
694 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
696 static const D3DCOLOR expected2[] =
698 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
699 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
700 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
701 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
704 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
705 10, 10, 640, 480, 0, 0, 0, 0);
706 ShowWindow(window, SW_SHOW);
707 if (!(ddraw = create_ddraw()))
709 skip("Failed to create a ddraw object, skipping test.\n");
710 DestroyWindow(window);
711 return;
714 ret = GetClientRect(window, &client_rect);
715 ok(ret, "Failed to get client rect.\n");
716 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
717 ok(ret, "Failed to map client rect.\n");
719 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
720 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
722 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
723 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
724 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
725 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
726 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
727 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
728 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
729 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
730 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
731 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
732 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
733 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
734 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
735 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
736 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
737 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
738 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
739 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
740 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
741 HeapFree(GetProcessHeap(), 0, rgn_data);
743 r1 = CreateRectRgn(0, 0, 320, 240);
744 ok(!!r1, "Failed to create region.\n");
745 r2 = CreateRectRgn(320, 240, 640, 480);
746 ok(!!r2, "Failed to create region.\n");
747 CombineRgn(r1, r1, r2, RGN_OR);
748 ret = GetRegionData(r1, 0, NULL);
749 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
750 ret = GetRegionData(r1, ret, rgn_data);
751 ok(!!ret, "Failed to get region data.\n");
753 DeleteObject(r2);
754 DeleteObject(r1);
756 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
757 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
758 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
759 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
760 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
761 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
763 HeapFree(GetProcessHeap(), 0, rgn_data);
765 memset(&surface_desc, 0, sizeof(surface_desc));
766 surface_desc.dwSize = sizeof(surface_desc);
767 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
768 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
769 surface_desc.dwWidth = 640;
770 surface_desc.dwHeight = 480;
771 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
772 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
773 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
774 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
775 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
776 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
778 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
779 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
780 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
781 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
783 memset(&fx, 0, sizeof(fx));
784 fx.dwSize = sizeof(fx);
785 hr = IDirectDrawSurface4_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
786 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
787 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
788 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
790 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
791 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
792 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
793 ptr = surface_desc.lpSurface;
794 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
795 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
796 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
797 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
798 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
800 hr = IDirectDrawSurface4_SetClipper(dst_surface, clipper);
801 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
803 SetRect(&src_rect, 1, 1, 5, 2);
804 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
805 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
806 for (i = 0; i < 4; ++i)
808 for (j = 0; j < 4; ++j)
810 x = 80 * ((2 * j) + 1);
811 y = 60 * ((2 * i) + 1);
812 color = get_surface_color(dst_surface, x, y);
813 ok(compare_color(color, expected1[i * 4 + j], 1),
814 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
818 U5(fx).dwFillColor = 0xff0000ff;
819 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
820 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
821 for (i = 0; i < 4; ++i)
823 for (j = 0; j < 4; ++j)
825 x = 80 * ((2 * j) + 1);
826 y = 60 * ((2 * i) + 1);
827 color = get_surface_color(dst_surface, x, y);
828 ok(compare_color(color, expected2[i * 4 + j], 1),
829 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
833 hr = IDirectDrawSurface4_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
834 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
836 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
837 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
838 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
839 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
840 DestroyWindow(window);
841 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
842 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
843 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
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 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
848 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
849 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
850 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
851 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
852 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
854 IDirectDrawSurface4_Release(dst_surface);
855 IDirectDrawSurface4_Release(src_surface);
856 IDirectDrawClipper_Release(clipper);
857 IDirectDraw4_Release(ddraw);
860 static void test_coop_level_d3d_state(void)
862 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
863 IDirectDrawSurface4 *rt, *surface;
864 IDirect3DViewport3 *viewport;
865 IDirect3DDevice3 *device;
866 IDirectDraw4 *ddraw;
867 IDirect3D3 *d3d;
868 D3DCOLOR color;
869 DWORD value;
870 HWND window;
871 HRESULT hr;
873 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
874 0, 0, 640, 480, 0, 0, 0, 0);
875 if (!(device = create_device(window, DDSCL_NORMAL)))
877 skip("Failed to create D3D device, skipping test.\n");
878 DestroyWindow(window);
879 return;
882 viewport = create_viewport(device, 0, 0, 640, 480);
884 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
885 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
886 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
887 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
888 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
889 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
890 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
891 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
892 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
893 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
894 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
895 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
896 color = get_surface_color(rt, 320, 240);
897 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
899 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
900 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
901 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
902 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
903 IDirect3D3_Release(d3d);
904 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
905 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
906 hr = IDirectDrawSurface4_IsLost(rt);
907 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
908 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
909 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
910 IDirectDraw4_Release(ddraw);
912 hr = IDirect3DDevice3_GetRenderTarget(device, &surface);
913 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
914 ok(surface == rt, "Got unexpected surface %p.\n", surface);
915 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
916 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
917 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
918 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
919 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
920 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
921 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
922 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
923 color = get_surface_color(rt, 320, 240);
924 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
926 destroy_viewport(device, viewport);
927 IDirectDrawSurface4_Release(surface);
928 IDirectDrawSurface4_Release(rt);
929 IDirect3DDevice3_Release(device);
930 DestroyWindow(window);
933 static void test_surface_interface_mismatch(void)
935 IDirectDraw4 *ddraw = NULL;
936 IDirect3D3 *d3d = NULL;
937 IDirectDrawSurface4 *surface = NULL, *ds;
938 IDirectDrawSurface3 *surface3 = NULL;
939 IDirect3DDevice3 *device = NULL;
940 IDirect3DViewport3 *viewport = NULL;
941 DDSURFACEDESC2 surface_desc;
942 DDPIXELFORMAT z_fmt;
943 ULONG refcount;
944 HRESULT hr;
945 D3DCOLOR color;
946 HWND window;
947 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
949 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
950 0, 0, 640, 480, 0, 0, 0, 0);
952 if (!(ddraw = create_ddraw()))
954 skip("Failed to create a ddraw object, skipping test.\n");
955 goto cleanup;
958 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
959 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
961 memset(&surface_desc, 0, sizeof(surface_desc));
962 surface_desc.dwSize = sizeof(surface_desc);
963 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
964 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
965 surface_desc.dwWidth = 640;
966 surface_desc.dwHeight = 480;
968 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
969 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
971 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
972 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
974 hr = IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d);
975 if (FAILED(hr))
977 skip("Failed to get the IDirect3D7 interface, skipping test.\n");
978 goto cleanup;
981 memset(&z_fmt, 0, sizeof(z_fmt));
982 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
983 if (FAILED(hr) || !z_fmt.dwSize)
985 skip("No depth buffer formats available, skipping test.\n");
986 goto cleanup;
989 memset(&surface_desc, 0, sizeof(surface_desc));
990 surface_desc.dwSize = sizeof(surface_desc);
991 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
992 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
993 U4(surface_desc).ddpfPixelFormat = z_fmt;
994 surface_desc.dwWidth = 640;
995 surface_desc.dwHeight = 480;
996 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
997 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
998 if (FAILED(hr))
999 goto cleanup;
1001 /* Using a different surface interface version still works */
1002 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1003 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1004 refcount = IDirectDrawSurface4_Release(ds);
1005 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1006 if (FAILED(hr))
1007 goto cleanup;
1009 /* Here too */
1010 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface4 *)surface3, &device, NULL);
1011 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1012 if (FAILED(hr))
1013 goto cleanup;
1015 viewport = create_viewport(device, 0, 0, 640, 480);
1017 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1018 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1019 color = get_surface_color(surface, 320, 240);
1020 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1022 cleanup:
1023 if (viewport)
1024 destroy_viewport(device, viewport);
1025 if (surface3) IDirectDrawSurface3_Release(surface3);
1026 if (surface) IDirectDrawSurface4_Release(surface);
1027 if (device) IDirect3DDevice3_Release(device);
1028 if (d3d) IDirect3D3_Release(d3d);
1029 if (ddraw) IDirectDraw4_Release(ddraw);
1030 DestroyWindow(window);
1033 static void test_coop_level_threaded(void)
1035 struct create_window_thread_param p;
1036 IDirectDraw4 *ddraw;
1037 HRESULT hr;
1039 if (!(ddraw = create_ddraw()))
1041 skip("Failed to create a ddraw object, skipping test.\n");
1042 return;
1044 create_window_thread(&p);
1046 hr = IDirectDraw4_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1047 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1049 IDirectDraw4_Release(ddraw);
1050 destroy_window_thread(&p);
1053 static void test_depth_blit(void)
1055 static struct
1057 float x, y, z;
1058 DWORD color;
1060 quad1[] =
1062 { -1.0, 1.0, 0.50f, 0xff00ff00},
1063 { 1.0, 1.0, 0.50f, 0xff00ff00},
1064 { -1.0, -1.0, 0.50f, 0xff00ff00},
1065 { 1.0, -1.0, 0.50f, 0xff00ff00},
1067 static const D3DCOLOR expected_colors[4][4] =
1069 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1070 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1071 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1072 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1074 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1076 IDirect3DDevice3 *device;
1077 IDirectDrawSurface4 *ds1, *ds2, *ds3, *rt;
1078 IDirect3DViewport3 *viewport;
1079 RECT src_rect, dst_rect;
1080 unsigned int i, j;
1081 D3DCOLOR color;
1082 HRESULT hr;
1083 IDirect3D3 *d3d;
1084 IDirectDraw4 *ddraw;
1085 DDBLTFX fx;
1086 HWND window;
1087 D3DRECT d3drect;
1089 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1090 0, 0, 640, 480, 0, 0, 0, 0);
1091 if (!(device = create_device(window, DDSCL_NORMAL)))
1093 skip("Failed to create D3D device, skipping test.\n");
1094 DestroyWindow(window);
1095 return;
1098 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1099 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
1100 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1101 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
1102 IDirect3D3_Release(d3d);
1104 ds1 = get_depth_stencil(device);
1106 memset(&ddsd_new, 0, sizeof(ddsd_new));
1107 ddsd_new.dwSize = sizeof(ddsd_new);
1108 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1109 ddsd_existing.dwSize = sizeof(ddsd_existing);
1110 hr = IDirectDrawSurface4_GetSurfaceDesc(ds1, &ddsd_existing);
1111 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1112 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1113 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1114 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1115 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1116 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1117 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
1118 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1119 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
1120 IDirectDraw4_Release(ddraw);
1122 viewport = create_viewport(device, 0, 0, ddsd_existing.dwWidth, ddsd_existing.dwHeight);
1123 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1124 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
1126 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1127 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1128 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1129 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1131 U1(d3drect).x1 = U2(d3drect).y1 = 0;
1132 U3(d3drect).x2 = ddsd_existing.dwWidth; U4(d3drect).y2 = ddsd_existing.dwHeight;
1133 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1134 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1136 /* Partial blit. */
1137 SetRect(&src_rect, 0, 0, 320, 240);
1138 SetRect(&dst_rect, 0, 0, 320, 240);
1139 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1140 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1141 /* Different locations. */
1142 SetRect(&src_rect, 0, 0, 320, 240);
1143 SetRect(&dst_rect, 320, 240, 640, 480);
1144 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1145 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1146 /* Streched. */
1147 SetRect(&src_rect, 0, 0, 320, 240);
1148 SetRect(&dst_rect, 0, 0, 640, 480);
1149 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1150 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1151 /* Flipped. */
1152 SetRect(&src_rect, 0, 480, 640, 0);
1153 SetRect(&dst_rect, 0, 0, 640, 480);
1154 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1155 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1156 SetRect(&src_rect, 0, 0, 640, 480);
1157 SetRect(&dst_rect, 0, 480, 640, 0);
1158 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1159 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1160 /* Full, explicit. */
1161 SetRect(&src_rect, 0, 0, 640, 480);
1162 SetRect(&dst_rect, 0, 0, 640, 480);
1163 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1164 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1165 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1167 /* Depth blit inside a BeginScene / EndScene pair */
1168 hr = IDirect3DDevice3_BeginScene(device);
1169 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#x.\n", hr);
1170 /* From the current depth stencil */
1171 hr = IDirectDrawSurface4_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1172 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1173 /* To the current depth stencil */
1174 hr = IDirectDrawSurface4_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1175 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1176 /* Between unbound surfaces */
1177 hr = IDirectDrawSurface4_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1178 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1179 hr = IDirect3DDevice3_EndScene(device);
1180 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#x.\n", hr);
1182 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1183 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1184 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1185 * a reliable result(z = 0.0) */
1186 memset(&fx, 0, sizeof(fx));
1187 fx.dwSize = sizeof(fx);
1188 hr = IDirectDrawSurface4_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1189 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1191 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1192 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1193 SetRect(&dst_rect, 0, 0, 320, 240);
1194 hr = IDirectDrawSurface4_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1195 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1196 IDirectDrawSurface4_Release(ds3);
1197 IDirectDrawSurface4_Release(ds2);
1198 IDirectDrawSurface4_Release(ds1);
1200 hr = IDirect3DDevice3_BeginScene(device);
1201 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#x.\n", hr);
1202 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1203 quad1, 4, 0);
1204 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1205 hr = IDirect3DDevice3_EndScene(device);
1206 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#x.\n", hr);
1208 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1209 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1210 for (i = 0; i < 4; ++i)
1212 for (j = 0; j < 4; ++j)
1214 unsigned int x = 80 * ((2 * j) + 1);
1215 unsigned int y = 60 * ((2 * i) + 1);
1216 color = get_surface_color(rt, x, y);
1217 ok(compare_color(color, expected_colors[i][j], 1),
1218 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1221 IDirectDrawSurface4_Release(rt);
1223 destroy_viewport(device, viewport);
1224 IDirect3DDevice3_Release(device);
1225 DestroyWindow(window);
1228 static void test_texture_load_ckey(void)
1230 IDirectDraw4 *ddraw;
1231 IDirectDrawSurface4 *src;
1232 IDirectDrawSurface4 *dst;
1233 IDirect3DTexture2 *src_tex;
1234 IDirect3DTexture2 *dst_tex;
1235 DDSURFACEDESC2 ddsd;
1236 HRESULT hr;
1237 DDCOLORKEY ckey;
1239 if (!(ddraw = create_ddraw()))
1241 skip("Failed to create ddraw object, skipping test.\n");
1242 return;
1244 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
1245 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1247 memset(&ddsd, 0, sizeof(ddsd));
1248 ddsd.dwSize = sizeof(ddsd);
1249 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1250 ddsd.dwHeight = 128;
1251 ddsd.dwWidth = 128;
1252 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1253 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &src, NULL);
1254 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1255 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1256 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &dst, NULL);
1257 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1259 hr = IDirectDrawSurface4_QueryInterface(src, &IID_IDirect3DTexture2, (void **)&src_tex);
1260 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr);
1261 if (FAILED(hr))
1263 /* 64 bit ddraw does not support d3d */
1264 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1265 IDirectDrawSurface4_Release(dst);
1266 IDirectDrawSurface4_Release(src);
1267 IDirectDraw4_Release(ddraw);
1268 return;
1270 hr = IDirectDrawSurface4_QueryInterface(dst, &IID_IDirect3DTexture2, (void **)&dst_tex);
1271 ok(SUCCEEDED(hr), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr);
1273 /* No surface has a color key */
1274 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1275 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1276 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1277 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1278 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1279 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1280 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1282 /* Source surface has a color key */
1283 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1284 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1285 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1286 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1287 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1288 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1289 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1290 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1291 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1293 /* Both surfaces have a color key: Dest ckey is overwritten */
1294 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1295 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1296 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1297 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1298 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1299 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1300 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1301 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1302 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1304 /* Only the destination has a color key: It is not deleted */
1305 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1306 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1307 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1308 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1309 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1310 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1311 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1312 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1313 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1314 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1316 IDirect3DTexture2_Release(dst_tex);
1317 IDirect3DTexture2_Release(src_tex);
1318 IDirectDrawSurface4_Release(dst);
1319 IDirectDrawSurface4_Release(src);
1320 IDirectDraw4_Release(ddraw);
1323 static ULONG get_refcount(IUnknown *test_iface)
1325 IUnknown_AddRef(test_iface);
1326 return IUnknown_Release(test_iface);
1329 static void test_viewport(void)
1331 IDirectDraw4 *ddraw;
1332 IDirect3D3 *d3d;
1333 HRESULT hr, old_d3d_ref;
1334 ULONG ref;
1335 IDirect3DViewport *viewport;
1336 IDirect3DViewport2 *viewport2;
1337 IDirect3DViewport3 *viewport3, *another_vp, *test_vp;
1338 IDirectDrawGammaControl *gamma;
1339 IUnknown *unknown;
1340 HWND window;
1341 IDirect3DDevice3 *device;
1343 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1344 0, 0, 640, 480, 0, 0, 0, 0);
1345 if (!(device = create_device(window, DDSCL_NORMAL)))
1347 skip("Failed to create D3D device, skipping test.\n");
1348 DestroyWindow(window);
1349 return;
1351 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1352 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
1353 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1354 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
1355 old_d3d_ref = get_refcount((IUnknown *) d3d);
1357 hr = IDirect3D3_CreateViewport(d3d, &viewport3, NULL);
1358 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1359 ref = get_refcount((IUnknown *)viewport3);
1360 ok(ref == 1, "Initial IDirect3DViewport3 refcount is %u\n", ref);
1361 ref = get_refcount((IUnknown *)d3d);
1362 ok(ref == old_d3d_ref, "IDirect3D3 refcount is %u\n", ref);
1364 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1365 hr = IDirect3DViewport2_QueryInterface(viewport3, &IID_IDirectDrawGammaControl, (void **)&gamma);
1366 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
1367 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
1368 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
1369 /* NULL iid: Segfaults */
1371 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport, (void **)&viewport);
1372 ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport, hr %#x.\n", hr);
1373 if (viewport)
1375 ref = get_refcount((IUnknown *)viewport);
1376 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1377 ref = get_refcount((IUnknown *)viewport3);
1378 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1379 IDirect3DViewport_Release(viewport);
1380 viewport = NULL;
1383 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport3, (void **)&viewport2);
1384 ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
1385 if (viewport2)
1387 ref = get_refcount((IUnknown *)viewport2);
1388 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
1389 ref = get_refcount((IUnknown *)viewport3);
1390 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1391 IDirect3DViewport3_Release(viewport2);
1394 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IUnknown, (void **)&unknown);
1395 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1396 if (unknown)
1398 ref = get_refcount((IUnknown *)viewport3);
1399 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1400 ref = get_refcount(unknown);
1401 ok(ref == 2, "IUnknown refcount is %u\n", ref);
1402 IUnknown_Release(unknown);
1405 /* AddViewport(NULL): Segfault */
1406 hr = IDirect3DDevice3_DeleteViewport(device, NULL);
1407 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1408 hr = IDirect3DDevice3_GetCurrentViewport(device, NULL);
1409 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1411 hr = IDirect3D3_CreateViewport(d3d, &another_vp, NULL);
1412 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1414 /* Setting a viewport not in the viewport list fails */
1415 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1416 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1418 hr = IDirect3DDevice3_AddViewport(device, viewport3);
1419 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1420 ref = get_refcount((IUnknown *) viewport3);
1421 ok(ref == 2, "viewport3 refcount is %d\n", ref);
1422 hr = IDirect3DDevice3_AddViewport(device, another_vp);
1423 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1424 ref = get_refcount((IUnknown *) another_vp);
1425 ok(ref == 2, "another_vp refcount is %d\n", ref);
1427 test_vp = (IDirect3DViewport3 *) 0xbaadc0de;
1428 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1429 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1430 ok(test_vp == (IDirect3DViewport3 *) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp);
1432 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1433 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1434 ref = get_refcount((IUnknown *) viewport3);
1435 ok(ref == 3, "viewport3 refcount is %d\n", ref);
1436 ref = get_refcount((IUnknown *) device);
1437 ok(ref == 1, "device refcount is %d\n", ref);
1439 test_vp = NULL;
1440 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1441 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1442 ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp);
1443 ref = get_refcount((IUnknown *) viewport3);
1444 ok(ref == 4, "viewport3 refcount is %d\n", ref);
1445 if(test_vp) IDirect3DViewport3_Release(test_vp);
1447 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1449 /* Cannot set the viewport to NULL */
1450 hr = IDirect3DDevice3_SetCurrentViewport(device, NULL);
1451 ok(hr == DDERR_INVALIDPARAMS, "Failed to set viewport to NULL, hr %#x.\n", hr);
1452 test_vp = NULL;
1453 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1454 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1455 ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp);
1456 if(test_vp) IDirect3DViewport3_Release(test_vp);
1458 /* SetCurrentViewport properly releases the old viewport's reference */
1459 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1460 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1461 ref = get_refcount((IUnknown *) viewport3);
1462 ok(ref == 2, "viewport3 refcount is %d\n", ref);
1463 ref = get_refcount((IUnknown *) another_vp);
1464 ok(ref == 3, "another_vp refcount is %d\n", ref);
1466 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1467 * reference held by SetCurrentViewport */
1468 hr = IDirect3DDevice3_DeleteViewport(device, another_vp);
1469 ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
1470 ref = get_refcount((IUnknown *) another_vp);
1471 ok(ref == 1, "another_vp refcount is %d\n", ref);
1473 /* GetCurrentViewport still fails */
1474 test_vp = NULL;
1475 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1476 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1477 ok(test_vp == NULL, "Got unexpected viewport %p\n", test_vp);
1478 if(test_vp) IDirect3DViewport3_Release(test_vp);
1480 /* Setting a different viewport doesn't have any surprises now */
1481 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1482 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1483 ref = get_refcount((IUnknown *) viewport3);
1484 ok(ref == 3, "viewport3 refcount is %d\n", ref);
1485 ref = get_refcount((IUnknown *) another_vp);
1486 ok(ref == 1, "another_vp refcount is %d\n", ref);
1488 /* Destroying the device removes the viewport and releases the reference */
1489 IDirect3DDevice3_Release(device);
1490 ref = get_refcount((IUnknown *) viewport3);
1491 ok(ref == 1, "viewport3 refcount is %d\n", ref);
1493 ref = IDirect3DViewport3_Release(another_vp);
1494 ok(ref == 0, "Got unexpected ref %d\n", ref);
1495 ref = IDirect3DViewport3_Release(viewport3);
1496 ok(ref == 0, "Got unexpected ref %d\n", ref);
1497 IDirect3D3_Release(d3d);
1498 DestroyWindow(window);
1499 IDirectDraw4_Release(ddraw);
1502 static void test_zenable(void)
1504 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1505 static struct
1507 struct vec4 position;
1508 D3DCOLOR diffuse;
1510 tquad[] =
1512 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1513 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1514 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1515 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1517 IDirect3DViewport3 *viewport;
1518 IDirect3DDevice3 *device;
1519 IDirectDrawSurface4 *rt;
1520 D3DCOLOR color;
1521 HWND window;
1522 HRESULT hr;
1523 UINT x, y;
1524 UINT i, j;
1526 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1527 0, 0, 640, 480, 0, 0, 0, 0);
1528 if (!(device = create_device(window, DDSCL_NORMAL)))
1530 skip("Failed to create D3D device, skipping test.\n");
1531 DestroyWindow(window);
1532 return;
1535 viewport = create_viewport(device, 0, 0, 640, 480);
1536 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1537 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1539 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1540 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1542 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1543 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1544 hr = IDirect3DDevice3_BeginScene(device);
1545 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1546 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1547 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1548 hr = IDirect3DDevice3_EndScene(device);
1549 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1551 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1552 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1553 for (i = 0; i < 4; ++i)
1555 for (j = 0; j < 4; ++j)
1557 x = 80 * ((2 * j) + 1);
1558 y = 60 * ((2 * i) + 1);
1559 color = get_surface_color(rt, x, y);
1560 ok(compare_color(color, 0x0000ff00, 1),
1561 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1564 IDirectDrawSurface4_Release(rt);
1566 destroy_viewport(device, viewport);
1567 IDirect3DDevice3_Release(device);
1568 DestroyWindow(window);
1571 static void test_ck_rgba(void)
1573 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1574 static struct
1576 struct vec4 position;
1577 struct vec2 texcoord;
1579 tquad[] =
1581 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1582 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1583 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1584 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1585 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1586 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1587 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1588 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1590 static const struct
1592 D3DCOLOR fill_color;
1593 BOOL color_key;
1594 BOOL blend;
1595 D3DCOLOR result1;
1596 D3DCOLOR result2;
1598 tests[] =
1600 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x000000ff},
1601 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x000000ff},
1602 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00},
1603 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1604 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00807f00},
1605 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x0000ff00},
1606 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00},
1607 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1610 IDirectDrawSurface4 *surface;
1611 IDirect3DViewport3 *viewport;
1612 DDSURFACEDESC2 surface_desc;
1613 IDirect3DTexture2 *texture;
1614 IDirect3DDevice3 *device;
1615 IDirectDrawSurface4 *rt;
1616 IDirectDraw4 *ddraw;
1617 IDirect3D3 *d3d;
1618 D3DCOLOR color;
1619 HWND window;
1620 DDBLTFX fx;
1621 HRESULT hr;
1622 UINT i;
1624 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1625 0, 0, 640, 480, 0, 0, 0, 0);
1626 if (!(device = create_device(window, DDSCL_NORMAL)))
1628 skip("Failed to create D3D device, skipping test.\n");
1629 DestroyWindow(window);
1630 return;
1633 viewport = create_viewport(device, 0, 0, 640, 480);
1634 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1635 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1637 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1638 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1639 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1640 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1641 IDirect3D3_Release(d3d);
1643 memset(&surface_desc, 0, sizeof(surface_desc));
1644 surface_desc.dwSize = sizeof(surface_desc);
1645 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1646 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1647 surface_desc.dwWidth = 256;
1648 surface_desc.dwHeight = 256;
1649 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1650 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1651 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1652 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1653 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1654 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1655 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1656 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1657 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1658 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1659 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1660 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
1661 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1663 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
1664 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1665 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1666 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1667 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1668 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1670 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1671 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1673 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1675 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1676 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1677 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1678 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1680 memset(&fx, 0, sizeof(fx));
1681 fx.dwSize = sizeof(fx);
1682 U5(fx).dwFillColor = tests[i].fill_color;
1683 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1684 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1686 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
1687 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1688 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1689 hr = IDirect3DDevice3_BeginScene(device);
1690 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1691 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1692 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1693 hr = IDirect3DDevice3_EndScene(device);
1694 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1696 color = get_surface_color(rt, 320, 240);
1697 if (i == 2)
1698 todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1699 tests[i].result1, i, color);
1700 else
1701 ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1702 tests[i].result1, i, color);
1704 U5(fx).dwFillColor = 0xff0000ff;
1705 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1706 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1708 hr = IDirect3DDevice3_BeginScene(device);
1709 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1710 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1711 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1712 hr = IDirect3DDevice3_EndScene(device);
1713 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1715 /* This tests that fragments that are masked out by the color key are
1716 * discarded, instead of just fully transparent. */
1717 color = get_surface_color(rt, 320, 240);
1718 if (i == 2)
1719 todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1720 tests[i].result2, i, color);
1721 else
1722 ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1723 tests[i].result2, i, color);
1726 IDirectDrawSurface4_Release(rt);
1727 IDirect3DTexture2_Release(texture);
1728 IDirectDrawSurface4_Release(surface);
1729 destroy_viewport(device, viewport);
1730 IDirectDraw4_Release(ddraw);
1731 IDirect3DDevice3_Release(device);
1732 DestroyWindow(window);
1735 static void test_ck_default(void)
1737 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1738 static struct
1740 struct vec4 position;
1741 struct vec2 texcoord;
1743 tquad[] =
1745 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1746 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1747 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1748 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1750 IDirectDrawSurface4 *surface, *rt;
1751 IDirect3DViewport3 *viewport;
1752 DDSURFACEDESC2 surface_desc;
1753 IDirect3DTexture2 *texture;
1754 IDirect3DDevice3 *device;
1755 IDirectDraw4 *ddraw;
1756 IDirect3D3 *d3d;
1757 D3DCOLOR color;
1758 DWORD value;
1759 HWND window;
1760 DDBLTFX fx;
1761 HRESULT hr;
1763 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1764 0, 0, 640, 480, 0, 0, 0, 0);
1766 if (!(device = create_device(window, DDSCL_NORMAL)))
1768 skip("Failed to create D3D device, skipping test.\n");
1769 DestroyWindow(window);
1770 return;
1773 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1774 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1775 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1776 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1777 IDirect3D3_Release(d3d);
1779 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1780 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1782 viewport = create_viewport(device, 0, 0, 640, 480);
1783 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1784 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1786 memset(&surface_desc, 0, sizeof(surface_desc));
1787 surface_desc.dwSize = sizeof(surface_desc);
1788 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1789 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1790 surface_desc.dwWidth = 256;
1791 surface_desc.dwHeight = 256;
1792 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1793 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1794 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1795 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1796 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1797 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1798 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1799 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1800 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1801 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1802 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
1803 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1804 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
1805 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1807 memset(&fx, 0, sizeof(fx));
1808 fx.dwSize = sizeof(fx);
1809 U5(fx).dwFillColor = 0x000000ff;
1810 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1811 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1813 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1814 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1815 hr = IDirect3DDevice3_BeginScene(device);
1816 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1817 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1818 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1819 ok(!value, "Got unexpected color keying state %#x.\n", value);
1820 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1821 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1822 hr = IDirect3DDevice3_EndScene(device);
1823 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1824 color = get_surface_color(rt, 320, 240);
1825 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1827 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1828 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1829 hr = IDirect3DDevice3_BeginScene(device);
1830 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1831 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1832 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1833 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1834 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1835 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1836 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1837 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1838 hr = IDirect3DDevice3_EndScene(device);
1839 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1840 color = get_surface_color(rt, 320, 240);
1841 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1843 IDirect3DTexture_Release(texture);
1844 IDirectDrawSurface4_Release(surface);
1845 destroy_viewport(device, viewport);
1846 IDirectDrawSurface4_Release(rt);
1847 IDirect3DDevice3_Release(device);
1848 IDirectDraw4_Release(ddraw);
1849 DestroyWindow(window);
1852 struct qi_test
1854 REFIID iid;
1855 REFIID refcount_iid;
1856 HRESULT hr;
1859 static void test_qi(const char *test_name, IUnknown *base_iface,
1860 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
1862 ULONG refcount, expected_refcount;
1863 IUnknown *iface1, *iface2;
1864 HRESULT hr;
1865 UINT i, j;
1867 for (i = 0; i < entry_count; ++i)
1869 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
1870 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
1871 if (SUCCEEDED(hr))
1873 for (j = 0; j < entry_count; ++j)
1875 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
1876 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
1877 if (SUCCEEDED(hr))
1879 expected_refcount = 0;
1880 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
1881 ++expected_refcount;
1882 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
1883 ++expected_refcount;
1884 refcount = IUnknown_Release(iface2);
1885 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1886 refcount, test_name, i, j, expected_refcount);
1890 expected_refcount = 0;
1891 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
1892 ++expected_refcount;
1893 refcount = IUnknown_Release(iface1);
1894 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1895 refcount, test_name, i, expected_refcount);
1900 static void test_surface_qi(void)
1902 static const struct qi_test tests[] =
1904 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface4, S_OK },
1905 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface4, S_OK },
1906 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
1907 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1908 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
1909 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
1910 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
1911 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
1912 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
1913 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
1914 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
1915 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
1916 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
1917 {&IID_IDirect3D7, NULL, E_INVALIDARG },
1918 {&IID_IDirect3D3, NULL, E_INVALIDARG },
1919 {&IID_IDirect3D2, NULL, E_INVALIDARG },
1920 {&IID_IDirect3D, NULL, E_INVALIDARG },
1921 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
1922 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
1923 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
1924 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
1925 {&IID_IDirectDraw, NULL, E_INVALIDARG },
1926 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
1927 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
1928 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
1929 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
1930 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
1931 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
1932 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
1933 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
1934 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
1935 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
1936 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
1937 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
1938 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
1941 IDirectDrawSurface4 *surface;
1942 DDSURFACEDESC2 surface_desc;
1943 IDirect3DDevice3 *device;
1944 IDirectDraw4 *ddraw;
1945 HWND window;
1946 HRESULT hr;
1948 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1950 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1951 return;
1954 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1955 0, 0, 640, 480, 0, 0, 0, 0);
1956 /* Try to create a D3D device to see if the ddraw implementation supports
1957 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1958 * doesn't support e.g. the IDirect3DTexture interfaces. */
1959 if (!(device = create_device(window, DDSCL_NORMAL)))
1961 skip("Failed to create D3D device, skipping test.\n");
1962 DestroyWindow(window);
1963 return;
1965 IDirect3DDevice_Release(device);
1966 if (!(ddraw = create_ddraw()))
1968 skip("Failed to create a ddraw object, skipping test.\n");
1969 DestroyWindow(window);
1970 return;
1972 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1973 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1975 memset(&surface_desc, 0, sizeof(surface_desc));
1976 surface_desc.dwSize = sizeof(surface_desc);
1977 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1978 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1979 surface_desc.dwWidth = 512;
1980 surface_desc.dwHeight = 512;
1981 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1982 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1984 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface4, tests, sizeof(tests) / sizeof(*tests));
1986 IDirectDrawSurface4_Release(surface);
1987 IDirectDraw4_Release(ddraw);
1988 DestroyWindow(window);
1991 static void test_device_qi(void)
1993 static const struct qi_test tests[] =
1995 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
1996 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
1997 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
1998 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
1999 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2000 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2001 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2002 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2003 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2004 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
2005 {&IID_IDirect3DDevice3, &IID_IDirect3DDevice3, S_OK },
2006 {&IID_IDirect3DDevice2, &IID_IDirect3DDevice3, S_OK },
2007 {&IID_IDirect3DDevice, &IID_IDirect3DDevice3, S_OK },
2008 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2009 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2010 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2011 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2012 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2013 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2014 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2015 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2016 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2017 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2018 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2019 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2020 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2021 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2022 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2023 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2024 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2025 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2026 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2027 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2028 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2029 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2030 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2031 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2032 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2033 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2034 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2035 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2036 {&IID_IUnknown, &IID_IDirect3DDevice3, S_OK },
2039 IDirect3DDevice3 *device;
2040 HWND window;
2042 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2043 0, 0, 640, 480, 0, 0, 0, 0);
2044 if (!(device = create_device(window, DDSCL_NORMAL)))
2046 skip("Failed to create D3D device, skipping test.\n");
2047 DestroyWindow(window);
2048 return;
2051 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice3, tests, sizeof(tests) / sizeof(*tests));
2053 IDirect3DDevice3_Release(device);
2054 DestroyWindow(window);
2057 static void test_wndproc(void)
2059 LONG_PTR proc, ddraw_proc;
2060 IDirectDraw4 *ddraw;
2061 WNDCLASSA wc = {0};
2062 HWND window;
2063 HRESULT hr;
2064 ULONG ref;
2066 static const UINT messages[] =
2068 WM_WINDOWPOSCHANGING,
2069 WM_MOVE,
2070 WM_SIZE,
2071 WM_WINDOWPOSCHANGING,
2072 WM_ACTIVATE,
2073 WM_SETFOCUS,
2077 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2078 if (!(ddraw = create_ddraw()))
2080 skip("Failed to create IDirectDraw4 object, skipping tests.\n");
2081 return;
2084 wc.lpfnWndProc = test_proc;
2085 wc.lpszClassName = "ddraw_test_wndproc_wc";
2086 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2088 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2089 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2091 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2092 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2093 (LONG_PTR)test_proc, proc);
2094 expect_messages = messages;
2095 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2096 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2097 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2098 expect_messages = NULL;
2099 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2100 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2101 (LONG_PTR)test_proc, proc);
2102 ref = IDirectDraw4_Release(ddraw);
2103 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2104 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2105 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2106 (LONG_PTR)test_proc, proc);
2108 /* DDSCL_NORMAL doesn't. */
2109 ddraw = create_ddraw();
2110 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2111 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2112 (LONG_PTR)test_proc, proc);
2113 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2114 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2115 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2116 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2117 (LONG_PTR)test_proc, proc);
2118 ref = IDirectDraw4_Release(ddraw);
2119 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2120 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2121 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2122 (LONG_PTR)test_proc, proc);
2124 /* The original window proc is only restored by ddraw if the current
2125 * window proc matches the one ddraw set. This also affects switching
2126 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2127 ddraw = create_ddraw();
2128 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2129 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2130 (LONG_PTR)test_proc, proc);
2131 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2132 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2133 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2134 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2135 (LONG_PTR)test_proc, proc);
2136 ddraw_proc = proc;
2137 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2138 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2139 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2140 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2141 (LONG_PTR)test_proc, proc);
2142 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2143 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2144 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2145 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2146 (LONG_PTR)test_proc, proc);
2147 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2148 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2149 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2150 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2151 (LONG_PTR)DefWindowProcA, proc);
2152 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2153 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2154 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2155 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2156 (LONG_PTR)DefWindowProcA, proc);
2157 ref = IDirectDraw4_Release(ddraw);
2158 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2159 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2160 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2161 (LONG_PTR)test_proc, proc);
2163 ddraw = create_ddraw();
2164 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2165 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2166 (LONG_PTR)test_proc, proc);
2167 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2168 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2169 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2170 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2171 (LONG_PTR)test_proc, proc);
2172 ref = IDirectDraw4_Release(ddraw);
2173 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2174 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2175 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2176 (LONG_PTR)DefWindowProcA, proc);
2178 fix_wndproc(window, (LONG_PTR)test_proc);
2179 expect_messages = NULL;
2180 DestroyWindow(window);
2181 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2184 static void test_window_style(void)
2186 LONG style, exstyle, tmp;
2187 RECT fullscreen_rect, r;
2188 IDirectDraw4 *ddraw;
2189 HWND window;
2190 HRESULT hr;
2191 ULONG ref;
2193 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2194 0, 0, 100, 100, 0, 0, 0, 0);
2195 if (!(ddraw = create_ddraw()))
2197 skip("Failed to create a ddraw object, skipping test.\n");
2198 DestroyWindow(window);
2199 return;
2202 style = GetWindowLongA(window, GWL_STYLE);
2203 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2204 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2206 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2207 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2209 tmp = GetWindowLongA(window, GWL_STYLE);
2210 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2211 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2212 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2214 GetWindowRect(window, &r);
2215 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2216 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2217 r.left, r.top, r.right, r.bottom);
2218 GetClientRect(window, &r);
2219 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2221 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2222 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2224 tmp = GetWindowLongA(window, GWL_STYLE);
2225 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2226 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2227 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2229 ref = IDirectDraw4_Release(ddraw);
2230 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2232 DestroyWindow(window);
2235 static void test_redundant_mode_set(void)
2237 DDSURFACEDESC2 surface_desc = {0};
2238 IDirectDraw4 *ddraw;
2239 HWND window;
2240 HRESULT hr;
2241 RECT r, s;
2242 ULONG ref;
2244 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2245 0, 0, 100, 100, 0, 0, 0, 0);
2246 if (!(ddraw = create_ddraw()))
2248 skip("Failed to create a ddraw object, skipping test.\n");
2249 DestroyWindow(window);
2250 return;
2253 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2254 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2256 surface_desc.dwSize = sizeof(surface_desc);
2257 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
2258 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2260 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2261 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2262 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2264 GetWindowRect(window, &r);
2265 r.right /= 2;
2266 r.bottom /= 2;
2267 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2268 GetWindowRect(window, &s);
2269 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2270 r.left, r.top, r.right, r.bottom,
2271 s.left, s.top, s.right, s.bottom);
2273 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2274 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2275 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2277 GetWindowRect(window, &s);
2278 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2279 r.left, r.top, r.right, r.bottom,
2280 s.left, s.top, s.right, s.bottom);
2282 ref = IDirectDraw4_Release(ddraw);
2283 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2285 DestroyWindow(window);
2288 static SIZE screen_size, screen_size2;
2290 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2292 if (message == WM_SIZE)
2294 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2295 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2298 return test_proc(hwnd, message, wparam, lparam);
2301 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2303 if (message == WM_SIZE)
2305 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2306 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2309 return test_proc(hwnd, message, wparam, lparam);
2312 static void test_coop_level_mode_set(void)
2314 IDirectDrawSurface4 *primary;
2315 RECT fullscreen_rect, r, s;
2316 IDirectDraw4 *ddraw;
2317 DDSURFACEDESC2 ddsd;
2318 WNDCLASSA wc = {0};
2319 HWND window, window2;
2320 HRESULT hr;
2321 ULONG ref;
2323 static const UINT exclusive_messages[] =
2325 WM_WINDOWPOSCHANGING,
2326 WM_WINDOWPOSCHANGED,
2327 WM_SIZE,
2328 WM_DISPLAYCHANGE,
2332 static const UINT normal_messages[] =
2334 WM_DISPLAYCHANGE,
2338 if (!(ddraw = create_ddraw()))
2340 skip("Failed to create a ddraw object, skipping test.\n");
2341 return;
2344 wc.lpfnWndProc = mode_set_proc;
2345 wc.lpszClassName = "ddraw_test_wndproc_wc";
2346 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2347 wc.lpfnWndProc = mode_set_proc2;
2348 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2349 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2351 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2352 0, 0, 100, 100, 0, 0, 0, 0);
2353 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2354 0, 0, 100, 100, 0, 0, 0, 0);
2356 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2357 SetRect(&s, 0, 0, 640, 480);
2359 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2360 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2362 GetWindowRect(window, &r);
2363 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2364 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2365 r.left, r.top, r.right, r.bottom);
2367 memset(&ddsd, 0, sizeof(ddsd));
2368 ddsd.dwSize = sizeof(ddsd);
2369 ddsd.dwFlags = DDSD_CAPS;
2370 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2372 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2373 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2374 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2375 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2376 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2377 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2378 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2379 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2381 GetWindowRect(window, &r);
2382 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2383 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2384 r.left, r.top, r.right, r.bottom);
2386 expect_messages = exclusive_messages;
2387 screen_size.cx = 0;
2388 screen_size.cy = 0;
2390 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
2391 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2393 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2394 expect_messages = NULL;
2395 ok(screen_size.cx == s.right && screen_size.cy == s.bottom,
2396 "Expected screen size %ux%u, got %ux%u.\n",
2397 s.right, s.bottom, screen_size.cx, screen_size.cy);
2399 GetWindowRect(window, &r);
2400 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2401 s.left, s.top, s.right, s.bottom,
2402 r.left, r.top, r.right, r.bottom);
2404 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2405 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2406 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2407 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2408 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2409 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2410 IDirectDrawSurface4_Release(primary);
2412 memset(&ddsd, 0, sizeof(ddsd));
2413 ddsd.dwSize = sizeof(ddsd);
2414 ddsd.dwFlags = DDSD_CAPS;
2415 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2417 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2418 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2419 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2420 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2421 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2422 s.right - s.left, ddsd.dwWidth);
2423 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2424 s.bottom - s.top, ddsd.dwHeight);
2426 GetWindowRect(window, &r);
2427 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2428 s.left, s.top, s.right, s.bottom,
2429 r.left, r.top, r.right, r.bottom);
2431 expect_messages = exclusive_messages;
2432 screen_size.cx = 0;
2433 screen_size.cy = 0;
2435 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2436 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2438 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2439 expect_messages = NULL;
2440 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2441 "Expected screen size %ux%u, got %ux%u.\n",
2442 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2444 GetWindowRect(window, &r);
2445 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2446 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2447 r.left, r.top, r.right, r.bottom);
2449 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2450 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2451 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2452 s.right - s.left, ddsd.dwWidth);
2453 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2454 s.bottom - s.top, ddsd.dwHeight);
2455 IDirectDrawSurface4_Release(primary);
2457 memset(&ddsd, 0, sizeof(ddsd));
2458 ddsd.dwSize = sizeof(ddsd);
2459 ddsd.dwFlags = DDSD_CAPS;
2460 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2462 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2463 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2464 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2465 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2466 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2467 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2468 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2469 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2471 GetWindowRect(window, &r);
2472 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2473 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2474 r.left, r.top, r.right, r.bottom);
2476 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2477 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2479 GetWindowRect(window, &r);
2480 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2481 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2482 r.left, r.top, r.right, r.bottom);
2484 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2485 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2486 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2487 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2488 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2489 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2490 IDirectDrawSurface4_Release(primary);
2492 memset(&ddsd, 0, sizeof(ddsd));
2493 ddsd.dwSize = sizeof(ddsd);
2494 ddsd.dwFlags = DDSD_CAPS;
2495 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2497 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2498 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2499 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2500 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2501 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2502 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2503 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2504 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2506 GetWindowRect(window, &r);
2507 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2508 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2509 r.left, r.top, r.right, r.bottom);
2511 expect_messages = normal_messages;
2512 screen_size.cx = 0;
2513 screen_size.cy = 0;
2515 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
2516 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2518 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2519 expect_messages = NULL;
2520 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2522 GetWindowRect(window, &r);
2523 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2524 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2525 r.left, r.top, r.right, r.bottom);
2527 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2528 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2529 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2530 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2531 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2532 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2533 IDirectDrawSurface4_Release(primary);
2535 memset(&ddsd, 0, sizeof(ddsd));
2536 ddsd.dwSize = sizeof(ddsd);
2537 ddsd.dwFlags = DDSD_CAPS;
2538 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2540 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2541 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2542 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2543 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2544 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2545 s.right - s.left, ddsd.dwWidth);
2546 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2547 s.bottom - s.top, ddsd.dwHeight);
2549 GetWindowRect(window, &r);
2550 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2551 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2552 r.left, r.top, r.right, r.bottom);
2554 expect_messages = normal_messages;
2555 screen_size.cx = 0;
2556 screen_size.cy = 0;
2558 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2559 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2561 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2562 expect_messages = NULL;
2563 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2565 GetWindowRect(window, &r);
2566 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2567 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2568 r.left, r.top, r.right, r.bottom);
2570 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2571 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2572 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2573 s.right - s.left, ddsd.dwWidth);
2574 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2575 s.bottom - s.top, ddsd.dwHeight);
2576 IDirectDrawSurface4_Release(primary);
2578 memset(&ddsd, 0, sizeof(ddsd));
2579 ddsd.dwSize = sizeof(ddsd);
2580 ddsd.dwFlags = DDSD_CAPS;
2581 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2583 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2584 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2585 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2586 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2587 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2588 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2589 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2590 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2592 GetWindowRect(window, &r);
2593 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2594 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2595 r.left, r.top, r.right, r.bottom);
2597 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2598 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2599 * not DDSCL_FULLSCREEN. */
2600 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2601 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2603 GetWindowRect(window, &r);
2604 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2605 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2606 r.left, r.top, r.right, r.bottom);
2608 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2609 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2610 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2611 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2612 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2613 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2614 IDirectDrawSurface4_Release(primary);
2616 memset(&ddsd, 0, sizeof(ddsd));
2617 ddsd.dwSize = sizeof(ddsd);
2618 ddsd.dwFlags = DDSD_CAPS;
2619 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2621 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2622 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2623 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2624 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2625 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2626 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2627 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2628 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2630 GetWindowRect(window, &r);
2631 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2632 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2633 r.left, r.top, r.right, r.bottom);
2635 expect_messages = normal_messages;
2636 screen_size.cx = 0;
2637 screen_size.cy = 0;
2639 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
2640 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2642 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2643 expect_messages = NULL;
2644 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2646 GetWindowRect(window, &r);
2647 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2648 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2649 r.left, r.top, r.right, r.bottom);
2651 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2652 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2653 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2654 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2655 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2656 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2657 IDirectDrawSurface4_Release(primary);
2659 memset(&ddsd, 0, sizeof(ddsd));
2660 ddsd.dwSize = sizeof(ddsd);
2661 ddsd.dwFlags = DDSD_CAPS;
2662 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2664 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2665 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2666 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2667 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2668 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2669 s.right - s.left, ddsd.dwWidth);
2670 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2671 s.bottom - s.top, ddsd.dwHeight);
2673 GetWindowRect(window, &r);
2674 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2675 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2676 r.left, r.top, r.right, r.bottom);
2678 expect_messages = normal_messages;
2679 screen_size.cx = 0;
2680 screen_size.cy = 0;
2682 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2683 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2685 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2686 expect_messages = NULL;
2687 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2689 GetWindowRect(window, &r);
2690 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2691 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2692 r.left, r.top, r.right, r.bottom);
2694 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2695 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2696 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2697 s.right - s.left, ddsd.dwWidth);
2698 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2699 s.bottom - s.top, ddsd.dwHeight);
2700 IDirectDrawSurface4_Release(primary);
2702 memset(&ddsd, 0, sizeof(ddsd));
2703 ddsd.dwSize = sizeof(ddsd);
2704 ddsd.dwFlags = DDSD_CAPS;
2705 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2707 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2708 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2709 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2710 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2711 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2712 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2713 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2714 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2715 IDirectDrawSurface4_Release(primary);
2717 GetWindowRect(window, &r);
2718 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2719 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2720 r.left, r.top, r.right, r.bottom);
2722 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2723 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2724 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2725 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
2726 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2728 expect_messages = exclusive_messages;
2729 screen_size.cx = 0;
2730 screen_size.cy = 0;
2732 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2733 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2735 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2736 expect_messages = NULL;
2737 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2738 "Expected screen size %ux%u, got %ux%u.\n",
2739 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2741 GetWindowRect(window, &r);
2742 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2743 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2744 r.left, r.top, r.right, r.bottom);
2746 memset(&ddsd, 0, sizeof(ddsd));
2747 ddsd.dwSize = sizeof(ddsd);
2748 ddsd.dwFlags = DDSD_CAPS;
2749 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2751 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2752 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2753 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2754 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2755 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2756 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2757 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2758 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2759 IDirectDrawSurface_Release(primary);
2761 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2762 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2763 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2764 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
2765 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2767 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2768 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2770 memset(&ddsd, 0, sizeof(ddsd));
2771 ddsd.dwSize = sizeof(ddsd);
2772 ddsd.dwFlags = DDSD_CAPS;
2773 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2775 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2776 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2777 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2778 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2779 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2780 s.right - s.left, ddsd.dwWidth);
2781 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2782 s.bottom - s.top, ddsd.dwHeight);
2783 IDirectDrawSurface_Release(primary);
2785 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2786 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2788 /* If the window is changed at the same time, messages are sent to the new window. */
2789 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2790 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2791 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
2792 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2794 expect_messages = exclusive_messages;
2795 screen_size.cx = 0;
2796 screen_size.cy = 0;
2797 screen_size2.cx = 0;
2798 screen_size2.cy = 0;
2800 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
2801 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2803 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2804 expect_messages = NULL;
2805 ok(!screen_size.cx && !screen_size.cy, "Got unxpected screen size %ux%u.\n",
2806 screen_size.cx, screen_size.cy);
2807 ok(screen_size2.cx == fullscreen_rect.right && screen_size2.cy == fullscreen_rect.bottom,
2808 "Expected screen size 2 %ux%u, got %ux%u.\n",
2809 fullscreen_rect.right, fullscreen_rect.bottom, screen_size2.cx, screen_size2.cy);
2811 GetWindowRect(window, &r);
2812 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2813 s.left, s.top, s.right, s.bottom,
2814 r.left, r.top, r.right, r.bottom);
2815 GetWindowRect(window2, &r);
2816 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2817 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2818 r.left, r.top, r.right, r.bottom);
2820 memset(&ddsd, 0, sizeof(ddsd));
2821 ddsd.dwSize = sizeof(ddsd);
2822 ddsd.dwFlags = DDSD_CAPS;
2823 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2825 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2826 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2827 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2828 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2829 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2830 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2831 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2832 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2833 IDirectDrawSurface_Release(primary);
2835 ref = IDirectDraw4_Release(ddraw);
2836 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2838 GetWindowRect(window, &r);
2839 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2840 s.left, s.top, s.right, s.bottom,
2841 r.left, r.top, r.right, r.bottom);
2843 expect_messages = NULL;
2844 DestroyWindow(window);
2845 DestroyWindow(window2);
2846 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2847 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
2850 static void test_coop_level_mode_set_multi(void)
2852 IDirectDraw4 *ddraw1, *ddraw2;
2853 UINT orig_w, orig_h, w, h;
2854 HWND window;
2855 HRESULT hr;
2856 ULONG ref;
2858 if (!(ddraw1 = create_ddraw()))
2860 skip("Failed to create a ddraw object, skipping test.\n");
2861 return;
2864 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2865 0, 0, 100, 100, 0, 0, 0, 0);
2867 orig_w = GetSystemMetrics(SM_CXSCREEN);
2868 orig_h = GetSystemMetrics(SM_CYSCREEN);
2870 /* With just a single ddraw object, the display mode is restored on
2871 * release. */
2872 hr = IDirectDraw4_SetDisplayMode(ddraw1, 800, 600, 32, 0, 0);
2873 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2874 w = GetSystemMetrics(SM_CXSCREEN);
2875 ok(w == 800, "Got unexpected screen width %u.\n", w);
2876 h = GetSystemMetrics(SM_CYSCREEN);
2877 ok(h == 600, "Got unexpected screen height %u.\n", h);
2879 ref = IDirectDraw4_Release(ddraw1);
2880 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2881 w = GetSystemMetrics(SM_CXSCREEN);
2882 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2883 h = GetSystemMetrics(SM_CYSCREEN);
2884 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2886 /* When there are multiple ddraw objects, the display mode is restored to
2887 * the initial mode, before the first SetDisplayMode() call. */
2888 ddraw1 = create_ddraw();
2889 hr = IDirectDraw4_SetDisplayMode(ddraw1, 800, 600, 32, 0, 0);
2890 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2891 w = GetSystemMetrics(SM_CXSCREEN);
2892 ok(w == 800, "Got unexpected screen width %u.\n", w);
2893 h = GetSystemMetrics(SM_CYSCREEN);
2894 ok(h == 600, "Got unexpected screen height %u.\n", h);
2896 ddraw2 = create_ddraw();
2897 hr = IDirectDraw4_SetDisplayMode(ddraw2, 640, 480, 32, 0, 0);
2898 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2899 w = GetSystemMetrics(SM_CXSCREEN);
2900 ok(w == 640, "Got unexpected screen width %u.\n", w);
2901 h = GetSystemMetrics(SM_CYSCREEN);
2902 ok(h == 480, "Got unexpected screen height %u.\n", h);
2904 ref = IDirectDraw4_Release(ddraw2);
2905 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2906 w = GetSystemMetrics(SM_CXSCREEN);
2907 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2908 h = GetSystemMetrics(SM_CYSCREEN);
2909 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2911 ref = IDirectDraw4_Release(ddraw1);
2912 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2913 w = GetSystemMetrics(SM_CXSCREEN);
2914 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2915 h = GetSystemMetrics(SM_CYSCREEN);
2916 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2918 /* Regardless of release ordering. */
2919 ddraw1 = create_ddraw();
2920 hr = IDirectDraw4_SetDisplayMode(ddraw1, 800, 600, 32, 0, 0);
2921 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2922 w = GetSystemMetrics(SM_CXSCREEN);
2923 ok(w == 800, "Got unexpected screen width %u.\n", w);
2924 h = GetSystemMetrics(SM_CYSCREEN);
2925 ok(h == 600, "Got unexpected screen height %u.\n", h);
2927 ddraw2 = create_ddraw();
2928 hr = IDirectDraw4_SetDisplayMode(ddraw2, 640, 480, 32, 0, 0);
2929 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2930 w = GetSystemMetrics(SM_CXSCREEN);
2931 ok(w == 640, "Got unexpected screen width %u.\n", w);
2932 h = GetSystemMetrics(SM_CYSCREEN);
2933 ok(h == 480, "Got unexpected screen height %u.\n", h);
2935 ref = IDirectDraw4_Release(ddraw1);
2936 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2937 w = GetSystemMetrics(SM_CXSCREEN);
2938 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2939 h = GetSystemMetrics(SM_CYSCREEN);
2940 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2942 ref = IDirectDraw4_Release(ddraw2);
2943 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2944 w = GetSystemMetrics(SM_CXSCREEN);
2945 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2946 h = GetSystemMetrics(SM_CYSCREEN);
2947 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2949 /* But only for ddraw objects that called SetDisplayMode(). */
2950 ddraw1 = create_ddraw();
2951 ddraw2 = create_ddraw();
2952 hr = IDirectDraw4_SetDisplayMode(ddraw2, 640, 480, 32, 0, 0);
2953 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2954 w = GetSystemMetrics(SM_CXSCREEN);
2955 ok(w == 640, "Got unexpected screen width %u.\n", w);
2956 h = GetSystemMetrics(SM_CYSCREEN);
2957 ok(h == 480, "Got unexpected screen height %u.\n", h);
2959 ref = IDirectDraw4_Release(ddraw1);
2960 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2961 w = GetSystemMetrics(SM_CXSCREEN);
2962 ok(w == 640, "Got unexpected screen width %u.\n", w);
2963 h = GetSystemMetrics(SM_CYSCREEN);
2964 ok(h == 480, "Got unexpected screen height %u.\n", h);
2966 ref = IDirectDraw4_Release(ddraw2);
2967 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2968 w = GetSystemMetrics(SM_CXSCREEN);
2969 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
2970 h = GetSystemMetrics(SM_CYSCREEN);
2971 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
2973 /* If there's a ddraw object that's currently in exclusive mode, it blocks
2974 * restoring the display mode. */
2975 ddraw1 = create_ddraw();
2976 hr = IDirectDraw4_SetDisplayMode(ddraw1, 800, 600, 32, 0, 0);
2977 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2978 w = GetSystemMetrics(SM_CXSCREEN);
2979 ok(w == 800, "Got unexpected screen width %u.\n", w);
2980 h = GetSystemMetrics(SM_CYSCREEN);
2981 ok(h == 600, "Got unexpected screen height %u.\n", h);
2983 ddraw2 = create_ddraw();
2984 hr = IDirectDraw4_SetDisplayMode(ddraw2, 640, 480, 32, 0, 0);
2985 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2986 w = GetSystemMetrics(SM_CXSCREEN);
2987 ok(w == 640, "Got unexpected screen width %u.\n", w);
2988 h = GetSystemMetrics(SM_CYSCREEN);
2989 ok(h == 480, "Got unexpected screen height %u.\n", h);
2991 hr = IDirectDraw4_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2992 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2994 ref = IDirectDraw4_Release(ddraw1);
2995 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2996 w = GetSystemMetrics(SM_CXSCREEN);
2997 ok(w == 640, "Got unexpected screen width %u.\n", w);
2998 h = GetSystemMetrics(SM_CYSCREEN);
2999 ok(h == 480, "Got unexpected screen height %u.\n", h);
3001 ref = IDirectDraw4_Release(ddraw2);
3002 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3003 w = GetSystemMetrics(SM_CXSCREEN);
3004 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3005 h = GetSystemMetrics(SM_CYSCREEN);
3006 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3008 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3009 ddraw1 = create_ddraw();
3010 hr = IDirectDraw4_SetDisplayMode(ddraw1, 800, 600, 32, 0, 0);
3011 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
3012 w = GetSystemMetrics(SM_CXSCREEN);
3013 ok(w == 800, "Got unexpected screen width %u.\n", w);
3014 h = GetSystemMetrics(SM_CYSCREEN);
3015 ok(h == 600, "Got unexpected screen height %u.\n", h);
3017 hr = IDirectDraw4_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3018 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3020 ddraw2 = create_ddraw();
3021 hr = IDirectDraw4_SetDisplayMode(ddraw2, 640, 480, 32, 0, 0);
3022 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3024 ref = IDirectDraw4_Release(ddraw1);
3025 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3026 w = GetSystemMetrics(SM_CXSCREEN);
3027 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3028 h = GetSystemMetrics(SM_CYSCREEN);
3029 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3031 ref = IDirectDraw4_Release(ddraw2);
3032 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3033 w = GetSystemMetrics(SM_CXSCREEN);
3034 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3035 h = GetSystemMetrics(SM_CYSCREEN);
3036 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3038 DestroyWindow(window);
3041 static void test_initialize(void)
3043 IDirectDraw4 *ddraw;
3044 HRESULT hr;
3046 if (!(ddraw = create_ddraw()))
3048 skip("Failed to create a ddraw object, skipping test.\n");
3049 return;
3052 hr = IDirectDraw4_Initialize(ddraw, NULL);
3053 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3054 IDirectDraw4_Release(ddraw);
3056 CoInitialize(NULL);
3057 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw4, (void **)&ddraw);
3058 ok(SUCCEEDED(hr), "Failed to create IDirectDraw4 instance, hr %#x.\n", hr);
3059 hr = IDirectDraw4_Initialize(ddraw, NULL);
3060 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3061 hr = IDirectDraw4_Initialize(ddraw, NULL);
3062 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3063 IDirectDraw4_Release(ddraw);
3064 CoUninitialize();
3067 static void test_coop_level_surf_create(void)
3069 IDirectDrawSurface4 *surface;
3070 IDirectDraw4 *ddraw;
3071 DDSURFACEDESC2 ddsd;
3072 HRESULT hr;
3074 if (!(ddraw = create_ddraw()))
3076 skip("Failed to create a ddraw object, skipping test.\n");
3077 return;
3080 memset(&ddsd, 0, sizeof(ddsd));
3081 ddsd.dwSize = sizeof(ddsd);
3082 ddsd.dwFlags = DDSD_CAPS;
3083 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3084 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
3085 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3087 IDirectDraw4_Release(ddraw);
3090 static void test_vb_discard(void)
3092 static const struct vec4 quad[] =
3094 { 0.0f, 480.0f, 0.0f, 1.0f},
3095 { 0.0f, 0.0f, 0.0f, 1.0f},
3096 {640.0f, 480.0f, 0.0f, 1.0f},
3097 {640.0f, 0.0f, 0.0f, 1.0f},
3100 IDirect3DDevice3 *device;
3101 IDirect3D3 *d3d;
3102 IDirect3DVertexBuffer *buffer;
3103 HWND window;
3104 HRESULT hr;
3105 D3DVERTEXBUFFERDESC desc;
3106 BYTE *data;
3107 static const unsigned int vbsize = 16;
3108 unsigned int i;
3110 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3111 0, 0, 640, 480, 0, 0, 0, 0);
3113 if (!(device = create_device(window, DDSCL_NORMAL)))
3115 skip("Failed to create D3D device, skipping test.\n");
3116 DestroyWindow(window);
3117 return;
3120 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
3121 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3123 memset(&desc, 0, sizeof(desc));
3124 desc.dwSize = sizeof(desc);
3125 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3126 desc.dwFVF = D3DFVF_XYZRHW;
3127 desc.dwNumVertices = vbsize;
3128 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
3129 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3131 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3132 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3133 memcpy(data, quad, sizeof(quad));
3134 hr = IDirect3DVertexBuffer_Unlock(buffer);
3135 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3137 hr = IDirect3DDevice3_BeginScene(device);
3138 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3139 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3140 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3141 hr = IDirect3DDevice3_EndScene(device);
3142 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3144 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3145 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3146 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3147 hr = IDirect3DVertexBuffer_Unlock(buffer);
3148 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3150 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3151 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3152 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3154 if (data[i] != 0xaa)
3156 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3157 break;
3160 hr = IDirect3DVertexBuffer_Unlock(buffer);
3161 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3163 IDirect3DVertexBuffer_Release(buffer);
3164 IDirect3D3_Release(d3d);
3165 IDirect3DDevice3_Release(device);
3166 DestroyWindow(window);
3169 static void test_coop_level_multi_window(void)
3171 HWND window1, window2;
3172 IDirectDraw4 *ddraw;
3173 HRESULT hr;
3175 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3176 0, 0, 640, 480, 0, 0, 0, 0);
3177 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3178 0, 0, 640, 480, 0, 0, 0, 0);
3179 if (!(ddraw = create_ddraw()))
3181 skip("Failed to create a ddraw object, skipping test.\n");
3182 DestroyWindow(window2);
3183 DestroyWindow(window1);
3184 return;
3187 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3188 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3189 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3190 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3191 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3192 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3194 IDirectDraw4_Release(ddraw);
3195 DestroyWindow(window2);
3196 DestroyWindow(window1);
3199 static void test_draw_strided(void)
3201 static struct vec3 position[] =
3203 {-1.0, -1.0, 0.0},
3204 {-1.0, 1.0, 0.0},
3205 { 1.0, 1.0, 0.0},
3206 { 1.0, -1.0, 0.0},
3208 static DWORD diffuse[] =
3210 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3212 static WORD indices[] =
3214 0, 1, 2, 2, 3, 0
3217 IDirectDrawSurface4 *rt;
3218 IDirect3DDevice3 *device;
3219 D3DCOLOR color;
3220 HWND window;
3221 HRESULT hr;
3222 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3223 IDirect3DViewport3 *viewport;
3224 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3226 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3227 0, 0, 640, 480, 0, 0, 0, 0);
3229 if (!(device = create_device(window, DDSCL_NORMAL)))
3231 skip("Failed to create D3D device, skipping test.\n");
3232 DestroyWindow(window);
3233 return;
3236 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3237 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3238 viewport = create_viewport(device, 0, 0, 640, 480);
3239 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3240 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
3241 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
3242 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3244 hr = IDirect3DDevice3_BeginScene(device);
3245 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3247 memset(&strided, 0x55, sizeof(strided));
3248 strided.position.lpvData = position;
3249 strided.position.dwStride = sizeof(*position);
3250 strided.diffuse.lpvData = diffuse;
3251 strided.diffuse.dwStride = sizeof(*diffuse);
3252 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3253 &strided, 4, indices, 6, 0);
3254 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3256 hr = IDirect3DDevice3_EndScene(device);
3257 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3259 color = get_surface_color(rt, 320, 240);
3260 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3262 IDirect3DViewport3_Release(viewport);
3263 IDirectDrawSurface4_Release(rt);
3264 IDirect3DDevice3_Release(device);
3265 DestroyWindow(window);
3268 static void test_clear_rect_count(void)
3270 IDirectDrawSurface4 *rt;
3271 IDirect3DDevice3 *device;
3272 D3DCOLOR color;
3273 HWND window;
3274 HRESULT hr;
3275 IDirect3DViewport3 *viewport;
3276 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3278 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3279 0, 0, 640, 480, 0, 0, 0, 0);
3280 if (!(device = create_device(window, DDSCL_NORMAL)))
3282 skip("Failed to create D3D device, skipping test.\n");
3283 DestroyWindow(window);
3284 return;
3287 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3288 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3290 viewport = create_viewport(device, 0, 0, 640, 480);
3291 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3292 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
3293 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00ffffff, 0.0f, 0);
3294 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3295 hr = IDirect3DViewport3_Clear2(viewport, 0, &clear_rect, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
3296 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3297 hr = IDirect3DViewport3_Clear2(viewport, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
3298 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3299 hr = IDirect3DViewport3_Clear2(viewport, 1, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
3300 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3302 color = get_surface_color(rt, 320, 240);
3303 ok(compare_color(color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", color);
3305 IDirect3DViewport3_Release(viewport);
3306 IDirectDrawSurface4_Release(rt);
3307 IDirect3DDevice3_Release(device);
3308 DestroyWindow(window);
3311 static BOOL test_mode_restored(IDirectDraw4 *ddraw, HWND window)
3313 DDSURFACEDESC2 ddsd1, ddsd2;
3314 HRESULT hr;
3316 memset(&ddsd1, 0, sizeof(ddsd1));
3317 ddsd1.dwSize = sizeof(ddsd1);
3318 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd1);
3319 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3321 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3322 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3323 hr = IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 32, 0, 0);
3324 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
3325 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3326 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3328 memset(&ddsd2, 0, sizeof(ddsd2));
3329 ddsd2.dwSize = sizeof(ddsd2);
3330 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd2);
3331 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3332 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3333 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3335 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
3338 static void test_coop_level_versions(void)
3340 HWND window;
3341 IDirectDraw *ddraw;
3342 HRESULT hr;
3343 BOOL restored;
3344 IDirectDrawSurface *surface;
3345 IDirectDraw4 *ddraw4;
3346 DDSURFACEDESC ddsd;
3348 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3349 0, 0, 640, 480, 0, 0, 0, 0);
3351 if (!(ddraw4 = create_ddraw()))
3352 goto done;
3353 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3354 restored = test_mode_restored(ddraw4, window);
3355 ok(restored, "Display mode not restored in new ddraw object\n");
3357 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3358 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3359 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3361 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3362 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3363 restored = test_mode_restored(ddraw4, window);
3364 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3366 /* A successful one does */
3367 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3368 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3369 restored = test_mode_restored(ddraw4, window);
3370 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3372 IDirectDraw_Release(ddraw);
3373 IDirectDraw4_Release(ddraw4);
3375 if (!(ddraw4 = create_ddraw()))
3376 goto done;
3377 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3378 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3380 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
3381 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3382 restored = test_mode_restored(ddraw4, window);
3383 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3385 IDirectDraw_Release(ddraw);
3386 IDirectDraw4_Release(ddraw4);
3388 /* A failing call does not restore the ddraw2+ behavior */
3389 if (!(ddraw4 = create_ddraw()))
3390 goto done;
3391 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3392 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3394 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3395 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3396 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3397 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3398 restored = test_mode_restored(ddraw4, window);
3399 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3401 IDirectDraw_Release(ddraw);
3402 IDirectDraw4_Release(ddraw4);
3404 /* Neither does a sequence of successful calls with the new interface */
3405 if (!(ddraw4 = create_ddraw()))
3406 goto done;
3407 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3408 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3410 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3411 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3412 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3413 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3414 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
3415 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3417 restored = test_mode_restored(ddraw4, window);
3418 ok(!restored, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
3419 IDirectDraw_Release(ddraw);
3420 IDirectDraw4_Release(ddraw4);
3422 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3423 if (!(ddraw4 = create_ddraw()))
3424 goto done;
3425 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3426 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3428 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
3429 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3431 memset(&ddsd, 0, sizeof(ddsd));
3432 ddsd.dwSize = sizeof(ddsd);
3433 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3434 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3435 ddsd.dwWidth = ddsd.dwHeight = 8;
3436 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3437 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
3438 IDirectDrawSurface_Release(surface);
3439 restored = test_mode_restored(ddraw4, window);
3440 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
3442 IDirectDraw_Release(ddraw);
3443 IDirectDraw4_Release(ddraw4);
3445 done:
3446 DestroyWindow(window);
3449 static void test_lighting_interface_versions(void)
3451 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3452 IDirect3DMaterial3 *emissive;
3453 IDirect3DViewport3 *viewport;
3454 IDirect3DDevice3 *device;
3455 IDirectDrawSurface4 *rt;
3456 IDirect3D3 *d3d;
3457 D3DCOLOR color;
3458 HWND window;
3459 HRESULT hr;
3460 D3DMATERIALHANDLE mat_handle;
3461 D3DMATERIAL mat_desc;
3462 DWORD rs;
3463 unsigned int i;
3464 ULONG ref;
3465 static D3DVERTEX quad[] =
3467 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3468 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3469 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3470 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3473 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3474 static struct
3476 struct vec3 position;
3477 struct vec3 normal;
3478 DWORD diffuse, specular;
3480 quad2[] =
3482 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3483 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3484 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3485 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3488 static D3DLVERTEX lquad[] =
3490 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3491 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3492 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3493 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3496 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3497 static struct
3499 struct vec3 position;
3500 DWORD diffuse, specular;
3501 struct vec2 texcoord;
3503 lquad2[] =
3505 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3506 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3507 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3508 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3511 static D3DTLVERTEX tlquad[] =
3513 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3514 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3515 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3516 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3519 #define FVF_TLVERTEX2 (D3DFVF_XYZRHW | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3520 static struct
3522 struct vec4 position;
3523 struct vec3 normal;
3524 DWORD diffuse, specular;
3526 tlquad2[] =
3528 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0xff0000ff, 0xff808080},
3529 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0xff0000ff, 0xff808080},
3530 {{ 640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0xff0000ff, 0xff808080},
3531 {{ 640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, 0xff0000ff, 0xff808080},
3534 static const struct
3536 DWORD vertextype;
3537 void *data;
3538 DWORD d3drs_lighting, d3drs_specular;
3539 DWORD draw_flags;
3540 D3DCOLOR color;
3542 tests[] =
3544 /* Lighting is enabled when all of these conditions are met:
3545 * 1) No pretransformed position(D3DFVF_XYZRHW)
3546 * 2) Normals are available (D3DFVF_NORMAL)
3547 * 3) D3DDP_DONOTLIGHT is not set.
3549 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
3550 * in this d3d version */
3552 /* 0 */
3553 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x0000ff00},
3554 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
3555 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3556 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3557 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x0000ff00},
3558 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
3559 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3560 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3562 /* 8 */
3563 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x0000ff00},
3564 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
3565 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3566 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3567 /* The specular color in the vertex is ignored because
3568 * D3DRENDERSTATE_COLORVERTEX is not enabled */
3569 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x0000ff00},
3570 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
3571 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3572 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3574 /* 16 */
3575 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
3576 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x00ff0000},
3577 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3578 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3579 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
3580 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x00ff8080},
3581 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3582 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3584 /* 24 */
3585 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
3586 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x00ff0000},
3587 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3588 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3589 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
3590 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x00ff8080},
3591 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3592 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3594 /* 32 */
3595 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
3596 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
3597 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3598 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3599 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
3600 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
3601 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3602 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3604 /* 40 */
3605 { FVF_TLVERTEX2, tlquad2, FALSE, FALSE, 0, 0x000000ff},
3606 { FVF_TLVERTEX2, tlquad2, TRUE, FALSE, 0, 0x000000ff},
3607 { FVF_TLVERTEX2, tlquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3608 { FVF_TLVERTEX2, tlquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3609 { FVF_TLVERTEX2, tlquad2, FALSE, TRUE, 0, 0x008080ff},
3610 { FVF_TLVERTEX2, tlquad2, TRUE, TRUE, 0, 0x008080ff},
3611 { FVF_TLVERTEX2, tlquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3612 { FVF_TLVERTEX2, tlquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3615 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3616 0, 0, 640, 480, 0, 0, 0, 0);
3618 if (!(device = create_device(window, DDSCL_NORMAL)))
3620 skip("Failed to create D3D device, skipping test.\n");
3621 DestroyWindow(window);
3622 return;
3624 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
3625 ok(SUCCEEDED(hr), "Failed to get IDirect3D3 interface, hr %#x.\n", hr);
3627 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3628 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3630 viewport = create_viewport(device, 0, 0, 640, 480);
3631 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3632 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
3634 memset(&mat_desc, 0, sizeof(mat_desc));
3635 mat_desc.dwSize = sizeof(mat_desc);
3636 U2(U3(mat_desc).dcvEmissive).g = 1.0f;
3637 hr = IDirect3D3_CreateMaterial(d3d, &emissive, NULL);
3638 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
3639 hr = IDirect3DMaterial3_SetMaterial(emissive, &mat_desc);
3640 ok(SUCCEEDED(hr), "Failed to set material, hr %#x.\n", hr);
3641 hr = IDirect3DMaterial3_GetHandle(emissive, device, &mat_handle);
3642 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
3643 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
3644 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
3645 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3646 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
3648 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
3649 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
3650 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
3652 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3654 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
3655 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3657 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
3658 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
3659 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
3660 tests[i].d3drs_specular);
3661 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
3663 hr = IDirect3DDevice3_BeginScene(device);
3664 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3665 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
3666 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
3667 hr = IDirect3DDevice3_EndScene(device);
3668 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3670 color = get_surface_color(rt, 320, 240);
3671 ok(compare_color(color, tests[i].color, 1),
3672 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3673 color, tests[i].color, i);
3676 IDirect3DMaterial3_Release(emissive);
3677 IDirectDrawSurface4_Release(rt);
3678 ref = IDirect3DDevice3_Release(device);
3679 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
3680 ref = IDirect3D3_Release(d3d);
3681 ok(ref == 0, "D3d not properly released, refcount %u.\n", ref);
3684 static struct
3686 BOOL received;
3687 IDirectDraw4 *ddraw;
3688 HWND window;
3689 DWORD coop_level;
3690 } activateapp_testdata;
3692 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3694 if (message == WM_ACTIVATEAPP)
3696 if (activateapp_testdata.ddraw)
3698 HRESULT hr;
3699 activateapp_testdata.received = FALSE;
3700 hr = IDirectDraw4_SetCooperativeLevel(activateapp_testdata.ddraw,
3701 activateapp_testdata.window, activateapp_testdata.coop_level);
3702 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3703 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3705 activateapp_testdata.received = TRUE;
3708 return DefWindowProcA(hwnd, message, wparam, lparam);
3711 static void test_coop_level_activateapp(void)
3713 IDirectDraw4 *ddraw;
3714 HRESULT hr;
3715 HWND window;
3716 WNDCLASSA wc = {0};
3717 DDSURFACEDESC2 ddsd;
3718 IDirectDrawSurface4 *surface;
3720 if (!(ddraw = create_ddraw()))
3722 skip("Failed to create IDirectDraw4 object, skipping tests.\n");
3723 return;
3726 wc.lpfnWndProc = activateapp_test_proc;
3727 wc.lpszClassName = "ddraw_test_wndproc_wc";
3728 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3730 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3731 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3733 /* Exclusive with window already active. */
3734 SetActiveWindow(window);
3735 activateapp_testdata.received = FALSE;
3736 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3737 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3738 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3739 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3740 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3742 /* Exclusive with window not active. */
3743 SetActiveWindow(NULL);
3744 activateapp_testdata.received = FALSE;
3745 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3746 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3747 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3748 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3749 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3751 /* Normal with window not active, then exclusive with the same window. */
3752 SetActiveWindow(NULL);
3753 activateapp_testdata.received = FALSE;
3754 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3755 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3756 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3757 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3758 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3759 /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
3760 * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken. */
3761 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3762 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3763 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3764 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3766 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3767 SetActiveWindow(NULL);
3768 activateapp_testdata.received = FALSE;
3769 activateapp_testdata.ddraw = ddraw;
3770 activateapp_testdata.window = window;
3771 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3772 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3773 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3774 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3775 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3776 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3777 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3779 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3780 * succeeding. Another switch to exclusive and back to normal is needed to release the
3781 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3782 * WM_ACTIVATEAPP messages. */
3783 activateapp_testdata.ddraw = NULL;
3784 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3785 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3786 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3787 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3789 /* Setting DDSCL_NORMAL with recursive invocation. */
3790 SetActiveWindow(NULL);
3791 activateapp_testdata.received = FALSE;
3792 activateapp_testdata.ddraw = ddraw;
3793 activateapp_testdata.window = window;
3794 activateapp_testdata.coop_level = DDSCL_NORMAL;
3795 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3796 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3797 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3798 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3800 /* DDraw is in exlusive mode now. */
3801 memset(&ddsd, 0, sizeof(ddsd));
3802 ddsd.dwSize = sizeof(ddsd);
3803 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3804 ddsd.dwBackBufferCount = 1;
3805 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3806 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
3807 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3808 IDirectDrawSurface4_Release(surface);
3810 /* Recover again, just to be sure. */
3811 activateapp_testdata.ddraw = NULL;
3812 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3813 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3814 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3815 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3817 DestroyWindow(window);
3818 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3819 IDirectDraw4_Release(ddraw);
3822 static void test_texturemanage(void)
3824 IDirectDraw4 *ddraw;
3825 HRESULT hr;
3826 DDSURFACEDESC2 ddsd;
3827 IDirectDrawSurface4 *surface;
3828 unsigned int i;
3829 DDCAPS hal_caps, hel_caps;
3830 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
3831 static const struct
3833 DWORD caps_in, caps2_in;
3834 HRESULT hr;
3835 DWORD caps_out, caps2_out;
3837 tests[] =
3839 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3840 ~0U, ~0U},
3841 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3842 ~0U, ~0U},
3843 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
3844 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
3845 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
3846 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
3847 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
3848 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
3850 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3851 ~0U, ~0U},
3852 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3853 ~0U, ~0U},
3854 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3855 ~0U, ~0U},
3856 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
3857 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
3858 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
3859 DDSCAPS_SYSTEMMEMORY, 0},
3862 if (!(ddraw = create_ddraw()))
3864 skip("Failed to create IDirectDraw4 object, skipping tests.\n");
3865 return;
3868 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3869 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3871 memset(&hal_caps, 0, sizeof(hal_caps));
3872 hal_caps.dwSize = sizeof(hal_caps);
3873 memset(&hel_caps, 0, sizeof(hel_caps));
3874 hel_caps.dwSize = sizeof(hel_caps);
3875 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
3876 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
3877 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
3879 skip("Managed textures not supported, skipping managed texture test.\n");
3880 IDirectDraw4_Release(ddraw);
3881 return;
3884 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3886 memset(&ddsd, 0, sizeof(ddsd));
3887 ddsd.dwSize = sizeof(ddsd);
3888 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3889 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
3890 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
3891 ddsd.dwWidth = 4;
3892 ddsd.dwHeight = 4;
3894 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
3895 ok(hr == tests[i].hr, "Got unexpected, hr %#x, case %u.\n", hr, i);
3896 if (FAILED(hr))
3897 continue;
3899 memset(&ddsd, 0, sizeof(ddsd));
3900 ddsd.dwSize = sizeof(ddsd);
3901 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
3902 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3904 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
3905 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
3906 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
3907 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
3908 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
3909 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
3911 IDirectDrawSurface4_Release(surface);
3914 IDirectDraw4_Release(ddraw);
3917 #define SUPPORT_DXT1 0x01
3918 #define SUPPORT_DXT2 0x02
3919 #define SUPPORT_DXT3 0x04
3920 #define SUPPORT_DXT4 0x08
3921 #define SUPPORT_DXT5 0x10
3922 #define SUPPORT_YUY2 0x20
3923 #define SUPPORT_UYVY 0x40
3925 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
3927 DWORD *supported_fmts = ctx;
3929 if (!(fmt->dwFlags & DDPF_FOURCC))
3930 return DDENUMRET_OK;
3932 switch (fmt->dwFourCC)
3934 case MAKEFOURCC('D','X','T','1'):
3935 *supported_fmts |= SUPPORT_DXT1;
3936 break;
3937 case MAKEFOURCC('D','X','T','2'):
3938 *supported_fmts |= SUPPORT_DXT2;
3939 break;
3940 case MAKEFOURCC('D','X','T','3'):
3941 *supported_fmts |= SUPPORT_DXT3;
3942 break;
3943 case MAKEFOURCC('D','X','T','4'):
3944 *supported_fmts |= SUPPORT_DXT4;
3945 break;
3946 case MAKEFOURCC('D','X','T','5'):
3947 *supported_fmts |= SUPPORT_DXT5;
3948 break;
3949 case MAKEFOURCC('Y','U','Y','2'):
3950 *supported_fmts |= SUPPORT_YUY2;
3951 break;
3952 case MAKEFOURCC('U','Y','V','Y'):
3953 *supported_fmts |= SUPPORT_UYVY;
3954 break;
3955 default:
3956 break;
3959 return DDENUMRET_OK;
3962 static void test_block_formats_creation(void)
3964 HRESULT hr, expect_hr;
3965 unsigned int i, j, w, h;
3966 HWND window;
3967 IDirectDraw4 *ddraw;
3968 IDirect3D3 *d3d;
3969 IDirect3DDevice3 *device;
3970 IDirectDrawSurface4 *surface;
3971 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
3972 DWORD num_fourcc_codes = 0, *fourcc_codes;
3973 DDSURFACEDESC2 ddsd;
3974 static const struct
3976 DWORD fourcc;
3977 const char *name;
3978 DWORD support_flag;
3979 unsigned int block_width;
3980 unsigned int block_height;
3981 BOOL create_size_checked, overlay;
3983 formats[] =
3985 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, TRUE, FALSE},
3986 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, TRUE, FALSE},
3987 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, TRUE, FALSE},
3988 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, TRUE, FALSE},
3989 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, TRUE, FALSE},
3990 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, FALSE, TRUE },
3991 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, FALSE, TRUE },
3993 const struct
3995 DWORD caps, caps2;
3996 const char *name;
3997 BOOL overlay;
3999 types[] =
4001 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4002 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4004 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4005 * Other hw / drivers successfully create those surfaces. Ignore them, this
4006 * suggests that no game uses this, otherwise Nvidia would support it. */
4008 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4009 "videomemory texture", FALSE
4012 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4013 "videomemory overlay", TRUE
4016 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4017 "systemmemory texture", FALSE
4020 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4021 "managed texture", FALSE
4025 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4026 0, 0, 640, 480, 0, 0, 0, 0);
4028 if (!(device = create_device(window, DDSCL_NORMAL)))
4030 skip("Failed to create D3D device, skipping test.\n");
4031 DestroyWindow(window);
4032 return;
4035 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4036 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4037 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
4038 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4039 IDirect3D3_Release(d3d);
4041 hr = IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb,
4042 &supported_fmts);
4043 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4045 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4046 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4047 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4048 num_fourcc_codes * sizeof(*fourcc_codes));
4049 if (!fourcc_codes)
4050 goto cleanup;
4051 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
4052 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4053 for (i = 0; i < num_fourcc_codes; i++)
4055 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
4057 if (fourcc_codes[i] == formats[j].fourcc)
4058 supported_overlay_fmts |= formats[j].support_flag;
4061 HeapFree(GetProcessHeap(), 0, fourcc_codes);
4063 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4065 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
4067 BOOL support;
4068 if (formats[i].overlay != types[j].overlay)
4069 continue;
4071 if (formats[i].overlay)
4072 support = supported_overlay_fmts & formats[i].support_flag;
4073 else
4074 support = supported_fmts & formats[i].support_flag;
4076 for (w = 1; w <= 8; w++)
4078 for (h = 1; h <= 8; h++)
4080 BOOL block_aligned = TRUE;
4081 BOOL todo = FALSE;
4083 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
4084 block_aligned = FALSE;
4086 memset(&ddsd, 0, sizeof(ddsd));
4087 ddsd.dwSize = sizeof(ddsd);
4088 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4089 ddsd.ddsCaps.dwCaps = types[j].caps;
4090 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
4091 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
4092 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4093 ddsd.ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4094 ddsd.dwWidth = w;
4095 ddsd.dwHeight = h;
4097 /* TODO: Handle power of two limitations. I cannot test the pow2
4098 * behavior on windows because I have no hardware that doesn't at
4099 * least support np2_conditional. There's probably no HW that
4100 * supports DXTN textures but no conditional np2 textures. */
4101 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
4102 expect_hr = DDERR_INVALIDPARAMS;
4103 else if (formats[i].create_size_checked && !block_aligned)
4105 expect_hr = DDERR_INVALIDPARAMS;
4106 if (!(types[j].caps & DDSCAPS_TEXTURE))
4107 todo = TRUE;
4109 else
4110 expect_hr = D3D_OK;
4112 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4113 if (todo)
4114 todo_wine ok(hr == expect_hr,
4115 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4116 hr, formats[i].name, types[j].name, w, h, expect_hr);
4117 else
4118 ok(hr == expect_hr,
4119 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4120 hr, formats[i].name, types[j].name, w, h, expect_hr);
4122 if (SUCCEEDED(hr))
4123 IDirectDrawSurface4_Release(surface);
4129 cleanup:
4130 IDirectDraw4_Release(ddraw);
4131 IDirect3DDevice3_Release(device);
4132 DestroyWindow(window);
4135 struct format_support_check
4137 const DDPIXELFORMAT *format;
4138 BOOL supported;
4141 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
4143 struct format_support_check *format = ctx;
4145 if (!memcmp(format->format, fmt, sizeof(*fmt)))
4147 format->supported = TRUE;
4148 return DDENUMRET_CANCEL;
4151 return DDENUMRET_OK;
4154 static void test_unsupported_formats(void)
4156 HRESULT hr;
4157 BOOL expect_success;
4158 HWND window;
4159 IDirectDraw4 *ddraw;
4160 IDirect3D3 *d3d;
4161 IDirect3DDevice3 *device;
4162 IDirectDrawSurface4 *surface;
4163 DDSURFACEDESC2 ddsd;
4164 unsigned int i, j;
4165 DWORD expected_caps;
4166 static const struct
4168 const char *name;
4169 DDPIXELFORMAT fmt;
4171 formats[] =
4174 "D3DFMT_A8R8G8B8",
4176 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
4177 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4181 "D3DFMT_P8",
4183 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4184 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4188 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
4190 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4191 0, 0, 640, 480, 0, 0, 0, 0);
4193 if (!(device = create_device(window, DDSCL_NORMAL)))
4195 skip("Failed to create D3D device, skipping test.\n");
4196 DestroyWindow(window);
4197 return;
4200 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4201 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4202 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
4203 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4204 IDirect3D3_Release(d3d);
4206 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4208 struct format_support_check check = {&formats[i].fmt, FALSE};
4209 hr = IDirect3DDevice3_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
4210 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4212 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
4214 memset(&ddsd, 0, sizeof(ddsd));
4215 ddsd.dwSize = sizeof(ddsd);
4216 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4217 ddsd.ddpfPixelFormat = formats[i].fmt;
4218 ddsd.dwWidth = 4;
4219 ddsd.dwHeight = 4;
4220 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
4222 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
4223 expect_success = FALSE;
4224 else
4225 expect_success = TRUE;
4227 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4228 ok(SUCCEEDED(hr) == expect_success,
4229 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4230 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
4231 if (FAILED(hr))
4232 continue;
4234 memset(&ddsd, 0, sizeof(ddsd));
4235 ddsd.dwSize = sizeof(ddsd);
4236 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
4237 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4239 if (caps[j] & DDSCAPS_VIDEOMEMORY)
4240 expected_caps = DDSCAPS_VIDEOMEMORY;
4241 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
4242 expected_caps = DDSCAPS_SYSTEMMEMORY;
4243 else if (check.supported)
4244 expected_caps = DDSCAPS_VIDEOMEMORY;
4245 else
4246 expected_caps = DDSCAPS_SYSTEMMEMORY;
4248 ok(ddsd.ddsCaps.dwCaps & expected_caps,
4249 "Expected capability %#x, format %s, input cap %#x.\n",
4250 expected_caps, formats[i].name, caps[j]);
4252 IDirectDrawSurface4_Release(surface);
4256 IDirectDraw4_Release(ddraw);
4257 IDirect3DDevice3_Release(device);
4258 DestroyWindow(window);
4260 START_TEST(ddraw4)
4262 test_process_vertices();
4263 test_coop_level_create_device_window();
4264 test_clipper_blt();
4265 test_coop_level_d3d_state();
4266 test_surface_interface_mismatch();
4267 test_coop_level_threaded();
4268 test_depth_blit();
4269 test_texture_load_ckey();
4270 test_viewport();
4271 test_zenable();
4272 test_ck_rgba();
4273 test_ck_default();
4274 test_surface_qi();
4275 test_device_qi();
4276 test_wndproc();
4277 test_window_style();
4278 test_redundant_mode_set();
4279 test_coop_level_mode_set();
4280 test_coop_level_mode_set_multi();
4281 test_initialize();
4282 test_coop_level_surf_create();
4283 test_vb_discard();
4284 test_coop_level_multi_window();
4285 test_draw_strided();
4286 test_clear_rect_count();
4287 test_coop_level_versions();
4288 test_lighting_interface_versions();
4289 test_coop_level_activateapp();
4290 test_texturemanage();
4291 test_block_formats_creation();
4292 test_unsupported_formats();