wined3d: Set palettes on the swapchain.
[wine/multimedia.git] / dlls / ddraw / tests / ddraw4.c
blob655fbfbda5233b0d97aa49d45116a3cd49042c44
1 /*
2 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
3 * Copyright 2012-2014 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 (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
100 DispatchMessageA(&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 = CreateEventA(NULL, FALSE, FALSE, NULL);
121 ok(!!p->window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
122 p->destroy_window = CreateEventA(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 HRESULT set_display_mode(IDirectDraw4 *ddraw, DWORD width, DWORD height)
155 if (SUCCEEDED(IDirectDraw4_SetDisplayMode(ddraw, width, height, 32, 0, 0)))
156 return DD_OK;
157 return IDirectDraw4_SetDisplayMode(ddraw, width, height, 24, 0, 0);
160 static D3DCOLOR get_surface_color(IDirectDrawSurface4 *surface, UINT x, UINT y)
162 RECT rect = {x, y, x + 1, y + 1};
163 DDSURFACEDESC2 surface_desc;
164 D3DCOLOR color;
165 HRESULT hr;
167 memset(&surface_desc, 0, sizeof(surface_desc));
168 surface_desc.dwSize = sizeof(surface_desc);
170 hr = IDirectDrawSurface4_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
171 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
172 if (FAILED(hr))
173 return 0xdeadbeef;
175 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
177 hr = IDirectDrawSurface4_Unlock(surface, &rect);
178 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
180 return color;
183 static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
185 DDPIXELFORMAT *z_fmt = ctx;
187 if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
188 *z_fmt = *format;
190 return DDENUMRET_OK;
193 static IDirectDraw4 *create_ddraw(void)
195 IDirectDraw4 *ddraw4;
196 IDirectDraw *ddraw1;
197 HRESULT hr;
199 if (FAILED(DirectDrawCreate(NULL, &ddraw1, NULL)))
200 return NULL;
202 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw4, (void **)&ddraw4);
203 IDirectDraw_Release(ddraw1);
204 if (FAILED(hr))
205 return NULL;
207 return ddraw4;
210 static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
212 IDirectDrawSurface4 *surface, *ds;
213 IDirect3DDevice3 *device = NULL;
214 DDSURFACEDESC2 surface_desc;
215 IDirectDraw4 *ddraw4;
216 DDPIXELFORMAT z_fmt;
217 IDirect3D3 *d3d3;
218 HRESULT hr;
220 if (!(ddraw4 = create_ddraw()))
221 return NULL;
223 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, coop_level);
224 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
226 memset(&surface_desc, 0, sizeof(surface_desc));
227 surface_desc.dwSize = sizeof(surface_desc);
228 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
229 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
230 surface_desc.dwWidth = 640;
231 surface_desc.dwHeight = 480;
233 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &surface, NULL);
234 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
236 if (coop_level & DDSCL_NORMAL)
238 IDirectDrawClipper *clipper;
240 hr = IDirectDraw4_CreateClipper(ddraw4, 0, &clipper, NULL);
241 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
242 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
243 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
244 hr = IDirectDrawSurface4_SetClipper(surface, clipper);
245 ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
246 IDirectDrawClipper_Release(clipper);
249 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirect3D3, (void **)&d3d3);
250 IDirectDraw4_Release(ddraw4);
251 if (FAILED(hr))
253 IDirectDrawSurface4_Release(surface);
254 return NULL;
257 memset(&z_fmt, 0, sizeof(z_fmt));
258 hr = IDirect3D3_EnumZBufferFormats(d3d3, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
259 if (FAILED(hr) || !z_fmt.dwSize)
261 IDirect3D3_Release(d3d3);
262 IDirectDrawSurface4_Release(surface);
263 return NULL;
266 memset(&surface_desc, 0, sizeof(surface_desc));
267 surface_desc.dwSize = sizeof(surface_desc);
268 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
269 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
270 U4(surface_desc).ddpfPixelFormat = z_fmt;
271 surface_desc.dwWidth = 640;
272 surface_desc.dwHeight = 480;
273 hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &ds, NULL);
274 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
275 if (FAILED(hr))
277 IDirect3D3_Release(d3d3);
278 IDirectDrawSurface4_Release(surface);
279 return NULL;
282 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
283 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
284 IDirectDrawSurface4_Release(ds);
285 if (FAILED(hr))
287 IDirect3D3_Release(d3d3);
288 IDirectDrawSurface4_Release(surface);
289 return NULL;
292 hr = IDirect3D3_CreateDevice(d3d3, &IID_IDirect3DHALDevice, surface, &device, NULL);
293 IDirect3D3_Release(d3d3);
294 IDirectDrawSurface4_Release(surface);
295 if (FAILED(hr))
296 return NULL;
298 return device;
301 static IDirect3DViewport3 *create_viewport(IDirect3DDevice3 *device, UINT x, UINT y, UINT w, UINT h)
303 IDirect3DViewport3 *viewport;
304 D3DVIEWPORT2 vp;
305 IDirect3D3 *d3d;
306 HRESULT hr;
308 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
309 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
310 hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
311 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
312 hr = IDirect3DDevice3_AddViewport(device, viewport);
313 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
314 memset(&vp, 0, sizeof(vp));
315 vp.dwSize = sizeof(vp);
316 vp.dwX = x;
317 vp.dwY = y;
318 vp.dwWidth = w;
319 vp.dwHeight = h;
320 vp.dvClipX = -1.0f;
321 vp.dvClipY = 1.0f;
322 vp.dvClipWidth = 2.0f;
323 vp.dvClipHeight = 2.0f;
324 vp.dvMinZ = 0.0f;
325 vp.dvMaxZ = 1.0f;
326 hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
327 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
328 IDirect3D3_Release(d3d);
330 return viewport;
333 static void destroy_viewport(IDirect3DDevice3 *device, IDirect3DViewport3 *viewport)
335 HRESULT hr;
337 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
338 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
339 IDirect3DViewport3_Release(viewport);
342 static IDirect3DMaterial3 *create_material(IDirect3DDevice3 *device, D3DMATERIAL *mat)
344 IDirect3DMaterial3 *material;
345 IDirect3D3 *d3d;
346 HRESULT hr;
348 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
349 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
350 hr = IDirect3D3_CreateMaterial(d3d, &material, NULL);
351 ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
352 hr = IDirect3DMaterial3_SetMaterial(material, mat);
353 ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
354 IDirect3D3_Release(d3d);
356 return material;
359 static IDirect3DMaterial3 *create_diffuse_material(IDirect3DDevice3 *device, float r, float g, float b, float a)
361 D3DMATERIAL mat;
363 memset(&mat, 0, sizeof(mat));
364 mat.dwSize = sizeof(mat);
365 U1(U(mat).diffuse).r = r;
366 U2(U(mat).diffuse).g = g;
367 U3(U(mat).diffuse).b = b;
368 U4(U(mat).diffuse).a = a;
370 return create_material(device, &mat);
373 static IDirect3DMaterial3 *create_emissive_material(IDirect3DDevice3 *device, float r, float g, float b, float a)
375 D3DMATERIAL mat;
377 memset(&mat, 0, sizeof(mat));
378 mat.dwSize = sizeof(mat);
379 U1(U3(mat).emissive).r = r;
380 U2(U3(mat).emissive).g = g;
381 U3(U3(mat).emissive).b = b;
382 U4(U3(mat).emissive).a = a;
384 return create_material(device, &mat);
387 static void destroy_material(IDirect3DMaterial3 *material)
389 IDirect3DMaterial3_Release(material);
392 static const UINT *expect_messages;
394 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
396 if (expect_messages && message == *expect_messages)
397 ++expect_messages;
399 return DefWindowProcA(hwnd, message, wparam, lparam);
402 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
403 * interface. This prevents subsequent SetCooperativeLevel() calls on a
404 * different window from failing with DDERR_HWNDALREADYSET. */
405 static void fix_wndproc(HWND window, LONG_PTR proc)
407 IDirectDraw4 *ddraw;
408 HRESULT hr;
410 if (!(ddraw = create_ddraw()))
411 return;
413 SetWindowLongPtrA(window, GWLP_WNDPROC, proc);
414 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
415 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
416 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
417 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
419 IDirectDraw4_Release(ddraw);
422 static void test_process_vertices(void)
424 IDirect3DVertexBuffer *src_vb, *dst_vb;
425 IDirect3DViewport3 *viewport;
426 D3DVERTEXBUFFERDESC vb_desc;
427 IDirect3DDevice3 *device;
428 struct vec3 *src_data;
429 struct vec4 *dst_data;
430 IDirect3D3 *d3d3;
431 D3DVIEWPORT2 vp2;
432 D3DVIEWPORT vp1;
433 HWND window;
434 HRESULT hr;
436 static D3DMATRIX identity =
438 1.0f, 0.0f, 0.0f, 0.0f,
439 0.0f, 1.0f, 0.0f, 0.0f,
440 0.0f, 0.0f, 1.0f, 0.0f,
441 0.0f, 0.0f, 0.0f, 1.0f,
443 static D3DMATRIX projection =
445 1.0f, 0.0f, 0.0f, 0.0f,
446 0.0f, 1.0f, 0.0f, 0.0f,
447 0.0f, 0.0f, 1.0f, 0.0f,
448 6.0f, 7.0f, 8.0f, 1.0f,
451 window = CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW,
452 0, 0, 640, 480, 0, 0, 0, 0);
453 if (!(device = create_device(window, DDSCL_NORMAL)))
455 skip("Failed to create a 3D device, skipping test.\n");
456 DestroyWindow(window);
457 return;
460 hr = IDirect3DDevice3_GetDirect3D(device, &d3d3);
461 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
463 memset(&vb_desc, 0, sizeof(vb_desc));
464 vb_desc.dwSize = sizeof(vb_desc);
465 vb_desc.dwFVF = D3DFVF_XYZ;
466 vb_desc.dwNumVertices = 3;
467 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &src_vb, 0, NULL);
468 ok(SUCCEEDED(hr), "Failed to create source vertex buffer, hr %#x.\n", hr);
470 hr = IDirect3DVertexBuffer_Lock(src_vb, DDLOCK_WRITEONLY, (void **)&src_data, NULL);
471 ok(SUCCEEDED(hr), "Failed to lock source vertex buffer, hr %#x.\n", hr);
472 src_data[0].x = -1.0f;
473 src_data[0].y = -1.0f;
474 src_data[0].z = -1.0f;
475 src_data[1].x = 0.0f;
476 src_data[1].y = 0.0f;
477 src_data[1].z = 0.0f;
478 src_data[2].x = 1.0f;
479 src_data[2].y = 1.0f;
480 src_data[2].z = 1.0f;
481 hr = IDirect3DVertexBuffer_Unlock(src_vb);
482 ok(SUCCEEDED(hr), "Failed to unlock source vertex buffer, hr %#x.\n", hr);
484 memset(&vb_desc, 0, sizeof(vb_desc));
485 vb_desc.dwSize = sizeof(vb_desc);
486 vb_desc.dwFVF = D3DFVF_XYZRHW;
487 vb_desc.dwNumVertices = 3;
488 hr = IDirect3D3_CreateVertexBuffer(d3d3, &vb_desc, &dst_vb, 0, NULL);
489 ok(SUCCEEDED(hr), "Failed to create destination vertex buffer, hr %#x.\n", hr);
491 hr = IDirect3D3_CreateViewport(d3d3, &viewport, NULL);
492 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
493 hr = IDirect3DDevice3_AddViewport(device, viewport);
494 ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
495 vp2.dwSize = sizeof(vp2);
496 vp2.dwX = 10;
497 vp2.dwY = 20;
498 vp2.dwWidth = 100;
499 vp2.dwHeight = 200;
500 vp2.dvClipX = 2.0f;
501 vp2.dvClipY = 3.0f;
502 vp2.dvClipWidth = 4.0f;
503 vp2.dvClipHeight = 5.0f;
504 vp2.dvMinZ = -2.0f;
505 vp2.dvMaxZ = 3.0f;
506 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
507 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
508 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
509 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
511 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &identity);
512 ok(SUCCEEDED(hr), "Failed to set world transformation, hr %#x.\n", hr);
513 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &identity);
514 ok(SUCCEEDED(hr), "Failed to set view transformation, hr %#x.\n", hr);
515 hr = IDirect3DDevice3_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &identity);
516 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
518 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
519 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
521 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
522 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
523 ok(compare_vec4(&dst_data[0], -6.500e+1f, +1.800e+2f, +2.000e-1f, +1.000e+0f, 4096),
524 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
525 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
526 ok(compare_vec4(&dst_data[1], -4.000e+1f, +1.400e+2f, +4.000e-1f, +1.000e+0f, 4096),
527 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
528 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
529 ok(compare_vec4(&dst_data[2], -1.500e+1f, +1.000e+2f, +6.000e-1f, +1.000e+0f, 4096),
530 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
531 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
532 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
533 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
535 hr = IDirect3DDevice3_MultiplyTransform(device, D3DTRANSFORMSTATE_PROJECTION, &projection);
536 ok(SUCCEEDED(hr), "Failed to set projection transformation, hr %#x.\n", hr);
538 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
539 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
541 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
542 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
543 ok(compare_vec4(&dst_data[0], +8.500e+1f, -1.000e+2f, +1.800e+0f, +1.000e+0f, 4096),
544 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
545 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
546 ok(compare_vec4(&dst_data[1], +1.100e+2f, -1.400e+2f, +2.000e+0f, +1.000e+0f, 4096),
547 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
548 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
549 ok(compare_vec4(&dst_data[2], +1.350e+2f, -1.800e+2f, +2.200e+0f, +1.000e+0f, 4096),
550 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
551 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
552 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
553 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
555 vp2.dwSize = sizeof(vp2);
556 vp2.dwX = 30;
557 vp2.dwY = 40;
558 vp2.dwWidth = 90;
559 vp2.dwHeight = 80;
560 vp2.dvClipX = 4.0f;
561 vp2.dvClipY = 6.0f;
562 vp2.dvClipWidth = 2.0f;
563 vp2.dvClipHeight = 4.0f;
564 vp2.dvMinZ = 3.0f;
565 vp2.dvMaxZ = -2.0f;
566 hr = IDirect3DViewport3_SetViewport2(viewport, &vp2);
567 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
569 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
570 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
572 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
573 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
574 ok(compare_vec4(&dst_data[0], +7.500e+1f, +4.000e+1f, -8.000e-1f, +1.000e+0f, 4096),
575 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
576 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
577 ok(compare_vec4(&dst_data[1], +1.200e+2f, +2.000e+1f, -1.000e+0f, +1.000e+0f, 4096),
578 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
579 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
580 ok(compare_vec4(&dst_data[2], +1.650e+2f, +0.000e+0f, -1.200e+0f, +1.000e+0f, 4096),
581 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
582 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
583 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
584 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
586 vp1.dwSize = sizeof(vp1);
587 vp1.dwX = 30;
588 vp1.dwY = 40;
589 vp1.dwWidth = 90;
590 vp1.dwHeight = 80;
591 vp1.dvScaleX = 7.0f;
592 vp1.dvScaleY = 2.0f;
593 vp1.dvMaxX = 6.0f;
594 vp1.dvMaxY = 10.0f;
595 vp1.dvMinZ = -2.0f;
596 vp1.dvMaxZ = 3.0f;
597 hr = IDirect3DViewport3_SetViewport(viewport, &vp1);
598 ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
600 hr = IDirect3DVertexBuffer_ProcessVertices(dst_vb, D3DVOP_TRANSFORM, 0, 3, src_vb, 0, device, 0);
601 ok(SUCCEEDED(hr), "Failed to process vertices, hr %#x.\n", hr);
603 hr = IDirect3DVertexBuffer_Lock(dst_vb, DDLOCK_READONLY, (void **)&dst_data, NULL);
604 ok(SUCCEEDED(hr), "Failed to lock destination vertex buffer, hr %#x.\n", hr);
605 ok(compare_vec4(&dst_data[0], +1.100e+2f, +6.800e+1f, +7.000e+0f, +1.000e+0f, 4096),
606 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
607 dst_data[0].x, dst_data[0].y, dst_data[0].z, dst_data[0].w);
608 ok(compare_vec4(&dst_data[1], +1.170e+2f, +6.600e+1f, +8.000e+0f, +1.000e+0f, 4096),
609 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
610 dst_data[1].x, dst_data[1].y, dst_data[1].z, dst_data[1].w);
611 ok(compare_vec4(&dst_data[2], +1.240e+2f, +6.400e+1f, +9.000e+0f, +1.000e+0f, 4096),
612 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
613 dst_data[2].x, dst_data[2].y, dst_data[2].z, dst_data[2].w);
614 hr = IDirect3DVertexBuffer_Unlock(dst_vb);
615 ok(SUCCEEDED(hr), "Failed to unlock destination vertex buffer, hr %#x.\n", hr);
617 hr = IDirect3DDevice3_DeleteViewport(device, viewport);
618 ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
620 IDirect3DVertexBuffer_Release(dst_vb);
621 IDirect3DVertexBuffer_Release(src_vb);
622 IDirect3DViewport3_Release(viewport);
623 IDirect3D3_Release(d3d3);
624 IDirect3DDevice3_Release(device);
625 DestroyWindow(window);
628 static void test_coop_level_create_device_window(void)
630 HWND focus_window, device_window;
631 IDirectDraw4 *ddraw;
632 HRESULT hr;
634 focus_window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
635 0, 0, 640, 480, 0, 0, 0, 0);
636 ddraw = create_ddraw();
637 ok(!!ddraw, "Failed to create a ddraw object.\n");
639 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
640 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
641 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
642 ok(!device_window, "Unexpected device window found.\n");
643 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW);
644 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
645 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
646 ok(!device_window, "Unexpected device window found.\n");
647 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL);
648 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
649 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
650 ok(!device_window, "Unexpected device window found.\n");
651 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_NORMAL | DDSCL_FULLSCREEN);
652 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
653 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
654 ok(!device_window, "Unexpected device window found.\n");
655 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
656 ok(hr == DDERR_NOFOCUSWINDOW || broken(hr == DDERR_INVALIDPARAMS), "Got unexpected hr %#x.\n", hr);
657 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
658 ok(!device_window, "Unexpected device window found.\n");
660 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
661 if (broken(hr == DDERR_INVALIDPARAMS))
663 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
664 IDirectDraw4_Release(ddraw);
665 DestroyWindow(focus_window);
666 return;
669 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
670 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
671 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
672 ok(!device_window, "Unexpected device window found.\n");
673 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
674 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
675 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
676 ok(!device_window, "Unexpected device window found.\n");
678 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
679 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
680 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
681 ok(!device_window, "Unexpected device window found.\n");
682 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_SETFOCUSWINDOW
683 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
684 ok(hr == DDERR_NOHWND, "Got unexpected hr %#x.\n", hr);
685 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
686 ok(!!device_window, "Device window not found.\n");
688 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
689 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
690 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
691 ok(!device_window, "Unexpected device window found.\n");
692 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW
693 | DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
694 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
695 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
696 ok(!!device_window, "Device window not found.\n");
698 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
699 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
700 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
701 ok(!device_window, "Unexpected device window found.\n");
702 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
703 ok(hr == DDERR_NOFOCUSWINDOW, "Got unexpected hr %#x.\n", hr);
704 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
705 ok(!device_window, "Unexpected device window found.\n");
706 hr = IDirectDraw4_SetCooperativeLevel(ddraw, focus_window, DDSCL_SETFOCUSWINDOW);
707 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
708 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
709 ok(!device_window, "Unexpected device window found.\n");
710 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
711 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
712 device_window = FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
713 ok(!!device_window, "Device window not found.\n");
715 IDirectDraw4_Release(ddraw);
716 DestroyWindow(focus_window);
719 static void test_clipper_blt(void)
721 IDirectDrawSurface4 *src_surface, *dst_surface;
722 RECT client_rect, src_rect;
723 IDirectDrawClipper *clipper;
724 DDSURFACEDESC2 surface_desc;
725 unsigned int i, j, x, y;
726 IDirectDraw4 *ddraw;
727 RGNDATA *rgn_data;
728 D3DCOLOR color;
729 HRGN r1, r2;
730 HWND window;
731 DDBLTFX fx;
732 HRESULT hr;
733 DWORD *ptr;
734 DWORD ret;
736 static const DWORD src_data[] =
738 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
739 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
740 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
742 static const D3DCOLOR expected1[] =
744 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
745 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
746 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
747 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
749 /* Nvidia on Windows seems to have an off-by-one error
750 * when processing source rectangles. Our left = 1 and
751 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
752 * read as well, but only for the edge pixels on the
753 * output image. The bug happens on the y axis as well,
754 * but we only read one row there, and all source rows
755 * contain the same data. This bug is not dependent on
756 * the presence of a clipper. */
757 static const D3DCOLOR expected1_broken[] =
759 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
760 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
761 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
762 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
764 static const D3DCOLOR expected2[] =
766 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
767 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
768 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
769 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
772 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
773 10, 10, 640, 480, 0, 0, 0, 0);
774 ShowWindow(window, SW_SHOW);
775 ddraw = create_ddraw();
776 ok(!!ddraw, "Failed to create a ddraw object.\n");
778 ret = GetClientRect(window, &client_rect);
779 ok(ret, "Failed to get client rect.\n");
780 ret = MapWindowPoints(window, NULL, (POINT *)&client_rect, 2);
781 ok(ret, "Failed to map client rect.\n");
783 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
784 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
786 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
787 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
788 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
789 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
790 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
791 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
792 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
793 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
794 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
795 hr = IDirectDrawClipper_GetClipList(clipper, NULL, rgn_data, &ret);
796 ok(SUCCEEDED(hr), "Failed to get clip list, hr %#x.\n", hr);
797 ok(rgn_data->rdh.dwSize == sizeof(rgn_data->rdh), "Got unexpected structure size %#x.\n", rgn_data->rdh.dwSize);
798 ok(rgn_data->rdh.iType == RDH_RECTANGLES, "Got unexpected type %#x.\n", rgn_data->rdh.iType);
799 ok(rgn_data->rdh.nCount >= 1, "Got unexpected count %u.\n", rgn_data->rdh.nCount);
800 ok(EqualRect(&rgn_data->rdh.rcBound, &client_rect),
801 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
802 rgn_data->rdh.rcBound.left, rgn_data->rdh.rcBound.top,
803 rgn_data->rdh.rcBound.right, rgn_data->rdh.rcBound.bottom,
804 client_rect.left, client_rect.top, client_rect.right, client_rect.bottom);
805 HeapFree(GetProcessHeap(), 0, rgn_data);
807 r1 = CreateRectRgn(0, 0, 320, 240);
808 ok(!!r1, "Failed to create region.\n");
809 r2 = CreateRectRgn(320, 240, 640, 480);
810 ok(!!r2, "Failed to create region.\n");
811 CombineRgn(r1, r1, r2, RGN_OR);
812 ret = GetRegionData(r1, 0, NULL);
813 rgn_data = HeapAlloc(GetProcessHeap(), 0, ret);
814 ret = GetRegionData(r1, ret, rgn_data);
815 ok(!!ret, "Failed to get region data.\n");
817 DeleteObject(r2);
818 DeleteObject(r1);
820 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
821 ok(hr == DDERR_CLIPPERISUSINGHWND, "Got unexpected hr %#x.\n", hr);
822 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
823 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
824 hr = IDirectDrawClipper_SetClipList(clipper, rgn_data, 0);
825 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
827 HeapFree(GetProcessHeap(), 0, rgn_data);
829 memset(&surface_desc, 0, sizeof(surface_desc));
830 surface_desc.dwSize = sizeof(surface_desc);
831 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
832 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
833 surface_desc.dwWidth = 640;
834 surface_desc.dwHeight = 480;
835 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
836 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
837 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
838 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
839 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
840 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
842 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src_surface, NULL);
843 ok(SUCCEEDED(hr), "Failed to create source surface, hr %#x.\n", hr);
844 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst_surface, NULL);
845 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
847 memset(&fx, 0, sizeof(fx));
848 fx.dwSize = sizeof(fx);
849 hr = IDirectDrawSurface4_Blt(src_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
850 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
851 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
852 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
854 hr = IDirectDrawSurface4_Lock(src_surface, NULL, &surface_desc, DDLOCK_WAIT, NULL);
855 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
856 ok(U1(surface_desc).lPitch == 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc).lPitch);
857 ptr = surface_desc.lpSurface;
858 memcpy(&ptr[ 0], &src_data[ 0], 6 * sizeof(DWORD));
859 memcpy(&ptr[ 640], &src_data[ 6], 6 * sizeof(DWORD));
860 memcpy(&ptr[1280], &src_data[12], 6 * sizeof(DWORD));
861 hr = IDirectDrawSurface4_Unlock(src_surface, NULL);
862 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
864 hr = IDirectDrawSurface4_SetClipper(dst_surface, clipper);
865 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
867 SetRect(&src_rect, 1, 1, 5, 2);
868 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, src_surface, &src_rect, DDBLT_WAIT, NULL);
869 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
870 for (i = 0; i < 4; ++i)
872 for (j = 0; j < 4; ++j)
874 x = 80 * ((2 * j) + 1);
875 y = 60 * ((2 * i) + 1);
876 color = get_surface_color(dst_surface, x, y);
877 ok(compare_color(color, expected1[i * 4 + j], 1)
878 || broken(compare_color(color, expected1_broken[i * 4 + j], 1)),
879 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1[i * 4 + j], x, y, color);
883 U5(fx).dwFillColor = 0xff0000ff;
884 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
885 ok(SUCCEEDED(hr), "Failed to clear destination surface, hr %#x.\n", hr);
886 for (i = 0; i < 4; ++i)
888 for (j = 0; j < 4; ++j)
890 x = 80 * ((2 * j) + 1);
891 y = 60 * ((2 * i) + 1);
892 color = get_surface_color(dst_surface, x, y);
893 ok(compare_color(color, expected2[i * 4 + j], 1),
894 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2[i * 4 + j], x, y, color);
898 hr = IDirectDrawSurface4_BltFast(dst_surface, 0, 0, src_surface, NULL, DDBLTFAST_WAIT);
899 ok(hr == DDERR_BLTFASTCANTCLIP, "Got unexpected hr %#x.\n", hr);
901 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
902 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
903 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
904 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
905 DestroyWindow(window);
906 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
907 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
908 hr = IDirectDrawClipper_SetHWnd(clipper, 0, NULL);
909 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
910 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
911 ok(SUCCEEDED(hr), "Failed to get clip list size, hr %#x.\n", hr);
912 hr = IDirectDrawClipper_SetClipList(clipper, NULL, 0);
913 ok(SUCCEEDED(hr), "Failed to set clip list, hr %#x.\n", hr);
914 hr = IDirectDrawClipper_GetClipList(clipper, NULL, NULL, &ret);
915 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
916 hr = IDirectDrawSurface4_Blt(dst_surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
917 ok(hr == DDERR_NOCLIPLIST, "Got unexpected hr %#x.\n", hr);
919 IDirectDrawSurface4_Release(dst_surface);
920 IDirectDrawSurface4_Release(src_surface);
921 IDirectDrawClipper_Release(clipper);
922 IDirectDraw4_Release(ddraw);
925 static void test_coop_level_d3d_state(void)
927 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
928 IDirectDrawSurface4 *rt, *surface;
929 IDirect3DViewport3 *viewport;
930 IDirect3DDevice3 *device;
931 IDirectDraw4 *ddraw;
932 IDirect3D3 *d3d;
933 D3DCOLOR color;
934 DWORD value;
935 HWND window;
936 HRESULT hr;
938 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
939 0, 0, 640, 480, 0, 0, 0, 0);
940 if (!(device = create_device(window, DDSCL_NORMAL)))
942 skip("Failed to create a 3D device, skipping test.\n");
943 DestroyWindow(window);
944 return;
947 viewport = create_viewport(device, 0, 0, 640, 480);
949 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
950 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
951 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
952 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
953 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
954 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
955 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
956 ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
957 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
958 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
959 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
960 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
961 color = get_surface_color(rt, 320, 240);
962 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
964 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
965 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
966 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
967 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
968 IDirect3D3_Release(d3d);
969 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
970 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
971 hr = IDirectDrawSurface4_IsLost(rt);
972 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
973 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
974 ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
975 IDirectDraw4_Release(ddraw);
977 hr = IDirect3DDevice3_GetRenderTarget(device, &surface);
978 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
979 ok(surface == rt, "Got unexpected surface %p.\n", surface);
980 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
981 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
982 ok(!!value, "Got unexpected z-enable state %#x.\n", value);
983 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
984 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
985 ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
986 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
987 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
988 color = get_surface_color(rt, 320, 240);
989 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
991 destroy_viewport(device, viewport);
992 IDirectDrawSurface4_Release(surface);
993 IDirectDrawSurface4_Release(rt);
994 IDirect3DDevice3_Release(device);
995 DestroyWindow(window);
998 static void test_surface_interface_mismatch(void)
1000 IDirectDraw4 *ddraw = NULL;
1001 IDirect3D3 *d3d = NULL;
1002 IDirectDrawSurface4 *surface = NULL, *ds;
1003 IDirectDrawSurface3 *surface3 = NULL;
1004 IDirect3DDevice3 *device = NULL;
1005 IDirect3DViewport3 *viewport = NULL;
1006 DDSURFACEDESC2 surface_desc;
1007 DDPIXELFORMAT z_fmt;
1008 ULONG refcount;
1009 HRESULT hr;
1010 D3DCOLOR color;
1011 HWND window;
1012 D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1014 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1015 0, 0, 640, 480, 0, 0, 0, 0);
1016 ddraw = create_ddraw();
1017 ok(!!ddraw, "Failed to create a ddraw object.\n");
1018 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
1019 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1021 memset(&surface_desc, 0, sizeof(surface_desc));
1022 surface_desc.dwSize = sizeof(surface_desc);
1023 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1024 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
1025 surface_desc.dwWidth = 640;
1026 surface_desc.dwHeight = 480;
1028 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1029 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1031 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
1032 ok(SUCCEEDED(hr), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr);
1034 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
1036 skip("D3D interface is not available, skipping test.\n");
1037 goto cleanup;
1040 memset(&z_fmt, 0, sizeof(z_fmt));
1041 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
1042 if (FAILED(hr) || !z_fmt.dwSize)
1044 skip("No depth buffer formats available, skipping test.\n");
1045 goto cleanup;
1048 memset(&surface_desc, 0, sizeof(surface_desc));
1049 surface_desc.dwSize = sizeof(surface_desc);
1050 surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
1051 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1052 U4(surface_desc).ddpfPixelFormat = z_fmt;
1053 surface_desc.dwWidth = 640;
1054 surface_desc.dwHeight = 480;
1055 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &ds, NULL);
1056 ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
1057 if (FAILED(hr))
1058 goto cleanup;
1060 /* Using a different surface interface version still works */
1061 hr = IDirectDrawSurface3_AddAttachedSurface(surface3, (IDirectDrawSurface3 *)ds);
1062 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
1063 refcount = IDirectDrawSurface4_Release(ds);
1064 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1065 if (FAILED(hr))
1066 goto cleanup;
1068 /* Here too */
1069 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, (IDirectDrawSurface4 *)surface3, &device, NULL);
1070 ok(SUCCEEDED(hr), "Failed to create d3d device.\n");
1071 if (FAILED(hr))
1072 goto cleanup;
1074 viewport = create_viewport(device, 0, 0, 640, 480);
1076 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
1077 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1078 color = get_surface_color(surface, 320, 240);
1079 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
1081 cleanup:
1082 if (viewport)
1083 destroy_viewport(device, viewport);
1084 if (surface3) IDirectDrawSurface3_Release(surface3);
1085 if (surface) IDirectDrawSurface4_Release(surface);
1086 if (device) IDirect3DDevice3_Release(device);
1087 if (d3d) IDirect3D3_Release(d3d);
1088 if (ddraw) IDirectDraw4_Release(ddraw);
1089 DestroyWindow(window);
1092 static void test_coop_level_threaded(void)
1094 struct create_window_thread_param p;
1095 IDirectDraw4 *ddraw;
1096 HRESULT hr;
1098 ddraw = create_ddraw();
1099 ok(!!ddraw, "Failed to create a ddraw object.\n");
1100 create_window_thread(&p);
1102 hr = IDirectDraw4_SetCooperativeLevel(ddraw, p.window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
1103 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1105 IDirectDraw4_Release(ddraw);
1106 destroy_window_thread(&p);
1109 static void test_depth_blit(void)
1111 static struct
1113 float x, y, z;
1114 DWORD color;
1116 quad1[] =
1118 { -1.0, 1.0, 0.50f, 0xff00ff00},
1119 { 1.0, 1.0, 0.50f, 0xff00ff00},
1120 { -1.0, -1.0, 0.50f, 0xff00ff00},
1121 { 1.0, -1.0, 0.50f, 0xff00ff00},
1123 static const D3DCOLOR expected_colors[4][4] =
1125 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1126 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1127 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1128 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1130 DDSURFACEDESC2 ddsd_new, ddsd_existing;
1132 IDirect3DDevice3 *device;
1133 IDirectDrawSurface4 *ds1, *ds2, *ds3, *rt;
1134 IDirect3DViewport3 *viewport;
1135 RECT src_rect, dst_rect;
1136 unsigned int i, j;
1137 D3DCOLOR color;
1138 HRESULT hr;
1139 IDirect3D3 *d3d;
1140 IDirectDraw4 *ddraw;
1141 DDBLTFX fx;
1142 HWND window;
1143 D3DRECT d3drect;
1145 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1146 0, 0, 640, 480, 0, 0, 0, 0);
1147 if (!(device = create_device(window, DDSCL_NORMAL)))
1149 skip("Failed to create a 3D device, skipping test.\n");
1150 DestroyWindow(window);
1151 return;
1154 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1155 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
1156 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1157 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
1158 IDirect3D3_Release(d3d);
1160 ds1 = get_depth_stencil(device);
1162 memset(&ddsd_new, 0, sizeof(ddsd_new));
1163 ddsd_new.dwSize = sizeof(ddsd_new);
1164 memset(&ddsd_existing, 0, sizeof(ddsd_existing));
1165 ddsd_existing.dwSize = sizeof(ddsd_existing);
1166 hr = IDirectDrawSurface4_GetSurfaceDesc(ds1, &ddsd_existing);
1167 ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
1168 ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
1169 ddsd_new.dwWidth = ddsd_existing.dwWidth;
1170 ddsd_new.dwHeight = ddsd_existing.dwHeight;
1171 U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
1172 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
1173 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
1174 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
1175 ok(SUCCEEDED(hr), "Failed to create a surface, hr %#x.\n", hr);
1176 IDirectDraw4_Release(ddraw);
1178 viewport = create_viewport(device, 0, 0, ddsd_existing.dwWidth, ddsd_existing.dwHeight);
1179 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1180 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
1182 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
1183 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
1184 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
1185 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
1187 U1(d3drect).x1 = U2(d3drect).y1 = 0;
1188 U3(d3drect).x2 = ddsd_existing.dwWidth; U4(d3drect).y2 = ddsd_existing.dwHeight;
1189 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
1190 ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
1192 /* Partial blit. */
1193 SetRect(&src_rect, 0, 0, 320, 240);
1194 SetRect(&dst_rect, 0, 0, 320, 240);
1195 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1196 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1197 /* Different locations. */
1198 SetRect(&src_rect, 0, 0, 320, 240);
1199 SetRect(&dst_rect, 320, 240, 640, 480);
1200 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1201 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1202 /* Streched. */
1203 SetRect(&src_rect, 0, 0, 320, 240);
1204 SetRect(&dst_rect, 0, 0, 640, 480);
1205 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1206 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1207 /* Flipped. */
1208 SetRect(&src_rect, 0, 480, 640, 0);
1209 SetRect(&dst_rect, 0, 0, 640, 480);
1210 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1211 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1212 SetRect(&src_rect, 0, 0, 640, 480);
1213 SetRect(&dst_rect, 0, 480, 640, 0);
1214 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1215 ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
1216 /* Full, explicit. */
1217 SetRect(&src_rect, 0, 0, 640, 480);
1218 SetRect(&dst_rect, 0, 0, 640, 480);
1219 hr = IDirectDrawSurface4_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
1220 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1221 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1223 /* Depth blit inside a BeginScene / EndScene pair */
1224 hr = IDirect3DDevice3_BeginScene(device);
1225 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#x.\n", hr);
1226 /* From the current depth stencil */
1227 hr = IDirectDrawSurface4_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
1228 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1229 /* To the current depth stencil */
1230 hr = IDirectDrawSurface4_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1231 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1232 /* Between unbound surfaces */
1233 hr = IDirectDrawSurface4_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
1234 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1235 hr = IDirect3DDevice3_EndScene(device);
1236 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#x.\n", hr);
1238 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1239 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1240 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1241 * a reliable result(z = 0.0) */
1242 memset(&fx, 0, sizeof(fx));
1243 fx.dwSize = sizeof(fx);
1244 hr = IDirectDrawSurface4_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
1245 ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
1247 hr = IDirect3DViewport3_Clear2(viewport, 1, &d3drect, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
1248 ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
1249 SetRect(&dst_rect, 0, 0, 320, 240);
1250 hr = IDirectDrawSurface4_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
1251 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1252 IDirectDrawSurface4_Release(ds3);
1253 IDirectDrawSurface4_Release(ds2);
1254 IDirectDrawSurface4_Release(ds1);
1256 hr = IDirect3DDevice3_BeginScene(device);
1257 ok(SUCCEEDED(hr), "Failed to start a scene, hr %#x.\n", hr);
1258 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
1259 quad1, 4, 0);
1260 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1261 hr = IDirect3DDevice3_EndScene(device);
1262 ok(SUCCEEDED(hr), "Failed to end a scene, hr %#x.\n", hr);
1264 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1265 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1266 for (i = 0; i < 4; ++i)
1268 for (j = 0; j < 4; ++j)
1270 unsigned int x = 80 * ((2 * j) + 1);
1271 unsigned int y = 60 * ((2 * i) + 1);
1272 color = get_surface_color(rt, x, y);
1273 ok(compare_color(color, expected_colors[i][j], 1),
1274 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
1277 IDirectDrawSurface4_Release(rt);
1279 destroy_viewport(device, viewport);
1280 IDirect3DDevice3_Release(device);
1281 DestroyWindow(window);
1284 static void test_texture_load_ckey(void)
1286 IDirectDraw4 *ddraw;
1287 IDirectDrawSurface4 *src;
1288 IDirectDrawSurface4 *dst;
1289 IDirect3DTexture2 *src_tex;
1290 IDirect3DTexture2 *dst_tex;
1291 DDSURFACEDESC2 ddsd;
1292 HRESULT hr;
1293 DDCOLORKEY ckey;
1295 ddraw = create_ddraw();
1296 ok(!!ddraw, "Failed to create a ddraw object.\n");
1297 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
1298 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
1300 memset(&ddsd, 0, sizeof(ddsd));
1301 ddsd.dwSize = sizeof(ddsd);
1302 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
1303 ddsd.dwHeight = 128;
1304 ddsd.dwWidth = 128;
1305 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY;
1306 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &src, NULL);
1307 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
1308 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1309 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &dst, NULL);
1310 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
1312 hr = IDirectDrawSurface4_QueryInterface(src, &IID_IDirect3DTexture2, (void **)&src_tex);
1313 ok(SUCCEEDED(hr) || hr == E_NOINTERFACE, "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr);
1314 if (FAILED(hr))
1316 /* 64 bit ddraw does not support d3d */
1317 skip("Could not get Direct3DTexture2 interface, skipping texture::Load color keying tests.\n");
1318 IDirectDrawSurface4_Release(dst);
1319 IDirectDrawSurface4_Release(src);
1320 IDirectDraw4_Release(ddraw);
1321 return;
1323 hr = IDirectDrawSurface4_QueryInterface(dst, &IID_IDirect3DTexture2, (void **)&dst_tex);
1324 ok(SUCCEEDED(hr), "Failed to get Direct3DTexture2 interface, hr %#x.\n", hr);
1326 /* No surface has a color key */
1327 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1328 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1329 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0xdeadbeef;
1330 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1331 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1332 ok(ckey.dwColorSpaceLowValue == 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1333 ok(ckey.dwColorSpaceHighValue == 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1335 /* Source surface has a color key */
1336 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x0000ff00;
1337 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, &ckey);
1338 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1339 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1340 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1341 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1342 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1343 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1344 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1346 /* Both surfaces have a color key: Dest ckey is overwritten */
1347 ckey.dwColorSpaceLowValue = ckey.dwColorSpaceHighValue = 0x000000ff;
1348 hr = IDirectDrawSurface4_SetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1349 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1350 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1351 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1352 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1353 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1354 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1355 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1357 /* Only the destination has a color key: It is not deleted */
1358 hr = IDirectDrawSurface4_SetColorKey(src, DDCKEY_SRCBLT, NULL);
1359 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1360 hr = IDirectDrawSurface4_GetColorKey(src, DDCKEY_SRCBLT, &ckey);
1361 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1362 hr = IDirect3DTexture2_Load(dst_tex, src_tex);
1363 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1364 hr = IDirectDrawSurface4_GetColorKey(dst, DDCKEY_SRCBLT, &ckey);
1365 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
1366 ok(ckey.dwColorSpaceLowValue == 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey.dwColorSpaceLowValue);
1367 ok(ckey.dwColorSpaceHighValue == 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey.dwColorSpaceHighValue);
1369 IDirect3DTexture2_Release(dst_tex);
1370 IDirect3DTexture2_Release(src_tex);
1371 IDirectDrawSurface4_Release(dst);
1372 IDirectDrawSurface4_Release(src);
1373 IDirectDraw4_Release(ddraw);
1376 static ULONG get_refcount(IUnknown *test_iface)
1378 IUnknown_AddRef(test_iface);
1379 return IUnknown_Release(test_iface);
1382 static void test_viewport(void)
1384 IDirectDraw4 *ddraw;
1385 IDirect3D3 *d3d;
1386 HRESULT hr, old_d3d_ref;
1387 ULONG ref;
1388 IDirect3DViewport *viewport;
1389 IDirect3DViewport2 *viewport2;
1390 IDirect3DViewport3 *viewport3, *another_vp, *test_vp;
1391 IDirectDrawGammaControl *gamma;
1392 IUnknown *unknown;
1393 HWND window;
1394 IDirect3DDevice3 *device;
1396 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1397 0, 0, 640, 480, 0, 0, 0, 0);
1398 if (!(device = create_device(window, DDSCL_NORMAL)))
1400 skip("Failed to create a 3D device, skipping test.\n");
1401 DestroyWindow(window);
1402 return;
1404 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1405 ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr);
1406 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1407 ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr);
1408 old_d3d_ref = get_refcount((IUnknown *) d3d);
1410 hr = IDirect3D3_CreateViewport(d3d, &viewport3, NULL);
1411 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1412 ref = get_refcount((IUnknown *)viewport3);
1413 ok(ref == 1, "Initial IDirect3DViewport3 refcount is %u\n", ref);
1414 ref = get_refcount((IUnknown *)d3d);
1415 ok(ref == old_d3d_ref, "IDirect3D3 refcount is %u\n", ref);
1417 gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1418 hr = IDirect3DViewport2_QueryInterface(viewport3, &IID_IDirectDrawGammaControl, (void **)&gamma);
1419 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
1420 ok(gamma == NULL, "Interface not set to NULL by failed QI call: %p\n", gamma);
1421 if (SUCCEEDED(hr)) IDirectDrawGammaControl_Release(gamma);
1422 /* NULL iid: Segfaults */
1424 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport, (void **)&viewport);
1425 ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport, hr %#x.\n", hr);
1426 if (viewport)
1428 ref = get_refcount((IUnknown *)viewport);
1429 ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1430 ref = get_refcount((IUnknown *)viewport3);
1431 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1432 IDirect3DViewport_Release(viewport);
1433 viewport = NULL;
1436 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport3, (void **)&viewport2);
1437 ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr);
1438 if (viewport2)
1440 ref = get_refcount((IUnknown *)viewport2);
1441 ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
1442 ref = get_refcount((IUnknown *)viewport3);
1443 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1444 IDirect3DViewport3_Release(viewport2);
1447 hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IUnknown, (void **)&unknown);
1448 ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1449 if (unknown)
1451 ref = get_refcount((IUnknown *)viewport3);
1452 ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1453 ref = get_refcount(unknown);
1454 ok(ref == 2, "IUnknown refcount is %u\n", ref);
1455 IUnknown_Release(unknown);
1458 /* AddViewport(NULL): Segfault */
1459 hr = IDirect3DDevice3_DeleteViewport(device, NULL);
1460 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1461 hr = IDirect3DDevice3_GetCurrentViewport(device, NULL);
1462 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1464 hr = IDirect3D3_CreateViewport(d3d, &another_vp, NULL);
1465 ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1467 /* Setting a viewport not in the viewport list fails */
1468 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1469 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
1471 hr = IDirect3DDevice3_AddViewport(device, viewport3);
1472 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1473 ref = get_refcount((IUnknown *) viewport3);
1474 ok(ref == 2, "viewport3 refcount is %d\n", ref);
1475 hr = IDirect3DDevice3_AddViewport(device, another_vp);
1476 ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr);
1477 ref = get_refcount((IUnknown *) another_vp);
1478 ok(ref == 2, "another_vp refcount is %d\n", ref);
1480 test_vp = (IDirect3DViewport3 *) 0xbaadc0de;
1481 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1482 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1483 ok(test_vp == (IDirect3DViewport3 *) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp);
1485 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1486 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1487 ref = get_refcount((IUnknown *) viewport3);
1488 ok(ref == 3, "viewport3 refcount is %d\n", ref);
1489 ref = get_refcount((IUnknown *) device);
1490 ok(ref == 1, "device refcount is %d\n", ref);
1492 test_vp = NULL;
1493 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1494 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1495 ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp);
1496 ref = get_refcount((IUnknown *) viewport3);
1497 ok(ref == 4, "viewport3 refcount is %d\n", ref);
1498 if(test_vp) IDirect3DViewport3_Release(test_vp);
1500 /* GetCurrentViewport with a viewport set and NULL input param: Segfault */
1502 /* Cannot set the viewport to NULL */
1503 hr = IDirect3DDevice3_SetCurrentViewport(device, NULL);
1504 ok(hr == DDERR_INVALIDPARAMS, "Failed to set viewport to NULL, hr %#x.\n", hr);
1505 test_vp = NULL;
1506 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1507 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1508 ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp);
1509 if(test_vp) IDirect3DViewport3_Release(test_vp);
1511 /* SetCurrentViewport properly releases the old viewport's reference */
1512 hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp);
1513 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1514 ref = get_refcount((IUnknown *) viewport3);
1515 ok(ref == 2, "viewport3 refcount is %d\n", ref);
1516 ref = get_refcount((IUnknown *) another_vp);
1517 ok(ref == 3, "another_vp refcount is %d\n", ref);
1519 /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the
1520 * reference held by SetCurrentViewport */
1521 hr = IDirect3DDevice3_DeleteViewport(device, another_vp);
1522 ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr);
1523 ref = get_refcount((IUnknown *) another_vp);
1524 ok(ref == 1, "another_vp refcount is %d\n", ref);
1526 /* GetCurrentViewport still fails */
1527 test_vp = NULL;
1528 hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp);
1529 ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
1530 ok(test_vp == NULL, "Got unexpected viewport %p\n", test_vp);
1531 if(test_vp) IDirect3DViewport3_Release(test_vp);
1533 /* Setting a different viewport doesn't have any surprises now */
1534 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3);
1535 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1536 ref = get_refcount((IUnknown *) viewport3);
1537 ok(ref == 3, "viewport3 refcount is %d\n", ref);
1538 ref = get_refcount((IUnknown *) another_vp);
1539 ok(ref == 1, "another_vp refcount is %d\n", ref);
1541 /* Destroying the device removes the viewport and releases the reference */
1542 IDirect3DDevice3_Release(device);
1543 ref = get_refcount((IUnknown *) viewport3);
1544 ok(ref == 1, "viewport3 refcount is %d\n", ref);
1546 ref = IDirect3DViewport3_Release(another_vp);
1547 ok(ref == 0, "Got unexpected ref %d\n", ref);
1548 ref = IDirect3DViewport3_Release(viewport3);
1549 ok(ref == 0, "Got unexpected ref %d\n", ref);
1550 IDirect3D3_Release(d3d);
1551 DestroyWindow(window);
1552 IDirectDraw4_Release(ddraw);
1555 static void test_zenable(void)
1557 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1558 static struct
1560 struct vec4 position;
1561 D3DCOLOR diffuse;
1563 tquad[] =
1565 {{ 0.0f, 480.0f, -0.5f, 1.0f}, 0xff00ff00},
1566 {{ 0.0f, 0.0f, -0.5f, 1.0f}, 0xff00ff00},
1567 {{640.0f, 480.0f, 1.5f, 1.0f}, 0xff00ff00},
1568 {{640.0f, 0.0f, 1.5f, 1.0f}, 0xff00ff00},
1570 IDirect3DViewport3 *viewport;
1571 IDirect3DDevice3 *device;
1572 IDirectDrawSurface4 *rt;
1573 D3DCOLOR color;
1574 HWND window;
1575 HRESULT hr;
1576 UINT x, y;
1577 UINT i, j;
1579 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1580 0, 0, 640, 480, 0, 0, 0, 0);
1581 if (!(device = create_device(window, DDSCL_NORMAL)))
1583 skip("Failed to create a 3D device, skipping test.\n");
1584 DestroyWindow(window);
1585 return;
1588 viewport = create_viewport(device, 0, 0, 640, 480);
1589 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1590 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1592 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
1593 ok(SUCCEEDED(hr), "Failed to disable z-buffering, hr %#x.\n", hr);
1595 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0);
1596 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1597 hr = IDirect3DDevice3_BeginScene(device);
1598 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1599 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, tquad, 4, 0);
1600 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1601 hr = IDirect3DDevice3_EndScene(device);
1602 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1604 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1605 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1606 for (i = 0; i < 4; ++i)
1608 for (j = 0; j < 4; ++j)
1610 x = 80 * ((2 * j) + 1);
1611 y = 60 * ((2 * i) + 1);
1612 color = get_surface_color(rt, x, y);
1613 ok(compare_color(color, 0x0000ff00, 1),
1614 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x, y, color);
1617 IDirectDrawSurface4_Release(rt);
1619 destroy_viewport(device, viewport);
1620 IDirect3DDevice3_Release(device);
1621 DestroyWindow(window);
1624 static void test_ck_rgba(void)
1626 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1627 static struct
1629 struct vec4 position;
1630 struct vec2 texcoord;
1632 tquad[] =
1634 {{ 0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
1635 {{ 0.0f, 0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
1636 {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
1637 {{640.0f, 0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
1638 {{ 0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
1639 {{ 0.0f, 0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
1640 {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
1641 {{640.0f, 0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
1643 static const struct
1645 D3DCOLOR fill_color;
1646 BOOL color_key;
1647 BOOL blend;
1648 D3DCOLOR result1;
1649 D3DCOLOR result2;
1651 tests[] =
1653 {0xff00ff00, TRUE, TRUE, 0x00ff0000, 0x000000ff},
1654 {0xff00ff00, TRUE, FALSE, 0x00ff0000, 0x000000ff},
1655 {0xff00ff00, FALSE, TRUE, 0x0000ff00, 0x0000ff00},
1656 {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1657 {0x7f00ff00, TRUE, TRUE, 0x00807f00, 0x00807f00},
1658 {0x7f00ff00, TRUE, FALSE, 0x0000ff00, 0x0000ff00},
1659 {0x7f00ff00, FALSE, TRUE, 0x00807f00, 0x00807f00},
1660 {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
1663 IDirectDrawSurface4 *surface;
1664 IDirect3DViewport3 *viewport;
1665 DDSURFACEDESC2 surface_desc;
1666 IDirect3DTexture2 *texture;
1667 IDirect3DDevice3 *device;
1668 IDirectDrawSurface4 *rt;
1669 IDirectDraw4 *ddraw;
1670 IDirect3D3 *d3d;
1671 D3DCOLOR color;
1672 HWND window;
1673 DDBLTFX fx;
1674 HRESULT hr;
1675 UINT i;
1677 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1678 0, 0, 640, 480, 0, 0, 0, 0);
1679 if (!(device = create_device(window, DDSCL_NORMAL)))
1681 skip("Failed to create a 3D device, skipping test.\n");
1682 DestroyWindow(window);
1683 return;
1686 viewport = create_viewport(device, 0, 0, 640, 480);
1687 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1688 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1690 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1691 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1692 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1693 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1694 IDirect3D3_Release(d3d);
1696 memset(&surface_desc, 0, sizeof(surface_desc));
1697 surface_desc.dwSize = sizeof(surface_desc);
1698 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1699 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1700 surface_desc.dwWidth = 256;
1701 surface_desc.dwHeight = 256;
1702 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1703 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
1704 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1705 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1706 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1707 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1708 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
1709 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
1710 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
1711 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1712 ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
1713 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
1714 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1716 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
1717 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1718 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
1719 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1720 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
1721 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1723 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1724 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1726 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1728 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
1729 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1730 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
1731 ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
1733 memset(&fx, 0, sizeof(fx));
1734 fx.dwSize = sizeof(fx);
1735 U5(fx).dwFillColor = tests[i].fill_color;
1736 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1737 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1739 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
1740 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
1741 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1742 hr = IDirect3DDevice3_BeginScene(device);
1743 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1744 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1745 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1746 hr = IDirect3DDevice3_EndScene(device);
1747 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1749 color = get_surface_color(rt, 320, 240);
1750 if (i == 2)
1751 todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1752 tests[i].result1, i, color);
1753 else
1754 ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1755 tests[i].result1, i, color);
1757 U5(fx).dwFillColor = 0xff0000ff;
1758 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1759 ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
1761 hr = IDirect3DDevice3_BeginScene(device);
1762 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1763 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
1764 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1765 hr = IDirect3DDevice3_EndScene(device);
1766 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1768 /* This tests that fragments that are masked out by the color key are
1769 * discarded, instead of just fully transparent. */
1770 color = get_surface_color(rt, 320, 240);
1771 if (i == 2)
1772 todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1773 tests[i].result2, i, color);
1774 else
1775 ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1776 tests[i].result2, i, color);
1779 IDirectDrawSurface4_Release(rt);
1780 IDirect3DTexture2_Release(texture);
1781 IDirectDrawSurface4_Release(surface);
1782 destroy_viewport(device, viewport);
1783 IDirectDraw4_Release(ddraw);
1784 IDirect3DDevice3_Release(device);
1785 DestroyWindow(window);
1788 static void test_ck_default(void)
1790 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
1791 static struct
1793 struct vec4 position;
1794 struct vec2 texcoord;
1796 tquad[] =
1798 {{ 0.0f, 480.0f, 0.0f, 1.0f}, {0.0f, 0.0f}},
1799 {{ 0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}},
1800 {{640.0f, 480.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
1801 {{640.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
1803 IDirectDrawSurface4 *surface, *rt;
1804 IDirect3DViewport3 *viewport;
1805 DDSURFACEDESC2 surface_desc;
1806 IDirect3DTexture2 *texture;
1807 IDirect3DDevice3 *device;
1808 IDirectDraw4 *ddraw;
1809 IDirect3D3 *d3d;
1810 D3DCOLOR color;
1811 DWORD value;
1812 HWND window;
1813 DDBLTFX fx;
1814 HRESULT hr;
1816 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1817 0, 0, 640, 480, 0, 0, 0, 0);
1819 if (!(device = create_device(window, DDSCL_NORMAL)))
1821 skip("Failed to create a 3D device, skipping test.\n");
1822 DestroyWindow(window);
1823 return;
1826 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1827 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1828 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1829 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1830 IDirect3D3_Release(d3d);
1832 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
1833 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
1835 viewport = create_viewport(device, 0, 0, 640, 480);
1836 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
1837 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
1839 memset(&surface_desc, 0, sizeof(surface_desc));
1840 surface_desc.dwSize = sizeof(surface_desc);
1841 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
1842 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1843 surface_desc.dwWidth = 256;
1844 surface_desc.dwHeight = 256;
1845 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
1846 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
1847 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
1848 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
1849 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
1850 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
1851 surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0x000000ff;
1852 surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0x000000ff;
1853 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1854 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1855 hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
1856 ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
1857 hr = IDirect3DDevice3_SetTexture(device, 0, texture);
1858 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
1860 memset(&fx, 0, sizeof(fx));
1861 fx.dwSize = sizeof(fx);
1862 U5(fx).dwFillColor = 0x000000ff;
1863 hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
1864 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
1866 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1867 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1868 hr = IDirect3DDevice3_BeginScene(device);
1869 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1870 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1871 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1872 ok(!value, "Got unexpected color keying state %#x.\n", value);
1873 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1874 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1875 hr = IDirect3DDevice3_EndScene(device);
1876 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1877 color = get_surface_color(rt, 320, 240);
1878 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
1880 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 1.0f, 0);
1881 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
1882 hr = IDirect3DDevice3_BeginScene(device);
1883 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
1884 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, TRUE);
1885 ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
1886 hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
1887 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
1888 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, &value);
1889 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1890 ok(!!value, "Got unexpected color keying state %#x.\n", value);
1891 hr = IDirect3DDevice3_EndScene(device);
1892 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
1893 color = get_surface_color(rt, 320, 240);
1894 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
1896 IDirect3DTexture_Release(texture);
1897 IDirectDrawSurface4_Release(surface);
1898 destroy_viewport(device, viewport);
1899 IDirectDrawSurface4_Release(rt);
1900 IDirect3DDevice3_Release(device);
1901 IDirectDraw4_Release(ddraw);
1902 DestroyWindow(window);
1905 static void test_ck_complex(void)
1907 IDirectDrawSurface4 *surface, *mipmap, *tmp;
1908 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
1909 DDSURFACEDESC2 surface_desc;
1910 IDirect3DDevice3 *device;
1911 DDCOLORKEY color_key;
1912 IDirectDraw4 *ddraw;
1913 IDirect3D3 *d3d;
1914 unsigned int i;
1915 ULONG refcount;
1916 HWND window;
1917 HRESULT hr;
1919 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
1920 0, 0, 640, 480, 0, 0, 0, 0);
1921 if (!(device = create_device(window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN)))
1923 skip("Failed to create a 3D device, skipping test.\n");
1924 DestroyWindow(window);
1925 return;
1927 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
1928 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
1929 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
1930 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
1931 IDirect3D3_Release(d3d);
1933 memset(&surface_desc, 0, sizeof(surface_desc));
1934 surface_desc.dwSize = sizeof(surface_desc);
1935 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
1936 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
1937 surface_desc.dwWidth = 128;
1938 surface_desc.dwHeight = 128;
1939 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
1940 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
1942 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1943 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
1944 color_key.dwColorSpaceLowValue = 0x0000ff00;
1945 color_key.dwColorSpaceHighValue = 0x0000ff00;
1946 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1947 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
1948 memset(&color_key, 0, sizeof(color_key));
1949 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1950 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1951 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1952 color_key.dwColorSpaceLowValue);
1953 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1954 color_key.dwColorSpaceHighValue);
1956 mipmap = surface;
1957 IDirectDrawSurface_AddRef(mipmap);
1958 for (i = 0; i < 7; ++i)
1960 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
1961 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
1963 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1964 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
1965 color_key.dwColorSpaceLowValue = 0x000000ff;
1966 color_key.dwColorSpaceHighValue = 0x000000ff;
1967 hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1968 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x, i %u.\n", hr, i);
1969 memset(&color_key, 0, sizeof(color_key));
1970 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
1971 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x, i %u.\n", hr, i);
1972 ok(color_key.dwColorSpaceLowValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1973 color_key.dwColorSpaceLowValue, i);
1974 ok(color_key.dwColorSpaceHighValue == 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1975 color_key.dwColorSpaceHighValue, i);
1977 IDirectDrawSurface_Release(mipmap);
1978 mipmap = tmp;
1981 memset(&color_key, 0, sizeof(color_key));
1982 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
1983 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
1984 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1985 color_key.dwColorSpaceLowValue);
1986 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
1987 color_key.dwColorSpaceHighValue);
1989 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
1990 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
1991 IDirectDrawSurface_Release(mipmap);
1992 refcount = IDirectDrawSurface4_Release(surface);
1993 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1995 memset(&surface_desc, 0, sizeof(surface_desc));
1996 surface_desc.dwSize = sizeof(surface_desc);
1997 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
1998 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
1999 surface_desc.dwBackBufferCount = 1;
2000 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2001 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2003 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2004 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x.\n", hr);
2005 color_key.dwColorSpaceLowValue = 0x0000ff00;
2006 color_key.dwColorSpaceHighValue = 0x0000ff00;
2007 hr = IDirectDrawSurface4_SetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2008 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
2009 memset(&color_key, 0, sizeof(color_key));
2010 hr = IDirectDrawSurface4_GetColorKey(surface, DDCKEY_SRCBLT, &color_key);
2011 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
2012 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2013 color_key.dwColorSpaceLowValue);
2014 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2015 color_key.dwColorSpaceHighValue);
2017 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &tmp);
2018 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
2020 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2021 ok(hr == DDERR_NOCOLORKEY, "Got unexpected hr %#x, i %u.\n", hr, i);
2022 color_key.dwColorSpaceLowValue = 0x0000ff00;
2023 color_key.dwColorSpaceHighValue = 0x0000ff00;
2024 hr = IDirectDrawSurface4_SetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2025 ok(SUCCEEDED(hr), "Failed to set color key, hr %#x.\n", hr);
2026 memset(&color_key, 0, sizeof(color_key));
2027 hr = IDirectDrawSurface4_GetColorKey(tmp, DDCKEY_SRCBLT, &color_key);
2028 ok(SUCCEEDED(hr), "Failed to get color key, hr %#x.\n", hr);
2029 ok(color_key.dwColorSpaceLowValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2030 color_key.dwColorSpaceLowValue);
2031 ok(color_key.dwColorSpaceHighValue == 0x0000ff00, "Got unexpected value 0x%08x.\n",
2032 color_key.dwColorSpaceHighValue);
2034 IDirectDrawSurface_Release(tmp);
2036 refcount = IDirectDrawSurface4_Release(surface);
2037 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2038 IDirectDraw4_Release(ddraw);
2039 refcount = IDirect3DDevice3_Release(device);
2040 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2041 DestroyWindow(window);
2044 struct qi_test
2046 REFIID iid;
2047 REFIID refcount_iid;
2048 HRESULT hr;
2051 static void test_qi(const char *test_name, IUnknown *base_iface,
2052 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2054 ULONG refcount, expected_refcount;
2055 IUnknown *iface1, *iface2;
2056 HRESULT hr;
2057 UINT i, j;
2059 for (i = 0; i < entry_count; ++i)
2061 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2062 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
2063 if (SUCCEEDED(hr))
2065 for (j = 0; j < entry_count; ++j)
2067 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2068 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2069 if (SUCCEEDED(hr))
2071 expected_refcount = 0;
2072 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2073 ++expected_refcount;
2074 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2075 ++expected_refcount;
2076 refcount = IUnknown_Release(iface2);
2077 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2078 refcount, test_name, i, j, expected_refcount);
2082 expected_refcount = 0;
2083 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2084 ++expected_refcount;
2085 refcount = IUnknown_Release(iface1);
2086 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2087 refcount, test_name, i, expected_refcount);
2092 static void test_surface_qi(void)
2094 static const struct qi_test tests[] =
2096 {&IID_IDirect3DTexture2, &IID_IDirectDrawSurface4, S_OK },
2097 {&IID_IDirect3DTexture, &IID_IDirectDrawSurface4, S_OK },
2098 {&IID_IDirectDrawGammaControl, &IID_IDirectDrawGammaControl, S_OK },
2099 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2100 {&IID_IDirectDrawSurface7, &IID_IDirectDrawSurface7, S_OK },
2101 {&IID_IDirectDrawSurface4, &IID_IDirectDrawSurface4, S_OK },
2102 {&IID_IDirectDrawSurface3, &IID_IDirectDrawSurface3, S_OK },
2103 {&IID_IDirectDrawSurface2, &IID_IDirectDrawSurface2, S_OK },
2104 {&IID_IDirectDrawSurface, &IID_IDirectDrawSurface, S_OK },
2105 {&IID_IDirect3DDevice7, NULL, E_INVALIDARG },
2106 {&IID_IDirect3DDevice3, NULL, E_INVALIDARG },
2107 {&IID_IDirect3DDevice2, NULL, E_INVALIDARG },
2108 {&IID_IDirect3DDevice, NULL, E_INVALIDARG },
2109 {&IID_IDirect3D7, NULL, E_INVALIDARG },
2110 {&IID_IDirect3D3, NULL, E_INVALIDARG },
2111 {&IID_IDirect3D2, NULL, E_INVALIDARG },
2112 {&IID_IDirect3D, NULL, E_INVALIDARG },
2113 {&IID_IDirectDraw7, NULL, E_INVALIDARG },
2114 {&IID_IDirectDraw4, NULL, E_INVALIDARG },
2115 {&IID_IDirectDraw3, NULL, E_INVALIDARG },
2116 {&IID_IDirectDraw2, NULL, E_INVALIDARG },
2117 {&IID_IDirectDraw, NULL, E_INVALIDARG },
2118 {&IID_IDirect3DLight, NULL, E_INVALIDARG },
2119 {&IID_IDirect3DMaterial, NULL, E_INVALIDARG },
2120 {&IID_IDirect3DMaterial2, NULL, E_INVALIDARG },
2121 {&IID_IDirect3DMaterial3, NULL, E_INVALIDARG },
2122 {&IID_IDirect3DExecuteBuffer, NULL, E_INVALIDARG },
2123 {&IID_IDirect3DViewport, NULL, E_INVALIDARG },
2124 {&IID_IDirect3DViewport2, NULL, E_INVALIDARG },
2125 {&IID_IDirect3DViewport3, NULL, E_INVALIDARG },
2126 {&IID_IDirect3DVertexBuffer, NULL, E_INVALIDARG },
2127 {&IID_IDirect3DVertexBuffer7, NULL, E_INVALIDARG },
2128 {&IID_IDirectDrawPalette, NULL, E_INVALIDARG },
2129 {&IID_IDirectDrawClipper, NULL, E_INVALIDARG },
2130 {&IID_IUnknown, &IID_IDirectDrawSurface, S_OK },
2133 IDirectDrawSurface4 *surface;
2134 DDSURFACEDESC2 surface_desc;
2135 IDirect3DDevice3 *device;
2136 IDirectDraw4 *ddraw;
2137 HWND window;
2138 HRESULT hr;
2140 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
2142 win_skip("DirectDrawCreateEx not available, skipping test.\n");
2143 return;
2146 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2147 0, 0, 640, 480, 0, 0, 0, 0);
2148 /* Try to create a D3D device to see if the ddraw implementation supports
2149 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
2150 * doesn't support e.g. the IDirect3DTexture interfaces. */
2151 if (!(device = create_device(window, DDSCL_NORMAL)))
2153 skip("Failed to create a 3D device, skipping test.\n");
2154 DestroyWindow(window);
2155 return;
2157 IDirect3DDevice_Release(device);
2158 ddraw = create_ddraw();
2159 ok(!!ddraw, "Failed to create a ddraw object.\n");
2160 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2161 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
2163 memset(&surface_desc, 0, sizeof(surface_desc));
2164 surface_desc.dwSize = sizeof(surface_desc);
2165 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
2166 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
2167 surface_desc.dwWidth = 512;
2168 surface_desc.dwHeight = 512;
2169 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
2170 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
2172 test_qi("surface_qi", (IUnknown *)surface, &IID_IDirectDrawSurface4, tests, sizeof(tests) / sizeof(*tests));
2174 IDirectDrawSurface4_Release(surface);
2175 IDirectDraw4_Release(ddraw);
2176 DestroyWindow(window);
2179 static void test_device_qi(void)
2181 static const struct qi_test tests[] =
2183 {&IID_IDirect3DTexture2, NULL, E_NOINTERFACE},
2184 {&IID_IDirect3DTexture, NULL, E_NOINTERFACE},
2185 {&IID_IDirectDrawGammaControl, NULL, E_NOINTERFACE},
2186 {&IID_IDirectDrawColorControl, NULL, E_NOINTERFACE},
2187 {&IID_IDirectDrawSurface7, NULL, E_NOINTERFACE},
2188 {&IID_IDirectDrawSurface4, NULL, E_NOINTERFACE},
2189 {&IID_IDirectDrawSurface3, NULL, E_NOINTERFACE},
2190 {&IID_IDirectDrawSurface2, NULL, E_NOINTERFACE},
2191 {&IID_IDirectDrawSurface, NULL, E_NOINTERFACE},
2192 {&IID_IDirect3DDevice7, NULL, E_NOINTERFACE},
2193 {&IID_IDirect3DDevice3, &IID_IDirect3DDevice3, S_OK },
2194 {&IID_IDirect3DDevice2, &IID_IDirect3DDevice3, S_OK },
2195 {&IID_IDirect3DDevice, &IID_IDirect3DDevice3, S_OK },
2196 {&IID_IDirect3DRampDevice, NULL, E_NOINTERFACE},
2197 {&IID_IDirect3DRGBDevice, NULL, E_NOINTERFACE},
2198 {&IID_IDirect3DHALDevice, NULL, E_NOINTERFACE},
2199 {&IID_IDirect3DMMXDevice, NULL, E_NOINTERFACE},
2200 {&IID_IDirect3DRefDevice, NULL, E_NOINTERFACE},
2201 {&IID_IDirect3DTnLHalDevice, NULL, E_NOINTERFACE},
2202 {&IID_IDirect3DNullDevice, NULL, E_NOINTERFACE},
2203 {&IID_IDirect3D7, NULL, E_NOINTERFACE},
2204 {&IID_IDirect3D3, NULL, E_NOINTERFACE},
2205 {&IID_IDirect3D2, NULL, E_NOINTERFACE},
2206 {&IID_IDirect3D, NULL, E_NOINTERFACE},
2207 {&IID_IDirectDraw7, NULL, E_NOINTERFACE},
2208 {&IID_IDirectDraw4, NULL, E_NOINTERFACE},
2209 {&IID_IDirectDraw3, NULL, E_NOINTERFACE},
2210 {&IID_IDirectDraw2, NULL, E_NOINTERFACE},
2211 {&IID_IDirectDraw, NULL, E_NOINTERFACE},
2212 {&IID_IDirect3DLight, NULL, E_NOINTERFACE},
2213 {&IID_IDirect3DMaterial, NULL, E_NOINTERFACE},
2214 {&IID_IDirect3DMaterial2, NULL, E_NOINTERFACE},
2215 {&IID_IDirect3DMaterial3, NULL, E_NOINTERFACE},
2216 {&IID_IDirect3DExecuteBuffer, NULL, E_NOINTERFACE},
2217 {&IID_IDirect3DViewport, NULL, E_NOINTERFACE},
2218 {&IID_IDirect3DViewport2, NULL, E_NOINTERFACE},
2219 {&IID_IDirect3DViewport3, NULL, E_NOINTERFACE},
2220 {&IID_IDirect3DVertexBuffer, NULL, E_NOINTERFACE},
2221 {&IID_IDirect3DVertexBuffer7, NULL, E_NOINTERFACE},
2222 {&IID_IDirectDrawPalette, NULL, E_NOINTERFACE},
2223 {&IID_IDirectDrawClipper, NULL, E_NOINTERFACE},
2224 {&IID_IUnknown, &IID_IDirect3DDevice3, S_OK },
2227 IDirect3DDevice3 *device;
2228 HWND window;
2230 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2231 0, 0, 640, 480, 0, 0, 0, 0);
2232 if (!(device = create_device(window, DDSCL_NORMAL)))
2234 skip("Failed to create a 3D device, skipping test.\n");
2235 DestroyWindow(window);
2236 return;
2239 test_qi("device_qi", (IUnknown *)device, &IID_IDirect3DDevice3, tests, sizeof(tests) / sizeof(*tests));
2241 IDirect3DDevice3_Release(device);
2242 DestroyWindow(window);
2245 static void test_wndproc(void)
2247 LONG_PTR proc, ddraw_proc;
2248 IDirectDraw4 *ddraw;
2249 WNDCLASSA wc = {0};
2250 HWND window;
2251 HRESULT hr;
2252 ULONG ref;
2254 static const UINT messages[] =
2256 WM_WINDOWPOSCHANGING,
2257 WM_MOVE,
2258 WM_SIZE,
2259 WM_WINDOWPOSCHANGING,
2260 WM_ACTIVATE,
2261 WM_SETFOCUS,
2265 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2266 ddraw = create_ddraw();
2267 ok(!!ddraw, "Failed to create a ddraw object.\n");
2269 wc.lpfnWndProc = test_proc;
2270 wc.lpszClassName = "ddraw_test_wndproc_wc";
2271 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2273 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2274 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
2276 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2277 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2278 (LONG_PTR)test_proc, proc);
2279 expect_messages = messages;
2280 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2281 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2282 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2283 expect_messages = NULL;
2284 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2285 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2286 (LONG_PTR)test_proc, proc);
2287 ref = IDirectDraw4_Release(ddraw);
2288 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2289 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2290 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2291 (LONG_PTR)test_proc, proc);
2293 /* DDSCL_NORMAL doesn't. */
2294 ddraw = create_ddraw();
2295 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2296 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2297 (LONG_PTR)test_proc, proc);
2298 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2299 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2300 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2301 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2302 (LONG_PTR)test_proc, proc);
2303 ref = IDirectDraw4_Release(ddraw);
2304 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2305 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2306 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2307 (LONG_PTR)test_proc, proc);
2309 /* The original window proc is only restored by ddraw if the current
2310 * window proc matches the one ddraw set. This also affects switching
2311 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2312 ddraw = create_ddraw();
2313 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2314 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2315 (LONG_PTR)test_proc, proc);
2316 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2317 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2318 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2319 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2320 (LONG_PTR)test_proc, proc);
2321 ddraw_proc = proc;
2322 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2323 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2324 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2325 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2326 (LONG_PTR)test_proc, proc);
2327 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2328 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2329 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2330 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2331 (LONG_PTR)test_proc, proc);
2332 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2333 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2334 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2335 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2336 (LONG_PTR)DefWindowProcA, proc);
2337 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2338 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2339 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)ddraw_proc);
2340 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2341 (LONG_PTR)DefWindowProcA, proc);
2342 ref = IDirectDraw4_Release(ddraw);
2343 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2344 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2345 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2346 (LONG_PTR)test_proc, proc);
2348 ddraw = create_ddraw();
2349 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2350 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2351 (LONG_PTR)test_proc, proc);
2352 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2353 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2354 proc = SetWindowLongPtrA(window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2355 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2356 (LONG_PTR)test_proc, proc);
2357 ref = IDirectDraw4_Release(ddraw);
2358 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2359 proc = GetWindowLongPtrA(window, GWLP_WNDPROC);
2360 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2361 (LONG_PTR)DefWindowProcA, proc);
2363 fix_wndproc(window, (LONG_PTR)test_proc);
2364 expect_messages = NULL;
2365 DestroyWindow(window);
2366 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
2369 static void test_window_style(void)
2371 LONG style, exstyle, tmp;
2372 RECT fullscreen_rect, r;
2373 IDirectDraw4 *ddraw;
2374 HWND window;
2375 HRESULT hr;
2376 ULONG ref;
2378 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2379 0, 0, 100, 100, 0, 0, 0, 0);
2380 ddraw = create_ddraw();
2381 ok(!!ddraw, "Failed to create a ddraw object.\n");
2383 style = GetWindowLongA(window, GWL_STYLE);
2384 exstyle = GetWindowLongA(window, GWL_EXSTYLE);
2385 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2387 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2388 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2390 tmp = GetWindowLongA(window, GWL_STYLE);
2391 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2392 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2393 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2395 GetWindowRect(window, &r);
2396 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2397 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2398 r.left, r.top, r.right, r.bottom);
2399 GetClientRect(window, &r);
2400 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
2402 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2403 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2405 tmp = GetWindowLongA(window, GWL_STYLE);
2406 todo_wine ok(tmp == style, "Expected window style %#x, got %#x.\n", style, tmp);
2407 tmp = GetWindowLongA(window, GWL_EXSTYLE);
2408 todo_wine ok(tmp == exstyle, "Expected window extended style %#x, got %#x.\n", exstyle, tmp);
2410 ref = IDirectDraw4_Release(ddraw);
2411 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2413 DestroyWindow(window);
2416 static void test_redundant_mode_set(void)
2418 DDSURFACEDESC2 surface_desc = {0};
2419 IDirectDraw4 *ddraw;
2420 HWND window;
2421 HRESULT hr;
2422 RECT r, s;
2423 ULONG ref;
2425 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
2426 0, 0, 100, 100, 0, 0, 0, 0);
2427 ddraw = create_ddraw();
2428 ok(!!ddraw, "Failed to create a ddraw object.\n");
2430 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2431 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2433 surface_desc.dwSize = sizeof(surface_desc);
2434 hr = IDirectDraw4_GetDisplayMode(ddraw, &surface_desc);
2435 ok(SUCCEEDED(hr), "GetDipslayMode failed, hr %#x.\n", hr);
2437 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2438 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2439 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2441 GetWindowRect(window, &r);
2442 r.right /= 2;
2443 r.bottom /= 2;
2444 SetWindowPos(window, HWND_TOP, r.left, r.top, r.right, r.bottom, 0);
2445 GetWindowRect(window, &s);
2446 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2447 r.left, r.top, r.right, r.bottom,
2448 s.left, s.top, s.right, s.bottom);
2450 hr = IDirectDraw4_SetDisplayMode(ddraw, surface_desc.dwWidth, surface_desc.dwHeight,
2451 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount, 0, 0);
2452 ok(SUCCEEDED(hr), "SetDisplayMode failed, hr %#x.\n", hr);
2454 GetWindowRect(window, &s);
2455 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2456 r.left, r.top, r.right, r.bottom,
2457 s.left, s.top, s.right, s.bottom);
2459 ref = IDirectDraw4_Release(ddraw);
2460 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
2462 DestroyWindow(window);
2465 static SIZE screen_size, screen_size2;
2467 static LRESULT CALLBACK mode_set_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2469 if (message == WM_SIZE)
2471 screen_size.cx = GetSystemMetrics(SM_CXSCREEN);
2472 screen_size.cy = GetSystemMetrics(SM_CYSCREEN);
2475 return test_proc(hwnd, message, wparam, lparam);
2478 static LRESULT CALLBACK mode_set_proc2(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2480 if (message == WM_SIZE)
2482 screen_size2.cx = GetSystemMetrics(SM_CXSCREEN);
2483 screen_size2.cy = GetSystemMetrics(SM_CYSCREEN);
2486 return test_proc(hwnd, message, wparam, lparam);
2489 static void test_coop_level_mode_set(void)
2491 IDirectDrawSurface4 *primary;
2492 RECT fullscreen_rect, r, s;
2493 IDirectDraw4 *ddraw;
2494 DDSURFACEDESC2 ddsd;
2495 WNDCLASSA wc = {0};
2496 HWND window, window2;
2497 HRESULT hr;
2498 ULONG ref;
2499 MSG msg;
2501 static const UINT exclusive_messages[] =
2503 WM_WINDOWPOSCHANGING,
2504 WM_WINDOWPOSCHANGED,
2505 WM_SIZE,
2506 WM_DISPLAYCHANGE,
2510 static const UINT normal_messages[] =
2512 WM_DISPLAYCHANGE,
2516 ddraw = create_ddraw();
2517 ok(!!ddraw, "Failed to create a ddraw object.\n");
2519 wc.lpfnWndProc = mode_set_proc;
2520 wc.lpszClassName = "ddraw_test_wndproc_wc";
2521 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2522 wc.lpfnWndProc = mode_set_proc2;
2523 wc.lpszClassName = "ddraw_test_wndproc_wc2";
2524 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2526 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW,
2527 0, 0, 100, 100, 0, 0, 0, 0);
2528 window2 = CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW,
2529 0, 0, 100, 100, 0, 0, 0, 0);
2531 SetRect(&fullscreen_rect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2532 SetRect(&s, 0, 0, 640, 480);
2534 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2535 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2537 GetWindowRect(window, &r);
2538 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2539 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2540 r.left, r.top, r.right, r.bottom);
2542 memset(&ddsd, 0, sizeof(ddsd));
2543 ddsd.dwSize = sizeof(ddsd);
2544 ddsd.dwFlags = DDSD_CAPS;
2545 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2547 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2548 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2549 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2550 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2551 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2552 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2553 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2554 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2556 GetWindowRect(window, &r);
2557 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2558 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2559 r.left, r.top, r.right, r.bottom);
2561 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2562 expect_messages = exclusive_messages;
2563 screen_size.cx = 0;
2564 screen_size.cy = 0;
2566 hr = set_display_mode(ddraw, 640, 480);
2567 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2569 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2570 expect_messages = NULL;
2571 ok(screen_size.cx == s.right && screen_size.cy == s.bottom,
2572 "Expected screen size %ux%u, got %ux%u.\n",
2573 s.right, s.bottom, screen_size.cx, screen_size.cy);
2575 GetWindowRect(window, &r);
2576 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2577 s.left, s.top, s.right, s.bottom,
2578 r.left, r.top, r.right, r.bottom);
2580 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2581 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2582 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2583 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2584 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2585 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2586 IDirectDrawSurface4_Release(primary);
2588 memset(&ddsd, 0, sizeof(ddsd));
2589 ddsd.dwSize = sizeof(ddsd);
2590 ddsd.dwFlags = DDSD_CAPS;
2591 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2593 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2594 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2595 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2596 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2597 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2598 s.right - s.left, ddsd.dwWidth);
2599 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2600 s.bottom - s.top, ddsd.dwHeight);
2602 GetWindowRect(window, &r);
2603 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2604 s.left, s.top, s.right, s.bottom,
2605 r.left, r.top, r.right, r.bottom);
2607 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2608 expect_messages = exclusive_messages;
2609 screen_size.cx = 0;
2610 screen_size.cy = 0;
2612 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2613 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2615 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2616 expect_messages = NULL;
2617 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2618 "Expected screen size %ux%u, got %ux%u.\n",
2619 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2621 GetWindowRect(window, &r);
2622 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2623 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2624 r.left, r.top, r.right, r.bottom);
2626 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2627 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2628 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2629 s.right - s.left, ddsd.dwWidth);
2630 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2631 s.bottom - s.top, ddsd.dwHeight);
2632 IDirectDrawSurface4_Release(primary);
2634 memset(&ddsd, 0, sizeof(ddsd));
2635 ddsd.dwSize = sizeof(ddsd);
2636 ddsd.dwFlags = DDSD_CAPS;
2637 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2639 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2640 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2641 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2642 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2643 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2644 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2645 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2646 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2648 GetWindowRect(window, &r);
2649 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2650 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2651 r.left, r.top, r.right, r.bottom);
2653 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2654 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2656 GetWindowRect(window, &r);
2657 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2658 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2659 r.left, r.top, r.right, r.bottom);
2661 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2662 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2663 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2664 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2665 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2666 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2667 IDirectDrawSurface4_Release(primary);
2669 memset(&ddsd, 0, sizeof(ddsd));
2670 ddsd.dwSize = sizeof(ddsd);
2671 ddsd.dwFlags = DDSD_CAPS;
2672 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2674 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2675 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2676 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2677 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2678 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2679 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2680 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2681 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2683 GetWindowRect(window, &r);
2684 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2685 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2686 r.left, r.top, r.right, r.bottom);
2688 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2689 expect_messages = normal_messages;
2690 screen_size.cx = 0;
2691 screen_size.cy = 0;
2693 hr = set_display_mode(ddraw, 640, 480);
2694 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2696 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2697 expect_messages = NULL;
2698 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2700 GetWindowRect(window, &r);
2701 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2702 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2703 r.left, r.top, r.right, r.bottom);
2705 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2706 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2707 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2708 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2709 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2710 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2711 IDirectDrawSurface4_Release(primary);
2713 memset(&ddsd, 0, sizeof(ddsd));
2714 ddsd.dwSize = sizeof(ddsd);
2715 ddsd.dwFlags = DDSD_CAPS;
2716 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2718 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2719 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2720 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2721 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2722 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2723 s.right - s.left, ddsd.dwWidth);
2724 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2725 s.bottom - s.top, ddsd.dwHeight);
2727 GetWindowRect(window, &r);
2728 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2729 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2730 r.left, r.top, r.right, r.bottom);
2732 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2733 expect_messages = normal_messages;
2734 screen_size.cx = 0;
2735 screen_size.cy = 0;
2737 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2738 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2740 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2741 expect_messages = NULL;
2742 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2744 GetWindowRect(window, &r);
2745 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2746 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2747 r.left, r.top, r.right, r.bottom);
2749 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2750 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2751 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2752 s.right - s.left, ddsd.dwWidth);
2753 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2754 s.bottom - s.top, ddsd.dwHeight);
2755 IDirectDrawSurface4_Release(primary);
2757 memset(&ddsd, 0, sizeof(ddsd));
2758 ddsd.dwSize = sizeof(ddsd);
2759 ddsd.dwFlags = DDSD_CAPS;
2760 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2762 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2763 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2764 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2765 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2766 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2767 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2768 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2769 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2771 GetWindowRect(window, &r);
2772 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2773 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2774 r.left, r.top, r.right, r.bottom);
2776 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2777 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2778 * not DDSCL_FULLSCREEN. */
2779 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2780 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2782 GetWindowRect(window, &r);
2783 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2784 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2785 r.left, r.top, r.right, r.bottom);
2787 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2788 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2789 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2790 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2791 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2792 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2793 IDirectDrawSurface4_Release(primary);
2795 memset(&ddsd, 0, sizeof(ddsd));
2796 ddsd.dwSize = sizeof(ddsd);
2797 ddsd.dwFlags = DDSD_CAPS;
2798 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2800 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2801 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2802 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2803 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2804 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2805 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2806 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2807 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2809 GetWindowRect(window, &r);
2810 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2811 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2812 r.left, r.top, r.right, r.bottom);
2814 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2815 expect_messages = normal_messages;
2816 screen_size.cx = 0;
2817 screen_size.cy = 0;
2819 hr = set_display_mode(ddraw, 640, 480);
2820 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2822 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2823 expect_messages = NULL;
2824 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2826 GetWindowRect(window, &r);
2827 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2828 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2829 r.left, r.top, r.right, r.bottom);
2831 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2832 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2833 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2834 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2835 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2836 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2837 IDirectDrawSurface4_Release(primary);
2839 memset(&ddsd, 0, sizeof(ddsd));
2840 ddsd.dwSize = sizeof(ddsd);
2841 ddsd.dwFlags = DDSD_CAPS;
2842 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2844 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2845 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2846 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2847 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2848 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2849 s.right - s.left, ddsd.dwWidth);
2850 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2851 s.bottom - s.top, ddsd.dwHeight);
2853 GetWindowRect(window, &r);
2854 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2855 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2856 r.left, r.top, r.right, r.bottom);
2858 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2859 expect_messages = normal_messages;
2860 screen_size.cx = 0;
2861 screen_size.cy = 0;
2863 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2864 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2866 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2867 expect_messages = NULL;
2868 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n", screen_size.cx, screen_size.cy);
2870 GetWindowRect(window, &r);
2871 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2872 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2873 r.left, r.top, r.right, r.bottom);
2875 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2876 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2877 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2878 s.right - s.left, ddsd.dwWidth);
2879 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2880 s.bottom - s.top, ddsd.dwHeight);
2881 IDirectDrawSurface4_Release(primary);
2883 memset(&ddsd, 0, sizeof(ddsd));
2884 ddsd.dwSize = sizeof(ddsd);
2885 ddsd.dwFlags = DDSD_CAPS;
2886 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2888 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2889 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2890 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &ddsd);
2891 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2892 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2893 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2894 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2895 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2896 IDirectDrawSurface4_Release(primary);
2898 GetWindowRect(window, &r);
2899 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2900 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2901 r.left, r.top, r.right, r.bottom);
2903 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2904 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2905 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2906 hr = set_display_mode(ddraw, 640, 480);
2907 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2909 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2910 expect_messages = exclusive_messages;
2911 screen_size.cx = 0;
2912 screen_size.cy = 0;
2914 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2915 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2917 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2918 expect_messages = NULL;
2919 ok(screen_size.cx == fullscreen_rect.right && screen_size.cy == fullscreen_rect.bottom,
2920 "Expected screen size %ux%u, got %ux%u.\n",
2921 fullscreen_rect.right, fullscreen_rect.bottom, screen_size.cx, screen_size.cy);
2923 GetWindowRect(window, &r);
2924 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2925 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
2926 r.left, r.top, r.right, r.bottom);
2928 memset(&ddsd, 0, sizeof(ddsd));
2929 ddsd.dwSize = sizeof(ddsd);
2930 ddsd.dwFlags = DDSD_CAPS;
2931 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2933 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2934 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2935 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2936 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2937 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
2938 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
2939 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
2940 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
2941 IDirectDrawSurface_Release(primary);
2943 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2944 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL | DDSCL_FULLSCREEN);
2945 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2946 hr = set_display_mode(ddraw, 640, 480);
2947 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2949 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
2950 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2952 memset(&ddsd, 0, sizeof(ddsd));
2953 ddsd.dwSize = sizeof(ddsd);
2954 ddsd.dwFlags = DDSD_CAPS;
2955 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
2957 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
2958 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
2959 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
2960 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
2961 ok(ddsd.dwWidth == s.right - s.left, "Expected surface width %u, got %u.\n",
2962 s.right - s.left, ddsd.dwWidth);
2963 ok(ddsd.dwHeight == s.bottom - s.top, "Expected surface height %u, got %u.\n",
2964 s.bottom - s.top, ddsd.dwHeight);
2965 IDirectDrawSurface_Release(primary);
2967 hr = IDirectDraw_RestoreDisplayMode(ddraw);
2968 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2970 /* If the window is changed at the same time, messages are sent to the new window. */
2971 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
2972 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2973 hr = set_display_mode(ddraw, 640, 480);
2974 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
2976 PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);
2977 expect_messages = exclusive_messages;
2978 screen_size.cx = 0;
2979 screen_size.cy = 0;
2980 screen_size2.cx = 0;
2981 screen_size2.cy = 0;
2983 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
2984 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
2986 ok(!*expect_messages, "Expected message %#x, but didn't receive it.\n", *expect_messages);
2987 expect_messages = NULL;
2988 ok(!screen_size.cx && !screen_size.cy, "Got unexpected screen size %ux%u.\n",
2989 screen_size.cx, screen_size.cy);
2990 ok(screen_size2.cx == fullscreen_rect.right && screen_size2.cy == fullscreen_rect.bottom,
2991 "Expected screen size 2 %ux%u, got %ux%u.\n",
2992 fullscreen_rect.right, fullscreen_rect.bottom, screen_size2.cx, screen_size2.cy);
2994 GetWindowRect(window, &r);
2995 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2996 s.left, s.top, s.right, s.bottom,
2997 r.left, r.top, r.right, r.bottom);
2998 GetWindowRect(window2, &r);
2999 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3000 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3001 r.left, r.top, r.right, r.bottom);
3003 memset(&ddsd, 0, sizeof(ddsd));
3004 ddsd.dwSize = sizeof(ddsd);
3005 ddsd.dwFlags = DDSD_CAPS;
3006 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3008 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
3009 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
3010 hr = IDirectDrawSurface_GetSurfaceDesc(primary, &ddsd);
3011 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
3012 ok(ddsd.dwWidth == fullscreen_rect.right - fullscreen_rect.left, "Expected surface width %u, got %u.\n",
3013 fullscreen_rect.right - fullscreen_rect.left, ddsd.dwWidth);
3014 ok(ddsd.dwHeight == fullscreen_rect.bottom - fullscreen_rect.top, "Expected surface height %u, got %u.\n",
3015 fullscreen_rect.bottom - fullscreen_rect.top, ddsd.dwHeight);
3016 IDirectDrawSurface_Release(primary);
3018 ref = IDirectDraw4_Release(ddraw);
3019 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3021 GetWindowRect(window, &r);
3022 ok(EqualRect(&r, &s), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3023 s.left, s.top, s.right, s.bottom,
3024 r.left, r.top, r.right, r.bottom);
3026 expect_messages = NULL;
3027 DestroyWindow(window);
3028 DestroyWindow(window2);
3029 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3030 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL));
3033 static void test_coop_level_mode_set_multi(void)
3035 IDirectDraw4 *ddraw1, *ddraw2;
3036 UINT orig_w, orig_h, w, h;
3037 HWND window;
3038 HRESULT hr;
3039 ULONG ref;
3041 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3042 0, 0, 100, 100, 0, 0, 0, 0);
3043 ddraw1 = create_ddraw();
3044 ok(!!ddraw1, "Failed to create a ddraw object.\n");
3046 orig_w = GetSystemMetrics(SM_CXSCREEN);
3047 orig_h = GetSystemMetrics(SM_CYSCREEN);
3049 /* With just a single ddraw object, the display mode is restored on
3050 * release. */
3051 hr = set_display_mode(ddraw1, 800, 600);
3052 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3053 w = GetSystemMetrics(SM_CXSCREEN);
3054 ok(w == 800, "Got unexpected screen width %u.\n", w);
3055 h = GetSystemMetrics(SM_CYSCREEN);
3056 ok(h == 600, "Got unexpected screen height %u.\n", h);
3058 ref = IDirectDraw4_Release(ddraw1);
3059 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3060 w = GetSystemMetrics(SM_CXSCREEN);
3061 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3062 h = GetSystemMetrics(SM_CYSCREEN);
3063 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3065 /* When there are multiple ddraw objects, the display mode is restored to
3066 * the initial mode, before the first SetDisplayMode() call. */
3067 ddraw1 = create_ddraw();
3068 hr = set_display_mode(ddraw1, 800, 600);
3069 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3070 w = GetSystemMetrics(SM_CXSCREEN);
3071 ok(w == 800, "Got unexpected screen width %u.\n", w);
3072 h = GetSystemMetrics(SM_CYSCREEN);
3073 ok(h == 600, "Got unexpected screen height %u.\n", h);
3075 ddraw2 = create_ddraw();
3076 hr = set_display_mode(ddraw2, 640, 480);
3077 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3078 w = GetSystemMetrics(SM_CXSCREEN);
3079 ok(w == 640, "Got unexpected screen width %u.\n", w);
3080 h = GetSystemMetrics(SM_CYSCREEN);
3081 ok(h == 480, "Got unexpected screen height %u.\n", h);
3083 ref = IDirectDraw4_Release(ddraw2);
3084 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3085 w = GetSystemMetrics(SM_CXSCREEN);
3086 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3087 h = GetSystemMetrics(SM_CYSCREEN);
3088 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3090 ref = IDirectDraw4_Release(ddraw1);
3091 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3092 w = GetSystemMetrics(SM_CXSCREEN);
3093 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3094 h = GetSystemMetrics(SM_CYSCREEN);
3095 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3097 /* Regardless of release ordering. */
3098 ddraw1 = create_ddraw();
3099 hr = set_display_mode(ddraw1, 800, 600);
3100 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3101 w = GetSystemMetrics(SM_CXSCREEN);
3102 ok(w == 800, "Got unexpected screen width %u.\n", w);
3103 h = GetSystemMetrics(SM_CYSCREEN);
3104 ok(h == 600, "Got unexpected screen height %u.\n", h);
3106 ddraw2 = create_ddraw();
3107 hr = set_display_mode(ddraw2, 640, 480);
3108 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3109 w = GetSystemMetrics(SM_CXSCREEN);
3110 ok(w == 640, "Got unexpected screen width %u.\n", w);
3111 h = GetSystemMetrics(SM_CYSCREEN);
3112 ok(h == 480, "Got unexpected screen height %u.\n", h);
3114 ref = IDirectDraw4_Release(ddraw1);
3115 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3116 w = GetSystemMetrics(SM_CXSCREEN);
3117 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3118 h = GetSystemMetrics(SM_CYSCREEN);
3119 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3121 ref = IDirectDraw4_Release(ddraw2);
3122 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3123 w = GetSystemMetrics(SM_CXSCREEN);
3124 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3125 h = GetSystemMetrics(SM_CYSCREEN);
3126 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3128 /* But only for ddraw objects that called SetDisplayMode(). */
3129 ddraw1 = create_ddraw();
3130 ddraw2 = create_ddraw();
3131 hr = set_display_mode(ddraw2, 640, 480);
3132 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3133 w = GetSystemMetrics(SM_CXSCREEN);
3134 ok(w == 640, "Got unexpected screen width %u.\n", w);
3135 h = GetSystemMetrics(SM_CYSCREEN);
3136 ok(h == 480, "Got unexpected screen height %u.\n", h);
3138 ref = IDirectDraw4_Release(ddraw1);
3139 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3140 w = GetSystemMetrics(SM_CXSCREEN);
3141 ok(w == 640, "Got unexpected screen width %u.\n", w);
3142 h = GetSystemMetrics(SM_CYSCREEN);
3143 ok(h == 480, "Got unexpected screen height %u.\n", h);
3145 ref = IDirectDraw4_Release(ddraw2);
3146 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3147 w = GetSystemMetrics(SM_CXSCREEN);
3148 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3149 h = GetSystemMetrics(SM_CYSCREEN);
3150 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3152 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3153 * restoring the display mode. */
3154 ddraw1 = create_ddraw();
3155 hr = set_display_mode(ddraw1, 800, 600);
3156 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3157 w = GetSystemMetrics(SM_CXSCREEN);
3158 ok(w == 800, "Got unexpected screen width %u.\n", w);
3159 h = GetSystemMetrics(SM_CYSCREEN);
3160 ok(h == 600, "Got unexpected screen height %u.\n", h);
3162 ddraw2 = create_ddraw();
3163 hr = set_display_mode(ddraw2, 640, 480);
3164 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3165 w = GetSystemMetrics(SM_CXSCREEN);
3166 ok(w == 640, "Got unexpected screen width %u.\n", w);
3167 h = GetSystemMetrics(SM_CYSCREEN);
3168 ok(h == 480, "Got unexpected screen height %u.\n", h);
3170 hr = IDirectDraw4_SetCooperativeLevel(ddraw2, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3171 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3173 ref = IDirectDraw4_Release(ddraw1);
3174 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3175 w = GetSystemMetrics(SM_CXSCREEN);
3176 ok(w == 640, "Got unexpected screen width %u.\n", w);
3177 h = GetSystemMetrics(SM_CYSCREEN);
3178 ok(h == 480, "Got unexpected screen height %u.\n", h);
3180 ref = IDirectDraw4_Release(ddraw2);
3181 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3182 w = GetSystemMetrics(SM_CXSCREEN);
3183 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3184 h = GetSystemMetrics(SM_CYSCREEN);
3185 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3187 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3188 ddraw1 = create_ddraw();
3189 hr = set_display_mode(ddraw1, 800, 600);
3190 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3191 w = GetSystemMetrics(SM_CXSCREEN);
3192 ok(w == 800, "Got unexpected screen width %u.\n", w);
3193 h = GetSystemMetrics(SM_CYSCREEN);
3194 ok(h == 600, "Got unexpected screen height %u.\n", h);
3196 hr = IDirectDraw4_SetCooperativeLevel(ddraw1, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3197 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3199 ddraw2 = create_ddraw();
3200 hr = set_display_mode(ddraw2, 640, 480);
3201 ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
3203 ref = IDirectDraw4_Release(ddraw1);
3204 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3205 w = GetSystemMetrics(SM_CXSCREEN);
3206 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3207 h = GetSystemMetrics(SM_CYSCREEN);
3208 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3210 ref = IDirectDraw4_Release(ddraw2);
3211 ok(ref == 0, "The ddraw object was not properly freed: refcount %u.\n", ref);
3212 w = GetSystemMetrics(SM_CXSCREEN);
3213 ok(w == orig_w, "Got unexpected screen width %u.\n", w);
3214 h = GetSystemMetrics(SM_CYSCREEN);
3215 ok(h == orig_h, "Got unexpected screen height %u.\n", h);
3217 DestroyWindow(window);
3220 static void test_initialize(void)
3222 IDirectDraw4 *ddraw;
3223 HRESULT hr;
3225 ddraw = create_ddraw();
3226 ok(!!ddraw, "Failed to create a ddraw object.\n");
3228 hr = IDirectDraw4_Initialize(ddraw, NULL);
3229 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x.\n", hr);
3230 IDirectDraw4_Release(ddraw);
3232 CoInitialize(NULL);
3233 hr = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectDraw4, (void **)&ddraw);
3234 ok(SUCCEEDED(hr), "Failed to create IDirectDraw4 instance, hr %#x.\n", hr);
3235 hr = IDirectDraw4_Initialize(ddraw, NULL);
3236 ok(hr == DD_OK, "Initialize returned hr %#x, expected DD_OK.\n", hr);
3237 hr = IDirectDraw4_Initialize(ddraw, NULL);
3238 ok(hr == DDERR_ALREADYINITIALIZED, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr);
3239 IDirectDraw4_Release(ddraw);
3240 CoUninitialize();
3243 static void test_coop_level_surf_create(void)
3245 IDirectDrawSurface4 *surface;
3246 IDirectDraw4 *ddraw;
3247 DDSURFACEDESC2 ddsd;
3248 HRESULT hr;
3250 ddraw = create_ddraw();
3251 ok(!!ddraw, "Failed to create a ddraw object.\n");
3253 memset(&ddsd, 0, sizeof(ddsd));
3254 ddsd.dwSize = sizeof(ddsd);
3255 ddsd.dwFlags = DDSD_CAPS;
3256 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
3257 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
3258 ok(hr == DDERR_NOCOOPERATIVELEVELSET, "Surface creation returned hr %#x.\n", hr);
3260 IDirectDraw4_Release(ddraw);
3263 static void test_vb_discard(void)
3265 static const struct vec4 quad[] =
3267 { 0.0f, 480.0f, 0.0f, 1.0f},
3268 { 0.0f, 0.0f, 0.0f, 1.0f},
3269 {640.0f, 480.0f, 0.0f, 1.0f},
3270 {640.0f, 0.0f, 0.0f, 1.0f},
3273 IDirect3DDevice3 *device;
3274 IDirect3D3 *d3d;
3275 IDirect3DVertexBuffer *buffer;
3276 HWND window;
3277 HRESULT hr;
3278 D3DVERTEXBUFFERDESC desc;
3279 BYTE *data;
3280 static const unsigned int vbsize = 16;
3281 unsigned int i;
3283 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3284 0, 0, 640, 480, 0, 0, 0, 0);
3286 if (!(device = create_device(window, DDSCL_NORMAL)))
3288 skip("Failed to create a 3D device, skipping test.\n");
3289 DestroyWindow(window);
3290 return;
3293 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
3294 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
3296 memset(&desc, 0, sizeof(desc));
3297 desc.dwSize = sizeof(desc);
3298 desc.dwCaps = D3DVBCAPS_WRITEONLY;
3299 desc.dwFVF = D3DFVF_XYZRHW;
3300 desc.dwNumVertices = vbsize;
3301 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
3302 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
3304 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3305 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3306 memcpy(data, quad, sizeof(quad));
3307 hr = IDirect3DVertexBuffer_Unlock(buffer);
3308 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3310 hr = IDirect3DDevice3_BeginScene(device);
3311 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3312 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
3313 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3314 hr = IDirect3DDevice3_EndScene(device);
3315 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3317 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3318 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3319 memset(data, 0xaa, sizeof(struct vec4) * vbsize);
3320 hr = IDirect3DVertexBuffer_Unlock(buffer);
3321 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3323 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, (void **)&data, NULL);
3324 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
3325 for (i = 0; i < sizeof(struct vec4) * vbsize; i++)
3327 if (data[i] != 0xaa)
3329 ok(FALSE, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i, data[i]);
3330 break;
3333 hr = IDirect3DVertexBuffer_Unlock(buffer);
3334 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
3336 IDirect3DVertexBuffer_Release(buffer);
3337 IDirect3D3_Release(d3d);
3338 IDirect3DDevice3_Release(device);
3339 DestroyWindow(window);
3342 static void test_coop_level_multi_window(void)
3344 HWND window1, window2;
3345 IDirectDraw4 *ddraw;
3346 HRESULT hr;
3348 window1 = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3349 0, 0, 640, 480, 0, 0, 0, 0);
3350 window2 = CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW,
3351 0, 0, 640, 480, 0, 0, 0, 0);
3352 ddraw = create_ddraw();
3353 ok(!!ddraw, "Failed to create a ddraw object.\n");
3355 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window1, DDSCL_NORMAL);
3356 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3357 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window2, DDSCL_NORMAL);
3358 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3359 ok(IsWindow(window1), "Window 1 was destroyed.\n");
3360 ok(IsWindow(window2), "Window 2 was destroyed.\n");
3362 IDirectDraw4_Release(ddraw);
3363 DestroyWindow(window2);
3364 DestroyWindow(window1);
3367 static void test_draw_strided(void)
3369 static struct vec3 position[] =
3371 {-1.0, -1.0, 0.0},
3372 {-1.0, 1.0, 0.0},
3373 { 1.0, 1.0, 0.0},
3374 { 1.0, -1.0, 0.0},
3376 static DWORD diffuse[] =
3378 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3380 static WORD indices[] =
3382 0, 1, 2, 2, 3, 0
3385 IDirectDrawSurface4 *rt;
3386 IDirect3DDevice3 *device;
3387 D3DCOLOR color;
3388 HWND window;
3389 HRESULT hr;
3390 D3DDRAWPRIMITIVESTRIDEDDATA strided;
3391 IDirect3DViewport3 *viewport;
3392 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3394 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3395 0, 0, 640, 480, 0, 0, 0, 0);
3397 if (!(device = create_device(window, DDSCL_NORMAL)))
3399 skip("Failed to create a 3D device, skipping test.\n");
3400 DestroyWindow(window);
3401 return;
3404 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3405 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3406 viewport = create_viewport(device, 0, 0, 640, 480);
3407 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3408 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
3409 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
3410 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3412 hr = IDirect3DDevice3_BeginScene(device);
3413 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3415 memset(&strided, 0x55, sizeof(strided));
3416 strided.position.lpvData = position;
3417 strided.position.dwStride = sizeof(*position);
3418 strided.diffuse.lpvData = diffuse;
3419 strided.diffuse.dwStride = sizeof(*diffuse);
3420 hr = IDirect3DDevice3_DrawIndexedPrimitiveStrided(device, D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE,
3421 &strided, 4, indices, 6, 0);
3422 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
3424 hr = IDirect3DDevice3_EndScene(device);
3425 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3427 color = get_surface_color(rt, 320, 240);
3428 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
3430 IDirect3DViewport3_Release(viewport);
3431 IDirectDrawSurface4_Release(rt);
3432 IDirect3DDevice3_Release(device);
3433 DestroyWindow(window);
3436 static void test_clear_rect_count(void)
3438 IDirectDrawSurface4 *rt;
3439 IDirect3DDevice3 *device;
3440 D3DCOLOR color;
3441 HWND window;
3442 HRESULT hr;
3443 IDirect3DViewport3 *viewport;
3444 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3446 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3447 0, 0, 640, 480, 0, 0, 0, 0);
3448 if (!(device = create_device(window, DDSCL_NORMAL)))
3450 skip("Failed to create a 3D device, skipping test.\n");
3451 DestroyWindow(window);
3452 return;
3455 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3456 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3458 viewport = create_viewport(device, 0, 0, 640, 480);
3459 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3460 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
3461 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0x00ffffff, 0.0f, 0);
3462 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3463 hr = IDirect3DViewport3_Clear2(viewport, 0, &clear_rect, D3DCLEAR_TARGET, 0x00ff0000, 0.0f, 0);
3464 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3465 hr = IDirect3DViewport3_Clear2(viewport, 0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
3466 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3467 hr = IDirect3DViewport3_Clear2(viewport, 1, NULL, D3DCLEAR_TARGET, 0x000000ff, 0.0f, 0);
3468 ok(SUCCEEDED(hr), "Failed to clear the viewport, hr %#x.\n", hr);
3470 color = get_surface_color(rt, 320, 240);
3471 ok(compare_color(color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", color);
3473 IDirect3DViewport3_Release(viewport);
3474 IDirectDrawSurface4_Release(rt);
3475 IDirect3DDevice3_Release(device);
3476 DestroyWindow(window);
3479 static BOOL test_mode_restored(IDirectDraw4 *ddraw, HWND window)
3481 DDSURFACEDESC2 ddsd1, ddsd2;
3482 HRESULT hr;
3484 memset(&ddsd1, 0, sizeof(ddsd1));
3485 ddsd1.dwSize = sizeof(ddsd1);
3486 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd1);
3487 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3489 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3490 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3491 hr = set_display_mode(ddraw, 640, 480);
3492 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
3493 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3494 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3496 memset(&ddsd2, 0, sizeof(ddsd2));
3497 ddsd2.dwSize = sizeof(ddsd2);
3498 hr = IDirectDraw4_GetDisplayMode(ddraw, &ddsd2);
3499 ok(SUCCEEDED(hr), "GetDisplayMode failed, hr %#x.\n", hr);
3500 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
3501 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3503 return ddsd1.dwWidth == ddsd2.dwWidth && ddsd1.dwHeight == ddsd2.dwHeight;
3506 static void test_coop_level_versions(void)
3508 HWND window;
3509 IDirectDraw *ddraw;
3510 HRESULT hr;
3511 BOOL restored;
3512 IDirectDrawSurface *surface;
3513 IDirectDraw4 *ddraw4;
3514 DDSURFACEDESC ddsd;
3516 window = CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW,
3517 0, 0, 640, 480, 0, 0, 0, 0);
3519 ddraw4 = create_ddraw();
3520 ok(!!ddraw4, "Failed to create a ddraw object.\n");
3521 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3522 restored = test_mode_restored(ddraw4, window);
3523 ok(restored, "Display mode not restored in new ddraw object\n");
3525 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3526 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3527 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3529 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3530 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3531 restored = test_mode_restored(ddraw4, window);
3532 ok(restored, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3534 /* A successful one does */
3535 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3536 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3537 restored = test_mode_restored(ddraw4, window);
3538 ok(!restored, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3540 IDirectDraw_Release(ddraw);
3541 IDirectDraw4_Release(ddraw4);
3543 ddraw4 = create_ddraw();
3544 ok(!!ddraw4, "Failed to create a ddraw object.\n");
3545 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3546 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3548 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_SETFOCUSWINDOW);
3549 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3550 restored = test_mode_restored(ddraw4, window);
3551 ok(!restored, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3553 IDirectDraw_Release(ddraw);
3554 IDirectDraw4_Release(ddraw4);
3556 /* A failing call does not restore the ddraw2+ behavior */
3557 ddraw4 = create_ddraw();
3558 ok(!!ddraw4, "Failed to create a ddraw object.\n");
3559 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3560 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3562 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3563 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3564 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3565 ok(FAILED(hr), "SetCooperativeLevel returned %#x, expected failure.\n", hr);
3566 restored = test_mode_restored(ddraw4, window);
3567 ok(!restored, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3569 IDirectDraw_Release(ddraw);
3570 IDirectDraw4_Release(ddraw4);
3572 /* Neither does a sequence of successful calls with the new interface */
3573 ddraw4 = create_ddraw();
3574 ok(!!ddraw4, "Failed to create a ddraw object.\n");
3575 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3576 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3578 hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3579 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3580 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
3581 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3582 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
3583 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3585 restored = test_mode_restored(ddraw4, window);
3586 ok(!restored, "Display mode restored after ddraw1-ddraw4 SetCooperativeLevel() call sequence\n");
3587 IDirectDraw_Release(ddraw);
3588 IDirectDraw4_Release(ddraw4);
3590 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3591 ddraw4 = create_ddraw();
3592 ok(!!ddraw4, "Failed to create a ddraw object.\n");
3593 hr = IDirectDraw4_QueryInterface(ddraw4, &IID_IDirectDraw, (void **)&ddraw);
3594 ok(SUCCEEDED(hr), "QueryInterface failed, hr %#x.\n", hr);
3596 hr = IDirectDraw4_SetCooperativeLevel(ddraw4, window, DDSCL_NORMAL);
3597 ok(SUCCEEDED(hr), "SetCooperativeLevel failed, hr %#x.\n", hr);
3599 memset(&ddsd, 0, sizeof(ddsd));
3600 ddsd.dwSize = sizeof(ddsd);
3601 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
3602 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3603 ddsd.dwWidth = ddsd.dwHeight = 8;
3604 hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
3605 ok(SUCCEEDED(hr), "CreateSurface failed, hr %#x.\n", hr);
3606 IDirectDrawSurface_Release(surface);
3607 restored = test_mode_restored(ddraw4, window);
3608 ok(restored, "Display mode not restored after ddraw1::CreateSurface() call\n");
3610 IDirectDraw_Release(ddraw);
3611 IDirectDraw4_Release(ddraw4);
3612 DestroyWindow(window);
3615 static void test_lighting_interface_versions(void)
3617 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
3618 IDirect3DMaterial3 *emissive;
3619 IDirect3DViewport3 *viewport;
3620 IDirect3DDevice3 *device;
3621 IDirectDrawSurface4 *rt;
3622 D3DCOLOR color;
3623 HWND window;
3624 HRESULT hr;
3625 D3DMATERIALHANDLE mat_handle;
3626 DWORD rs;
3627 unsigned int i;
3628 ULONG ref;
3629 static D3DVERTEX quad[] =
3631 {{-1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3632 {{ 1.0f}, { 1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3633 {{-1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3634 {{ 1.0f}, {-1.0f}, {0.0f}, {1.0f}, {0.0f}, {0.0f}},
3637 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3638 static struct
3640 struct vec3 position;
3641 struct vec3 normal;
3642 DWORD diffuse, specular;
3644 quad2[] =
3646 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3647 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3648 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3649 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000, 0xff808080},
3652 static D3DLVERTEX lquad[] =
3654 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3655 {{ 1.0f}, { 1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3656 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3657 {{ 1.0f}, {-1.0f}, {0.0f}, 0, {0xffff0000}, {0xff808080}},
3660 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3661 static struct
3663 struct vec3 position;
3664 DWORD diffuse, specular;
3665 struct vec2 texcoord;
3667 lquad2[] =
3669 {{-1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3670 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000, 0xff808080},
3671 {{-1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3672 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000, 0xff808080},
3675 static D3DTLVERTEX tlquad[] =
3677 {{ 0.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3678 {{ 0.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3679 {{ 640.0f}, { 480.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3680 {{ 640.0f}, { 0.0f}, {0.0f}, {1.0f}, {0xff0000ff}, {0xff808080}},
3683 static const struct
3685 DWORD vertextype;
3686 void *data;
3687 DWORD d3drs_lighting, d3drs_specular;
3688 DWORD draw_flags;
3689 D3DCOLOR color;
3691 tests[] =
3693 /* Lighting is enabled when all of these conditions are met:
3694 * 1) No pretransformed position(D3DFVF_XYZRHW)
3695 * 2) Normals are available (D3DFVF_NORMAL)
3696 * 3) D3DDP_DONOTLIGHT is not set.
3698 * D3DRENDERSTATE_LIGHTING is ignored, it is not defined
3699 * in this d3d version */
3701 /* 0 */
3702 { D3DFVF_VERTEX, quad, FALSE, FALSE, 0, 0x0000ff00},
3703 { D3DFVF_VERTEX, quad, TRUE, FALSE, 0, 0x0000ff00},
3704 { D3DFVF_VERTEX, quad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3705 { D3DFVF_VERTEX, quad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ffffff},
3706 { D3DFVF_VERTEX, quad, FALSE, TRUE, 0, 0x0000ff00},
3707 { D3DFVF_VERTEX, quad, TRUE, TRUE, 0, 0x0000ff00},
3708 { D3DFVF_VERTEX, quad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3709 { D3DFVF_VERTEX, quad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ffffff},
3711 /* 8 */
3712 { FVF_COLORVERTEX, quad2, FALSE, FALSE, 0, 0x0000ff00},
3713 { FVF_COLORVERTEX, quad2, TRUE, FALSE, 0, 0x0000ff00},
3714 { FVF_COLORVERTEX, quad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3715 { FVF_COLORVERTEX, quad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3716 /* The specular color in the vertex is ignored because
3717 * D3DRENDERSTATE_COLORVERTEX is not enabled */
3718 { FVF_COLORVERTEX, quad2, FALSE, TRUE, 0, 0x0000ff00},
3719 { FVF_COLORVERTEX, quad2, TRUE, TRUE, 0, 0x0000ff00},
3720 { FVF_COLORVERTEX, quad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3721 { FVF_COLORVERTEX, quad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3723 /* 16 */
3724 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, 0, 0x00ff0000},
3725 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, 0, 0x00ff0000},
3726 { D3DFVF_LVERTEX, lquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3727 { D3DFVF_LVERTEX, lquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3728 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, 0, 0x00ff8080},
3729 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, 0, 0x00ff8080},
3730 { D3DFVF_LVERTEX, lquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3731 { D3DFVF_LVERTEX, lquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3733 /* 24 */
3734 { FVF_LVERTEX2, lquad2, FALSE, FALSE, 0, 0x00ff0000},
3735 { FVF_LVERTEX2, lquad2, TRUE, FALSE, 0, 0x00ff0000},
3736 { FVF_LVERTEX2, lquad2, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3737 { FVF_LVERTEX2, lquad2, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x00ff0000},
3738 { FVF_LVERTEX2, lquad2, FALSE, TRUE, 0, 0x00ff8080},
3739 { FVF_LVERTEX2, lquad2, TRUE, TRUE, 0, 0x00ff8080},
3740 { FVF_LVERTEX2, lquad2, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3741 { FVF_LVERTEX2, lquad2, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x00ff8080},
3743 /* 32 */
3744 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, 0, 0x000000ff},
3745 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, 0, 0x000000ff},
3746 { D3DFVF_TLVERTEX, tlquad, FALSE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3747 { D3DFVF_TLVERTEX, tlquad, TRUE, FALSE, D3DDP_DONOTLIGHT, 0x000000ff},
3748 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, 0, 0x008080ff},
3749 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, 0, 0x008080ff},
3750 { D3DFVF_TLVERTEX, tlquad, FALSE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3751 { D3DFVF_TLVERTEX, tlquad, TRUE, TRUE, D3DDP_DONOTLIGHT, 0x008080ff},
3754 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
3755 0, 0, 640, 480, 0, 0, 0, 0);
3757 if (!(device = create_device(window, DDSCL_NORMAL)))
3759 skip("Failed to create a 3D device, skipping test.\n");
3760 DestroyWindow(window);
3761 return;
3764 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
3765 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
3767 viewport = create_viewport(device, 0, 0, 640, 480);
3768 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
3769 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
3771 emissive = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
3772 hr = IDirect3DMaterial3_GetHandle(emissive, device, &mat_handle);
3773 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
3774 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
3775 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
3776 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
3777 ok(SUCCEEDED(hr), "Failed to disable z test, hr %#x.\n", hr);
3779 hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_SPECULARENABLE, &rs);
3780 ok(SUCCEEDED(hr), "Failed to get specularenable render state, hr %#x.\n", hr);
3781 ok(rs == FALSE, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs);
3783 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
3785 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff202020, 0.0f, 0);
3786 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
3788 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, tests[i].d3drs_lighting);
3789 ok(SUCCEEDED(hr), "Failed to set lighting render state, hr %#x.\n", hr);
3790 hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SPECULARENABLE,
3791 tests[i].d3drs_specular);
3792 ok(SUCCEEDED(hr), "Failed to set specularenable render state, hr %#x.\n", hr);
3794 hr = IDirect3DDevice3_BeginScene(device);
3795 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
3796 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
3797 tests[i].vertextype, tests[i].data, 4, tests[i].draw_flags | D3DDP_WAIT);
3798 hr = IDirect3DDevice3_EndScene(device);
3799 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
3801 color = get_surface_color(rt, 320, 240);
3802 ok(compare_color(color, tests[i].color, 1),
3803 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3804 color, tests[i].color, i);
3807 destroy_material(emissive);
3808 IDirectDrawSurface4_Release(rt);
3809 ref = IDirect3DDevice3_Release(device);
3810 ok(ref == 0, "Device not properly released, refcount %u.\n", ref);
3811 DestroyWindow(window);
3814 static struct
3816 BOOL received;
3817 IDirectDraw4 *ddraw;
3818 HWND window;
3819 DWORD coop_level;
3820 } activateapp_testdata;
3822 static LRESULT CALLBACK activateapp_test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
3824 if (message == WM_ACTIVATEAPP)
3826 if (activateapp_testdata.ddraw)
3828 HRESULT hr;
3829 activateapp_testdata.received = FALSE;
3830 hr = IDirectDraw4_SetCooperativeLevel(activateapp_testdata.ddraw,
3831 activateapp_testdata.window, activateapp_testdata.coop_level);
3832 ok(SUCCEEDED(hr), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr);
3833 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3835 activateapp_testdata.received = TRUE;
3838 return DefWindowProcA(hwnd, message, wparam, lparam);
3841 static void test_coop_level_activateapp(void)
3843 IDirectDraw4 *ddraw;
3844 HRESULT hr;
3845 HWND window;
3846 WNDCLASSA wc = {0};
3847 DDSURFACEDESC2 ddsd;
3848 IDirectDrawSurface4 *surface;
3850 ddraw = create_ddraw();
3851 ok(!!ddraw, "Failed to create a ddraw object.\n");
3853 wc.lpfnWndProc = activateapp_test_proc;
3854 wc.lpszClassName = "ddraw_test_wndproc_wc";
3855 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3857 window = CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3858 WS_MAXIMIZE | WS_CAPTION , 0, 0, 640, 480, 0, 0, 0, 0);
3860 /* Exclusive with window already active. */
3861 SetActiveWindow(window);
3862 activateapp_testdata.received = FALSE;
3863 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3864 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3865 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP although window was already active.\n");
3866 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3867 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3869 /* Exclusive with window not active. */
3870 SetActiveWindow(NULL);
3871 activateapp_testdata.received = FALSE;
3872 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3873 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3874 ok(activateapp_testdata.received, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3875 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3876 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3878 /* Normal with window not active, then exclusive with the same window. */
3879 SetActiveWindow(NULL);
3880 activateapp_testdata.received = FALSE;
3881 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3882 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3883 ok(!activateapp_testdata.received, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3884 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3885 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3886 /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
3887 * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken. */
3888 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3889 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3890 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3891 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3893 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3894 SetActiveWindow(NULL);
3895 activateapp_testdata.received = FALSE;
3896 activateapp_testdata.ddraw = ddraw;
3897 activateapp_testdata.window = window;
3898 activateapp_testdata.coop_level = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
3899 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3900 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3901 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3902 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3903 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3904 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3906 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3907 * succeeding. Another switch to exclusive and back to normal is needed to release the
3908 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3909 * WM_ACTIVATEAPP messages. */
3910 activateapp_testdata.ddraw = NULL;
3911 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3912 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3913 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3914 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3916 /* Setting DDSCL_NORMAL with recursive invocation. */
3917 SetActiveWindow(NULL);
3918 activateapp_testdata.received = FALSE;
3919 activateapp_testdata.ddraw = ddraw;
3920 activateapp_testdata.window = window;
3921 activateapp_testdata.coop_level = DDSCL_NORMAL;
3922 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3923 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3924 ok(activateapp_testdata.received || broken(!activateapp_testdata.received),
3925 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3927 /* DDraw is in exlusive mode now. */
3928 memset(&ddsd, 0, sizeof(ddsd));
3929 ddsd.dwSize = sizeof(ddsd);
3930 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
3931 ddsd.dwBackBufferCount = 1;
3932 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
3933 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
3934 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3935 IDirectDrawSurface4_Release(surface);
3937 /* Recover again, just to be sure. */
3938 activateapp_testdata.ddraw = NULL;
3939 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
3940 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3941 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
3942 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3944 DestroyWindow(window);
3945 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL));
3946 IDirectDraw4_Release(ddraw);
3949 static void test_texturemanage(void)
3951 IDirectDraw4 *ddraw;
3952 HRESULT hr;
3953 DDSURFACEDESC2 ddsd;
3954 IDirectDrawSurface4 *surface;
3955 unsigned int i;
3956 DDCAPS hal_caps, hel_caps;
3957 DWORD needed_caps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY;
3958 static const struct
3960 DWORD caps_in, caps2_in;
3961 HRESULT hr;
3962 DWORD caps_out, caps2_out;
3964 tests[] =
3966 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3967 ~0U, ~0U},
3968 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3969 ~0U, ~0U},
3970 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3971 ~0U, ~0U},
3972 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3973 ~0U, ~0U},
3974 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, DD_OK,
3975 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE},
3976 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, DD_OK,
3977 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE},
3978 {DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
3979 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE | DDSCAPS_LOCALVIDMEM, 0},
3980 {DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0, DD_OK,
3981 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0},
3983 {0, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3984 ~0U, ~0U},
3985 {0, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3986 ~0U, ~0U},
3987 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3988 ~0U, ~0U},
3989 {DDSCAPS_SYSTEMMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3990 ~0U, ~0U},
3991 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_TEXTUREMANAGE, DDERR_INVALIDCAPS,
3992 ~0U, ~0U},
3993 {DDSCAPS_VIDEOMEMORY, DDSCAPS2_D3DTEXTUREMANAGE, DDERR_INVALIDCAPS,
3994 ~0U, ~0U},
3995 {DDSCAPS_VIDEOMEMORY, 0, DD_OK,
3996 DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY, 0},
3997 {DDSCAPS_SYSTEMMEMORY, 0, DD_OK,
3998 DDSCAPS_SYSTEMMEMORY, 0},
4001 ddraw = create_ddraw();
4002 ok(!!ddraw, "Failed to create a ddraw object.\n");
4003 hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
4004 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4006 memset(&hal_caps, 0, sizeof(hal_caps));
4007 hal_caps.dwSize = sizeof(hal_caps);
4008 memset(&hel_caps, 0, sizeof(hel_caps));
4009 hel_caps.dwSize = sizeof(hel_caps);
4010 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, &hel_caps);
4011 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4012 if ((hal_caps.ddsCaps.dwCaps & needed_caps) != needed_caps)
4014 skip("Managed textures not supported, skipping managed texture test.\n");
4015 IDirectDraw4_Release(ddraw);
4016 return;
4019 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
4021 memset(&ddsd, 0, sizeof(ddsd));
4022 ddsd.dwSize = sizeof(ddsd);
4023 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4024 ddsd.ddsCaps.dwCaps = tests[i].caps_in;
4025 ddsd.ddsCaps.dwCaps2 = tests[i].caps2_in;
4026 ddsd.dwWidth = 4;
4027 ddsd.dwHeight = 4;
4029 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4030 ok(hr == tests[i].hr, "Got unexpected, hr %#x, case %u.\n", hr, i);
4031 if (FAILED(hr))
4032 continue;
4034 memset(&ddsd, 0, sizeof(ddsd));
4035 ddsd.dwSize = sizeof(ddsd);
4036 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
4037 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4039 ok(ddsd.ddsCaps.dwCaps == tests[i].caps_out,
4040 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4041 tests[i].caps_in, tests[i].caps2_in, tests[i].caps_out, ddsd.ddsCaps.dwCaps, i);
4042 ok(ddsd.ddsCaps.dwCaps2 == tests[i].caps2_out,
4043 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4044 tests[i].caps_in, tests[i].caps2_in, tests[i].caps2_out, ddsd.ddsCaps.dwCaps2, i);
4046 IDirectDrawSurface4_Release(surface);
4049 IDirectDraw4_Release(ddraw);
4052 #define SUPPORT_DXT1 0x01
4053 #define SUPPORT_DXT2 0x02
4054 #define SUPPORT_DXT3 0x04
4055 #define SUPPORT_DXT4 0x08
4056 #define SUPPORT_DXT5 0x10
4057 #define SUPPORT_YUY2 0x20
4058 #define SUPPORT_UYVY 0x40
4060 static HRESULT WINAPI test_block_formats_creation_cb(DDPIXELFORMAT *fmt, void *ctx)
4062 DWORD *supported_fmts = ctx;
4064 if (!(fmt->dwFlags & DDPF_FOURCC))
4065 return DDENUMRET_OK;
4067 switch (fmt->dwFourCC)
4069 case MAKEFOURCC('D','X','T','1'):
4070 *supported_fmts |= SUPPORT_DXT1;
4071 break;
4072 case MAKEFOURCC('D','X','T','2'):
4073 *supported_fmts |= SUPPORT_DXT2;
4074 break;
4075 case MAKEFOURCC('D','X','T','3'):
4076 *supported_fmts |= SUPPORT_DXT3;
4077 break;
4078 case MAKEFOURCC('D','X','T','4'):
4079 *supported_fmts |= SUPPORT_DXT4;
4080 break;
4081 case MAKEFOURCC('D','X','T','5'):
4082 *supported_fmts |= SUPPORT_DXT5;
4083 break;
4084 case MAKEFOURCC('Y','U','Y','2'):
4085 *supported_fmts |= SUPPORT_YUY2;
4086 break;
4087 case MAKEFOURCC('U','Y','V','Y'):
4088 *supported_fmts |= SUPPORT_UYVY;
4089 break;
4090 default:
4091 break;
4094 return DDENUMRET_OK;
4097 static void test_block_formats_creation(void)
4099 HRESULT hr, expect_hr;
4100 unsigned int i, j, w, h;
4101 HWND window;
4102 IDirectDraw4 *ddraw;
4103 IDirect3D3 *d3d;
4104 IDirect3DDevice3 *device;
4105 IDirectDrawSurface4 *surface;
4106 DWORD supported_fmts = 0, supported_overlay_fmts = 0;
4107 DWORD num_fourcc_codes = 0, *fourcc_codes;
4108 DDSURFACEDESC2 ddsd;
4109 DDCAPS hal_caps;
4110 void *mem;
4112 static const struct
4114 DWORD fourcc;
4115 const char *name;
4116 DWORD support_flag;
4117 unsigned int block_width;
4118 unsigned int block_height;
4119 unsigned int block_size;
4120 BOOL create_size_checked, overlay;
4122 formats[] =
4124 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1, 4, 4, 8, TRUE, FALSE},
4125 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2, 4, 4, 16, TRUE, FALSE},
4126 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3, 4, 4, 16, TRUE, FALSE},
4127 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4, 4, 4, 16, TRUE, FALSE},
4128 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5, 4, 4, 16, TRUE, FALSE},
4129 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2, 2, 1, 4, FALSE, TRUE },
4130 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY, 2, 1, 4, FALSE, TRUE },
4132 static const struct
4134 DWORD caps, caps2;
4135 const char *name;
4136 BOOL overlay;
4138 types[] =
4140 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4141 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4143 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4144 * Other hw / drivers successfully create those surfaces. Ignore them, this
4145 * suggests that no game uses this, otherwise Nvidia would support it. */
4147 DDSCAPS_VIDEOMEMORY | DDSCAPS_TEXTURE, 0,
4148 "videomemory texture", FALSE
4151 DDSCAPS_VIDEOMEMORY | DDSCAPS_OVERLAY, 0,
4152 "videomemory overlay", TRUE
4155 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE, 0,
4156 "systemmemory texture", FALSE
4159 DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
4160 "managed texture", FALSE
4163 enum size_type
4165 SIZE_TYPE_ZERO,
4166 SIZE_TYPE_PITCH,
4167 SIZE_TYPE_SIZE,
4169 static const struct
4171 DWORD flags;
4172 enum size_type size_type;
4173 int rel_size;
4174 HRESULT hr;
4176 user_mem_tests[] =
4178 {DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DD_OK},
4179 {DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4180 {DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4181 {DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4182 {DDSD_LPSURFACE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4183 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_ZERO, 0, DDERR_INVALIDPARAMS},
4184 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_PITCH, 0, DDERR_INVALIDPARAMS},
4185 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4186 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 1, DD_OK},
4187 {DDSD_LPSURFACE | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, -1, DDERR_INVALIDPARAMS},
4188 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_ZERO, 0, DD_OK},
4189 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_PITCH, 0, DD_OK},
4190 {DDSD_LPSURFACE | DDSD_PITCH, SIZE_TYPE_SIZE, 0, DD_OK},
4191 {DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, SIZE_TYPE_SIZE, 0, DD_OK},
4194 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4195 0, 0, 640, 480, 0, 0, 0, 0);
4197 if (!(device = create_device(window, DDSCL_NORMAL)))
4199 skip("Failed to create a 3D device, skipping test.\n");
4200 DestroyWindow(window);
4201 return;
4204 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4205 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4206 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
4207 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4208 IDirect3D3_Release(d3d);
4210 hr = IDirect3DDevice3_EnumTextureFormats(device, test_block_formats_creation_cb,
4211 &supported_fmts);
4212 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4214 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, NULL);
4215 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4216 fourcc_codes = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4217 num_fourcc_codes * sizeof(*fourcc_codes));
4218 if (!fourcc_codes)
4219 goto cleanup;
4220 hr = IDirectDraw4_GetFourCCCodes(ddraw, &num_fourcc_codes, fourcc_codes);
4221 ok(SUCCEEDED(hr), "Failed to get fourcc codes %#x.\n", hr);
4222 for (i = 0; i < num_fourcc_codes; i++)
4224 for (j = 0; j < sizeof(formats) / sizeof(*formats); j++)
4226 if (fourcc_codes[i] == formats[j].fourcc)
4227 supported_overlay_fmts |= formats[j].support_flag;
4230 HeapFree(GetProcessHeap(), 0, fourcc_codes);
4232 memset(&hal_caps, 0, sizeof(hal_caps));
4233 hal_caps.dwSize = sizeof(hal_caps);
4234 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
4235 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
4237 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2 * 2 * 16 + 1);
4239 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4241 for (j = 0; j < sizeof(types) / sizeof(*types); j++)
4243 BOOL support;
4245 if (formats[i].overlay != types[j].overlay
4246 || (types[j].overlay && !(hal_caps.dwCaps & DDCAPS_OVERLAY)))
4247 continue;
4249 if (formats[i].overlay)
4250 support = supported_overlay_fmts & formats[i].support_flag;
4251 else
4252 support = supported_fmts & formats[i].support_flag;
4254 for (w = 1; w <= 8; w++)
4256 for (h = 1; h <= 8; h++)
4258 BOOL block_aligned = TRUE;
4259 BOOL todo = FALSE;
4261 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
4262 block_aligned = FALSE;
4264 memset(&ddsd, 0, sizeof(ddsd));
4265 ddsd.dwSize = sizeof(ddsd);
4266 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
4267 ddsd.ddsCaps.dwCaps = types[j].caps;
4268 ddsd.ddsCaps.dwCaps2 = types[j].caps2;
4269 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4270 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4271 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4272 ddsd.dwWidth = w;
4273 ddsd.dwHeight = h;
4275 /* TODO: Handle power of two limitations. I cannot test the pow2
4276 * behavior on windows because I have no hardware that doesn't at
4277 * least support np2_conditional. There's probably no HW that
4278 * supports DXTN textures but no conditional np2 textures. */
4279 if (!support && !(types[j].caps & DDSCAPS_SYSTEMMEMORY))
4280 expect_hr = DDERR_INVALIDPARAMS;
4281 else if (formats[i].create_size_checked && !block_aligned)
4283 expect_hr = DDERR_INVALIDPARAMS;
4284 if (!(types[j].caps & DDSCAPS_TEXTURE))
4285 todo = TRUE;
4287 else
4288 expect_hr = D3D_OK;
4290 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4291 if (todo)
4292 todo_wine ok(hr == expect_hr,
4293 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4294 hr, formats[i].name, types[j].name, w, h, expect_hr);
4295 else
4296 ok(hr == expect_hr,
4297 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4298 hr, formats[i].name, types[j].name, w, h, expect_hr);
4300 if (SUCCEEDED(hr))
4301 IDirectDrawSurface4_Release(surface);
4306 if (formats[i].overlay)
4307 continue;
4309 for (j = 0; j < sizeof(user_mem_tests) / sizeof(*user_mem_tests); ++j)
4311 memset(&ddsd, 0, sizeof(ddsd));
4312 ddsd.dwSize = sizeof(ddsd);
4313 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | user_mem_tests[j].flags;
4314 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE;
4316 switch (user_mem_tests[j].size_type)
4318 case SIZE_TYPE_ZERO:
4319 U1(ddsd).dwLinearSize = 0;
4320 break;
4322 case SIZE_TYPE_PITCH:
4323 U1(ddsd).dwLinearSize = 2 * formats[i].block_size;
4324 break;
4326 case SIZE_TYPE_SIZE:
4327 U1(ddsd).dwLinearSize = 2 * 2 * formats[i].block_size;
4328 break;
4330 U1(ddsd).dwLinearSize += user_mem_tests[j].rel_size;
4332 ddsd.lpSurface = mem;
4333 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
4334 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_FOURCC;
4335 U4(ddsd).ddpfPixelFormat.dwFourCC = formats[i].fourcc;
4336 ddsd.dwWidth = 8;
4337 ddsd.dwHeight = 8;
4339 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4340 ok(hr == user_mem_tests[j].hr, "Test %u: Got unexpected hr %#x, format %s.\n", j, hr, formats[i].name);
4342 if (FAILED(hr))
4343 continue;
4345 memset(&ddsd, 0, sizeof(ddsd));
4346 ddsd.dwSize = sizeof(ddsd);
4347 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
4348 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", j, hr);
4349 ok(ddsd.dwFlags == (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_LINEARSIZE),
4350 "Test %u: Got unexpected flags %#x.\n", j, ddsd.dwFlags);
4351 if (user_mem_tests[j].flags & DDSD_LPSURFACE)
4352 ok(U1(ddsd).dwLinearSize == ~0u, "Test %u: Got unexpected linear size %#x.\n",
4353 j, U1(ddsd).dwLinearSize);
4354 else
4355 ok(U1(ddsd).dwLinearSize == 2 * 2 * formats[i].block_size,
4356 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
4357 j, U1(ddsd).dwLinearSize, 2 * 2 * formats[i].block_size);
4358 IDirectDrawSurface4_Release(surface);
4362 HeapFree(GetProcessHeap(), 0, mem);
4363 cleanup:
4364 IDirectDraw4_Release(ddraw);
4365 IDirect3DDevice3_Release(device);
4366 DestroyWindow(window);
4369 struct format_support_check
4371 const DDPIXELFORMAT *format;
4372 BOOL supported;
4375 static HRESULT WINAPI test_unsupported_formats_cb(DDPIXELFORMAT *fmt, void *ctx)
4377 struct format_support_check *format = ctx;
4379 if (!memcmp(format->format, fmt, sizeof(*fmt)))
4381 format->supported = TRUE;
4382 return DDENUMRET_CANCEL;
4385 return DDENUMRET_OK;
4388 static void test_unsupported_formats(void)
4390 HRESULT hr;
4391 BOOL expect_success;
4392 HWND window;
4393 IDirectDraw4 *ddraw;
4394 IDirect3D3 *d3d;
4395 IDirect3DDevice3 *device;
4396 IDirectDrawSurface4 *surface;
4397 DDSURFACEDESC2 ddsd;
4398 unsigned int i, j;
4399 DWORD expected_caps;
4400 static const struct
4402 const char *name;
4403 DDPIXELFORMAT fmt;
4405 formats[] =
4408 "D3DFMT_A8R8G8B8",
4410 sizeof(DDPIXELFORMAT), DDPF_RGB | DDPF_ALPHAPIXELS, 0,
4411 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4415 "D3DFMT_P8",
4417 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4418 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4422 static const DWORD caps[] = {0, DDSCAPS_SYSTEMMEMORY, DDSCAPS_VIDEOMEMORY};
4424 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4425 0, 0, 640, 480, 0, 0, 0, 0);
4427 if (!(device = create_device(window, DDSCL_NORMAL)))
4429 skip("Failed to create a 3D device, skipping test.\n");
4430 DestroyWindow(window);
4431 return;
4434 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
4435 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
4436 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **) &ddraw);
4437 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
4438 IDirect3D3_Release(d3d);
4440 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
4442 struct format_support_check check = {&formats[i].fmt, FALSE};
4443 hr = IDirect3DDevice3_EnumTextureFormats(device, test_unsupported_formats_cb, &check);
4444 ok(SUCCEEDED(hr), "Failed to enumerate texture formats %#x.\n", hr);
4446 for (j = 0; j < sizeof(caps) / sizeof(*caps); j++)
4448 memset(&ddsd, 0, sizeof(ddsd));
4449 ddsd.dwSize = sizeof(ddsd);
4450 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
4451 U4(ddsd).ddpfPixelFormat = formats[i].fmt;
4452 ddsd.dwWidth = 4;
4453 ddsd.dwHeight = 4;
4454 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | caps[j];
4456 if (caps[j] & DDSCAPS_VIDEOMEMORY && !check.supported)
4457 expect_success = FALSE;
4458 else
4459 expect_success = TRUE;
4461 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
4462 ok(SUCCEEDED(hr) == expect_success,
4463 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4464 hr, formats[i].name, caps[j], expect_success ? "success" : "failure");
4465 if (FAILED(hr))
4466 continue;
4468 memset(&ddsd, 0, sizeof(ddsd));
4469 ddsd.dwSize = sizeof(ddsd);
4470 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
4471 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4473 if (caps[j] & DDSCAPS_VIDEOMEMORY)
4474 expected_caps = DDSCAPS_VIDEOMEMORY;
4475 else if (caps[j] & DDSCAPS_SYSTEMMEMORY)
4476 expected_caps = DDSCAPS_SYSTEMMEMORY;
4477 else if (check.supported)
4478 expected_caps = DDSCAPS_VIDEOMEMORY;
4479 else
4480 expected_caps = DDSCAPS_SYSTEMMEMORY;
4482 ok(ddsd.ddsCaps.dwCaps & expected_caps,
4483 "Expected capability %#x, format %s, input cap %#x.\n",
4484 expected_caps, formats[i].name, caps[j]);
4486 IDirectDrawSurface4_Release(surface);
4490 IDirectDraw4_Release(ddraw);
4491 IDirect3DDevice3_Release(device);
4492 DestroyWindow(window);
4495 static void test_rt_caps(void)
4497 PALETTEENTRY palette_entries[256];
4498 IDirectDrawPalette *palette;
4499 IDirectDraw4 *ddraw;
4500 DDPIXELFORMAT z_fmt;
4501 IDirect3D3 *d3d;
4502 unsigned int i;
4503 ULONG refcount;
4504 HWND window;
4505 HRESULT hr;
4507 static const DDPIXELFORMAT p8_fmt =
4509 sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0,
4510 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4513 const struct
4515 const DDPIXELFORMAT *pf;
4516 DWORD caps_in;
4517 DWORD caps_out;
4518 HRESULT create_device_hr;
4519 HRESULT set_rt_hr, alternative_set_rt_hr;
4521 test_data[] =
4524 NULL,
4525 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4526 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4527 D3D_OK,
4528 D3D_OK,
4529 D3D_OK,
4532 NULL,
4533 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4534 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4535 D3D_OK,
4536 D3D_OK,
4537 D3D_OK,
4540 NULL,
4541 DDSCAPS_OFFSCREENPLAIN,
4542 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4543 DDERR_INVALIDCAPS,
4544 DDERR_INVALIDCAPS,
4545 DDERR_INVALIDCAPS,
4548 NULL,
4549 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4550 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4551 D3DERR_SURFACENOTINVIDMEM,
4552 D3D_OK,
4553 D3D_OK,
4556 NULL,
4557 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4558 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4559 DDERR_INVALIDCAPS,
4560 DDERR_INVALIDCAPS,
4561 DDERR_INVALIDCAPS,
4564 NULL,
4565 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY,
4566 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4567 D3D_OK,
4568 D3D_OK,
4569 D3D_OK,
4572 NULL,
4573 DDSCAPS_3DDEVICE,
4574 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4575 D3D_OK,
4576 D3D_OK,
4577 D3D_OK,
4580 NULL,
4582 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4583 DDERR_INVALIDCAPS,
4584 DDERR_INVALIDCAPS,
4585 DDERR_INVALIDCAPS,
4588 NULL,
4589 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4590 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4591 D3DERR_SURFACENOTINVIDMEM,
4592 D3D_OK,
4593 D3D_OK,
4596 NULL,
4597 DDSCAPS_SYSTEMMEMORY,
4598 DDSCAPS_SYSTEMMEMORY,
4599 DDERR_INVALIDCAPS,
4600 DDERR_INVALIDCAPS,
4601 DDERR_INVALIDCAPS,
4604 &p8_fmt,
4606 DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4607 DDERR_INVALIDCAPS,
4608 DDERR_INVALIDCAPS,
4609 DDERR_INVALIDCAPS,
4612 &p8_fmt,
4613 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
4614 ~0U /* AMD r200 */,
4615 DDERR_NOPALETTEATTACHED,
4616 DDERR_INVALIDCAPS,
4617 DDERR_INVALIDCAPS,
4620 &p8_fmt,
4621 DDSCAPS_OFFSCREENPLAIN,
4622 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM,
4623 DDERR_INVALIDCAPS,
4624 DDERR_INVALIDCAPS,
4625 DDERR_INVALIDCAPS,
4628 &p8_fmt,
4629 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4630 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE,
4631 DDERR_NOPALETTEATTACHED,
4632 DDERR_INVALIDCAPS,
4633 DDERR_INVALIDCAPS,
4636 &p8_fmt,
4637 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4638 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4639 DDERR_INVALIDCAPS,
4640 DDERR_INVALIDCAPS,
4641 DDERR_INVALIDCAPS,
4644 &z_fmt,
4645 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER,
4646 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4647 DDERR_INVALIDCAPS,
4648 DDERR_INVALIDPIXELFORMAT,
4649 D3D_OK /* r200 */,
4652 &z_fmt,
4653 DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4654 DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4655 DDERR_INVALIDCAPS,
4656 DDERR_INVALIDPIXELFORMAT,
4657 D3D_OK /* r200 */,
4660 &z_fmt,
4661 DDSCAPS_ZBUFFER,
4662 DDSCAPS_VIDEOMEMORY | DDSCAPS_ZBUFFER | DDSCAPS_LOCALVIDMEM,
4663 DDERR_INVALIDCAPS,
4664 DDERR_INVALIDCAPS,
4665 DDERR_INVALIDCAPS,
4668 &z_fmt,
4669 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4670 DDSCAPS_SYSTEMMEMORY | DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER,
4671 DDERR_INVALIDCAPS,
4672 DDERR_INVALIDPIXELFORMAT,
4673 D3D_OK /* r200 */,
4676 &z_fmt,
4677 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4678 DDSCAPS_SYSTEMMEMORY | DDSCAPS_ZBUFFER,
4679 DDERR_INVALIDCAPS,
4680 DDERR_INVALIDCAPS,
4681 DDERR_INVALIDCAPS,
4685 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4686 0, 0, 640, 480, 0, 0, 0, 0);
4687 ddraw = create_ddraw();
4688 ok(!!ddraw, "Failed to create a ddraw object.\n");
4689 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4690 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4692 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
4694 skip("D3D interface is not available, skipping test.\n");
4695 goto done;
4698 memset(&z_fmt, 0, sizeof(z_fmt));
4699 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
4700 if (FAILED(hr) || !z_fmt.dwSize)
4702 skip("No depth buffer formats available, skipping test.\n");
4703 IDirect3D3_Release(d3d);
4704 goto done;
4707 memset(palette_entries, 0, sizeof(palette_entries));
4708 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
4709 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
4711 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4713 IDirectDrawSurface4 *surface, *rt, *expected_rt, *tmp;
4714 DDSURFACEDESC2 surface_desc;
4715 IDirect3DDevice3 *device;
4717 memset(&surface_desc, 0, sizeof(surface_desc));
4718 surface_desc.dwSize = sizeof(surface_desc);
4719 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4720 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4721 if (test_data[i].pf)
4723 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4724 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4726 surface_desc.dwWidth = 640;
4727 surface_desc.dwHeight = 480;
4728 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4729 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4730 i, test_data[i].caps_in, hr);
4732 memset(&surface_desc, 0, sizeof(surface_desc));
4733 surface_desc.dwSize = sizeof(surface_desc);
4734 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
4735 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4736 ok(test_data[i].caps_out == ~0U || surface_desc.ddsCaps.dwCaps == test_data[i].caps_out,
4737 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4738 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4740 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device, NULL);
4741 ok(hr == test_data[i].create_device_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4742 i, hr, test_data[i].create_device_hr);
4743 if (FAILED(hr))
4745 if (hr == DDERR_NOPALETTEATTACHED)
4747 hr = IDirectDrawSurface4_SetPalette(surface, palette);
4748 ok(SUCCEEDED(hr), "Test %u: Failed to set palette, hr %#x.\n", i, hr);
4749 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device, NULL);
4750 if (surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
4751 ok(hr == DDERR_INVALIDPIXELFORMAT, "Test %u: Got unexpected hr %#x.\n", i, hr);
4752 else
4753 ok(hr == D3DERR_SURFACENOTINVIDMEM, "Test %u: Got unexpected hr %#x.\n", i, hr);
4755 IDirectDrawSurface4_Release(surface);
4757 memset(&surface_desc, 0, sizeof(surface_desc));
4758 surface_desc.dwSize = sizeof(surface_desc);
4759 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4760 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4761 surface_desc.dwWidth = 640;
4762 surface_desc.dwHeight = 480;
4763 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4764 ok(SUCCEEDED(hr), "Test %u: Failed to create surface, hr %#x.\n", i, hr);
4766 hr = IDirect3D3_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device, NULL);
4767 ok(SUCCEEDED(hr), "Test %u: Failed to create device, hr %#x.\n", i, hr);
4770 memset(&surface_desc, 0, sizeof(surface_desc));
4771 surface_desc.dwSize = sizeof(surface_desc);
4772 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4773 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4774 if (test_data[i].pf)
4776 surface_desc.dwFlags |= DDSD_PIXELFORMAT;
4777 U4(surface_desc).ddpfPixelFormat = *test_data[i].pf;
4779 surface_desc.dwWidth = 640;
4780 surface_desc.dwHeight = 480;
4781 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &rt, NULL);
4782 ok(SUCCEEDED(hr), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4783 i, test_data[i].caps_in, hr);
4785 hr = IDirect3DDevice3_SetRenderTarget(device, rt, 0);
4786 ok(hr == test_data[i].set_rt_hr || broken(hr == test_data[i].alternative_set_rt_hr),
4787 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4788 i, hr, test_data[i].set_rt_hr);
4789 if (SUCCEEDED(hr) || hr == DDERR_INVALIDPIXELFORMAT)
4790 expected_rt = rt;
4791 else
4792 expected_rt = surface;
4794 hr = IDirect3DDevice3_GetRenderTarget(device, &tmp);
4795 ok(SUCCEEDED(hr), "Test %u: Failed to get render target, hr %#x.\n", i, hr);
4796 ok(tmp == expected_rt, "Test %u: Got unexpected rt %p.\n", i, tmp);
4798 IDirectDrawSurface4_Release(tmp);
4799 IDirectDrawSurface4_Release(rt);
4800 refcount = IDirect3DDevice3_Release(device);
4801 ok(refcount == 0, "Test %u: The device was not properly freed, refcount %u.\n", i, refcount);
4802 refcount = IDirectDrawSurface4_Release(surface);
4803 ok(refcount == 0, "Test %u: The surface was not properly freed, refcount %u.\n", i, refcount);
4806 IDirectDrawPalette_Release(palette);
4807 IDirect3D3_Release(d3d);
4809 done:
4810 refcount = IDirectDraw4_Release(ddraw);
4811 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4812 DestroyWindow(window);
4815 static void test_primary_caps(void)
4817 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
4818 IDirectDrawSurface4 *surface;
4819 DDSURFACEDESC2 surface_desc;
4820 IDirectDraw4 *ddraw;
4821 unsigned int i;
4822 ULONG refcount;
4823 HWND window;
4824 HRESULT hr;
4826 static const struct
4828 DWORD coop_level;
4829 DWORD caps_in;
4830 DWORD back_buffer_count;
4831 HRESULT hr;
4832 DWORD caps_out;
4834 test_data[] =
4837 DDSCL_NORMAL,
4838 DDSCAPS_PRIMARYSURFACE,
4839 ~0u,
4840 DD_OK,
4841 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE,
4844 DDSCL_NORMAL,
4845 DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE,
4846 ~0u,
4847 DDERR_INVALIDCAPS,
4848 ~0u,
4851 DDSCL_NORMAL,
4852 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER,
4853 ~0u,
4854 DDERR_INVALIDCAPS,
4855 ~0u,
4858 DDSCL_NORMAL,
4859 DDSCAPS_PRIMARYSURFACE | DDSCAPS_BACKBUFFER,
4860 ~0u,
4861 DDERR_INVALIDCAPS,
4862 ~0u,
4865 DDSCL_NORMAL,
4866 DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP,
4867 ~0u,
4868 DDERR_INVALIDCAPS,
4869 ~0u,
4872 DDSCL_NORMAL,
4873 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX,
4874 ~0u,
4875 DDERR_INVALIDCAPS,
4876 ~0u,
4879 DDSCL_NORMAL,
4880 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4881 ~0u,
4882 DDERR_INVALIDCAPS,
4883 ~0u,
4886 DDSCL_NORMAL,
4887 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4889 DDERR_INVALIDCAPS,
4890 ~0u,
4893 DDSCL_NORMAL,
4894 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4896 DDERR_NOEXCLUSIVEMODE,
4897 ~0u,
4900 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4901 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4903 DDERR_INVALIDCAPS,
4904 ~0u,
4907 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4908 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP,
4910 DD_OK,
4911 DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX,
4914 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4915 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER,
4917 DDERR_INVALIDCAPS,
4918 ~0u,
4921 DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN,
4922 DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_BACKBUFFER,
4924 DDERR_INVALIDCAPS,
4925 ~0u,
4929 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
4930 0, 0, 640, 480, 0, 0, 0, 0);
4931 ddraw = create_ddraw();
4932 ok(!!ddraw, "Failed to create a ddraw object.\n");
4934 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
4936 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, test_data[i].coop_level);
4937 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4939 memset(&surface_desc, 0, sizeof(surface_desc));
4940 surface_desc.dwSize = sizeof(surface_desc);
4941 surface_desc.dwFlags = DDSD_CAPS;
4942 if (test_data[i].back_buffer_count != ~0u)
4943 surface_desc.dwFlags |= DDSD_BACKBUFFERCOUNT;
4944 surface_desc.ddsCaps.dwCaps = test_data[i].caps_in;
4945 surface_desc.dwBackBufferCount = test_data[i].back_buffer_count;
4946 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4947 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
4948 if (FAILED(hr))
4949 continue;
4951 memset(&surface_desc, 0, sizeof(surface_desc));
4952 surface_desc.dwSize = sizeof(surface_desc);
4953 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
4954 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
4955 ok((surface_desc.ddsCaps.dwCaps & ~placement) == test_data[i].caps_out,
4956 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4957 i, surface_desc.ddsCaps.dwCaps, test_data[i].caps_out);
4959 IDirectDrawSurface4_Release(surface);
4962 refcount = IDirectDraw4_Release(ddraw);
4963 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
4964 DestroyWindow(window);
4967 static void test_surface_lock(void)
4969 IDirectDraw4 *ddraw;
4970 IDirect3D3 *d3d = NULL;
4971 IDirectDrawSurface4 *surface;
4972 HRESULT hr;
4973 HWND window;
4974 unsigned int i;
4975 DDSURFACEDESC2 ddsd;
4976 ULONG refcount;
4977 DDPIXELFORMAT z_fmt;
4978 static const struct
4980 DWORD caps;
4981 DWORD caps2;
4982 const char *name;
4984 tests[] =
4987 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
4989 "videomemory offscreenplain"
4992 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
4994 "systemmemory offscreenplain"
4997 DDSCAPS_PRIMARYSURFACE,
4999 "primary"
5002 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5004 "videomemory texture"
5007 DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY,
5008 DDSCAPS2_OPAQUE,
5009 "opaque videomemory texture"
5012 DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY,
5014 "systemmemory texture"
5017 DDSCAPS_TEXTURE,
5018 DDSCAPS2_TEXTUREMANAGE,
5019 "managed texture"
5022 DDSCAPS_TEXTURE,
5023 DDSCAPS2_D3DTEXTUREMANAGE,
5024 "managed texture"
5027 DDSCAPS_TEXTURE,
5028 DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_OPAQUE,
5029 "opaque managed texture"
5032 DDSCAPS_TEXTURE,
5033 DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_OPAQUE,
5034 "opaque managed texture"
5037 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE,
5039 "render target"
5042 DDSCAPS_ZBUFFER,
5044 "Z buffer"
5048 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5049 0, 0, 640, 480, 0, 0, 0, 0);
5050 ddraw = create_ddraw();
5051 ok(!!ddraw, "Failed to create a ddraw object.\n");
5052 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5053 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5055 if (FAILED(IDirectDraw4_QueryInterface(ddraw, &IID_IDirect3D3, (void **)&d3d)))
5057 skip("D3D interface is not available, skipping test.\n");
5058 goto done;
5061 memset(&z_fmt, 0, sizeof(z_fmt));
5062 hr = IDirect3D3_EnumZBufferFormats(d3d, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
5063 if (FAILED(hr) || !z_fmt.dwSize)
5065 skip("No depth buffer formats available, skipping test.\n");
5066 goto done;
5069 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5071 memset(&ddsd, 0, sizeof(ddsd));
5072 ddsd.dwSize = sizeof(ddsd);
5073 ddsd.dwFlags = DDSD_CAPS;
5074 if (!(tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5076 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5077 ddsd.dwWidth = 64;
5078 ddsd.dwHeight = 64;
5080 if (tests[i].caps & DDSCAPS_ZBUFFER)
5082 ddsd.dwFlags |= DDSD_PIXELFORMAT;
5083 U4(ddsd).ddpfPixelFormat = z_fmt;
5085 ddsd.ddsCaps.dwCaps = tests[i].caps;
5086 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5088 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5089 ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
5091 memset(&ddsd, 0, sizeof(ddsd));
5092 ddsd.dwSize = sizeof(ddsd);
5093 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_WAIT, NULL);
5094 ok(SUCCEEDED(hr), "Failed to lock surface, type %s, hr %#x.\n", tests[i].name, hr);
5095 if (SUCCEEDED(hr))
5097 hr = IDirectDrawSurface4_Unlock(surface, NULL);
5098 ok(SUCCEEDED(hr), "Failed to unlock surface, type %s, hr %#x.\n", tests[i].name, hr);
5101 IDirectDrawSurface4_Release(surface);
5104 done:
5105 if (d3d)
5106 IDirect3D3_Release(d3d);
5107 refcount = IDirectDraw4_Release(ddraw);
5108 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5109 DestroyWindow(window);
5112 static void test_surface_discard(void)
5114 IDirect3DDevice3 *device;
5115 IDirect3D3 *d3d;
5116 IDirectDraw4 *ddraw;
5117 HRESULT hr;
5118 HWND window;
5119 DDSURFACEDESC2 ddsd;
5120 IDirectDrawSurface4 *surface, *target;
5121 void *addr;
5122 static const struct
5124 DWORD caps, caps2;
5125 BOOL discard;
5127 tests[] =
5129 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5130 {DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5131 {DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, 0, TRUE},
5132 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, FALSE},
5133 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE},
5134 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5135 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE},
5136 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE | DDSCAPS2_HINTDYNAMIC, FALSE},
5138 unsigned int i;
5140 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5141 0, 0, 640, 480, 0, 0, 0, 0);
5143 if (!(device = create_device(window, DDSCL_NORMAL)))
5145 skip("Failed to create a 3D device, skipping test.\n");
5146 DestroyWindow(window);
5147 return;
5149 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
5150 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
5151 hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
5152 ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
5153 hr = IDirect3DDevice3_GetRenderTarget(device, &target);
5154 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
5156 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5158 BOOL discarded;
5160 memset(&ddsd, 0, sizeof(ddsd));
5161 ddsd.dwSize = sizeof(ddsd);
5162 ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5163 ddsd.ddsCaps.dwCaps = tests[i].caps;
5164 ddsd.ddsCaps.dwCaps2 = tests[i].caps2;
5165 ddsd.dwWidth = 64;
5166 ddsd.dwHeight = 64;
5167 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5168 ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x, case %u.\n", hr, i);
5170 memset(&ddsd, 0, sizeof(ddsd));
5171 ddsd.dwSize = sizeof(ddsd);
5172 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, 0, NULL);
5173 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5174 addr = ddsd.lpSurface;
5175 hr = IDirectDrawSurface4_Unlock(surface, NULL);
5176 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5178 memset(&ddsd, 0, sizeof(ddsd));
5179 ddsd.dwSize = sizeof(ddsd);
5180 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5181 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5182 discarded = ddsd.lpSurface != addr;
5183 hr = IDirectDrawSurface4_Unlock(surface, NULL);
5184 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5186 hr = IDirectDrawSurface4_Blt(target, NULL, surface, NULL, DDBLT_WAIT, NULL);
5187 ok(SUCCEEDED(hr), "Failed to blit, hr %#x.\n", hr);
5189 memset(&ddsd, 0, sizeof(ddsd));
5190 ddsd.dwSize = sizeof(ddsd);
5191 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, DDLOCK_DISCARDCONTENTS, NULL);
5192 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5193 discarded |= ddsd.lpSurface != addr;
5194 hr = IDirectDrawSurface4_Unlock(surface, NULL);
5195 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5197 IDirectDrawSurface4_Release(surface);
5199 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5200 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5201 ok(!discarded || tests[i].discard, "Expected surface not to be discarded, case %u\n", i);
5204 IDirectDrawSurface4_Release(target);
5205 IDirectDraw4_Release(ddraw);
5206 IDirect3D3_Release(d3d);
5207 IDirect3DDevice3_Release(device);
5208 DestroyWindow(window);
5211 static void test_flip(void)
5213 const DWORD placement = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
5214 IDirectDrawSurface4 *primary, *backbuffer1, *backbuffer2, *backbuffer3, *surface;
5215 DDSCAPS2 caps = {DDSCAPS_FLIP, 0, 0, 0};
5216 DDSURFACEDESC2 surface_desc;
5217 BOOL sysmem_primary;
5218 IDirectDraw4 *ddraw;
5219 D3DCOLOR color;
5220 ULONG refcount;
5221 HWND window;
5222 DDBLTFX fx;
5223 HRESULT hr;
5225 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5226 0, 0, 640, 480, 0, 0, 0, 0);
5227 ddraw = create_ddraw();
5228 ok(!!ddraw, "Failed to create a ddraw object.\n");
5230 hr = set_display_mode(ddraw, 640, 480);
5231 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
5232 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5233 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5235 memset(&surface_desc, 0, sizeof(surface_desc));
5236 surface_desc.dwSize = sizeof(surface_desc);
5237 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5238 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5239 surface_desc.dwBackBufferCount = 3;
5240 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5241 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5243 memset(&surface_desc, 0, sizeof(surface_desc));
5244 surface_desc.dwSize = sizeof(surface_desc);
5245 hr = IDirectDrawSurface4_GetSurfaceDesc(primary, &surface_desc);
5246 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5247 ok((surface_desc.ddsCaps.dwCaps & ~placement)
5248 == (DDSCAPS_VISIBLE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER | DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5249 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5250 sysmem_primary = surface_desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
5252 hr = IDirectDrawSurface4_GetAttachedSurface(primary, &caps, &backbuffer1);
5253 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5254 memset(&surface_desc, 0, sizeof(surface_desc));
5255 surface_desc.dwSize = sizeof(surface_desc);
5256 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer1, &surface_desc);
5257 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5258 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5259 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_BACKBUFFER),
5260 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5262 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer1, &caps, &backbuffer2);
5263 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5264 memset(&surface_desc, 0, sizeof(surface_desc));
5265 surface_desc.dwSize = sizeof(surface_desc);
5266 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer2, &surface_desc);
5267 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5268 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5269 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5270 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5272 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer2, &caps, &backbuffer3);
5273 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5274 memset(&surface_desc, 0, sizeof(surface_desc));
5275 surface_desc.dwSize = sizeof(surface_desc);
5276 hr = IDirectDrawSurface4_GetSurfaceDesc(backbuffer3, &surface_desc);
5277 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5278 ok(!surface_desc.dwBackBufferCount, "Got unexpected back buffer count %u.\n", surface_desc.dwBackBufferCount);
5279 ok((surface_desc.ddsCaps.dwCaps & ~placement) == (DDSCAPS_FLIP | DDSCAPS_COMPLEX),
5280 "Got unexpected caps %#x.\n", surface_desc.ddsCaps.dwCaps);
5282 hr = IDirectDrawSurface4_GetAttachedSurface(backbuffer3, &caps, &surface);
5283 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5284 ok(surface == primary, "Got unexpected surface %p, expected %p.\n", surface, primary);
5285 IDirectDrawSurface4_Release(surface);
5287 memset(&surface_desc, 0, sizeof(surface_desc));
5288 surface_desc.dwSize = sizeof(surface_desc);
5289 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5290 surface_desc.ddsCaps.dwCaps = 0;
5291 surface_desc.dwWidth = 640;
5292 surface_desc.dwHeight = 480;
5293 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5294 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5295 hr = IDirectDrawSurface4_Flip(primary, surface, DDFLIP_WAIT);
5296 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5297 IDirectDrawSurface4_Release(surface);
5299 hr = IDirectDrawSurface4_Flip(primary, primary, DDFLIP_WAIT);
5300 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5301 hr = IDirectDrawSurface4_Flip(backbuffer1, NULL, DDFLIP_WAIT);
5302 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5303 hr = IDirectDrawSurface4_Flip(backbuffer2, NULL, DDFLIP_WAIT);
5304 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5305 hr = IDirectDrawSurface4_Flip(backbuffer3, NULL, DDFLIP_WAIT);
5306 ok(hr == DDERR_NOTFLIPPABLE, "Got unexpected hr %#x.\n", hr);
5308 memset(&fx, 0, sizeof(fx));
5309 fx.dwSize = sizeof(fx);
5310 U5(fx).dwFillColor = 0xffff0000;
5311 hr = IDirectDrawSurface4_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5312 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5313 U5(fx).dwFillColor = 0xff00ff00;
5314 hr = IDirectDrawSurface4_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5315 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5316 U5(fx).dwFillColor = 0xff0000ff;
5317 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5318 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5320 hr = IDirectDrawSurface4_Flip(primary, NULL, DDFLIP_WAIT);
5321 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5322 color = get_surface_color(backbuffer1, 320, 240);
5323 /* The testbot seems to just copy the contents of one surface to all the
5324 * others, instead of properly flipping. */
5325 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5326 "Got unexpected color 0x%08x.\n", color);
5327 color = get_surface_color(backbuffer2, 320, 240);
5328 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5329 U5(fx).dwFillColor = 0xffff0000;
5330 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5331 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5333 hr = IDirectDrawSurface4_Flip(primary, NULL, DDFLIP_WAIT);
5334 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5335 color = get_surface_color(backbuffer1, 320, 240);
5336 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5337 "Got unexpected color 0x%08x.\n", color);
5338 color = get_surface_color(backbuffer2, 320, 240);
5339 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5340 U5(fx).dwFillColor = 0xff00ff00;
5341 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5342 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5344 hr = IDirectDrawSurface4_Flip(primary, NULL, DDFLIP_WAIT);
5345 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5346 color = get_surface_color(backbuffer1, 320, 240);
5347 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5348 "Got unexpected color 0x%08x.\n", color);
5349 color = get_surface_color(backbuffer2, 320, 240);
5350 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5351 U5(fx).dwFillColor = 0xff0000ff;
5352 hr = IDirectDrawSurface4_Blt(backbuffer3, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5353 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5355 hr = IDirectDrawSurface4_Flip(primary, backbuffer1, DDFLIP_WAIT);
5356 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5357 color = get_surface_color(backbuffer2, 320, 240);
5358 ok(compare_color(color, 0x0000ff00, 1) || broken(sysmem_primary && compare_color(color, 0x000000ff, 1)),
5359 "Got unexpected color 0x%08x.\n", color);
5360 color = get_surface_color(backbuffer3, 320, 240);
5361 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
5362 U5(fx).dwFillColor = 0xffff0000;
5363 hr = IDirectDrawSurface4_Blt(backbuffer1, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5364 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5366 hr = IDirectDrawSurface4_Flip(primary, backbuffer2, DDFLIP_WAIT);
5367 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5368 color = get_surface_color(backbuffer1, 320, 240);
5369 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
5370 color = get_surface_color(backbuffer3, 320, 240);
5371 ok(compare_color(color, 0x000000ff, 1) || broken(sysmem_primary && compare_color(color, 0x00ff0000, 1)),
5372 "Got unexpected color 0x%08x.\n", color);
5373 U5(fx).dwFillColor = 0xff00ff00;
5374 hr = IDirectDrawSurface4_Blt(backbuffer2, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
5375 ok(SUCCEEDED(hr), "Failed to fill surface, hr %#x.\n", hr);
5377 hr = IDirectDrawSurface4_Flip(primary, backbuffer3, DDFLIP_WAIT);
5378 ok(SUCCEEDED(hr), "Failed to flip, hr %#x.\n", hr);
5379 color = get_surface_color(backbuffer1, 320, 240);
5380 ok(compare_color(color, 0x00ff0000, 1) || broken(sysmem_primary && compare_color(color, 0x0000ff00, 1)),
5381 "Got unexpected color 0x%08x.\n", color);
5382 color = get_surface_color(backbuffer2, 320, 240);
5383 ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
5385 IDirectDrawSurface4_Release(backbuffer3);
5386 IDirectDrawSurface4_Release(backbuffer2);
5387 IDirectDrawSurface4_Release(backbuffer1);
5388 IDirectDrawSurface4_Release(primary);
5389 refcount = IDirectDraw4_Release(ddraw);
5390 ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
5391 DestroyWindow(window);
5394 static void reset_ddsd(DDSURFACEDESC2 *ddsd)
5396 memset(ddsd, 0, sizeof(*ddsd));
5397 ddsd->dwSize = sizeof(*ddsd);
5400 static void test_set_surface_desc(void)
5402 IDirectDraw4 *ddraw;
5403 HWND window;
5404 HRESULT hr;
5405 DDSURFACEDESC2 ddsd;
5406 IDirectDrawSurface4 *surface;
5407 BYTE data[16*16*4];
5408 ULONG ref;
5409 unsigned int i;
5410 static const struct
5412 DWORD caps, caps2;
5413 BOOL supported;
5414 const char *name;
5416 invalid_caps_tests[] =
5418 {DDSCAPS_VIDEOMEMORY, 0, FALSE, "videomemory plain"},
5419 {DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY, 0, TRUE, "systemmemory texture"},
5420 {DDSCAPS_TEXTURE, DDSCAPS2_D3DTEXTUREMANAGE, FALSE, "managed texture"},
5421 {DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE, FALSE, "managed texture"},
5422 {DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY, 0, FALSE, "systemmemory primary"},
5425 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5426 0, 0, 640, 480, 0, 0, 0, 0);
5427 ddraw = create_ddraw();
5428 ok(!!ddraw, "Failed to create a ddraw object.\n");
5429 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5430 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5432 reset_ddsd(&ddsd);
5433 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5434 ddsd.dwWidth = 8;
5435 ddsd.dwHeight = 8;
5436 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5437 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5438 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5439 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5440 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5441 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5442 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5444 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5445 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5447 reset_ddsd(&ddsd);
5448 ddsd.dwFlags = DDSD_LPSURFACE;
5449 ddsd.lpSurface = data;
5450 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5451 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5453 /* Redundantly setting the same lpSurface is not an error. */
5454 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5455 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5456 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5457 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5458 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5459 ok(ddsd.lpSurface == NULL, "lpSurface is %p, expected NULL.\n", ddsd.lpSurface);
5461 hr = IDirectDrawSurface4_Lock(surface, NULL, &ddsd, 0, NULL);
5462 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5463 ok(!(ddsd.dwFlags & DDSD_LPSURFACE), "DDSD_LPSURFACE is set.\n");
5464 ok(ddsd.lpSurface == data, "lpSurface is %p, expected %p.\n", data, data);
5465 hr = IDirectDrawSurface4_Unlock(surface, NULL);
5466 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5468 reset_ddsd(&ddsd);
5469 ddsd.dwFlags = DDSD_LPSURFACE;
5470 ddsd.lpSurface = data;
5471 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 1);
5472 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with flags=1 returned %#x.\n", hr);
5474 ddsd.lpSurface = NULL;
5475 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5476 ok(hr == DDERR_INVALIDPARAMS, "Setting lpSurface=NULL returned %#x.\n", hr);
5478 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, NULL, 0);
5479 ok(hr == DDERR_INVALIDPARAMS, "SetSurfaceDesc with NULL desc returned %#x.\n", hr);
5481 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5482 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5483 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5484 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5485 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5487 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5488 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5489 ok(hr == DDERR_INVALIDPARAMS, "Setting the original desc returned %#x.\n", hr);
5491 ddsd.dwFlags = DDSD_CAPS;
5492 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5493 ok(hr == DDERR_INVALIDPARAMS, "Setting DDSD_CAPS returned %#x.\n", hr);
5495 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
5496 ddsd.dwFlags = DDSD_CAPS | DDSD_LPSURFACE;
5497 ddsd.lpSurface = data;
5498 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5499 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5500 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5501 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5502 ok(hr == DDERR_INVALIDCAPS, "Setting DDSD_CAPS returned %#x.\n", hr);
5503 ddsd.ddsCaps.dwCaps = 0;
5504 ddsd.ddsCaps.dwCaps2 = 0xdeadbeef;
5505 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5506 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5508 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5509 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5510 ok(ddsd.ddsCaps.dwCaps == (DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN),
5511 "Got unexpected caps %#x.\n", ddsd.ddsCaps.dwCaps);
5512 ok(ddsd.ddsCaps.dwCaps2 == 0, "Got unexpected caps2 %#x.\n", 0);
5514 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5515 reset_ddsd(&ddsd);
5516 ddsd.dwFlags = DDSD_HEIGHT;
5517 ddsd.dwHeight = 16;
5518 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5519 ok(hr == DDERR_INVALIDPARAMS, "Setting height without lpSurface returned %#x.\n", hr);
5521 ddsd.lpSurface = data;
5522 ddsd.dwFlags = DDSD_HEIGHT | DDSD_LPSURFACE;
5523 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5524 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5526 ddsd.dwHeight = 0;
5527 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5528 ok(hr == DDERR_INVALIDPARAMS, "Setting height=0 returned %#x.\n", hr);
5530 reset_ddsd(&ddsd);
5531 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5532 ok(SUCCEEDED(hr), "GetSurfaceDesc failed, hr %#x.\n", hr);
5533 ok(ddsd.dwWidth == 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5534 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5536 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0 */
5537 reset_ddsd(&ddsd);
5538 ddsd.dwFlags = DDSD_PITCH;
5539 U1(ddsd).lPitch = 8 * 4;
5540 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5541 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch without lpSurface or width returned %#x.\n", hr);
5543 ddsd.dwFlags = DDSD_WIDTH;
5544 ddsd.dwWidth = 16;
5545 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5546 ok(hr == DDERR_INVALIDPARAMS, "Setting width without lpSurface or pitch returned %#x.\n", hr);
5548 ddsd.dwFlags = DDSD_PITCH | DDSD_LPSURFACE;
5549 ddsd.lpSurface = data;
5550 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5551 ok(hr == DDERR_INVALIDPARAMS, "Setting pitch and lpSurface without width returned %#x.\n", hr);
5553 ddsd.dwFlags = DDSD_WIDTH | DDSD_LPSURFACE;
5554 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5555 ok(hr == DDERR_INVALIDPARAMS, "Setting width and lpSurface without pitch returned %#x.\n", hr);
5557 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5558 U1(ddsd).lPitch = 16 * 4;
5559 ddsd.dwWidth = 16;
5560 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5561 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5563 reset_ddsd(&ddsd);
5564 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
5565 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5566 ok(ddsd.dwWidth == 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd.dwWidth);
5567 ok(ddsd.dwHeight == 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd.dwHeight);
5568 ok(U1(ddsd).lPitch == 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd).lPitch);
5570 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5572 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5573 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5574 U1(ddsd).lPitch = 4 * 4;
5575 ddsd.lpSurface = data;
5576 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5577 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5579 U1(ddsd).lPitch = 4;
5580 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5581 ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPARAMS), "Failed to set surface desc, hr %#x.\n", hr);
5583 U1(ddsd).lPitch = 16 * 4 + 1;
5584 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5585 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5587 U1(ddsd).lPitch = 16 * 4 + 3;
5588 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5589 ok(hr == DDERR_INVALIDPARAMS, "Setting misaligned pitch returned %#x.\n", hr);
5591 U1(ddsd).lPitch = -4;
5592 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5593 ok(hr == DDERR_INVALIDPARAMS, "Setting negative pitch returned %#x.\n", hr);
5595 U1(ddsd).lPitch = 16 * 4;
5596 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5597 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5599 reset_ddsd(&ddsd);
5600 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5601 U1(ddsd).lPitch = 0;
5602 ddsd.dwWidth = 16;
5603 ddsd.lpSurface = data;
5604 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5605 ok(hr == DDERR_INVALIDPARAMS, "Setting zero pitch returned %#x.\n", hr);
5607 ddsd.dwFlags = DDSD_WIDTH | DDSD_PITCH | DDSD_LPSURFACE;
5608 U1(ddsd).lPitch = 16 * 4;
5609 ddsd.dwWidth = 0;
5610 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5611 ok(hr == DDERR_INVALIDPARAMS, "Setting zero width returned %#x.\n", hr);
5613 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5614 ddsd.dwFlags = DDSD_PIXELFORMAT;
5615 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5616 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5617 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5618 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5619 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5620 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5621 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5622 ok(hr == DDERR_INVALIDPARAMS, "Setting the pixel format returned %#x.\n", hr);
5624 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_LPSURFACE;
5625 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5626 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5628 /* Can't set color keys. */
5629 reset_ddsd(&ddsd);
5630 ddsd.dwFlags = DDSD_CKSRCBLT;
5631 ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = 0x00ff0000;
5632 ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = 0x00ff0000;
5633 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5634 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5636 ddsd.dwFlags = DDSD_CKSRCBLT | DDSD_LPSURFACE;
5637 ddsd.lpSurface = data;
5638 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5639 ok(hr == DDERR_INVALIDPARAMS, "Setting ddckCKSrcBlt returned %#x.\n", hr);
5641 IDirectDrawSurface4_Release(surface);
5643 /* SetSurfaceDesc needs systemmemory surfaces.
5645 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5646 for (i = 0; i < sizeof(invalid_caps_tests) / sizeof(*invalid_caps_tests); i++)
5648 reset_ddsd(&ddsd);
5649 ddsd.dwFlags = DDSD_CAPS;
5650 ddsd.ddsCaps.dwCaps = invalid_caps_tests[i].caps;
5651 ddsd.ddsCaps.dwCaps2 = invalid_caps_tests[i].caps2;
5652 if (!(invalid_caps_tests[i].caps & DDSCAPS_PRIMARYSURFACE))
5654 ddsd.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
5655 ddsd.dwWidth = 8;
5656 ddsd.dwHeight = 8;
5657 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5658 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5659 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5660 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5661 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5662 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5665 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5666 ok(SUCCEEDED(hr) || hr == DDERR_NODIRECTDRAWHW, "Failed to create surface, hr %#x.\n", hr);
5667 if (FAILED(hr))
5669 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5670 invalid_caps_tests[i].name);
5671 goto done;
5674 reset_ddsd(&ddsd);
5675 ddsd.dwFlags = DDSD_LPSURFACE;
5676 ddsd.lpSurface = data;
5677 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5678 if (invalid_caps_tests[i].supported)
5680 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5682 else
5684 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5685 invalid_caps_tests[i].name, hr);
5687 /* Check priority of error conditions. */
5688 ddsd.dwFlags = DDSD_WIDTH;
5689 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5690 ok(hr == DDERR_INVALIDSURFACETYPE, "SetSurfaceDesc on a %s surface returned %#x.\n",
5691 invalid_caps_tests[i].name, hr);
5694 IDirectDrawSurface4_Release(surface);
5697 done:
5698 ref = IDirectDraw4_Release(ddraw);
5699 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5700 DestroyWindow(window);
5703 static void test_user_memory_getdc(void)
5705 IDirectDraw4 *ddraw;
5706 HWND window;
5707 HRESULT hr;
5708 DDSURFACEDESC2 ddsd;
5709 IDirectDrawSurface4 *surface;
5710 DWORD data[16][16];
5711 ULONG ref;
5712 HDC dc;
5713 unsigned int x, y;
5715 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5716 0, 0, 640, 480, 0, 0, 0, 0);
5717 ddraw = create_ddraw();
5718 ok(!!ddraw, "Failed to create a ddraw object.\n");
5720 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5721 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5723 reset_ddsd(&ddsd);
5724 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT;
5725 ddsd.dwWidth = 16;
5726 ddsd.dwHeight = 16;
5727 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5728 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5729 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5730 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5731 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5732 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5733 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
5734 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5735 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5737 memset(data, 0xaa, sizeof(data));
5738 reset_ddsd(&ddsd);
5739 ddsd.dwFlags = DDSD_LPSURFACE;
5740 ddsd.lpSurface = data;
5741 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5742 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5744 hr = IDirectDrawSurface4_GetDC(surface, &dc);
5745 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5746 BitBlt(dc, 0, 0, 16, 8, NULL, 0, 0, WHITENESS);
5747 BitBlt(dc, 0, 8, 16, 8, NULL, 0, 0, BLACKNESS);
5748 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
5749 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5751 ok(data[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data[0][0]);
5752 ok(data[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data[15][15]);
5754 ddsd.dwFlags = DDSD_LPSURFACE | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH;
5755 ddsd.lpSurface = data;
5756 ddsd.dwWidth = 4;
5757 ddsd.dwHeight = 8;
5758 U1(ddsd).lPitch = sizeof(*data);
5759 hr = IDirectDrawSurface4_SetSurfaceDesc(surface, &ddsd, 0);
5760 ok(SUCCEEDED(hr), "Failed to set surface desc, hr %#x.\n", hr);
5762 memset(data, 0xaa, sizeof(data));
5763 hr = IDirectDrawSurface4_GetDC(surface, &dc);
5764 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
5765 BitBlt(dc, 0, 0, 4, 8, NULL, 0, 0, BLACKNESS);
5766 BitBlt(dc, 1, 1, 2, 2, NULL, 0, 0, WHITENESS);
5767 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
5768 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
5770 for (y = 0; y < 4; y++)
5772 for (x = 0; x < 4; x++)
5774 if ((x == 1 || x == 2) && (y == 1 || y == 2))
5775 ok(data[y][x] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5776 x, y, data[y][x]);
5777 else
5778 ok(data[y][x] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
5779 x, y, data[y][x]);
5782 ok(data[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5783 data[0][5]);
5784 ok(data[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5785 data[7][3]);
5786 ok(data[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5787 data[7][4]);
5788 ok(data[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5789 data[8][0]);
5791 IDirectDrawSurface4_Release(surface);
5792 ref = IDirectDraw4_Release(ddraw);
5793 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5794 DestroyWindow(window);
5797 static void test_sysmem_overlay(void)
5799 IDirectDraw4 *ddraw;
5800 HWND window;
5801 HRESULT hr;
5802 DDSURFACEDESC2 ddsd;
5803 IDirectDrawSurface4 *surface;
5804 ULONG ref;
5806 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5807 0, 0, 640, 480, 0, 0, 0, 0);
5808 ddraw = create_ddraw();
5809 ok(!!ddraw, "Failed to create a ddraw object.\n");
5811 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5812 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5814 reset_ddsd(&ddsd);
5815 ddsd.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
5816 ddsd.dwWidth = 16;
5817 ddsd.dwHeight = 16;
5818 ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OVERLAY;
5819 U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
5820 U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
5821 U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 32;
5822 U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
5823 U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
5824 U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x000000ff;
5825 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
5826 ok(hr == DDERR_NOOVERLAYHW, "Got unexpected hr %#x.\n", hr);
5828 ref = IDirectDraw4_Release(ddraw);
5829 ok(ref == 0, "Ddraw object not properly released, refcount %u.\n", ref);
5830 DestroyWindow(window);
5833 static void test_primary_palette(void)
5835 DDSCAPS2 surface_caps = {DDSCAPS_FLIP, 0, 0, 0};
5836 IDirectDrawSurface4 *primary, *backbuffer;
5837 PALETTEENTRY palette_entries[256];
5838 IDirectDrawPalette *palette, *tmp;
5839 DDSURFACEDESC2 surface_desc;
5840 IDirectDraw4 *ddraw;
5841 DWORD palette_caps;
5842 ULONG refcount;
5843 HWND window;
5844 HRESULT hr;
5846 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5847 0, 0, 640, 480, 0, 0, 0, 0);
5848 ddraw = create_ddraw();
5849 ok(!!ddraw, "Failed to create a ddraw object.\n");
5850 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
5852 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5853 IDirectDraw4_Release(ddraw);
5854 DestroyWindow(window);
5855 return;
5857 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
5858 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5860 memset(&surface_desc, 0, sizeof(surface_desc));
5861 surface_desc.dwSize = sizeof(surface_desc);
5862 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
5863 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
5864 surface_desc.dwBackBufferCount = 1;
5865 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
5866 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5867 hr = IDirectDrawSurface4_GetAttachedSurface(primary, &surface_caps, &backbuffer);
5868 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
5870 memset(palette_entries, 0, sizeof(palette_entries));
5871 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256, palette_entries, &palette, NULL);
5872 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
5873 refcount = get_refcount((IUnknown *)palette);
5874 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5876 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5877 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5878 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
5880 hr = IDirectDrawSurface4_SetPalette(primary, palette);
5881 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5883 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5884 * and is generally somewhat broken with respect to 8 bpp / palette
5885 * handling. */
5886 if (SUCCEEDED(IDirectDrawSurface4_GetPalette(backbuffer, &tmp)))
5888 win_skip("Broken palette handling detected, skipping tests.\n");
5889 IDirectDrawPalette_Release(tmp);
5890 IDirectDrawPalette_Release(palette);
5891 /* The Windows 8 testbot keeps extra references to the primary and
5892 * backbuffer while in 8 bpp mode. */
5893 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
5894 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
5895 goto done;
5898 refcount = get_refcount((IUnknown *)palette);
5899 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5901 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5902 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5903 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE | DDPCAPS_ALLOW256),
5904 "Got unexpected palette caps %#x.\n", palette_caps);
5906 hr = IDirectDrawSurface4_SetPalette(primary, NULL);
5907 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5908 refcount = get_refcount((IUnknown *)palette);
5909 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5911 hr = IDirectDrawPalette_GetCaps(palette, &palette_caps);
5912 ok(SUCCEEDED(hr), "Failed to get palette caps, hr %#x.\n", hr);
5913 ok(palette_caps == (DDPCAPS_8BIT | DDPCAPS_ALLOW256), "Got unexpected palette caps %#x.\n", palette_caps);
5915 hr = IDirectDrawSurface4_SetPalette(primary, palette);
5916 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
5917 refcount = get_refcount((IUnknown *)palette);
5918 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5920 hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
5921 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
5922 ok(tmp == palette, "Got unexpected palette %p, expected %p.\n", tmp, palette);
5923 IDirectDrawPalette_Release(tmp);
5924 hr = IDirectDrawSurface4_GetPalette(backbuffer, &tmp);
5925 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
5927 refcount = IDirectDrawPalette_Release(palette);
5928 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5929 refcount = IDirectDrawPalette_Release(palette);
5930 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5932 /* Note that this only seems to work when the palette is attached to the
5933 * primary surface. When attached to a regular surface, attempting to get
5934 * the palette here will cause an access violation. */
5935 hr = IDirectDrawSurface4_GetPalette(primary, &tmp);
5936 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
5938 done:
5939 refcount = IDirectDrawSurface4_Release(backbuffer);
5940 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5941 refcount = IDirectDrawSurface4_Release(primary);
5942 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5943 refcount = IDirectDraw4_Release(ddraw);
5944 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5945 DestroyWindow(window);
5948 static HRESULT WINAPI surface_counter(IDirectDrawSurface4 *surface, DDSURFACEDESC2 *desc, void *context)
5950 UINT *surface_count = context;
5952 ++(*surface_count);
5953 IDirectDrawSurface_Release(surface);
5955 return DDENUMRET_OK;
5958 static void test_surface_attachment(void)
5960 IDirectDrawSurface4 *surface1, *surface2, *surface3, *surface4;
5961 IDirectDrawSurface *surface1v1, *surface2v1;
5962 DDSCAPS2 caps = {DDSCAPS_TEXTURE, 0, 0, 0};
5963 DDSURFACEDESC2 surface_desc;
5964 IDirectDraw4 *ddraw;
5965 UINT surface_count;
5966 ULONG refcount;
5967 HWND window;
5968 HRESULT hr;
5970 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
5971 0, 0, 640, 480, 0, 0, 0, 0);
5972 ddraw = create_ddraw();
5973 ok(!!ddraw, "Failed to create a ddraw object.\n");
5974 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5975 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5977 memset(&surface_desc, 0, sizeof(surface_desc));
5978 surface_desc.dwSize = sizeof(surface_desc);
5979 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
5980 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
5981 U2(surface_desc).dwMipMapCount = 3;
5982 surface_desc.dwWidth = 128;
5983 surface_desc.dwHeight = 128;
5984 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
5985 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5987 hr = IDirectDrawSurface4_GetAttachedSurface(surface1, &caps, &surface2);
5988 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
5989 hr = IDirectDrawSurface4_GetAttachedSurface(surface2, &caps, &surface3);
5990 ok(SUCCEEDED(hr), "Failed to get mip level, hr %#x.\n", hr);
5991 hr = IDirectDrawSurface4_GetAttachedSurface(surface3, &caps, &surface4);
5992 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5994 surface_count = 0;
5995 IDirectDrawSurface4_EnumAttachedSurfaces(surface1, &surface_count, surface_counter);
5996 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
5997 surface_count = 0;
5998 IDirectDrawSurface4_EnumAttachedSurfaces(surface2, &surface_count, surface_counter);
5999 ok(surface_count == 1, "Got unexpected surface_count %u.\n", surface_count);
6000 surface_count = 0;
6001 IDirectDrawSurface4_EnumAttachedSurfaces(surface3, &surface_count, surface_counter);
6002 ok(!surface_count, "Got unexpected surface_count %u.\n", surface_count);
6004 memset(&surface_desc, 0, sizeof(surface_desc));
6005 surface_desc.dwSize = sizeof(surface_desc);
6006 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6007 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6008 surface_desc.dwWidth = 16;
6009 surface_desc.dwHeight = 16;
6010 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6011 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6013 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4);
6014 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6015 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
6016 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6017 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface4);
6018 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6019 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface3);
6020 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6021 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface4);
6022 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6023 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface2);
6024 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6026 IDirectDrawSurface4_Release(surface4);
6028 memset(&surface_desc, 0, sizeof(surface_desc));
6029 surface_desc.dwSize = sizeof(surface_desc);
6030 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6031 surface_desc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
6032 surface_desc.dwWidth = 16;
6033 surface_desc.dwHeight = 16;
6034 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6035 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6037 if (SUCCEEDED(hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4)))
6039 skip("Running on refrast, skipping some tests.\n");
6040 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface4);
6041 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6043 else
6045 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6046 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
6047 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6048 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface4);
6049 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6050 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface3);
6051 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6052 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface4);
6053 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6054 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface2);
6055 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6058 IDirectDrawSurface4_Release(surface4);
6059 IDirectDrawSurface4_Release(surface3);
6060 IDirectDrawSurface4_Release(surface2);
6061 IDirectDrawSurface4_Release(surface1);
6063 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
6064 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6066 /* Try a single primary and two offscreen plain surfaces. */
6067 memset(&surface_desc, 0, sizeof(surface_desc));
6068 surface_desc.dwSize = sizeof(surface_desc);
6069 surface_desc.dwFlags = DDSD_CAPS;
6070 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6071 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6072 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6074 memset(&surface_desc, 0, sizeof(surface_desc));
6075 surface_desc.dwSize = sizeof(surface_desc);
6076 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6077 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6078 surface_desc.dwWidth = GetSystemMetrics(SM_CXSCREEN);
6079 surface_desc.dwHeight = GetSystemMetrics(SM_CYSCREEN);
6080 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6081 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6083 memset(&surface_desc, 0, sizeof(surface_desc));
6084 surface_desc.dwSize = sizeof(surface_desc);
6085 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6086 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6087 surface_desc.dwWidth = GetSystemMetrics(SM_CXSCREEN);
6088 surface_desc.dwHeight = GetSystemMetrics(SM_CYSCREEN);
6089 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6090 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6092 /* This one has a different size. */
6093 memset(&surface_desc, 0, sizeof(surface_desc));
6094 surface_desc.dwSize = sizeof(surface_desc);
6095 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6096 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6097 surface_desc.dwWidth = 128;
6098 surface_desc.dwHeight = 128;
6099 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface4, NULL);
6100 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6102 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
6103 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6104 /* Try the reverse without detaching first. */
6105 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface1);
6106 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
6107 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
6108 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6110 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface1);
6111 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6112 /* Try to detach reversed. */
6113 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
6114 ok(hr == DDERR_CANNOTDETACHSURFACE, "Got unexpected hr %#x.\n", hr);
6115 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface2, 0, surface1);
6116 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6118 hr = IDirectDrawSurface4_AddAttachedSurface(surface2, surface3);
6119 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6120 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface2, 0, surface3);
6121 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6123 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface4);
6124 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6125 hr = IDirectDrawSurface4_AddAttachedSurface(surface4, surface1);
6126 ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6128 IDirectDrawSurface4_Release(surface4);
6129 IDirectDrawSurface4_Release(surface3);
6130 IDirectDrawSurface4_Release(surface2);
6131 IDirectDrawSurface4_Release(surface1);
6133 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6134 memset(&surface_desc, 0, sizeof(surface_desc));
6135 surface_desc.dwSize = sizeof(surface_desc);
6136 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6137 surface_desc.dwWidth = 64;
6138 surface_desc.dwHeight = 64;
6139 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
6140 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6141 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB; /* D3DFMT_R5G6B5 */
6142 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 16;
6143 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0xf800;
6144 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x07e0;
6145 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x001f;
6146 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface1, NULL);
6147 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6148 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface3, NULL);
6149 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6151 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
6152 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
6153 U1(U4(surface_desc).ddpfPixelFormat).dwZBufferBitDepth = 16;
6154 U3(U4(surface_desc).ddpfPixelFormat).dwZBitMask = 0x0000ffff;
6155 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface2, NULL);
6156 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6158 hr = IDirectDrawSurface4_QueryInterface(surface1, &IID_IDirectDrawSurface, (void **)&surface1v1);
6159 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6160 hr = IDirectDrawSurface4_QueryInterface(surface2, &IID_IDirectDrawSurface, (void **)&surface2v1);
6161 ok(SUCCEEDED(hr), "Failed to get interface, hr %#x.\n", hr);
6163 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
6164 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6165 refcount = get_refcount((IUnknown *)surface2);
6166 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6167 refcount = get_refcount((IUnknown *)surface2v1);
6168 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6169 hr = IDirectDrawSurface4_AddAttachedSurface(surface1, surface2);
6170 ok(hr == DDERR_SURFACEALREADYATTACHED, "Got unexpected hr %#x.\n", hr);
6171 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6172 todo_wine ok(hr == DDERR_CANNOTATTACHSURFACE, "Got unexpected hr %#x.\n", hr);
6173 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6174 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6176 /* Attaching while already attached to other surface. */
6177 hr = IDirectDrawSurface4_AddAttachedSurface(surface3, surface2);
6178 todo_wine ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6179 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface3, 0, surface2);
6180 todo_wine ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6181 IDirectDrawSurface4_Release(surface3);
6183 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
6184 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6185 refcount = get_refcount((IUnknown *)surface2);
6186 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6187 refcount = get_refcount((IUnknown *)surface2v1);
6188 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6190 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6191 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6192 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6193 hr = IDirectDrawSurface4_DeleteAttachedSurface(surface1, 0, surface2);
6194 ok(hr == DDERR_SURFACENOTATTACHED, "Got unexpected hr %#x.\n", hr);
6195 hr = IDirectDrawSurface_DeleteAttachedSurface(surface1v1, 0, surface2v1);
6196 ok(SUCCEEDED(hr), "Failed to detach surface, hr %#x.\n", hr);
6197 refcount = IDirectDrawSurface4_Release(surface2);
6198 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6199 refcount = IDirectDrawSurface4_Release(surface1);
6200 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6202 /* Automatic detachment on release. */
6203 hr = IDirectDrawSurface_AddAttachedSurface(surface1v1, surface2v1);
6204 ok(SUCCEEDED(hr), "Failed to attach surface, hr %#x.\n", hr);
6205 refcount = get_refcount((IUnknown *)surface2v1);
6206 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
6207 refcount = IDirectDrawSurface_Release(surface1v1);
6208 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6209 refcount = IDirectDrawSurface_Release(surface2v1);
6210 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6211 refcount = IDirectDraw4_Release(ddraw);
6212 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6213 DestroyWindow(window);
6216 static void test_private_data(void)
6218 IDirectDraw4 *ddraw;
6219 IDirectDrawSurface4 *surface, *surface2;
6220 DDSURFACEDESC2 surface_desc;
6221 ULONG refcount, refcount2, refcount3;
6222 IUnknown *ptr;
6223 DWORD size = sizeof(ptr);
6224 HRESULT hr;
6225 HWND window;
6226 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6227 DWORD data[] = {1, 2, 3, 4};
6228 DDCAPS hal_caps;
6229 static const GUID ddraw_private_data_test_guid =
6231 0xfdb37466,
6232 0x428f,
6233 0x4edf,
6234 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6236 static const GUID ddraw_private_data_test_guid2 =
6238 0x2e5afac2,
6239 0x87b5,
6240 0x4c10,
6241 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6244 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6245 0, 0, 640, 480, 0, 0, 0, 0);
6246 ddraw = create_ddraw();
6247 ok(!!ddraw, "Failed to create a ddraw object.\n");
6248 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6249 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6251 reset_ddsd(&surface_desc);
6252 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
6253 surface_desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
6254 surface_desc.dwHeight = 4;
6255 surface_desc.dwWidth = 4;
6256 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6257 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6259 /* NULL pointers are not valid, but don't cause a crash. */
6260 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL,
6261 sizeof(IUnknown *), DDSPD_IUNKNOWNPOINTER);
6262 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6263 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 0, 0);
6264 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6265 hr = IDirectDrawSurface7_SetPrivateData(surface, &ddraw_private_data_test_guid, NULL, 1, 0);
6266 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6268 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6269 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6270 0, DDSPD_IUNKNOWNPOINTER);
6271 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6272 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6273 5, DDSPD_IUNKNOWNPOINTER);
6274 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6275 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6276 sizeof(ddraw) * 2, DDSPD_IUNKNOWNPOINTER);
6277 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6279 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6280 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6281 * erases the old content and returns an error. This behavior has
6282 * been fixed in d3d8 and d3d9. Unless an application is found
6283 * that depends on this we don't care about this behavior. */
6284 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6285 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6286 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6287 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6288 0, DDSPD_IUNKNOWNPOINTER);
6289 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6290 size = sizeof(ptr);
6291 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6292 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6293 hr = IDirectDrawSurface4_FreePrivateData(surface, &ddraw_private_data_test_guid);
6294 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6296 refcount = get_refcount((IUnknown *)ddraw);
6297 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6298 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6299 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6300 refcount2 = get_refcount((IUnknown *)ddraw);
6301 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6303 hr = IDirectDrawSurface4_FreePrivateData(surface, &ddraw_private_data_test_guid);
6304 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6305 refcount2 = get_refcount((IUnknown *)ddraw);
6306 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6308 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6309 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6310 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6311 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, surface,
6312 sizeof(surface), DDSPD_IUNKNOWNPOINTER);
6313 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6314 refcount2 = get_refcount((IUnknown *)ddraw);
6315 ok(refcount2 == refcount, "Got unexpected refcount %u.\n", refcount2);
6317 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, ddraw,
6318 sizeof(ddraw), DDSPD_IUNKNOWNPOINTER);
6319 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6320 size = 2 * sizeof(ptr);
6321 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6322 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6323 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6324 refcount2 = get_refcount(ptr);
6325 /* Object is NOT addref'ed by the getter. */
6326 ok(ptr == (IUnknown *)ddraw, "Returned interface pointer is %p, expected %p.\n", ptr, ddraw);
6327 ok(refcount2 == refcount + 1, "Got unexpected refcount %u.\n", refcount2);
6329 ptr = (IUnknown *)0xdeadbeef;
6330 size = 1;
6331 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6332 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6333 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6334 size = 2 * sizeof(ptr);
6335 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, &size);
6336 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6337 ok(size == 2 * sizeof(ptr), "Got unexpected size %u.\n", size);
6338 size = 1;
6339 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, &ptr, &size);
6340 ok(hr == DDERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6341 ok(size == sizeof(ddraw), "Got unexpected size %u.\n", size);
6342 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6343 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid2, NULL, NULL);
6344 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6345 size = 0xdeadbabe;
6346 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid2, &ptr, &size);
6347 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6348 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6349 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
6350 hr = IDirectDrawSurface4_GetPrivateData(surface, &ddraw_private_data_test_guid, NULL, NULL);
6351 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
6353 refcount3 = IDirectDrawSurface4_Release(surface);
6354 ok(!refcount3, "Got unexpected refcount %u.\n", refcount3);
6356 /* Destroying the surface frees the reference held on the private data. It also frees
6357 * the reference the surface is holding on its creating object. */
6358 refcount2 = get_refcount((IUnknown *)ddraw);
6359 ok(refcount2 == refcount - 1, "Got unexpected refcount %u.\n", refcount2);
6361 memset(&hal_caps, 0, sizeof(hal_caps));
6362 hal_caps.dwSize = sizeof(hal_caps);
6363 hr = IDirectDraw7_GetCaps(ddraw, &hal_caps, NULL);
6364 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6365 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) == (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6367 reset_ddsd(&surface_desc);
6368 surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_MIPMAPCOUNT;
6369 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6370 surface_desc.dwHeight = 4;
6371 surface_desc.dwWidth = 4;
6372 U2(surface_desc).dwMipMapCount = 2;
6373 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6374 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6375 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &surface2);
6376 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6378 hr = IDirectDrawSurface4_SetPrivateData(surface, &ddraw_private_data_test_guid, data, sizeof(data), 0);
6379 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6380 hr = IDirectDrawSurface4_GetPrivateData(surface2, &ddraw_private_data_test_guid, NULL, NULL);
6381 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6383 IDirectDrawSurface4_Release(surface2);
6384 IDirectDrawSurface4_Release(surface);
6386 else
6387 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
6389 refcount = IDirectDraw4_Release(ddraw);
6390 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6391 DestroyWindow(window);
6394 static void test_pixel_format(void)
6396 HWND window, window2 = NULL;
6397 HDC hdc, hdc2 = NULL;
6398 HMODULE gl = NULL;
6399 int format, test_format;
6400 PIXELFORMATDESCRIPTOR pfd;
6401 IDirectDraw4 *ddraw = NULL;
6402 IDirectDrawClipper *clipper = NULL;
6403 DDSURFACEDESC2 ddsd;
6404 IDirectDrawSurface4 *primary = NULL;
6405 DDBLTFX fx;
6406 HRESULT hr;
6408 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6409 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6410 if (!window)
6412 skip("Failed to create window\n");
6413 return;
6416 window2 = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6417 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6419 hdc = GetDC(window);
6420 if (!hdc)
6422 skip("Failed to get DC\n");
6423 goto cleanup;
6426 if (window2)
6427 hdc2 = GetDC(window2);
6429 gl = LoadLibraryA("opengl32.dll");
6430 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6432 format = GetPixelFormat(hdc);
6433 ok(format == 0, "new window has pixel format %d\n", format);
6435 ZeroMemory(&pfd, sizeof(pfd));
6436 pfd.nSize = sizeof(pfd);
6437 pfd.nVersion = 1;
6438 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
6439 pfd.iPixelType = PFD_TYPE_RGBA;
6440 pfd.iLayerType = PFD_MAIN_PLANE;
6441 format = ChoosePixelFormat(hdc, &pfd);
6442 if (format <= 0)
6444 skip("no pixel format available\n");
6445 goto cleanup;
6448 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
6450 skip("failed to set pixel format\n");
6451 goto cleanup;
6454 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
6456 skip("failed to set pixel format on second window\n");
6457 if (hdc2)
6459 ReleaseDC(window2, hdc2);
6460 hdc2 = NULL;
6464 ddraw = create_ddraw();
6465 ok(!!ddraw, "Failed to create a ddraw object.\n");
6467 test_format = GetPixelFormat(hdc);
6468 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6470 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6471 if (FAILED(hr))
6473 skip("Failed to set cooperative level, hr %#x.\n", hr);
6474 goto cleanup;
6477 test_format = GetPixelFormat(hdc);
6478 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6480 if (hdc2)
6482 hr = IDirectDraw4_CreateClipper(ddraw, 0, &clipper, NULL);
6483 ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
6484 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window2);
6485 ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
6487 test_format = GetPixelFormat(hdc);
6488 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6490 test_format = GetPixelFormat(hdc2);
6491 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6494 memset(&ddsd, 0, sizeof(ddsd));
6495 ddsd.dwSize = sizeof(ddsd);
6496 ddsd.dwFlags = DDSD_CAPS;
6497 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
6499 hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &primary, NULL);
6500 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n",hr);
6502 test_format = GetPixelFormat(hdc);
6503 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6505 if (hdc2)
6507 test_format = GetPixelFormat(hdc2);
6508 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6511 if (clipper)
6513 hr = IDirectDrawSurface4_SetClipper(primary, clipper);
6514 ok(SUCCEEDED(hr), "Failed to set clipper, hr %#x.\n", hr);
6516 test_format = GetPixelFormat(hdc);
6517 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6519 test_format = GetPixelFormat(hdc2);
6520 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6523 memset(&fx, 0, sizeof(fx));
6524 fx.dwSize = sizeof(fx);
6525 hr = IDirectDrawSurface4_Blt(primary, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
6526 ok(SUCCEEDED(hr), "Failed to clear source surface, hr %#x.\n", hr);
6528 test_format = GetPixelFormat(hdc);
6529 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6531 if (hdc2)
6533 test_format = GetPixelFormat(hdc2);
6534 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6537 cleanup:
6538 if (primary) IDirectDrawSurface4_Release(primary);
6539 if (clipper) IDirectDrawClipper_Release(clipper);
6540 if (ddraw) IDirectDraw4_Release(ddraw);
6541 if (gl) FreeLibrary(gl);
6542 if (hdc) ReleaseDC(window, hdc);
6543 if (hdc2) ReleaseDC(window2, hdc2);
6544 if (window) DestroyWindow(window);
6545 if (window2) DestroyWindow(window2);
6548 static void test_create_surface_pitch(void)
6550 IDirectDrawSurface4 *surface;
6551 DDSURFACEDESC2 surface_desc;
6552 IDirectDraw4 *ddraw;
6553 unsigned int i;
6554 ULONG refcount;
6555 HWND window;
6556 HRESULT hr;
6557 void *mem;
6559 static const struct
6561 DWORD placement;
6562 DWORD flags_in;
6563 DWORD pitch_in;
6564 HRESULT hr;
6565 DWORD flags_out;
6566 DWORD pitch_out32;
6567 DWORD pitch_out64;
6569 test_data[] =
6571 {DDSCAPS_VIDEOMEMORY, 0, 0, DD_OK,
6572 DDSD_PITCH, 0x100, 0x100},
6573 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x104, DD_OK,
6574 DDSD_PITCH, 0x100, 0x100},
6575 {DDSCAPS_VIDEOMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
6576 DDSD_PITCH, 0x100, 0x100},
6577 {DDSCAPS_VIDEOMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DDERR_INVALIDCAPS,
6578 0, 0, 0 },
6579 {DDSCAPS_SYSTEMMEMORY, 0, 0, DD_OK,
6580 DDSD_PITCH, 0x100, 0x0fc},
6581 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x104, DD_OK,
6582 DDSD_PITCH, 0x100, 0x0fc},
6583 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH, 0x0f8, DD_OK,
6584 DDSD_PITCH, 0x100, 0x0fc},
6585 {DDSCAPS_SYSTEMMEMORY, DDSD_PITCH | DDSD_LINEARSIZE, 0, DD_OK,
6586 DDSD_PITCH, 0x100, 0x0fc},
6587 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE, 0, DDERR_INVALIDPARAMS,
6588 0, 0, 0 },
6589 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x100, DD_OK,
6590 DDSD_PITCH, 0x100, 0x100},
6591 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fe, DDERR_INVALIDPARAMS,
6592 0, 0, 0 },
6593 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0fc, DD_OK,
6594 DDSD_PITCH, 0x0fc, 0x0fc},
6595 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH, 0x0f8, DDERR_INVALIDPARAMS,
6596 0, 0, 0 },
6597 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x100, DDERR_INVALIDPARAMS,
6598 0, 0, 0 },
6599 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_LINEARSIZE, 0x3f00, DDERR_INVALIDPARAMS,
6600 0, 0, 0 },
6601 {DDSCAPS_SYSTEMMEMORY, DDSD_LPSURFACE | DDSD_PITCH | DDSD_LINEARSIZE, 0x100, DD_OK,
6602 DDSD_PITCH, 0x100, 0x100},
6604 DWORD flags_mask = DDSD_PITCH | DDSD_LPSURFACE | DDSD_LINEARSIZE;
6606 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6607 0, 0, 640, 480, 0, 0, 0, 0);
6608 ddraw = create_ddraw();
6609 ok(!!ddraw, "Failed to create a ddraw object.\n");
6610 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6611 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6613 mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((63 * 4) + 8) * 63);
6615 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
6617 memset(&surface_desc, 0, sizeof(surface_desc));
6618 surface_desc.dwSize = sizeof(surface_desc);
6619 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | test_data[i].flags_in;
6620 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | test_data[i].placement;
6621 surface_desc.dwWidth = 63;
6622 surface_desc.dwHeight = 63;
6623 U1(surface_desc).lPitch = test_data[i].pitch_in;
6624 surface_desc.lpSurface = mem;
6625 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6626 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
6627 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6628 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6629 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6630 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6631 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6632 ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
6633 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
6634 if (FAILED(hr))
6635 continue;
6637 memset(&surface_desc, 0, sizeof(surface_desc));
6638 surface_desc.dwSize = sizeof(surface_desc);
6639 hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &surface_desc);
6640 ok(SUCCEEDED(hr), "Test %u: Failed to get surface desc, hr %#x.\n", i, hr);
6641 ok((surface_desc.dwFlags & flags_mask) == test_data[i].flags_out,
6642 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6643 i, surface_desc.dwFlags & flags_mask, test_data[i].flags_out);
6644 if (sizeof(void *) != sizeof(DWORD) && test_data[i].pitch_out32 != test_data[i].pitch_out64)
6645 todo_wine ok(U1(surface_desc).lPitch == test_data[i].pitch_out64,
6646 "Test %u: Got unexpected pitch %u, expected %u.\n",
6647 i, U1(surface_desc).lPitch, test_data[i].pitch_out64);
6648 else
6649 ok(U1(surface_desc).lPitch == test_data[i].pitch_out32,
6650 "Test %u: Got unexpected pitch %u, expected %u.\n",
6651 i, U1(surface_desc).lPitch, test_data[i].pitch_out32);
6653 IDirectDrawSurface4_Release(surface);
6656 HeapFree(GetProcessHeap(), 0, mem);
6657 refcount = IDirectDraw4_Release(ddraw);
6658 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6659 DestroyWindow(window);
6662 static void test_mipmap_lock(void)
6664 IDirectDrawSurface4 *surface, *surface2;
6665 DDSURFACEDESC2 surface_desc;
6666 IDirectDraw4 *ddraw;
6667 ULONG refcount;
6668 HWND window;
6669 HRESULT hr;
6670 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6671 DDCAPS hal_caps;
6673 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6674 0, 0, 640, 480, 0, 0, 0, 0);
6675 ddraw = create_ddraw();
6676 ok(!!ddraw, "Failed to create a ddraw object.\n");
6677 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6678 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6680 memset(&hal_caps, 0, sizeof(hal_caps));
6681 hal_caps.dwSize = sizeof(hal_caps);
6682 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
6683 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6684 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6686 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6687 IDirectDraw4_Release(ddraw);
6688 DestroyWindow(window);
6689 return;
6692 memset(&surface_desc, 0, sizeof(surface_desc));
6693 surface_desc.dwSize = sizeof(surface_desc);
6694 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
6695 surface_desc.dwWidth = 4;
6696 surface_desc.dwHeight = 4;
6697 U2(surface_desc).dwMipMapCount = 2;
6698 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
6699 | DDSCAPS_SYSTEMMEMORY;
6700 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6701 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6702 hr = IDirectDrawSurface4_GetAttachedSurface(surface, &caps, &surface2);
6703 ok(SUCCEEDED(hr), "Failed to get attached surface, hr %#x.\n", hr);
6705 memset(&surface_desc, 0, sizeof(surface_desc));
6706 surface_desc.dwSize = sizeof(surface_desc);
6707 hr = IDirectDrawSurface4_Lock(surface, NULL, &surface_desc, 0, NULL);
6708 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6709 memset(&surface_desc, 0, sizeof(surface_desc));
6710 surface_desc.dwSize = sizeof(surface_desc);
6711 hr = IDirectDrawSurface4_Lock(surface2, NULL, &surface_desc, 0, NULL);
6712 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6713 IDirectDrawSurface4_Unlock(surface2, NULL);
6714 IDirectDrawSurface4_Unlock(surface, NULL);
6716 IDirectDrawSurface4_Release(surface2);
6717 IDirectDrawSurface4_Release(surface);
6718 refcount = IDirectDraw4_Release(ddraw);
6719 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6720 DestroyWindow(window);
6723 static void test_palette_complex(void)
6725 IDirectDrawSurface4 *surface, *mipmap, *tmp;
6726 DDSURFACEDESC2 surface_desc;
6727 IDirectDraw4 *ddraw;
6728 IDirectDrawPalette *palette, *palette2, *palette_mipmap;
6729 ULONG refcount;
6730 HWND window;
6731 HRESULT hr;
6732 DDSCAPS2 caps = {DDSCAPS_COMPLEX, 0, 0, 0};
6733 DDCAPS hal_caps;
6734 PALETTEENTRY palette_entries[256];
6735 unsigned int i;
6736 HDC dc;
6737 RGBQUAD rgbquad;
6738 UINT count;
6740 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6741 0, 0, 640, 480, 0, 0, 0, 0);
6742 ddraw = create_ddraw();
6743 ok(!!ddraw, "Failed to create a ddraw object.\n");
6744 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6745 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6747 memset(&hal_caps, 0, sizeof(hal_caps));
6748 hal_caps.dwSize = sizeof(hal_caps);
6749 hr = IDirectDraw4_GetCaps(ddraw, &hal_caps, NULL);
6750 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6751 if ((hal_caps.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP)) != (DDSCAPS_TEXTURE | DDSCAPS_MIPMAP))
6753 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6754 IDirectDraw4_Release(ddraw);
6755 DestroyWindow(window);
6756 return;
6759 memset(&surface_desc, 0, sizeof(surface_desc));
6760 surface_desc.dwSize = sizeof(surface_desc);
6761 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6762 surface_desc.dwWidth = 128;
6763 surface_desc.dwHeight = 128;
6764 surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
6765 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6766 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
6767 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
6768 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
6769 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6771 memset(palette_entries, 0, sizeof(palette_entries));
6772 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6773 palette_entries, &palette, NULL);
6774 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6776 memset(palette_entries, 0, sizeof(palette_entries));
6777 palette_entries[1].peRed = 0xff;
6778 palette_entries[1].peGreen = 0x80;
6779 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6780 palette_entries, &palette_mipmap, NULL);
6781 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6783 palette2 = (void *)0xdeadbeef;
6784 hr = IDirectDrawSurface4_GetPalette(surface, &palette2);
6785 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x.\n", hr);
6786 ok(!palette2, "Got unexpected palette %p.\n", palette2);
6787 hr = IDirectDrawSurface4_SetPalette(surface, palette);
6788 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6789 hr = IDirectDrawSurface4_GetPalette(surface, &palette2);
6790 ok(SUCCEEDED(hr), "Failed to get palette, hr %#x.\n", hr);
6791 ok(palette == palette2, "Got unexpected palette %p.\n", palette2);
6792 IDirectDrawPalette_Release(palette2);
6794 mipmap = surface;
6795 IDirectDrawSurface4_AddRef(mipmap);
6796 for (i = 0; i < 7; ++i)
6798 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
6799 ok(SUCCEEDED(hr), "Failed to get attached surface, i %u, hr %#x.\n", i, hr);
6800 palette2 = (void *)0xdeadbeef;
6801 hr = IDirectDrawSurface4_GetPalette(tmp, &palette2);
6802 ok(hr == DDERR_NOPALETTEATTACHED, "Got unexpected hr %#x, i %u.\n", hr, i);
6803 ok(!palette2, "Got unexpected palette %p, i %u.\n", palette2, i);
6805 hr = IDirectDrawSurface4_SetPalette(tmp, palette_mipmap);
6806 ok(SUCCEEDED(hr), "Failed to set palette, i %u, hr %#x.\n", i, hr);
6808 hr = IDirectDrawSurface4_GetPalette(tmp, &palette2);
6809 ok(SUCCEEDED(hr), "Failed to get palette, i %u, hr %#x.\n", i, hr);
6810 ok(palette_mipmap == palette2, "Got unexpected palette %p.\n", palette2);
6811 IDirectDrawPalette_Release(palette2);
6813 hr = IDirectDrawSurface4_GetDC(tmp, &dc);
6814 ok(SUCCEEDED(hr), "Failed to get DC, i %u, hr %#x.\n", i, hr);
6815 count = GetDIBColorTable(dc, 1, 1, &rgbquad);
6816 ok(count == 1, "Expected count 1, got %u.\n", count);
6817 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad.rgbRed);
6818 ok(rgbquad.rgbGreen == 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad.rgbGreen);
6819 ok(rgbquad.rgbBlue == 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad.rgbBlue);
6820 hr = IDirectDrawSurface4_ReleaseDC(tmp, dc);
6821 ok(SUCCEEDED(hr), "Failed to release DC, i %u, hr %#x.\n", i, hr);
6823 IDirectDrawSurface4_Release(mipmap);
6824 mipmap = tmp;
6827 hr = IDirectDrawSurface4_GetAttachedSurface(mipmap, &caps, &tmp);
6828 ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6829 IDirectDrawSurface4_Release(mipmap);
6830 refcount = IDirectDrawSurface4_Release(surface);
6831 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6832 refcount = IDirectDrawPalette_Release(palette_mipmap);
6833 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6834 refcount = IDirectDrawPalette_Release(palette);
6835 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6837 refcount = IDirectDraw4_Release(ddraw);
6838 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6839 DestroyWindow(window);
6842 static void test_p8_rgb_blit(void)
6844 IDirectDrawSurface4 *src, *dst;
6845 DDSURFACEDESC2 surface_desc;
6846 IDirectDraw4 *ddraw;
6847 IDirectDrawPalette *palette;
6848 ULONG refcount;
6849 HWND window;
6850 HRESULT hr;
6851 PALETTEENTRY palette_entries[256];
6852 unsigned int x;
6853 static const BYTE src_data[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6854 static const D3DCOLOR expected[] =
6856 0x00101010, 0x00010101, 0x00020202, 0x00030303,
6857 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6859 D3DCOLOR color;
6861 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6862 0, 0, 640, 480, 0, 0, 0, 0);
6863 ddraw = create_ddraw();
6864 ok(!!ddraw, "Failed to create a ddraw object.\n");
6865 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6866 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6868 memset(palette_entries, 0, sizeof(palette_entries));
6869 palette_entries[1].peGreen = 0xff;
6870 palette_entries[2].peBlue = 0xff;
6871 palette_entries[3].peFlags = 0xff;
6872 palette_entries[4].peRed = 0xff;
6873 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
6874 palette_entries, &palette, NULL);
6875 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
6877 memset(&surface_desc, 0, sizeof(surface_desc));
6878 surface_desc.dwSize = sizeof(surface_desc);
6879 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6880 surface_desc.dwWidth = 8;
6881 surface_desc.dwHeight = 1;
6882 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6883 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6884 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
6885 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
6886 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &src, NULL);
6887 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6889 memset(&surface_desc, 0, sizeof(surface_desc));
6890 surface_desc.dwSize = sizeof(surface_desc);
6891 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
6892 surface_desc.dwWidth = 8;
6893 surface_desc.dwHeight = 1;
6894 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6895 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
6896 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
6897 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
6898 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
6899 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
6900 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
6901 U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
6902 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &dst, NULL);
6903 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6905 memset(&surface_desc, 0, sizeof(surface_desc));
6906 surface_desc.dwSize = sizeof(surface_desc);
6907 hr = IDirectDrawSurface4_Lock(src, NULL, &surface_desc, 0, NULL);
6908 ok(SUCCEEDED(hr), "Failed to lock source surface, hr %#x.\n", hr);
6909 memcpy(surface_desc.lpSurface, src_data, sizeof(src_data));
6910 hr = IDirectDrawSurface4_Unlock(src, NULL);
6911 ok(SUCCEEDED(hr), "Failed to unlock source surface, hr %#x.\n", hr);
6913 hr = IDirectDrawSurface4_SetPalette(src, palette);
6914 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
6915 hr = IDirectDrawSurface4_Blt(dst, NULL, src, NULL, DDBLT_WAIT, NULL);
6916 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6917 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6918 ok(SUCCEEDED(hr) || broken(hr == E_NOTIMPL) || broken(hr == E_FAIL),
6919 "Failed to blit, hr %#x.\n", hr);
6921 if (SUCCEEDED(hr))
6923 for (x = 0; x < sizeof(expected) / sizeof(*expected); x++)
6925 color = get_surface_color(dst, x, 0);
6926 todo_wine ok(compare_color(color, expected[x], 0),
6927 "Pixel %u: Got color %#x, expected %#x.\n",
6928 x, color, expected[x]);
6932 IDirectDrawSurface4_Release(src);
6933 IDirectDrawSurface4_Release(dst);
6934 IDirectDrawPalette_Release(palette);
6936 refcount = IDirectDraw4_Release(ddraw);
6937 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
6938 DestroyWindow(window);
6941 static void test_material(void)
6943 D3DMATERIALHANDLE mat_handle, tmp;
6944 IDirect3DMaterial3 *material;
6945 IDirect3DViewport3 *viewport;
6946 IDirect3DDevice3 *device;
6947 IDirectDrawSurface4 *rt;
6948 D3DCOLOR color;
6949 ULONG refcount;
6950 unsigned int i;
6951 HWND window;
6952 HRESULT hr;
6953 BOOL valid;
6955 static struct
6957 struct vec3 position;
6958 struct vec3 normal;
6959 D3DCOLOR diffuse;
6961 quad1[] =
6963 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
6964 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
6965 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
6966 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffffffff},
6968 quad2[] =
6970 {{-1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
6971 {{-1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
6972 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
6973 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, 0xffff0000},
6975 static const struct
6977 void *data;
6978 BOOL material;
6979 D3DCOLOR expected_color;
6981 test_data[] =
6983 {quad1, TRUE, 0x0000ff00},
6984 {quad2, TRUE, 0x0000ff00},
6985 {quad1, FALSE, 0x00ffffff},
6986 {quad2, FALSE, 0x00ff0000},
6988 static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
6990 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
6991 0, 0, 640, 480, 0, 0, 0, 0);
6992 if (!(device = create_device(window, DDSCL_NORMAL)))
6994 skip("Failed to create a 3D device, skipping test.\n");
6995 DestroyWindow(window);
6996 return;
6999 hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
7000 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
7002 viewport = create_viewport(device, 0, 0, 640, 480);
7003 hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
7004 ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
7006 material = create_emissive_material(device, 0.0f, 1.0f, 0.0f, 0.0f);
7007 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
7008 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
7010 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
7011 ok(SUCCEEDED(hr), "Failed to get light state, hr %#x.\n", hr);
7012 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
7013 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, mat_handle);
7014 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
7015 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
7016 ok(SUCCEEDED(hr), "Failed to get light state, hr %#x.\n", hr);
7017 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
7018 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, 0);
7019 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
7020 hr = IDirect3DDevice3_GetLightState(device, D3DLIGHTSTATE_MATERIAL, &tmp);
7021 ok(SUCCEEDED(hr), "Failed to get light state, hr %#x.\n", hr);
7022 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
7024 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); ++i)
7026 hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
7027 D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff0000ff, 1.0f, 0);
7028 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7030 hr = IDirect3DDevice3_SetLightState(device, D3DLIGHTSTATE_MATERIAL, test_data[i].material ? mat_handle : 0);
7031 ok(SUCCEEDED(hr), "Failed to set material state, hr %#x.\n", hr);
7033 hr = IDirect3DDevice3_BeginScene(device);
7034 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7035 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP,
7036 D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE, test_data[i].data, 4, 0);
7037 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7038 hr = IDirect3DDevice3_EndScene(device);
7039 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7040 color = get_surface_color(rt, 320, 240);
7041 ok(compare_color(color, test_data[i].expected_color, 1),
7042 "Got unexpected color 0x%08x, test %u.\n", color, i);
7045 destroy_material(material);
7046 material = create_diffuse_material(device, 1.0f, 0.0f, 0.0f, 1.0f);
7047 hr = IDirect3DMaterial3_GetHandle(material, device, &mat_handle);
7048 ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
7050 hr = IDirect3DViewport3_SetBackground(viewport, mat_handle);
7051 ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
7052 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
7053 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
7054 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
7055 ok(valid, "Got unexpected valid %#x.\n", valid);
7056 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7057 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7058 color = get_surface_color(rt, 320, 240);
7059 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7061 hr = IDirect3DViewport3_SetBackground(viewport, 0);
7062 ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr);
7063 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
7064 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
7065 ok(tmp == mat_handle, "Got unexpected material handle %#x, expected %#x.\n", tmp, mat_handle);
7066 ok(valid, "Got unexpected valid %#x.\n", valid);
7067 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7068 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7069 color = get_surface_color(rt, 320, 240);
7070 ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
7072 destroy_viewport(device, viewport);
7073 viewport = create_viewport(device, 0, 0, 640, 480);
7075 hr = IDirect3DViewport3_GetBackground(viewport, &tmp, &valid);
7076 ok(SUCCEEDED(hr), "Failed to get viewport background, hr %#x.\n", hr);
7077 ok(!tmp, "Got unexpected material handle %#x.\n", tmp);
7078 ok(!valid, "Got unexpected valid %#x.\n", valid);
7079 hr = IDirect3DViewport3_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
7080 ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
7081 color = get_surface_color(rt, 320, 240);
7082 ok(compare_color(color, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color);
7084 destroy_viewport(device, viewport);
7085 destroy_material(material);
7086 IDirectDrawSurface4_Release(rt);
7087 refcount = IDirect3DDevice3_Release(device);
7088 ok(!refcount, "Device has %u references left.\n", refcount);
7089 DestroyWindow(window);
7092 static void test_palette_gdi(void)
7094 IDirectDrawSurface4 *surface, *primary;
7095 DDSURFACEDESC2 surface_desc;
7096 IDirectDraw4 *ddraw;
7097 IDirectDrawPalette *palette, *palette2;
7098 ULONG refcount;
7099 HWND window;
7100 HRESULT hr;
7101 PALETTEENTRY palette_entries[256];
7102 UINT i;
7103 HDC dc;
7104 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7105 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7106 * not the point of this test. */
7107 static const RGBQUAD expected1[] =
7109 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7110 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7112 static const RGBQUAD expected2[] =
7114 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7115 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7117 static const RGBQUAD expected3[] =
7119 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7120 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7122 HPALETTE ddraw_palette_handle;
7123 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7124 RGBQUAD rgbquad[255];
7125 static const RGBQUAD rgb_zero = {0, 0, 0, 0};
7127 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7128 0, 0, 640, 480, 0, 0, 0, 0);
7129 ddraw = create_ddraw();
7130 ok(!!ddraw, "Failed to create a ddraw object.\n");
7131 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7132 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7134 memset(&surface_desc, 0, sizeof(surface_desc));
7135 surface_desc.dwSize = sizeof(surface_desc);
7136 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7137 surface_desc.dwWidth = 16;
7138 surface_desc.dwHeight = 16;
7139 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7140 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7141 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
7142 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 8;
7143 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7144 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7146 /* Avoid colors from the Windows default palette. */
7147 memset(palette_entries, 0, sizeof(palette_entries));
7148 palette_entries[1].peRed = 0x01;
7149 palette_entries[2].peGreen = 0x02;
7150 palette_entries[3].peBlue = 0x03;
7151 palette_entries[4].peRed = 0x13;
7152 palette_entries[4].peGreen = 0x14;
7153 palette_entries[4].peBlue = 0x15;
7154 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7155 palette_entries, &palette, NULL);
7156 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7158 /* If there is no palette assigned and the display mode is not 8 bpp, some
7159 * drivers refuse to create a DC while others allow it. If a DC is created,
7160 * the DIB color table is uninitialized and contains random colors. No error
7161 * is generated when trying to read pixels and random garbage is returned.
7163 * The most likely explanation is that if the driver creates a DC, it (or
7164 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7165 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7166 * contains uninitialized garbage. See comments below for the P8 case. */
7168 hr = IDirectDrawSurface4_SetPalette(surface, palette);
7169 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7170 hr = IDirectDrawSurface4_GetDC(surface, &dc);
7171 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7172 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7173 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE),
7174 "Got unexpected palette %p, expected %p.\n",
7175 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7177 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7178 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7179 for (i = 0; i < sizeof(expected1) / sizeof(*expected1); i++)
7181 ok(!memcmp(&rgbquad[i], &expected1[i], sizeof(rgbquad[i])),
7182 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7183 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7184 expected1[i].rgbRed, expected1[i].rgbGreen, expected1[i].rgbBlue);
7186 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7188 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7189 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7190 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7193 /* Update the palette while the DC is in use. This does not modify the DC. */
7194 palette_entries[4].peRed = 0x23;
7195 palette_entries[4].peGreen = 0x24;
7196 palette_entries[4].peBlue = 0x25;
7197 hr = IDirectDrawPalette_SetEntries(palette, 0, 4, 1, &palette_entries[4]);
7198 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
7200 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7201 ok(i == 1, "Expected count 1, got %u.\n", i);
7202 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7203 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7204 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7205 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7207 /* Neither does re-setting the palette. */
7208 hr = IDirectDrawSurface4_SetPalette(surface, NULL);
7209 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7210 hr = IDirectDrawSurface4_SetPalette(surface, palette);
7211 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7213 i = GetDIBColorTable(dc, 4, 1, &rgbquad[4]);
7214 ok(i == 1, "Expected count 1, got %u.\n", i);
7215 ok(!memcmp(&rgbquad[4], &expected1[4], sizeof(rgbquad[4])),
7216 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7217 i, rgbquad[4].rgbRed, rgbquad[4].rgbGreen, rgbquad[4].rgbBlue,
7218 expected1[4].rgbRed, expected1[4].rgbGreen, expected1[4].rgbBlue);
7220 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
7221 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7223 /* Refresh the DC. This updates the palette. */
7224 hr = IDirectDrawSurface4_GetDC(surface, &dc);
7225 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7226 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7227 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7228 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7230 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7231 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7232 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7233 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7235 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7237 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7238 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7239 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7241 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
7242 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7244 refcount = IDirectDrawSurface4_Release(surface);
7245 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7247 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7249 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7250 IDirectDrawPalette_Release(palette);
7251 IDirectDraw4_Release(ddraw);
7252 DestroyWindow(window);
7253 return;
7255 ok(SUCCEEDED(hr), "Failed to set display mode, hr %#x.\n", hr);
7256 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE);
7257 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7259 memset(&surface_desc, 0, sizeof(surface_desc));
7260 surface_desc.dwSize = sizeof(surface_desc);
7261 surface_desc.dwFlags = DDSD_CAPS;
7262 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7263 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &primary, NULL);
7264 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7266 hr = IDirectDrawSurface4_SetPalette(primary, palette);
7267 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7268 hr = IDirectDrawSurface4_GetDC(primary, &dc);
7269 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7270 ddraw_palette_handle = SelectPalette(dc, GetStockObject(DEFAULT_PALETTE), FALSE);
7271 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7272 ok(ddraw_palette_handle == GetStockObject(DEFAULT_PALETTE) || broken(TRUE),
7273 "Got unexpected palette %p, expected %p.\n",
7274 ddraw_palette_handle, GetStockObject(DEFAULT_PALETTE));
7275 SelectPalette(dc, ddraw_palette_handle, FALSE);
7277 /* The primary uses the system palette. In exclusive mode, the system palette matches
7278 * the ddraw palette attached to the primary, so the result is what you would expect
7279 * from a regular surface. Tests for the interaction between the ddraw palette and
7280 * the system palette are not included pending an application that depends on this.
7281 * The relation between those causes problems on Windows Vista and newer for games
7282 * like Age of Empires or Starcraft. Don't emulate it without a real need. */
7283 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7284 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7285 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7287 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7288 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7289 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7290 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7292 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7294 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7295 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7296 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7298 hr = IDirectDrawSurface4_ReleaseDC(primary, dc);
7299 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7301 memset(&surface_desc, 0, sizeof(surface_desc));
7302 surface_desc.dwSize = sizeof(surface_desc);
7303 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
7304 surface_desc.dwWidth = 16;
7305 surface_desc.dwHeight = 16;
7306 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7307 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7308 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7310 /* Here the offscreen surface appears to use the primary's palette,
7311 * but in all likelyhood it is actually the system palette. */
7312 hr = IDirectDrawSurface4_GetDC(surface, &dc);
7313 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7314 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7315 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7316 for (i = 0; i < sizeof(expected2) / sizeof(*expected2); i++)
7318 ok(!memcmp(&rgbquad[i], &expected2[i], sizeof(rgbquad[i])),
7319 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7320 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7321 expected2[i].rgbRed, expected2[i].rgbGreen, expected2[i].rgbBlue);
7323 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7325 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7326 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7327 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7329 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
7330 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7332 /* On real hardware a change to the primary surface's palette applies immediately,
7333 * even on device contexts from offscreen surfaces that do not have their own
7334 * palette. On the testbot VMs this is not the case. Don't test this until we
7335 * know of an application that depends on this. */
7337 memset(palette_entries, 0, sizeof(palette_entries));
7338 palette_entries[1].peBlue = 0x40;
7339 palette_entries[2].peRed = 0x40;
7340 palette_entries[3].peGreen = 0x40;
7341 palette_entries[4].peRed = 0x12;
7342 palette_entries[4].peGreen = 0x34;
7343 palette_entries[4].peBlue = 0x56;
7344 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_8BIT | DDPCAPS_ALLOW256,
7345 palette_entries, &palette2, NULL);
7346 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7347 hr = IDirectDrawSurface4_SetPalette(surface, palette2);
7348 ok(SUCCEEDED(hr), "Failed to set palette, hr %#x.\n", hr);
7350 /* A palette assigned to the offscreen surface overrides the primary / system
7351 * palette. */
7352 hr = IDirectDrawSurface4_GetDC(surface, &dc);
7353 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
7354 i = GetDIBColorTable(dc, 0, sizeof(rgbquad) / sizeof(*rgbquad), rgbquad);
7355 ok(i == sizeof(rgbquad) / sizeof(*rgbquad), "Expected count 255, got %u.\n", i);
7356 for (i = 0; i < sizeof(expected3) / sizeof(*expected3); i++)
7358 ok(!memcmp(&rgbquad[i], &expected3[i], sizeof(rgbquad[i])),
7359 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7360 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue,
7361 expected3[i].rgbRed, expected3[i].rgbGreen, expected3[i].rgbBlue);
7363 for (; i < sizeof(rgbquad) / sizeof(*rgbquad); i++)
7365 ok(!memcmp(&rgbquad[i], &rgb_zero, sizeof(rgbquad[i])),
7366 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7367 i, rgbquad[i].rgbRed, rgbquad[i].rgbGreen, rgbquad[i].rgbBlue);
7369 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
7370 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7372 refcount = IDirectDrawSurface4_Release(surface);
7373 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7375 /* The Windows 8 testbot keeps extra references to the primary and
7376 * backbuffer while in 8 bpp mode. */
7377 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
7378 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7380 refcount = IDirectDrawSurface4_Release(primary);
7381 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7382 refcount = IDirectDrawPalette_Release(palette2);
7383 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7384 refcount = IDirectDrawPalette_Release(palette);
7385 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7386 refcount = IDirectDraw4_Release(ddraw);
7387 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7388 DestroyWindow(window);
7391 static void test_palette_alpha(void)
7393 IDirectDrawSurface4 *surface;
7394 DDSURFACEDESC2 surface_desc;
7395 IDirectDraw4 *ddraw;
7396 IDirectDrawPalette *palette;
7397 ULONG refcount;
7398 HWND window;
7399 HRESULT hr;
7400 PALETTEENTRY palette_entries[256];
7401 unsigned int i;
7402 static const struct
7404 DWORD caps, flags;
7405 BOOL attach_allowed;
7406 const char *name;
7408 test_data[] =
7410 {DDSCAPS_OFFSCREENPLAIN, DDSD_WIDTH | DDSD_HEIGHT, FALSE, "offscreenplain"},
7411 {DDSCAPS_TEXTURE, DDSD_WIDTH | DDSD_HEIGHT, TRUE, "texture"},
7412 {DDSCAPS_PRIMARYSURFACE, 0, FALSE, "primary"}
7415 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7416 0, 0, 640, 480, 0, 0, 0, 0);
7417 ddraw = create_ddraw();
7418 ok(!!ddraw, "Failed to create a ddraw object.\n");
7419 if (FAILED(IDirectDraw4_SetDisplayMode(ddraw, 640, 480, 8, 0, 0)))
7421 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7422 IDirectDraw4_Release(ddraw);
7423 DestroyWindow(window);
7424 return;
7426 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7427 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7429 memset(palette_entries, 0, sizeof(palette_entries));
7430 palette_entries[1].peFlags = 0x42;
7431 palette_entries[2].peFlags = 0xff;
7432 palette_entries[3].peFlags = 0x80;
7433 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
7434 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7436 memset(palette_entries, 0x66, sizeof(palette_entries));
7437 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
7438 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
7439 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7440 palette_entries[0].peFlags);
7441 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7442 palette_entries[1].peFlags);
7443 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7444 palette_entries[2].peFlags);
7445 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7446 palette_entries[3].peFlags);
7448 IDirectDrawPalette_Release(palette);
7450 memset(palette_entries, 0, sizeof(palette_entries));
7451 palette_entries[1].peFlags = 0x42;
7452 palette_entries[1].peRed = 0xff;
7453 palette_entries[2].peFlags = 0xff;
7454 palette_entries[3].peFlags = 0x80;
7455 hr = IDirectDraw4_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT | DDPCAPS_ALPHA,
7456 palette_entries, &palette, NULL);
7457 ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr);
7459 memset(palette_entries, 0x66, sizeof(palette_entries));
7460 hr = IDirectDrawPalette_GetEntries(palette, 0, 1, 4, palette_entries);
7461 ok(SUCCEEDED(hr), "Failed to get palette entries, hr %#x.\n", hr);
7462 ok(palette_entries[0].peFlags == 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7463 palette_entries[0].peFlags);
7464 ok(palette_entries[1].peFlags == 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
7465 palette_entries[1].peFlags);
7466 ok(palette_entries[2].peFlags == 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
7467 palette_entries[2].peFlags);
7468 ok(palette_entries[3].peFlags == 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
7469 palette_entries[3].peFlags);
7471 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7473 memset(&surface_desc, 0, sizeof(surface_desc));
7474 surface_desc.dwSize = sizeof(surface_desc);
7475 surface_desc.dwFlags = DDSD_CAPS | test_data[i].flags;
7476 surface_desc.dwWidth = 128;
7477 surface_desc.dwHeight = 128;
7478 surface_desc.ddsCaps.dwCaps = test_data[i].caps;
7479 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7480 ok(SUCCEEDED(hr), "Failed to create %s surface, hr %#x.\n", test_data[i].name, hr);
7482 hr = IDirectDrawSurface4_SetPalette(surface, palette);
7483 if (test_data[i].attach_allowed)
7484 ok(SUCCEEDED(hr), "Failed to attach palette to %s surface, hr %#x.\n", test_data[i].name, hr);
7485 else
7486 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x, %s surface.\n", hr, test_data[i].name);
7488 if (SUCCEEDED(hr))
7490 HDC dc;
7491 RGBQUAD rgbquad;
7492 UINT retval;
7494 hr = IDirectDrawSurface4_GetDC(surface, &dc);
7495 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x, %s surface.\n", hr, test_data[i].name);
7496 retval = GetDIBColorTable(dc, 1, 1, &rgbquad);
7497 ok(retval == 1, "GetDIBColorTable returned unexpected result %u.\n", retval);
7498 ok(rgbquad.rgbRed == 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
7499 rgbquad.rgbRed, test_data[i].name);
7500 ok(rgbquad.rgbGreen == 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
7501 rgbquad.rgbGreen, test_data[i].name);
7502 ok(rgbquad.rgbBlue == 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
7503 rgbquad.rgbBlue, test_data[i].name);
7504 todo_wine ok(rgbquad.rgbReserved == 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
7505 rgbquad.rgbReserved, test_data[i].name);
7506 hr = IDirectDrawSurface4_ReleaseDC(surface, dc);
7507 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
7509 IDirectDrawSurface4_Release(surface);
7512 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
7513 memset(&surface_desc, 0, sizeof(surface_desc));
7514 surface_desc.dwSize = sizeof(surface_desc);
7515 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
7516 surface_desc.dwWidth = 128;
7517 surface_desc.dwHeight = 128;
7518 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
7519 U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
7520 U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
7521 U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
7522 U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
7523 U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
7524 U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
7525 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7526 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7527 hr = IDirectDrawSurface4_SetPalette(surface, palette);
7528 ok(hr == DDERR_INVALIDSURFACETYPE, "Got unexpected hr %#x.\n", hr);
7529 IDirectDrawSurface4_Release(surface);
7531 /* The Windows 8 testbot keeps extra references to the primary
7532 * while in 8 bpp mode. */
7533 hr = IDirectDraw4_RestoreDisplayMode(ddraw);
7534 ok(SUCCEEDED(hr), "Failed to restore display mode, hr %#x.\n", hr);
7536 refcount = IDirectDrawPalette_Release(palette);
7537 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7538 refcount = IDirectDraw4_Release(ddraw);
7539 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7540 DestroyWindow(window);
7543 static void test_vb_writeonly(void)
7545 IDirect3DDevice3 *device;
7546 IDirect3D3 *d3d;
7547 IDirect3DVertexBuffer *buffer;
7548 HWND window;
7549 HRESULT hr;
7550 D3DVERTEXBUFFERDESC desc;
7551 void *ptr;
7552 static const struct vec4 quad[] =
7554 { 0.0f, 480.0f, 0.0f, 1.0f},
7555 { 0.0f, 0.0f, 0.0f, 1.0f},
7556 {640.0f, 480.0f, 0.0f, 1.0f},
7557 {640.0f, 0.0f, 0.0f, 1.0f},
7560 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7561 0, 0, 640, 480, 0, 0, 0, 0);
7563 if (!(device = create_device(window, DDSCL_NORMAL)))
7565 skip("Failed to create a 3D device, skipping test.\n");
7566 DestroyWindow(window);
7567 return;
7570 hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
7571 ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
7573 memset(&desc, 0, sizeof(desc));
7574 desc.dwSize = sizeof(desc);
7575 desc.dwCaps = D3DVBCAPS_WRITEONLY;
7576 desc.dwFVF = D3DFVF_XYZRHW;
7577 desc.dwNumVertices = sizeof(quad) / sizeof(*quad);
7578 hr = IDirect3D3_CreateVertexBuffer(d3d, &desc, &buffer, 0, NULL);
7579 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
7581 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_DISCARDCONTENTS, &ptr, NULL);
7582 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7583 memcpy(ptr, quad, sizeof(quad));
7584 hr = IDirect3DVertexBuffer_Unlock(buffer);
7585 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7587 hr = IDirect3DDevice3_BeginScene(device);
7588 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
7589 hr = IDirect3DDevice3_DrawPrimitiveVB(device, D3DPT_TRIANGLESTRIP, buffer, 0, 4, 0);
7590 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7591 hr = IDirect3DDevice3_EndScene(device);
7592 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
7594 hr = IDirect3DVertexBuffer_Lock(buffer, 0, &ptr, NULL);
7595 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7596 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7597 hr = IDirect3DVertexBuffer_Unlock(buffer);
7598 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7600 hr = IDirect3DVertexBuffer_Lock(buffer, DDLOCK_READONLY, &ptr, NULL);
7601 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7602 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7603 hr = IDirect3DVertexBuffer_Unlock(buffer);
7604 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7606 IDirect3DVertexBuffer_Release(buffer);
7607 IDirect3D3_Release(d3d);
7608 IDirect3DDevice3_Release(device);
7609 DestroyWindow(window);
7612 static void test_lost_device(void)
7614 IDirectDrawSurface4 *surface;
7615 DDSURFACEDESC2 surface_desc;
7616 IDirectDraw4 *ddraw;
7617 ULONG refcount;
7618 HWND window;
7619 HRESULT hr;
7620 BOOL ret;
7622 window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
7623 0, 0, 640, 480, 0, 0, 0, 0);
7624 ddraw = create_ddraw();
7625 ok(!!ddraw, "Failed to create a ddraw object.\n");
7626 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7627 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
7629 memset(&surface_desc, 0, sizeof(surface_desc));
7630 surface_desc.dwSize = sizeof(surface_desc);
7631 surface_desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
7632 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
7633 surface_desc.dwBackBufferCount = 1;
7634 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7635 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7637 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7638 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7639 hr = IDirectDrawSurface4_IsLost(surface);
7640 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7641 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
7642 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7644 ret = SetForegroundWindow(GetDesktopWindow());
7645 ok(ret, "Failed to set foreground window.\n");
7646 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7647 todo_wine ok(hr == DDERR_NOEXCLUSIVEMODE, "Got unexpected hr %#x.\n", hr);
7648 hr = IDirectDrawSurface4_IsLost(surface);
7649 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7650 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
7651 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7653 ret = SetForegroundWindow(window);
7654 ok(ret, "Failed to set foreground window.\n");
7655 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7656 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7657 hr = IDirectDrawSurface4_IsLost(surface);
7658 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7659 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
7660 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7662 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
7663 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7664 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7665 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7666 hr = IDirectDrawSurface4_IsLost(surface);
7667 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7668 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
7669 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7671 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
7672 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7673 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7674 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7675 hr = IDirectDrawSurface4_IsLost(surface);
7676 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7677 hr = IDirectDrawSurface4_Flip(surface, NULL, DDFLIP_WAIT);
7678 todo_wine ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7680 /* Trying to restore the primary will crash, probably because flippable
7681 * surfaces can't exist in DDSCL_NORMAL. */
7682 IDirectDrawSurface4_Release(surface);
7683 memset(&surface_desc, 0, sizeof(surface_desc));
7684 surface_desc.dwSize = sizeof(surface_desc);
7685 surface_desc.dwFlags = DDSD_CAPS;
7686 surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
7687 hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
7688 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7690 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7691 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7692 hr = IDirectDrawSurface4_IsLost(surface);
7693 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7695 ret = SetForegroundWindow(GetDesktopWindow());
7696 ok(ret, "Failed to set foreground window.\n");
7697 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7698 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7699 hr = IDirectDrawSurface4_IsLost(surface);
7700 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7702 ret = SetForegroundWindow(window);
7703 ok(ret, "Failed to set foreground window.\n");
7704 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7705 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7706 hr = IDirectDrawSurface4_IsLost(surface);
7707 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7709 hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
7710 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7711 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7712 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7713 hr = IDirectDrawSurface4_IsLost(surface);
7714 ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
7716 hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
7717 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7718 hr = IDirectDraw4_TestCooperativeLevel(ddraw);
7719 ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7720 hr = IDirectDrawSurface4_IsLost(surface);
7721 todo_wine ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
7723 IDirectDrawSurface4_Release(surface);
7724 refcount = IDirectDraw4_Release(ddraw);
7725 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
7726 DestroyWindow(window);
7729 START_TEST(ddraw4)
7731 IDirectDraw4 *ddraw;
7733 if (!(ddraw = create_ddraw()))
7735 skip("Failed to create a ddraw object, skipping tests.\n");
7736 return;
7738 IDirectDraw4_Release(ddraw);
7740 test_process_vertices();
7741 test_coop_level_create_device_window();
7742 test_clipper_blt();
7743 test_coop_level_d3d_state();
7744 test_surface_interface_mismatch();
7745 test_coop_level_threaded();
7746 test_depth_blit();
7747 test_texture_load_ckey();
7748 test_viewport();
7749 test_zenable();
7750 test_ck_rgba();
7751 test_ck_default();
7752 test_ck_complex();
7753 test_surface_qi();
7754 test_device_qi();
7755 test_wndproc();
7756 test_window_style();
7757 test_redundant_mode_set();
7758 test_coop_level_mode_set();
7759 test_coop_level_mode_set_multi();
7760 test_initialize();
7761 test_coop_level_surf_create();
7762 test_vb_discard();
7763 test_coop_level_multi_window();
7764 test_draw_strided();
7765 test_clear_rect_count();
7766 test_coop_level_versions();
7767 test_lighting_interface_versions();
7768 test_coop_level_activateapp();
7769 test_texturemanage();
7770 test_block_formats_creation();
7771 test_unsupported_formats();
7772 test_rt_caps();
7773 test_primary_caps();
7774 test_surface_lock();
7775 test_surface_discard();
7776 test_flip();
7777 test_set_surface_desc();
7778 test_user_memory_getdc();
7779 test_sysmem_overlay();
7780 test_primary_palette();
7781 test_surface_attachment();
7782 test_private_data();
7783 test_pixel_format();
7784 test_create_surface_pitch();
7785 test_mipmap_lock();
7786 test_palette_complex();
7787 test_p8_rgb_blit();
7788 test_material();
7789 test_palette_gdi();
7790 test_palette_alpha();
7791 test_vb_writeonly();
7792 test_lost_device();