2 * Copyright 2006, 2012-2014 Stefan Dösinger for CodeWeavers
3 * Copyright 2011 Henri Verbeet for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
25 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(GUID
*guid
, void **ddraw
, REFIID iid
, IUnknown
*outer_unknown
);
42 struct create_window_thread_param
45 HANDLE window_created
;
46 HANDLE destroy_window
;
50 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
60 if (abs(x
- y
) > ulps
)
66 static BOOL
compare_vec3(struct vec3
*vec
, float x
, float y
, float z
, unsigned int ulps
)
68 return compare_float(vec
->x
, x
, ulps
)
69 && compare_float(vec
->y
, y
, ulps
)
70 && compare_float(vec
->z
, z
, ulps
);
73 static BOOL
compare_vec4(struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
75 return compare_float(vec
->x
, x
, ulps
)
76 && compare_float(vec
->y
, y
, ulps
)
77 && compare_float(vec
->z
, z
, ulps
)
78 && compare_float(vec
->w
, w
, ulps
);
81 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
83 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
85 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
87 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
89 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
93 static ULONG
get_refcount(IUnknown
*iface
)
95 IUnknown_AddRef(iface
);
96 return IUnknown_Release(iface
);
99 static DWORD WINAPI
create_window_thread_proc(void *param
)
101 struct create_window_thread_param
*p
= param
;
105 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
106 0, 0, 640, 480, 0, 0, 0, 0);
107 ret
= SetEvent(p
->window_created
);
108 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
114 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
115 DispatchMessageA(&msg
);
116 res
= WaitForSingleObject(p
->destroy_window
, 100);
117 if (res
== WAIT_OBJECT_0
)
119 if (res
!= WAIT_TIMEOUT
)
121 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
126 DestroyWindow(p
->window
);
131 static void create_window_thread(struct create_window_thread_param
*p
)
135 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
136 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
137 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
138 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
139 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
140 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
141 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
142 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
145 static void destroy_window_thread(struct create_window_thread_param
*p
)
147 SetEvent(p
->destroy_window
);
148 WaitForSingleObject(p
->thread
, INFINITE
);
149 CloseHandle(p
->destroy_window
);
150 CloseHandle(p
->window_created
);
151 CloseHandle(p
->thread
);
154 static IDirectDrawSurface7
*get_depth_stencil(IDirect3DDevice7
*device
)
156 IDirectDrawSurface7
*rt
, *ret
;
157 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, 0};
160 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
161 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
162 hr
= IDirectDrawSurface7_GetAttachedSurface(rt
, &caps
, &ret
);
163 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
164 IDirectDrawSurface7_Release(rt
);
168 static HRESULT
set_display_mode(IDirectDraw7
*ddraw
, DWORD width
, DWORD height
)
170 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
172 return IDirectDraw7_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
175 static D3DCOLOR
get_surface_color(IDirectDrawSurface7
*surface
, UINT x
, UINT y
)
177 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
178 DDSURFACEDESC2 surface_desc
;
182 memset(&surface_desc
, 0, sizeof(surface_desc
));
183 surface_desc
.dwSize
= sizeof(surface_desc
);
185 hr
= IDirectDrawSurface7_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
, NULL
);
186 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
190 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
192 hr
= IDirectDrawSurface7_Unlock(surface
, &rect
);
193 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
198 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
200 DDPIXELFORMAT
*z_fmt
= ctx
;
202 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
208 static IDirectDraw7
*create_ddraw(void)
212 if (FAILED(pDirectDrawCreateEx(NULL
, (void **)&ddraw
, &IID_IDirectDraw7
, NULL
)))
218 static HRESULT WINAPI
enum_devtype_cb(char *desc_str
, char *name
, D3DDEVICEDESC7
*desc
, void *ctx
)
221 if (IsEqualGUID(&desc
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
224 return DDENUMRET_CANCEL
;
229 static IDirect3DDevice7
*create_device(HWND window
, DWORD coop_level
)
231 IDirectDrawSurface7
*surface
, *ds
;
232 IDirect3DDevice7
*device
= NULL
;
233 DDSURFACEDESC2 surface_desc
;
239 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
241 if (!(ddraw
= create_ddraw()))
244 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, coop_level
);
245 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
247 memset(&surface_desc
, 0, sizeof(surface_desc
));
248 surface_desc
.dwSize
= sizeof(surface_desc
);
249 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
250 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
251 surface_desc
.dwWidth
= 640;
252 surface_desc
.dwHeight
= 480;
254 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
255 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
257 if (coop_level
& DDSCL_NORMAL
)
259 IDirectDrawClipper
*clipper
;
261 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
262 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
263 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
264 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
265 hr
= IDirectDrawSurface7_SetClipper(surface
, clipper
);
266 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
267 IDirectDrawClipper_Release(clipper
);
270 hr
= IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d7
);
271 IDirectDraw7_Release(ddraw
);
274 IDirectDrawSurface7_Release(surface
);
278 hr
= IDirect3D7_EnumDevices(d3d7
, enum_devtype_cb
, &hal_ok
);
279 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
280 if (hal_ok
) devtype
= &IID_IDirect3DTnLHalDevice
;
282 memset(&z_fmt
, 0, sizeof(z_fmt
));
283 hr
= IDirect3D7_EnumZBufferFormats(d3d7
, devtype
, enum_z_fmt
, &z_fmt
);
284 if (FAILED(hr
) || !z_fmt
.dwSize
)
286 IDirect3D7_Release(d3d7
);
287 IDirectDrawSurface7_Release(surface
);
291 memset(&surface_desc
, 0, sizeof(surface_desc
));
292 surface_desc
.dwSize
= sizeof(surface_desc
);
293 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
294 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
295 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
296 surface_desc
.dwWidth
= 640;
297 surface_desc
.dwHeight
= 480;
298 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
299 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
302 IDirect3D7_Release(d3d7
);
303 IDirectDrawSurface7_Release(surface
);
307 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
308 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
309 IDirectDrawSurface7_Release(ds
);
312 IDirect3D7_Release(d3d7
);
313 IDirectDrawSurface7_Release(surface
);
317 hr
= IDirect3D7_CreateDevice(d3d7
, devtype
, surface
, &device
);
318 IDirect3D7_Release(d3d7
);
319 IDirectDrawSurface7_Release(surface
);
326 static const UINT
*expect_messages
;
328 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
330 if (expect_messages
&& message
== *expect_messages
)
333 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
336 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
337 * interface. This prevents subsequent SetCooperativeLevel() calls on a
338 * different window from failing with DDERR_HWNDALREADYSET. */
339 static void fix_wndproc(HWND window
, LONG_PTR proc
)
344 if (!(ddraw
= create_ddraw()))
347 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
348 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
349 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
350 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
351 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
353 IDirectDraw7_Release(ddraw
);
356 static void test_process_vertices(void)
358 IDirect3DVertexBuffer7
*src_vb
, *dst_vb1
, *dst_vb2
;
359 D3DVERTEXBUFFERDESC vb_desc
;
360 IDirect3DDevice7
*device
;
361 struct vec4
*dst_data
;
362 struct vec3
*dst_data2
;
363 struct vec3
*src_data
;
369 static D3DMATRIX world
=
371 0.0f
, 1.0f
, 0.0f
, 0.0f
,
372 1.0f
, 0.0f
, 0.0f
, 0.0f
,
373 0.0f
, 0.0f
, 0.0f
, 1.0f
,
374 0.0f
, 1.0f
, 1.0f
, 1.0f
,
376 static D3DMATRIX view
=
378 2.0f
, 0.0f
, 0.0f
, 0.0f
,
379 0.0f
, -1.0f
, 0.0f
, 0.0f
,
380 0.0f
, 0.0f
, 1.0f
, 0.0f
,
381 0.0f
, 0.0f
, 0.0f
, 3.0f
,
383 static D3DMATRIX proj
=
385 1.0f
, 0.0f
, 0.0f
, 1.0f
,
386 0.0f
, 1.0f
, 1.0f
, 0.0f
,
387 0.0f
, 1.0f
, 1.0f
, 0.0f
,
388 1.0f
, 0.0f
, 0.0f
, 1.0f
,
391 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
392 0, 0, 640, 480, 0, 0, 0, 0);
393 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
395 skip("Failed to create a 3D device, skipping test.\n");
396 DestroyWindow(window
);
400 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d7
);
401 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
403 memset(&vb_desc
, 0, sizeof(vb_desc
));
404 vb_desc
.dwSize
= sizeof(vb_desc
);
405 vb_desc
.dwFVF
= D3DFVF_XYZ
;
406 vb_desc
.dwNumVertices
= 4;
407 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &src_vb
, 0);
408 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
410 hr
= IDirect3DVertexBuffer7_Lock(src_vb
, 0, (void **)&src_data
, NULL
);
411 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
412 src_data
[0].x
= 0.0f
;
413 src_data
[0].y
= 0.0f
;
414 src_data
[0].z
= 0.0f
;
415 src_data
[1].x
= 1.0f
;
416 src_data
[1].y
= 1.0f
;
417 src_data
[1].z
= 1.0f
;
418 src_data
[2].x
= -1.0f
;
419 src_data
[2].y
= -1.0f
;
420 src_data
[2].z
= 0.5f
;
421 src_data
[3].x
= 0.5f
;
422 src_data
[3].y
= -0.5f
;
423 src_data
[3].z
= 0.25f
;
424 hr
= IDirect3DVertexBuffer7_Unlock(src_vb
);
425 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
427 memset(&vb_desc
, 0, sizeof(vb_desc
));
428 vb_desc
.dwSize
= sizeof(vb_desc
);
429 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
430 vb_desc
.dwNumVertices
= 4;
431 /* MSDN says that the last parameter must be 0 - check that. */
432 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &dst_vb1
, 4);
433 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
435 memset(&vb_desc
, 0, sizeof(vb_desc
));
436 vb_desc
.dwSize
= sizeof(vb_desc
);
437 vb_desc
.dwFVF
= D3DFVF_XYZ
;
438 vb_desc
.dwNumVertices
= 5;
439 /* MSDN says that the last parameter must be 0 - check that. */
440 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &dst_vb2
, 12345678);
441 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
443 memset(&vp
, 0, sizeof(vp
));
450 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
451 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
453 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
454 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
455 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb2
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
456 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
458 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
459 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
460 ok(compare_vec4(&dst_data
[0], +1.280e+2f
, +1.280e+2f
, +0.000e+0f
, +1.000e+0f
, 4096),
461 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
462 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
463 ok(compare_vec4(&dst_data
[1], +1.920e+2f
, +6.400e+1f
, +1.000e+0f
, +1.000e+0f
, 4096),
464 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
465 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
466 ok(compare_vec4(&dst_data
[2], +6.400e+1f
, +1.920e+2f
, +5.000e-1f
, +1.000e+0f
, 4096),
467 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
468 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
469 ok(compare_vec4(&dst_data
[3], +1.600e+2f
, +1.600e+2f
, +2.500e-1f
, +1.000e+0f
, 4096),
470 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
471 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
472 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
473 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
475 hr
= IDirect3DVertexBuffer7_Lock(dst_vb2
, 0, (void **)&dst_data2
, NULL
);
476 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
477 /* Small thing without much practical meaning, but I stumbled upon it,
478 * so let's check for it: If the output vertex buffer has no RHW value,
479 * the RHW value of the last vertex is written into the next vertex. */
480 ok(compare_vec3(&dst_data2
[4], +1.000e+0f
, +0.000e+0f
, +0.000e+0f
, 4096),
481 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
482 dst_data2
[4].x
, dst_data2
[4].y
, dst_data2
[4].z
);
483 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb2
);
484 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
486 /* Try a more complicated viewport, same vertices. */
487 memset(&vp
, 0, sizeof(vp
));
494 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
495 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
497 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
498 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
500 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
501 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
502 ok(compare_vec4(&dst_data
[0], +1.330e+2f
, +7.000e+1f
, -2.000e+0f
, +1.000e+0f
, 4096),
503 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
504 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
505 ok(compare_vec4(&dst_data
[1], +2.560e+2f
, +5.000e+0f
, +4.000e+0f
, +1.000e+0f
, 4096),
506 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
507 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
508 ok(compare_vec4(&dst_data
[2], +1.000e+1f
, +1.350e+2f
, +1.000e+0f
, +1.000e+0f
, 4096),
509 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
510 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
511 ok(compare_vec4(&dst_data
[3], +1.945e+2f
, +1.025e+2f
, -5.000e-1f
, +1.000e+0f
, 4096),
512 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
513 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
514 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
515 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
517 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world
);
518 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
519 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &view
);
520 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
521 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
522 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
524 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
525 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
527 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
528 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
529 ok(compare_vec4(&dst_data
[0], +2.560e+2f
, +7.000e+1f
, -2.000e+0f
, +3.333e-1f
, 4096),
530 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
531 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
532 ok(compare_vec4(&dst_data
[1], +2.560e+2f
, +7.813e+1f
, -2.750e+0f
, +1.250e-1f
, 4096),
533 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
534 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
535 ok(compare_vec4(&dst_data
[2], +2.560e+2f
, +4.400e+1f
, +4.000e-1f
, +4.000e-1f
, 4096),
536 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
537 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
538 ok(compare_vec4(&dst_data
[3], +2.560e+2f
, +8.182e+1f
, -3.091e+0f
, +3.636e-1f
, 4096),
539 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
540 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
541 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
542 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
544 IDirect3DVertexBuffer7_Release(dst_vb2
);
545 IDirect3DVertexBuffer7_Release(dst_vb1
);
546 IDirect3DVertexBuffer7_Release(src_vb
);
547 IDirect3D7_Release(d3d7
);
548 IDirect3DDevice7_Release(device
);
549 DestroyWindow(window
);
552 static void test_coop_level_create_device_window(void)
554 HWND focus_window
, device_window
;
558 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
559 0, 0, 640, 480, 0, 0, 0, 0);
560 ddraw
= create_ddraw();
561 ok(!!ddraw
, "Failed to create a ddraw object.\n");
563 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
564 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
565 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
566 ok(!device_window
, "Unexpected device window found.\n");
567 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
568 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
569 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
570 ok(!device_window
, "Unexpected device window found.\n");
571 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
572 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
573 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
574 ok(!device_window
, "Unexpected device window found.\n");
575 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
576 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
577 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
578 ok(!device_window
, "Unexpected device window found.\n");
579 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
580 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
581 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
582 ok(!device_window
, "Unexpected device window found.\n");
584 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
585 if (broken(hr
== DDERR_INVALIDPARAMS
))
587 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
588 IDirectDraw7_Release(ddraw
);
589 DestroyWindow(focus_window
);
593 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
594 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
595 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
596 ok(!device_window
, "Unexpected device window found.\n");
597 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
598 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
599 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
600 ok(!device_window
, "Unexpected device window found.\n");
602 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
603 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
604 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
605 ok(!device_window
, "Unexpected device window found.\n");
606 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
607 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
608 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
609 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
610 ok(!!device_window
, "Device window not found.\n");
612 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
613 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
614 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
615 ok(!device_window
, "Unexpected device window found.\n");
616 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
617 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
618 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
619 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
620 ok(!!device_window
, "Device window not found.\n");
622 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
623 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
624 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
625 ok(!device_window
, "Unexpected device window found.\n");
626 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
627 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
628 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
629 ok(!device_window
, "Unexpected device window found.\n");
630 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
631 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
632 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
633 ok(!device_window
, "Unexpected device window found.\n");
634 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
635 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
636 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!!device_window
, "Device window not found.\n");
639 IDirectDraw7_Release(ddraw
);
640 DestroyWindow(focus_window
);
643 static void test_clipper_blt(void)
645 IDirectDrawSurface7
*src_surface
, *dst_surface
;
646 RECT client_rect
, src_rect
;
647 IDirectDrawClipper
*clipper
;
648 DDSURFACEDESC2 surface_desc
;
649 unsigned int i
, j
, x
, y
;
660 static const DWORD src_data
[] =
662 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
663 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
664 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
666 static const D3DCOLOR expected1
[] =
668 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
669 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
670 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
671 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
673 /* Nvidia on Windows seems to have an off-by-one error
674 * when processing source rectangles. Our left = 1 and
675 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
676 * read as well, but only for the edge pixels on the
677 * output image. The bug happens on the y axis as well,
678 * but we only read one row there, and all source rows
679 * contain the same data. This bug is not dependent on
680 * the presence of a clipper. */
681 static const D3DCOLOR expected1_broken
[] =
683 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
684 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
685 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
686 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
688 static const D3DCOLOR expected2
[] =
690 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
691 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
692 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
693 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
696 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
697 10, 10, 640, 480, 0, 0, 0, 0);
698 ShowWindow(window
, SW_SHOW
);
699 ddraw
= create_ddraw();
700 ok(!!ddraw
, "Failed to create a ddraw object.\n");
702 ret
= GetClientRect(window
, &client_rect
);
703 ok(ret
, "Failed to get client rect.\n");
704 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
705 ok(ret
, "Failed to map client rect.\n");
707 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
708 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
710 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
711 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
712 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
713 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
714 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
715 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
716 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
717 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
718 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
719 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
720 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
721 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
722 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
723 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
724 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
725 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
726 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
727 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
728 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
729 HeapFree(GetProcessHeap(), 0, rgn_data
);
731 r1
= CreateRectRgn(0, 0, 320, 240);
732 ok(!!r1
, "Failed to create region.\n");
733 r2
= CreateRectRgn(320, 240, 640, 480);
734 ok(!!r2
, "Failed to create region.\n");
735 CombineRgn(r1
, r1
, r2
, RGN_OR
);
736 ret
= GetRegionData(r1
, 0, NULL
);
737 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
738 ret
= GetRegionData(r1
, ret
, rgn_data
);
739 ok(!!ret
, "Failed to get region data.\n");
744 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
745 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
746 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
747 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
748 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
749 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
751 HeapFree(GetProcessHeap(), 0, rgn_data
);
753 memset(&surface_desc
, 0, sizeof(surface_desc
));
754 surface_desc
.dwSize
= sizeof(surface_desc
);
755 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
756 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
757 surface_desc
.dwWidth
= 640;
758 surface_desc
.dwHeight
= 480;
759 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
760 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
761 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
762 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
763 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
764 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
766 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
767 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
768 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
769 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
771 memset(&fx
, 0, sizeof(fx
));
772 fx
.dwSize
= sizeof(fx
);
773 hr
= IDirectDrawSurface7_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
774 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
775 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
776 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
778 hr
= IDirectDrawSurface7_Lock(src_surface
, NULL
, &surface_desc
, 0, NULL
);
779 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
780 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
781 ptr
= surface_desc
.lpSurface
;
782 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
783 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
784 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
785 hr
= IDirectDrawSurface7_Unlock(src_surface
, NULL
);
786 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
788 hr
= IDirectDrawSurface7_SetClipper(dst_surface
, clipper
);
789 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
791 SetRect(&src_rect
, 1, 1, 5, 2);
792 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
793 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
794 for (i
= 0; i
< 4; ++i
)
796 for (j
= 0; j
< 4; ++j
)
798 x
= 80 * ((2 * j
) + 1);
799 y
= 60 * ((2 * i
) + 1);
800 color
= get_surface_color(dst_surface
, x
, y
);
801 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
802 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
803 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
807 U5(fx
).dwFillColor
= 0xff0000ff;
808 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
809 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
810 for (i
= 0; i
< 4; ++i
)
812 for (j
= 0; j
< 4; ++j
)
814 x
= 80 * ((2 * j
) + 1);
815 y
= 60 * ((2 * i
) + 1);
816 color
= get_surface_color(dst_surface
, x
, y
);
817 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
818 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
822 hr
= IDirectDrawSurface7_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
823 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
825 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
826 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
827 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
828 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
829 DestroyWindow(window
);
830 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
831 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
832 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
833 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
834 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
835 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
836 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
837 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
838 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
839 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
840 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
841 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
843 IDirectDrawSurface7_Release(dst_surface
);
844 IDirectDrawSurface7_Release(src_surface
);
845 IDirectDrawClipper_Release(clipper
);
846 IDirectDraw7_Release(ddraw
);
849 static void test_coop_level_d3d_state(void)
851 IDirectDrawSurface7
*rt
, *surface
;
852 IDirect3DDevice7
*device
;
860 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
861 0, 0, 640, 480, 0, 0, 0, 0);
862 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
864 skip("Failed to create a 3D device, skipping test.\n");
865 DestroyWindow(window
);
869 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
870 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
871 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
872 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
873 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
874 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
875 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
876 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
877 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
878 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
879 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
880 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
881 color
= get_surface_color(rt
, 320, 240);
882 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
884 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
885 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
886 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
887 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
888 IDirect3D7_Release(d3d
);
889 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
890 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
891 hr
= IDirectDrawSurface7_IsLost(rt
);
892 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
893 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
894 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
895 IDirectDraw7_Release(ddraw
);
897 hr
= IDirect3DDevice7_GetRenderTarget(device
, &surface
);
898 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
899 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
900 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
901 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
902 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
903 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
904 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
905 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
906 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
907 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
908 color
= get_surface_color(rt
, 320, 240);
909 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
911 IDirectDrawSurface7_Release(surface
);
912 IDirectDrawSurface7_Release(rt
);
913 IDirect3DDevice7_Release(device
);
914 DestroyWindow(window
);
917 static void test_surface_interface_mismatch(void)
919 IDirectDraw7
*ddraw
= NULL
;
920 IDirect3D7
*d3d
= NULL
;
921 IDirectDrawSurface7
*surface
= NULL
, *ds
;
922 IDirectDrawSurface3
*surface3
= NULL
;
923 IDirect3DDevice7
*device
= NULL
;
924 DDSURFACEDESC2 surface_desc
;
931 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
932 0, 0, 640, 480, 0, 0, 0, 0);
933 ddraw
= create_ddraw();
934 ok(!!ddraw
, "Failed to create a ddraw object.\n");
935 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
936 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
938 memset(&surface_desc
, 0, sizeof(surface_desc
));
939 surface_desc
.dwSize
= sizeof(surface_desc
);
940 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
941 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
942 surface_desc
.dwWidth
= 640;
943 surface_desc
.dwHeight
= 480;
945 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
946 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
948 hr
= IDirectDrawSurface7_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
949 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
951 if (FAILED(hr
= IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
953 skip("D3D interface is not available, skipping test.\n");
957 memset(&z_fmt
, 0, sizeof(z_fmt
));
958 hr
= IDirect3D7_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
959 if (FAILED(hr
) || !z_fmt
.dwSize
)
961 skip("No depth buffer formats available, skipping test.\n");
965 memset(&surface_desc
, 0, sizeof(surface_desc
));
966 surface_desc
.dwSize
= sizeof(surface_desc
);
967 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
968 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
969 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
970 surface_desc
.dwWidth
= 640;
971 surface_desc
.dwHeight
= 480;
972 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
973 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
977 /* Using a different surface interface version still works */
978 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
979 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
980 refcount
= IDirectDrawSurface7_Release(ds
);
981 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
986 hr
= IDirect3D7_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface7
*)surface3
, &device
);
987 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
991 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
992 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
993 color
= get_surface_color(surface
, 320, 240);
994 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
997 if (surface3
) IDirectDrawSurface3_Release(surface3
);
998 if (surface
) IDirectDrawSurface7_Release(surface
);
999 if (device
) IDirect3DDevice7_Release(device
);
1000 if (d3d
) IDirect3D7_Release(d3d
);
1001 if (ddraw
) IDirectDraw7_Release(ddraw
);
1002 DestroyWindow(window
);
1005 static void test_coop_level_threaded(void)
1007 struct create_window_thread_param p
;
1008 IDirectDraw7
*ddraw
;
1011 ddraw
= create_ddraw();
1012 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1013 create_window_thread(&p
);
1015 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1016 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1018 IDirectDraw7_Release(ddraw
);
1019 destroy_window_thread(&p
);
1022 static void test_depth_blit(void)
1024 IDirect3DDevice7
*device
;
1032 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1033 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1034 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1035 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1037 static const D3DCOLOR expected_colors
[4][4] =
1039 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1040 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1041 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1042 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1044 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1046 IDirectDrawSurface7
*ds1
, *ds2
, *ds3
, *rt
;
1047 RECT src_rect
, dst_rect
;
1052 IDirectDraw7
*ddraw
;
1056 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1057 0, 0, 640, 480, 0, 0, 0, 0);
1058 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1060 skip("Failed to create a 3D device, skipping test.\n");
1061 DestroyWindow(window
);
1065 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1066 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
1067 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1068 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
1069 IDirect3D7_Release(d3d
);
1071 ds1
= get_depth_stencil(device
);
1073 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1074 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1075 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1076 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1077 hr
= IDirectDrawSurface7_GetSurfaceDesc(ds1
, &ddsd_existing
);
1078 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1079 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1080 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1081 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1082 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1083 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1084 ok(SUCCEEDED(hr
), "Failed to create a z buffer, hr %#x.\n", hr
);
1085 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1086 ok(SUCCEEDED(hr
), "Failed to create a z buffer, hr %#x.\n", hr
);
1087 IDirectDraw7_Release(ddraw
);
1089 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1090 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1091 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1092 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1093 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
1094 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
1096 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1097 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1100 SetRect(&src_rect
, 0, 0, 320, 240);
1101 SetRect(&dst_rect
, 0, 0, 320, 240);
1102 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1103 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1104 /* Different locations. */
1105 SetRect(&src_rect
, 0, 0, 320, 240);
1106 SetRect(&dst_rect
, 320, 240, 640, 480);
1107 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1108 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1110 SetRect(&src_rect
, 0, 0, 320, 240);
1111 SetRect(&dst_rect
, 0, 0, 640, 480);
1112 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1113 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1115 SetRect(&src_rect
, 0, 480, 640, 0);
1116 SetRect(&dst_rect
, 0, 0, 640, 480);
1117 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1118 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1119 SetRect(&src_rect
, 0, 0, 640, 480);
1120 SetRect(&dst_rect
, 0, 480, 640, 0);
1121 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1122 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1123 /* Full, explicit. */
1124 SetRect(&src_rect
, 0, 0, 640, 480);
1125 SetRect(&dst_rect
, 0, 0, 640, 480);
1126 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1127 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1128 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1130 /* Depth blit inside a BeginScene / EndScene pair */
1131 hr
= IDirect3DDevice7_BeginScene(device
);
1132 ok(SUCCEEDED(hr
), "Failed to start scene, hr %#x.\n", hr
);
1133 /* From the current depth stencil */
1134 hr
= IDirectDrawSurface7_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1135 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1136 /* To the current depth stencil */
1137 hr
= IDirectDrawSurface7_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1138 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1139 /* Between unbound surfaces */
1140 hr
= IDirectDrawSurface7_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1141 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1142 hr
= IDirect3DDevice7_EndScene(device
);
1143 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1145 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1146 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1147 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1148 * a reliable result(z = 0.0) */
1149 memset(&fx
, 0, sizeof(fx
));
1150 fx
.dwSize
= sizeof(fx
);
1151 hr
= IDirectDrawSurface7_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1152 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1154 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1155 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1156 SetRect(&dst_rect
, 0, 0, 320, 240);
1157 hr
= IDirectDrawSurface7_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1158 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1159 IDirectDrawSurface7_Release(ds3
);
1160 IDirectDrawSurface7_Release(ds2
);
1161 IDirectDrawSurface7_Release(ds1
);
1163 hr
= IDirect3DDevice7_BeginScene(device
);
1164 ok(SUCCEEDED(hr
), "Failed to start scene, hr %#x.\n", hr
);
1165 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1167 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1168 hr
= IDirect3DDevice7_EndScene(device
);
1169 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1171 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1172 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1173 for (i
= 0; i
< 4; ++i
)
1175 for (j
= 0; j
< 4; ++j
)
1177 unsigned int x
= 80 * ((2 * j
) + 1);
1178 unsigned int y
= 60 * ((2 * i
) + 1);
1179 color
= get_surface_color(rt
, x
, y
);
1180 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1181 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1185 IDirectDrawSurface7_Release(rt
);
1186 IDirect3DDevice7_Release(device
);
1187 DestroyWindow(window
);
1190 static void test_texture_load_ckey(void)
1193 IDirect3DDevice7
*device
;
1194 IDirectDraw7
*ddraw
;
1195 IDirectDrawSurface7
*src
;
1196 IDirectDrawSurface7
*dst
;
1197 DDSURFACEDESC2 ddsd
;
1202 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1203 0, 0, 640, 480, 0, 0, 0, 0);
1204 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1206 skip("Failed to create a 3D device, skipping test.\n");
1207 DestroyWindow(window
);
1211 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1212 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
1213 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1214 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
1215 IDirect3D7_Release(d3d
);
1217 memset(&ddsd
, 0, sizeof(ddsd
));
1218 ddsd
.dwSize
= sizeof(ddsd
);
1219 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1220 ddsd
.dwHeight
= 128;
1222 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1223 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1224 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1225 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1226 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1227 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1229 /* No surface has a color key */
1230 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1231 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1232 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1233 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1234 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1235 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1236 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1238 /* Source surface has a color key */
1239 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1240 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1241 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1242 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1243 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1244 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1245 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1246 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1247 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1249 /* Both surfaces have a color key: Dest ckey is overwritten */
1250 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1251 hr
= IDirectDrawSurface7_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1252 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1253 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1254 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1255 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1256 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1257 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1258 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1260 /* Only the destination has a color key: It is deleted. This behavior differs from
1261 * IDirect3DTexture(2)::Load */
1262 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1263 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1264 hr
= IDirectDrawSurface7_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1265 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1266 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1267 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1268 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1269 todo_wine
ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1271 IDirectDrawSurface7_Release(dst
);
1272 IDirectDrawSurface7_Release(src
);
1273 IDirectDraw7_Release(ddraw
);
1274 IDirect3DDevice7_Release(device
);
1275 DestroyWindow(window
);
1278 static void test_zenable(void)
1282 struct vec4 position
;
1287 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1288 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1289 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1290 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1292 IDirect3DDevice7
*device
;
1293 IDirectDrawSurface7
*rt
;
1300 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1301 0, 0, 640, 480, 0, 0, 0, 0);
1302 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1304 skip("Failed to create a 3D device, skipping test.\n");
1305 DestroyWindow(window
);
1309 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1310 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1312 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1313 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1314 hr
= IDirect3DDevice7_BeginScene(device
);
1315 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1316 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1317 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1318 hr
= IDirect3DDevice7_EndScene(device
);
1319 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1321 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1322 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1323 for (i
= 0; i
< 4; ++i
)
1325 for (j
= 0; j
< 4; ++j
)
1327 x
= 80 * ((2 * j
) + 1);
1328 y
= 60 * ((2 * i
) + 1);
1329 color
= get_surface_color(rt
, x
, y
);
1330 ok(compare_color(color
, 0x0000ff00, 1),
1331 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1334 IDirectDrawSurface7_Release(rt
);
1336 IDirect3DDevice7_Release(device
);
1337 DestroyWindow(window
);
1340 static void test_ck_rgba(void)
1344 struct vec4 position
;
1345 struct vec2 texcoord
;
1349 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1350 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1351 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1352 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1353 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1354 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1355 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1356 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1360 D3DCOLOR fill_color
;
1368 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x000000ff},
1369 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x000000ff},
1370 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00},
1371 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1372 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00807f00},
1373 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x0000ff00},
1374 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00},
1375 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00},
1378 IDirectDrawSurface7
*texture
;
1379 DDSURFACEDESC2 surface_desc
;
1380 IDirect3DDevice7
*device
;
1381 IDirectDrawSurface7
*rt
;
1382 IDirectDraw7
*ddraw
;
1390 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1391 0, 0, 640, 480, 0, 0, 0, 0);
1392 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1394 skip("Failed to create a 3D device, skipping test.\n");
1395 DestroyWindow(window
);
1399 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1400 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1401 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1402 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1403 IDirect3D7_Release(d3d
);
1405 memset(&surface_desc
, 0, sizeof(surface_desc
));
1406 surface_desc
.dwSize
= sizeof(surface_desc
);
1407 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1408 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1409 surface_desc
.dwWidth
= 256;
1410 surface_desc
.dwHeight
= 256;
1411 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1412 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1413 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1414 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1415 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1416 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1417 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1418 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1419 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1420 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
1421 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1423 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture
);
1424 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1425 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1426 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1427 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1428 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1430 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1431 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1433 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1435 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1436 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1437 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1438 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1440 memset(&fx
, 0, sizeof(fx
));
1441 fx
.dwSize
= sizeof(fx
);
1442 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1443 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1444 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1446 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1447 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1448 hr
= IDirect3DDevice7_BeginScene(device
);
1449 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1450 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1451 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1452 hr
= IDirect3DDevice7_EndScene(device
);
1453 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1455 color
= get_surface_color(rt
, 320, 240);
1457 todo_wine
ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1458 tests
[i
].result1
, i
, color
);
1460 ok(compare_color(color
, tests
[i
].result1
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1461 tests
[i
].result1
, i
, color
);
1463 U5(fx
).dwFillColor
= 0xff0000ff;
1464 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1465 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1467 hr
= IDirect3DDevice7_BeginScene(device
);
1468 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1469 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1470 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1471 hr
= IDirect3DDevice7_EndScene(device
);
1472 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1474 /* This tests that fragments that are masked out by the color key are
1475 * discarded, instead of just fully transparent. */
1476 color
= get_surface_color(rt
, 320, 240);
1478 todo_wine
ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1479 tests
[i
].result2
, i
, color
);
1481 ok(compare_color(color
, tests
[i
].result2
, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
1482 tests
[i
].result2
, i
, color
);
1485 IDirectDrawSurface7_Release(rt
);
1486 IDirectDrawSurface7_Release(texture
);
1487 IDirectDraw7_Release(ddraw
);
1488 IDirect3DDevice7_Release(device
);
1489 DestroyWindow(window
);
1492 static void test_ck_default(void)
1496 struct vec4 position
;
1497 struct vec2 texcoord
;
1501 {{ 0.0f
, 480.0f
, 0.0f
, 1.0f
}, {0.0f
, 0.0f
}},
1502 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, {0.0f
, 1.0f
}},
1503 {{640.0f
, 480.0f
, 0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
1504 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, {1.0f
, 1.0f
}},
1506 IDirectDrawSurface7
*surface
, *rt
;
1507 DDSURFACEDESC2 surface_desc
;
1508 IDirect3DDevice7
*device
;
1509 IDirectDraw7
*ddraw
;
1517 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1518 0, 0, 640, 480, 0, 0, 0, 0);
1520 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1522 skip("Failed to create a 3D device, skipping test.\n");
1523 DestroyWindow(window
);
1527 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1528 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1529 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1530 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1531 IDirect3D7_Release(d3d
);
1533 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1534 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1536 memset(&surface_desc
, 0, sizeof(surface_desc
));
1537 surface_desc
.dwSize
= sizeof(surface_desc
);
1538 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1539 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1540 surface_desc
.dwWidth
= 256;
1541 surface_desc
.dwHeight
= 256;
1542 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1543 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1544 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1545 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1546 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1547 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1548 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1549 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1550 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1551 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1552 hr
= IDirect3DDevice7_SetTexture(device
, 0, surface
);
1553 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1555 memset(&fx
, 0, sizeof(fx
));
1556 fx
.dwSize
= sizeof(fx
);
1557 U5(fx
).dwFillColor
= 0x000000ff;
1558 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1559 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1561 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1562 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1563 hr
= IDirect3DDevice7_BeginScene(device
);
1564 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1565 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1566 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1567 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1568 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1569 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1570 hr
= IDirect3DDevice7_EndScene(device
);
1571 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1572 color
= get_surface_color(rt
, 320, 240);
1573 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1575 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1576 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1577 hr
= IDirect3DDevice7_BeginScene(device
);
1578 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1579 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1580 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1581 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1582 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1583 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1584 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1585 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1586 hr
= IDirect3DDevice7_EndScene(device
);
1587 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1588 color
= get_surface_color(rt
, 320, 240);
1589 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1591 IDirectDrawSurface7_Release(surface
);
1592 IDirectDrawSurface7_Release(rt
);
1593 IDirect3DDevice7_Release(device
);
1594 IDirectDraw7_Release(ddraw
);
1595 DestroyWindow(window
);
1598 static void test_ck_complex(void)
1600 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
1601 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
1602 DDSURFACEDESC2 surface_desc
;
1603 IDirect3DDevice7
*device
;
1604 DDCOLORKEY color_key
;
1605 IDirectDraw7
*ddraw
;
1612 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1613 0, 0, 640, 480, 0, 0, 0, 0);
1614 if (!(device
= create_device(window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1616 skip("Failed to create a 3D device, skipping test.\n");
1617 DestroyWindow(window
);
1620 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1621 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1622 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1623 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1624 IDirect3D7_Release(d3d
);
1626 memset(&surface_desc
, 0, sizeof(surface_desc
));
1627 surface_desc
.dwSize
= sizeof(surface_desc
);
1628 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1629 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1630 surface_desc
.dwWidth
= 128;
1631 surface_desc
.dwHeight
= 128;
1632 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1633 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1635 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1636 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1637 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1638 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1639 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1640 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1641 memset(&color_key
, 0, sizeof(color_key
));
1642 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1643 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1644 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1645 color_key
.dwColorSpaceLowValue
);
1646 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1647 color_key
.dwColorSpaceHighValue
);
1650 IDirectDrawSurface_AddRef(mipmap
);
1651 for (i
= 0; i
< 7; ++i
)
1653 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1654 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1655 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1656 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1658 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1659 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1660 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1661 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1663 IDirectDrawSurface_Release(mipmap
);
1667 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1668 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1669 IDirectDrawSurface_Release(mipmap
);
1670 refcount
= IDirectDrawSurface7_Release(surface
);
1671 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1673 memset(&surface_desc
, 0, sizeof(surface_desc
));
1674 surface_desc
.dwSize
= sizeof(surface_desc
);
1675 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1676 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1677 surface_desc
.dwBackBufferCount
= 1;
1678 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1679 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1681 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1682 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1683 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1684 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1685 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1686 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1687 memset(&color_key
, 0, sizeof(color_key
));
1688 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1689 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1690 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1691 color_key
.dwColorSpaceLowValue
);
1692 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1693 color_key
.dwColorSpaceHighValue
);
1695 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &tmp
);
1696 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1698 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1699 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1700 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1701 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1702 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1703 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1704 memset(&color_key
, 0, sizeof(color_key
));
1705 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1706 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1707 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1708 color_key
.dwColorSpaceLowValue
);
1709 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1710 color_key
.dwColorSpaceHighValue
);
1712 IDirectDrawSurface_Release(tmp
);
1714 refcount
= IDirectDrawSurface7_Release(surface
);
1715 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1716 IDirectDraw7_Release(ddraw
);
1717 refcount
= IDirect3DDevice7_Release(device
);
1718 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1719 DestroyWindow(window
);
1725 REFIID refcount_iid
;
1729 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1730 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1732 ULONG refcount
, expected_refcount
;
1733 IUnknown
*iface1
, *iface2
;
1737 for (i
= 0; i
< entry_count
; ++i
)
1739 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1740 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1743 for (j
= 0; j
< entry_count
; ++j
)
1745 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1746 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1749 expected_refcount
= 0;
1750 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1751 ++expected_refcount
;
1752 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1753 ++expected_refcount
;
1754 refcount
= IUnknown_Release(iface2
);
1755 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1756 refcount
, test_name
, i
, j
, expected_refcount
);
1760 expected_refcount
= 0;
1761 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1762 ++expected_refcount
;
1763 refcount
= IUnknown_Release(iface1
);
1764 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1765 refcount
, test_name
, i
, expected_refcount
);
1770 static void test_surface_qi(void)
1772 static const struct qi_test tests
[] =
1774 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
1775 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
1776 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1777 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1778 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1779 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1780 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1781 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1782 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1783 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
1784 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
1785 {&IID_IDirect3DDevice2
, NULL
, E_NOINTERFACE
},
1786 {&IID_IDirect3DDevice
, NULL
, E_NOINTERFACE
},
1787 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
1788 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
1789 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
1790 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
1791 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
1792 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
1793 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
1794 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
1795 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
1796 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
1797 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
1798 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
1799 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
1800 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
1801 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
1802 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
1803 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
1804 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
1805 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
1806 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
1807 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
1808 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
1809 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
1810 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
1811 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
1812 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
1813 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
1814 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
1815 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1818 IDirectDrawSurface7
*surface
;
1819 DDSURFACEDESC2 surface_desc
;
1820 IDirect3DDevice7
*device
;
1821 IDirectDraw7
*ddraw
;
1825 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1826 0, 0, 640, 480, 0, 0, 0, 0);
1827 /* Try to create a D3D device to see if the ddraw implementation supports
1828 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1829 * doesn't support e.g. the IDirect3DTexture interfaces. */
1830 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1832 skip("Failed to create a 3D device, skipping test.\n");
1833 DestroyWindow(window
);
1836 IDirect3DDevice_Release(device
);
1837 ddraw
= create_ddraw();
1838 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1839 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1840 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1842 memset(&surface_desc
, 0, sizeof(surface_desc
));
1843 surface_desc
.dwSize
= sizeof(surface_desc
);
1844 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1845 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1846 surface_desc
.dwWidth
= 512;
1847 surface_desc
.dwHeight
= 512;
1848 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1849 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1851 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface7
, tests
, sizeof(tests
) / sizeof(*tests
));
1853 IDirectDrawSurface7_Release(surface
);
1854 IDirectDraw7_Release(ddraw
);
1855 DestroyWindow(window
);
1858 static void test_device_qi(void)
1860 static const struct qi_test tests
[] =
1862 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
1863 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
1864 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
1865 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1866 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
1867 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
1868 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
1869 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
1870 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
1871 {&IID_IDirect3DDevice7
, &IID_IDirect3DDevice7
, S_OK
},
1872 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
1873 {&IID_IDirect3DDevice2
, NULL
, E_NOINTERFACE
},
1874 {&IID_IDirect3DDevice
, NULL
, E_NOINTERFACE
},
1875 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
1876 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
1877 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
1878 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
1879 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
1880 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
1881 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
1882 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
1883 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
1884 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
1885 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
1886 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
1887 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
1888 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
1889 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
1890 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
1891 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
1892 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
1893 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
1894 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
1895 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
1896 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
1897 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
1898 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
1899 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
1900 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
1901 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
1902 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
1903 {&IID_IUnknown
, &IID_IDirect3DDevice7
, S_OK
},
1906 IDirect3DDevice7
*device
;
1909 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1910 0, 0, 640, 480, 0, 0, 0, 0);
1911 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1913 skip("Failed to create a 3D device, skipping test.\n");
1914 DestroyWindow(window
);
1918 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice7
, tests
, sizeof(tests
) / sizeof(*tests
));
1920 IDirect3DDevice7_Release(device
);
1921 DestroyWindow(window
);
1924 static void test_wndproc(void)
1926 LONG_PTR proc
, ddraw_proc
;
1927 IDirectDraw7
*ddraw
;
1933 static const UINT messages
[] =
1935 WM_WINDOWPOSCHANGING
,
1938 WM_WINDOWPOSCHANGING
,
1944 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
1945 ddraw
= create_ddraw();
1946 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1948 wc
.lpfnWndProc
= test_proc
;
1949 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
1950 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
1952 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
1953 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
1955 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1956 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1957 (LONG_PTR
)test_proc
, proc
);
1958 expect_messages
= messages
;
1959 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1960 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
1961 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
1962 expect_messages
= NULL
;
1963 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1964 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
1965 (LONG_PTR
)test_proc
, proc
);
1966 ref
= IDirectDraw7_Release(ddraw
);
1967 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
1968 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1969 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1970 (LONG_PTR
)test_proc
, proc
);
1972 /* DDSCL_NORMAL doesn't. */
1973 ddraw
= create_ddraw();
1974 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1975 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1976 (LONG_PTR
)test_proc
, proc
);
1977 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
1978 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
1979 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1980 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1981 (LONG_PTR
)test_proc
, proc
);
1982 ref
= IDirectDraw7_Release(ddraw
);
1983 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
1984 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1985 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1986 (LONG_PTR
)test_proc
, proc
);
1988 /* The original window proc is only restored by ddraw if the current
1989 * window proc matches the one ddraw set. This also affects switching
1990 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
1991 ddraw
= create_ddraw();
1992 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1993 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
1994 (LONG_PTR
)test_proc
, proc
);
1995 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1996 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
1997 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
1998 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
1999 (LONG_PTR
)test_proc
, proc
);
2001 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2002 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2003 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2004 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2005 (LONG_PTR
)test_proc
, proc
);
2006 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2007 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2008 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2009 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2010 (LONG_PTR
)test_proc
, proc
);
2011 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2012 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2013 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2014 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2015 (LONG_PTR
)DefWindowProcA
, proc
);
2016 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2017 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2018 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2019 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2020 (LONG_PTR
)DefWindowProcA
, proc
);
2021 ref
= IDirectDraw7_Release(ddraw
);
2022 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2023 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2024 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2025 (LONG_PTR
)test_proc
, proc
);
2027 ddraw
= create_ddraw();
2028 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2029 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2030 (LONG_PTR
)test_proc
, proc
);
2031 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2032 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2033 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2034 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2035 (LONG_PTR
)test_proc
, proc
);
2036 ref
= IDirectDraw7_Release(ddraw
);
2037 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2038 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2039 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2040 (LONG_PTR
)DefWindowProcA
, proc
);
2042 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2043 expect_messages
= NULL
;
2044 DestroyWindow(window
);
2045 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2048 static void test_window_style(void)
2050 LONG style
, exstyle
, tmp
;
2051 RECT fullscreen_rect
, r
;
2052 IDirectDraw7
*ddraw
;
2057 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2058 0, 0, 100, 100, 0, 0, 0, 0);
2059 ddraw
= create_ddraw();
2060 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2062 style
= GetWindowLongA(window
, GWL_STYLE
);
2063 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2064 SetRect(&fullscreen_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
2066 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2067 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2069 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2070 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2071 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2072 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2074 GetWindowRect(window
, &r
);
2075 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2076 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2077 r
.left
, r
.top
, r
.right
, r
.bottom
);
2078 GetClientRect(window
, &r
);
2079 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2081 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2082 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2084 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2085 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2086 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2087 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2089 ref
= IDirectDraw7_Release(ddraw
);
2090 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2092 DestroyWindow(window
);
2095 static void test_redundant_mode_set(void)
2097 DDSURFACEDESC2 surface_desc
= {0};
2098 IDirectDraw7
*ddraw
;
2104 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2105 0, 0, 100, 100, 0, 0, 0, 0);
2106 ddraw
= create_ddraw();
2107 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2108 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2109 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2111 surface_desc
.dwSize
= sizeof(surface_desc
);
2112 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &surface_desc
);
2113 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2115 hr
= IDirectDraw7_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2116 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2117 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2119 GetWindowRect(window
, &r
);
2122 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2123 GetWindowRect(window
, &s
);
2124 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2125 r
.left
, r
.top
, r
.right
, r
.bottom
,
2126 s
.left
, s
.top
, s
.right
, s
.bottom
);
2128 hr
= IDirectDraw7_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2129 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2130 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2132 GetWindowRect(window
, &s
);
2133 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2134 r
.left
, r
.top
, r
.right
, r
.bottom
,
2135 s
.left
, s
.top
, s
.right
, s
.bottom
);
2137 ref
= IDirectDraw7_Release(ddraw
);
2138 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2140 DestroyWindow(window
);
2143 static SIZE screen_size
, screen_size2
;
2145 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2147 if (message
== WM_SIZE
)
2149 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2150 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2153 return test_proc(hwnd
, message
, wparam
, lparam
);
2156 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2158 if (message
== WM_SIZE
)
2160 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2161 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2164 return test_proc(hwnd
, message
, wparam
, lparam
);
2167 static void test_coop_level_mode_set(void)
2169 IDirectDrawSurface7
*primary
;
2170 RECT fullscreen_rect
, r
, s
;
2171 IDirectDraw7
*ddraw
;
2172 DDSURFACEDESC2 ddsd
;
2174 HWND window
, window2
;
2179 static const UINT exclusive_messages
[] =
2181 WM_WINDOWPOSCHANGING
,
2182 WM_WINDOWPOSCHANGED
,
2188 static const UINT normal_messages
[] =
2194 ddraw
= create_ddraw();
2195 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2197 wc
.lpfnWndProc
= mode_set_proc
;
2198 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2199 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2200 wc
.lpfnWndProc
= mode_set_proc2
;
2201 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2202 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2204 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2205 0, 0, 100, 100, 0, 0, 0, 0);
2206 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2207 0, 0, 100, 100, 0, 0, 0, 0);
2209 SetRect(&fullscreen_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
2210 SetRect(&s
, 0, 0, 640, 480);
2212 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2213 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2215 GetWindowRect(window
, &r
);
2216 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2217 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2218 r
.left
, r
.top
, r
.right
, r
.bottom
);
2220 memset(&ddsd
, 0, sizeof(ddsd
));
2221 ddsd
.dwSize
= sizeof(ddsd
);
2222 ddsd
.dwFlags
= DDSD_CAPS
;
2223 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2225 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2226 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2227 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2228 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2229 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2230 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2231 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2232 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2234 GetWindowRect(window
, &r
);
2235 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2236 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2237 r
.left
, r
.top
, r
.right
, r
.bottom
);
2239 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2240 expect_messages
= exclusive_messages
;
2244 hr
= set_display_mode(ddraw
, 640, 480);
2245 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2247 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2248 expect_messages
= NULL
;
2249 ok(screen_size
.cx
== s
.right
&& screen_size
.cy
== s
.bottom
,
2250 "Expected screen size %ux%u, got %ux%u.\n",
2251 s
.right
, s
.bottom
, screen_size
.cx
, screen_size
.cy
);
2253 GetWindowRect(window
, &r
);
2254 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2255 s
.left
, s
.top
, s
.right
, s
.bottom
,
2256 r
.left
, r
.top
, r
.right
, r
.bottom
);
2258 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2259 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2260 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2261 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2262 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2263 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2264 IDirectDrawSurface7_Release(primary
);
2266 memset(&ddsd
, 0, sizeof(ddsd
));
2267 ddsd
.dwSize
= sizeof(ddsd
);
2268 ddsd
.dwFlags
= DDSD_CAPS
;
2269 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2271 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2272 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2273 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2274 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2275 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2276 s
.right
- s
.left
, ddsd
.dwWidth
);
2277 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2278 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2280 GetWindowRect(window
, &r
);
2281 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2282 s
.left
, s
.top
, s
.right
, s
.bottom
,
2283 r
.left
, r
.top
, r
.right
, r
.bottom
);
2285 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2286 expect_messages
= exclusive_messages
;
2290 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2291 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2293 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2294 expect_messages
= NULL
;
2295 ok(screen_size
.cx
== fullscreen_rect
.right
&& screen_size
.cy
== fullscreen_rect
.bottom
,
2296 "Expected screen size %ux%u, got %ux%u.\n",
2297 fullscreen_rect
.right
, fullscreen_rect
.bottom
, screen_size
.cx
, screen_size
.cy
);
2299 GetWindowRect(window
, &r
);
2300 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2301 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2302 r
.left
, r
.top
, r
.right
, r
.bottom
);
2304 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2305 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2306 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2307 s
.right
- s
.left
, ddsd
.dwWidth
);
2308 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2309 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2310 IDirectDrawSurface7_Release(primary
);
2312 memset(&ddsd
, 0, sizeof(ddsd
));
2313 ddsd
.dwSize
= sizeof(ddsd
);
2314 ddsd
.dwFlags
= DDSD_CAPS
;
2315 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2317 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2318 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2319 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2320 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2321 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2322 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2323 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2324 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2326 GetWindowRect(window
, &r
);
2327 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2328 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2329 r
.left
, r
.top
, r
.right
, r
.bottom
);
2331 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2332 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2334 GetWindowRect(window
, &r
);
2335 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2336 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2337 r
.left
, r
.top
, r
.right
, r
.bottom
);
2339 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2340 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2341 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2342 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2343 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2344 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2345 IDirectDrawSurface7_Release(primary
);
2347 memset(&ddsd
, 0, sizeof(ddsd
));
2348 ddsd
.dwSize
= sizeof(ddsd
);
2349 ddsd
.dwFlags
= DDSD_CAPS
;
2350 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2352 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2353 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2354 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2355 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2356 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2357 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2358 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2359 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2361 GetWindowRect(window
, &r
);
2362 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2363 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2364 r
.left
, r
.top
, r
.right
, r
.bottom
);
2366 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2367 expect_messages
= normal_messages
;
2371 hr
= set_display_mode(ddraw
, 640, 480);
2372 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2374 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2375 expect_messages
= NULL
;
2376 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2378 GetWindowRect(window
, &r
);
2379 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2380 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2381 r
.left
, r
.top
, r
.right
, r
.bottom
);
2383 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2384 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2385 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2386 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2387 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2388 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2389 IDirectDrawSurface7_Release(primary
);
2391 memset(&ddsd
, 0, sizeof(ddsd
));
2392 ddsd
.dwSize
= sizeof(ddsd
);
2393 ddsd
.dwFlags
= DDSD_CAPS
;
2394 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2396 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2397 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2398 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2399 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2400 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2401 s
.right
- s
.left
, ddsd
.dwWidth
);
2402 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2403 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2405 GetWindowRect(window
, &r
);
2406 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2407 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2408 r
.left
, r
.top
, r
.right
, r
.bottom
);
2410 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2411 expect_messages
= normal_messages
;
2415 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2416 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2418 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2419 expect_messages
= NULL
;
2420 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2422 GetWindowRect(window
, &r
);
2423 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2424 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2425 r
.left
, r
.top
, r
.right
, r
.bottom
);
2427 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2428 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2429 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2430 s
.right
- s
.left
, ddsd
.dwWidth
);
2431 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2432 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2433 IDirectDrawSurface7_Release(primary
);
2435 memset(&ddsd
, 0, sizeof(ddsd
));
2436 ddsd
.dwSize
= sizeof(ddsd
);
2437 ddsd
.dwFlags
= DDSD_CAPS
;
2438 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2440 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2441 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2442 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2443 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2444 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2445 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2446 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2447 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2449 GetWindowRect(window
, &r
);
2450 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2451 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2452 r
.left
, r
.top
, r
.right
, r
.bottom
);
2454 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2455 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2456 * not DDSCL_FULLSCREEN. */
2457 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2458 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2460 GetWindowRect(window
, &r
);
2461 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2462 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2463 r
.left
, r
.top
, r
.right
, r
.bottom
);
2465 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2466 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2467 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2468 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2469 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2470 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2471 IDirectDrawSurface7_Release(primary
);
2473 memset(&ddsd
, 0, sizeof(ddsd
));
2474 ddsd
.dwSize
= sizeof(ddsd
);
2475 ddsd
.dwFlags
= DDSD_CAPS
;
2476 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2478 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2479 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2480 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2481 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2482 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2483 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2484 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2485 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2487 GetWindowRect(window
, &r
);
2488 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2489 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2490 r
.left
, r
.top
, r
.right
, r
.bottom
);
2492 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2493 expect_messages
= normal_messages
;
2497 hr
= set_display_mode(ddraw
, 640, 480);
2498 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2500 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2501 expect_messages
= NULL
;
2502 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2504 GetWindowRect(window
, &r
);
2505 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2506 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2507 r
.left
, r
.top
, r
.right
, r
.bottom
);
2509 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2510 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2511 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2512 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2513 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2514 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2515 IDirectDrawSurface7_Release(primary
);
2517 memset(&ddsd
, 0, sizeof(ddsd
));
2518 ddsd
.dwSize
= sizeof(ddsd
);
2519 ddsd
.dwFlags
= DDSD_CAPS
;
2520 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2522 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2523 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2524 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2525 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2526 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2527 s
.right
- s
.left
, ddsd
.dwWidth
);
2528 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2529 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2531 GetWindowRect(window
, &r
);
2532 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2533 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2534 r
.left
, r
.top
, r
.right
, r
.bottom
);
2536 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2537 expect_messages
= normal_messages
;
2541 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2542 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2544 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2545 expect_messages
= NULL
;
2546 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2548 GetWindowRect(window
, &r
);
2549 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2550 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2551 r
.left
, r
.top
, r
.right
, r
.bottom
);
2553 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2554 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2555 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2556 s
.right
- s
.left
, ddsd
.dwWidth
);
2557 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2558 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2559 IDirectDrawSurface7_Release(primary
);
2561 memset(&ddsd
, 0, sizeof(ddsd
));
2562 ddsd
.dwSize
= sizeof(ddsd
);
2563 ddsd
.dwFlags
= DDSD_CAPS
;
2564 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2566 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2567 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2568 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2569 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2570 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2571 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2572 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2573 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2574 IDirectDrawSurface7_Release(primary
);
2576 GetWindowRect(window
, &r
);
2577 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2578 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2579 r
.left
, r
.top
, r
.right
, r
.bottom
);
2581 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2582 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2583 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2584 hr
= set_display_mode(ddraw
, 640, 480);
2585 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2587 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2588 expect_messages
= exclusive_messages
;
2592 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2593 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2595 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2596 expect_messages
= NULL
;
2597 ok(screen_size
.cx
== fullscreen_rect
.right
&& screen_size
.cy
== fullscreen_rect
.bottom
,
2598 "Expected screen size %ux%u, got %ux%u.\n",
2599 fullscreen_rect
.right
, fullscreen_rect
.bottom
, screen_size
.cx
, screen_size
.cy
);
2601 GetWindowRect(window
, &r
);
2602 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2603 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2604 r
.left
, r
.top
, r
.right
, r
.bottom
);
2606 memset(&ddsd
, 0, sizeof(ddsd
));
2607 ddsd
.dwSize
= sizeof(ddsd
);
2608 ddsd
.dwFlags
= DDSD_CAPS
;
2609 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2611 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2612 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2613 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2614 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2615 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2616 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2617 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2618 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2619 IDirectDrawSurface7_Release(primary
);
2621 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2622 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2623 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2624 hr
= set_display_mode(ddraw
, 640, 480);
2625 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2627 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2628 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2630 memset(&ddsd
, 0, sizeof(ddsd
));
2631 ddsd
.dwSize
= sizeof(ddsd
);
2632 ddsd
.dwFlags
= DDSD_CAPS
;
2633 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2635 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2636 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2637 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2638 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2639 ok(ddsd
.dwWidth
== s
.right
- s
.left
, "Expected surface width %u, got %u.\n",
2640 s
.right
- s
.left
, ddsd
.dwWidth
);
2641 ok(ddsd
.dwHeight
== s
.bottom
- s
.top
, "Expected surface height %u, got %u.\n",
2642 s
.bottom
- s
.top
, ddsd
.dwHeight
);
2643 IDirectDrawSurface7_Release(primary
);
2645 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2646 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2648 /* If the window is changed at the same time, messages are sent to the new window. */
2649 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2650 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2651 hr
= set_display_mode(ddraw
, 640, 480);
2652 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2654 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2655 expect_messages
= exclusive_messages
;
2658 screen_size2
.cx
= 0;
2659 screen_size2
.cy
= 0;
2661 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
2662 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2664 ok(!*expect_messages
, "Expected message %#x, but didn't receive it.\n", *expect_messages
);
2665 expect_messages
= NULL
;
2666 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
2667 screen_size
.cx
, screen_size
.cy
);
2668 ok(screen_size2
.cx
== fullscreen_rect
.right
&& screen_size2
.cy
== fullscreen_rect
.bottom
,
2669 "Expected screen size 2 %ux%u, got %ux%u.\n",
2670 fullscreen_rect
.right
, fullscreen_rect
.bottom
, screen_size2
.cx
, screen_size2
.cy
);
2672 GetWindowRect(window
, &r
);
2673 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2674 s
.left
, s
.top
, s
.right
, s
.bottom
,
2675 r
.left
, r
.top
, r
.right
, r
.bottom
);
2676 GetWindowRect(window2
, &r
);
2677 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2678 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2679 r
.left
, r
.top
, r
.right
, r
.bottom
);
2681 memset(&ddsd
, 0, sizeof(ddsd
));
2682 ddsd
.dwSize
= sizeof(ddsd
);
2683 ddsd
.dwFlags
= DDSD_CAPS
;
2684 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2686 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2687 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2688 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2689 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2690 ok(ddsd
.dwWidth
== fullscreen_rect
.right
- fullscreen_rect
.left
, "Expected surface width %u, got %u.\n",
2691 fullscreen_rect
.right
- fullscreen_rect
.left
, ddsd
.dwWidth
);
2692 ok(ddsd
.dwHeight
== fullscreen_rect
.bottom
- fullscreen_rect
.top
, "Expected surface height %u, got %u.\n",
2693 fullscreen_rect
.bottom
- fullscreen_rect
.top
, ddsd
.dwHeight
);
2694 IDirectDrawSurface7_Release(primary
);
2696 ref
= IDirectDraw7_Release(ddraw
);
2697 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2699 GetWindowRect(window
, &r
);
2700 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2701 s
.left
, s
.top
, s
.right
, s
.bottom
,
2702 r
.left
, r
.top
, r
.right
, r
.bottom
);
2704 expect_messages
= NULL
;
2705 DestroyWindow(window
);
2706 DestroyWindow(window2
);
2707 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2708 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
2711 static void test_coop_level_mode_set_multi(void)
2713 IDirectDraw7
*ddraw1
, *ddraw2
;
2714 UINT orig_w
, orig_h
, w
, h
;
2719 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2720 0, 0, 100, 100, 0, 0, 0, 0);
2721 ddraw1
= create_ddraw();
2722 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
2724 orig_w
= GetSystemMetrics(SM_CXSCREEN
);
2725 orig_h
= GetSystemMetrics(SM_CYSCREEN
);
2727 /* With just a single ddraw object, the display mode is restored on
2729 hr
= set_display_mode(ddraw1
, 800, 600);
2730 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2731 w
= GetSystemMetrics(SM_CXSCREEN
);
2732 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2733 h
= GetSystemMetrics(SM_CYSCREEN
);
2734 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2736 ref
= IDirectDraw7_Release(ddraw1
);
2737 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2738 w
= GetSystemMetrics(SM_CXSCREEN
);
2739 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2740 h
= GetSystemMetrics(SM_CYSCREEN
);
2741 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2743 /* When there are multiple ddraw objects, the display mode is restored to
2744 * the initial mode, before the first SetDisplayMode() call. */
2745 ddraw1
= create_ddraw();
2746 hr
= set_display_mode(ddraw1
, 800, 600);
2747 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2748 w
= GetSystemMetrics(SM_CXSCREEN
);
2749 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2750 h
= GetSystemMetrics(SM_CYSCREEN
);
2751 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2753 ddraw2
= create_ddraw();
2754 hr
= set_display_mode(ddraw2
, 640, 480);
2755 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2756 w
= GetSystemMetrics(SM_CXSCREEN
);
2757 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2758 h
= GetSystemMetrics(SM_CYSCREEN
);
2759 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2761 ref
= IDirectDraw7_Release(ddraw2
);
2762 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2763 w
= GetSystemMetrics(SM_CXSCREEN
);
2764 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2765 h
= GetSystemMetrics(SM_CYSCREEN
);
2766 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2768 ref
= IDirectDraw7_Release(ddraw1
);
2769 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2770 w
= GetSystemMetrics(SM_CXSCREEN
);
2771 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2772 h
= GetSystemMetrics(SM_CYSCREEN
);
2773 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2775 /* Regardless of release ordering. */
2776 ddraw1
= create_ddraw();
2777 hr
= set_display_mode(ddraw1
, 800, 600);
2778 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2779 w
= GetSystemMetrics(SM_CXSCREEN
);
2780 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2781 h
= GetSystemMetrics(SM_CYSCREEN
);
2782 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2784 ddraw2
= create_ddraw();
2785 hr
= set_display_mode(ddraw2
, 640, 480);
2786 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2787 w
= GetSystemMetrics(SM_CXSCREEN
);
2788 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2789 h
= GetSystemMetrics(SM_CYSCREEN
);
2790 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2792 ref
= IDirectDraw7_Release(ddraw1
);
2793 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2794 w
= GetSystemMetrics(SM_CXSCREEN
);
2795 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2796 h
= GetSystemMetrics(SM_CYSCREEN
);
2797 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2799 ref
= IDirectDraw7_Release(ddraw2
);
2800 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2801 w
= GetSystemMetrics(SM_CXSCREEN
);
2802 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2803 h
= GetSystemMetrics(SM_CYSCREEN
);
2804 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2806 /* But only for ddraw objects that called SetDisplayMode(). */
2807 ddraw1
= create_ddraw();
2808 ddraw2
= create_ddraw();
2809 hr
= set_display_mode(ddraw2
, 640, 480);
2810 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2811 w
= GetSystemMetrics(SM_CXSCREEN
);
2812 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2813 h
= GetSystemMetrics(SM_CYSCREEN
);
2814 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2816 ref
= IDirectDraw7_Release(ddraw1
);
2817 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2818 w
= GetSystemMetrics(SM_CXSCREEN
);
2819 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2820 h
= GetSystemMetrics(SM_CYSCREEN
);
2821 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2823 ref
= IDirectDraw7_Release(ddraw2
);
2824 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2825 w
= GetSystemMetrics(SM_CXSCREEN
);
2826 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2827 h
= GetSystemMetrics(SM_CYSCREEN
);
2828 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2830 /* If there's a ddraw object that's currently in exclusive mode, it blocks
2831 * restoring the display mode. */
2832 ddraw1
= create_ddraw();
2833 hr
= set_display_mode(ddraw1
, 800, 600);
2834 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2835 w
= GetSystemMetrics(SM_CXSCREEN
);
2836 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2837 h
= GetSystemMetrics(SM_CYSCREEN
);
2838 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2840 ddraw2
= create_ddraw();
2841 hr
= set_display_mode(ddraw2
, 640, 480);
2842 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2843 w
= GetSystemMetrics(SM_CXSCREEN
);
2844 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2845 h
= GetSystemMetrics(SM_CYSCREEN
);
2846 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2848 hr
= IDirectDraw7_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2849 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2851 ref
= IDirectDraw7_Release(ddraw1
);
2852 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2853 w
= GetSystemMetrics(SM_CXSCREEN
);
2854 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
2855 h
= GetSystemMetrics(SM_CYSCREEN
);
2856 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
2858 ref
= IDirectDraw7_Release(ddraw2
);
2859 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2860 w
= GetSystemMetrics(SM_CXSCREEN
);
2861 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2862 h
= GetSystemMetrics(SM_CYSCREEN
);
2863 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2865 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
2866 ddraw1
= create_ddraw();
2867 hr
= set_display_mode(ddraw1
, 800, 600);
2868 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2869 w
= GetSystemMetrics(SM_CXSCREEN
);
2870 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
2871 h
= GetSystemMetrics(SM_CYSCREEN
);
2872 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
2874 hr
= IDirectDraw7_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2875 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2877 ddraw2
= create_ddraw();
2878 hr
= set_display_mode(ddraw2
, 640, 480);
2879 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
2881 ref
= IDirectDraw7_Release(ddraw1
);
2882 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2883 w
= GetSystemMetrics(SM_CXSCREEN
);
2884 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2885 h
= GetSystemMetrics(SM_CYSCREEN
);
2886 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2888 ref
= IDirectDraw7_Release(ddraw2
);
2889 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2890 w
= GetSystemMetrics(SM_CXSCREEN
);
2891 ok(w
== orig_w
, "Got unexpected screen width %u.\n", w
);
2892 h
= GetSystemMetrics(SM_CYSCREEN
);
2893 ok(h
== orig_h
, "Got unexpected screen height %u.\n", h
);
2895 DestroyWindow(window
);
2898 static void test_initialize(void)
2900 IDirectDraw7
*ddraw
;
2903 ddraw
= create_ddraw();
2904 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2906 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
2907 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
2908 IDirectDraw7_Release(ddraw
);
2911 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw7
, (void **)&ddraw
);
2912 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr
);
2913 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
2914 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
2915 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
2916 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
2917 IDirectDraw7_Release(ddraw
);
2921 static void test_coop_level_surf_create(void)
2923 IDirectDrawSurface7
*surface
;
2924 IDirectDraw7
*ddraw
;
2925 DDSURFACEDESC2 ddsd
;
2928 ddraw
= create_ddraw();
2929 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2931 memset(&ddsd
, 0, sizeof(ddsd
));
2932 ddsd
.dwSize
= sizeof(ddsd
);
2933 ddsd
.dwFlags
= DDSD_CAPS
;
2934 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2935 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
2936 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
2938 IDirectDraw7_Release(ddraw
);
2941 static void test_vb_discard(void)
2943 static const struct vec4 quad
[] =
2945 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
2946 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
2947 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
2948 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
2951 IDirect3DDevice7
*device
;
2953 IDirect3DVertexBuffer7
*buffer
;
2956 D3DVERTEXBUFFERDESC desc
;
2958 static const unsigned int vbsize
= 16;
2961 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2962 0, 0, 640, 480, 0, 0, 0, 0);
2964 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
2966 skip("Failed to create a 3D device, skipping test.\n");
2967 DestroyWindow(window
);
2971 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
2972 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
2974 memset(&desc
, 0, sizeof(desc
));
2975 desc
.dwSize
= sizeof(desc
);
2976 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
2977 desc
.dwFVF
= D3DFVF_XYZRHW
;
2978 desc
.dwNumVertices
= vbsize
;
2979 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
2980 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
2982 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
2983 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
2984 memcpy(data
, quad
, sizeof(quad
));
2985 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
2986 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
2988 hr
= IDirect3DDevice7_BeginScene(device
);
2989 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2990 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
2991 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2992 hr
= IDirect3DDevice7_EndScene(device
);
2993 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2995 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
2996 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
2997 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
2998 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
2999 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3001 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3002 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3003 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3005 if (data
[i
] != 0xaa)
3007 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3011 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3012 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3014 IDirect3DVertexBuffer7_Release(buffer
);
3015 IDirect3D7_Release(d3d
);
3016 IDirect3DDevice7_Release(device
);
3017 DestroyWindow(window
);
3020 static void test_coop_level_multi_window(void)
3022 HWND window1
, window2
;
3023 IDirectDraw7
*ddraw
;
3026 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3027 0, 0, 640, 480, 0, 0, 0, 0);
3028 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3029 0, 0, 640, 480, 0, 0, 0, 0);
3030 ddraw
= create_ddraw();
3031 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3033 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3034 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3035 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3036 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3037 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3038 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3040 IDirectDraw7_Release(ddraw
);
3041 DestroyWindow(window2
);
3042 DestroyWindow(window1
);
3045 static void test_draw_strided(void)
3047 static struct vec3 position
[] =
3054 static DWORD diffuse
[] =
3056 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3058 static WORD indices
[] =
3063 IDirectDrawSurface7
*rt
;
3064 IDirect3DDevice7
*device
;
3068 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3070 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3071 0, 0, 640, 480, 0, 0, 0, 0);
3073 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3075 skip("Failed to create a 3D device, skipping test.\n");
3076 DestroyWindow(window
);
3080 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3081 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3083 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3084 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3085 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 1.0f
, 0);
3086 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3087 hr
= IDirect3DDevice7_BeginScene(device
);
3088 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3090 memset(&strided
, 0x55, sizeof(strided
));
3091 strided
.position
.lpvData
= position
;
3092 strided
.position
.dwStride
= sizeof(*position
);
3093 strided
.diffuse
.lpvData
= diffuse
;
3094 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3095 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3096 &strided
, 4, indices
, 6, 0);
3097 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3099 hr
= IDirect3DDevice7_EndScene(device
);
3100 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3102 color
= get_surface_color(rt
, 320, 240);
3103 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3105 IDirectDrawSurface7_Release(rt
);
3106 IDirect3DDevice7_Release(device
);
3107 DestroyWindow(window
);
3110 static void test_clear_rect_count(void)
3112 IDirectDrawSurface7
*rt
;
3113 IDirect3DDevice7
*device
;
3117 D3DRECT rect
= {{0}, {0}, {640}, {480}};
3119 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3120 0, 0, 640, 480, 0, 0, 0, 0);
3121 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3123 skip("Failed to create a 3D device, skipping test.\n");
3124 DestroyWindow(window
);
3128 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3129 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3131 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
3132 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3133 hr
= IDirect3DDevice7_Clear(device
, 0, &rect
, D3DCLEAR_TARGET
, 0x00ff0000, 1.0f
, 0);
3134 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3136 color
= get_surface_color(rt
, 320, 240);
3137 ok(compare_color(color
, 0x00ffffff, 1),
3138 "Clear with count = 0, rect != NULL has color %#08x.\n", color
);
3140 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
3141 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3142 hr
= IDirect3DDevice7_Clear(device
, 1, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
3143 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3145 color
= get_surface_color(rt
, 320, 240);
3146 ok(compare_color(color
, 0x0000ff00, 1),
3147 "Clear with count = 1, rect = NULL has color %#08x.\n", color
);
3149 IDirectDrawSurface7_Release(rt
);
3150 IDirect3DDevice7_Release(device
);
3151 DestroyWindow(window
);
3154 static BOOL
test_mode_restored(IDirectDraw7
*ddraw
, HWND window
)
3156 DDSURFACEDESC2 ddsd1
, ddsd2
;
3159 memset(&ddsd1
, 0, sizeof(ddsd1
));
3160 ddsd1
.dwSize
= sizeof(ddsd1
);
3161 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd1
);
3162 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3164 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3165 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3166 hr
= set_display_mode(ddraw
, 640, 480);
3167 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3168 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3169 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3171 memset(&ddsd2
, 0, sizeof(ddsd2
));
3172 ddsd2
.dwSize
= sizeof(ddsd2
);
3173 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd2
);
3174 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
3175 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
3176 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3178 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
3181 static void test_coop_level_versions(void)
3187 IDirectDrawSurface
*surface
;
3188 IDirectDraw7
*ddraw7
;
3191 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3192 0, 0, 640, 480, 0, 0, 0, 0);
3194 ddraw7
= create_ddraw();
3195 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
3196 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
3197 restored
= test_mode_restored(ddraw7
, window
);
3198 ok(restored
, "Display mode not restored in new ddraw object\n");
3200 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
3201 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
3202 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3204 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3205 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3206 restored
= test_mode_restored(ddraw7
, window
);
3207 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
3209 /* A successful one does */
3210 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3211 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3212 restored
= test_mode_restored(ddraw7
, window
);
3213 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
3215 IDirectDraw_Release(ddraw
);
3216 IDirectDraw7_Release(ddraw7
);
3218 ddraw7
= create_ddraw();
3219 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
3220 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
3221 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3223 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
3224 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3225 restored
= test_mode_restored(ddraw7
, window
);
3226 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
3228 IDirectDraw_Release(ddraw
);
3229 IDirectDraw7_Release(ddraw7
);
3231 /* A failing call does not restore the ddraw2+ behavior */
3232 ddraw7
= create_ddraw();
3233 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
3234 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
3235 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3237 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3238 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3239 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3240 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
3241 restored
= test_mode_restored(ddraw7
, window
);
3242 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
3244 IDirectDraw_Release(ddraw
);
3245 IDirectDraw7_Release(ddraw7
);
3247 /* Neither does a sequence of successful calls with the new interface */
3248 ddraw7
= create_ddraw();
3249 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
3250 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
3251 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3253 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3254 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3255 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
3256 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3257 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
3258 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3260 restored
= test_mode_restored(ddraw7
, window
);
3261 ok(!restored
, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
3262 IDirectDraw_Release(ddraw
);
3263 IDirectDraw7_Release(ddraw7
);
3265 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
3266 ddraw7
= create_ddraw();
3267 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
3268 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
3269 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
3271 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
3272 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3274 memset(&ddsd
, 0, sizeof(ddsd
));
3275 ddsd
.dwSize
= sizeof(ddsd
);
3276 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3277 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
3278 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
3279 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3280 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
3281 IDirectDrawSurface_Release(surface
);
3282 restored
= test_mode_restored(ddraw7
, window
);
3283 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
3285 IDirectDraw_Release(ddraw
);
3286 IDirectDraw7_Release(ddraw7
);
3287 DestroyWindow(window
);
3290 static void test_fog_special(void)
3294 struct vec3 position
;
3299 {{ -1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
3300 {{ 1.0f
, 1.0f
, 1.0f
}, 0xff00ff00},
3301 {{ -1.0f
, -1.0f
, 0.0f
}, 0xff00ff00},
3302 {{ 1.0f
, -1.0f
, 1.0f
}, 0xff00ff00},
3306 DWORD vertexmode
, tablemode
;
3307 D3DCOLOR color_left
, color_right
;
3311 {D3DFOG_LINEAR
, D3DFOG_NONE
, 0x00ff0000, 0x00ff0000},
3312 {D3DFOG_NONE
, D3DFOG_LINEAR
, 0x0000ff00, 0x00ff0000},
3323 IDirect3DDevice7
*device
;
3324 IDirectDrawSurface7
*rt
;
3326 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3327 0, 0, 640, 480, 0, 0, 0, 0);
3329 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3331 skip("Failed to create a 3D device, skipping test.\n");
3332 DestroyWindow(window
);
3336 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3337 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3339 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
3340 ok(SUCCEEDED(hr
), "Failed to enable fog, hr %#x.\n", hr
);
3341 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xffff0000);
3342 ok(SUCCEEDED(hr
), "Failed to set fog color, hr %#x.\n", hr
);
3343 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3344 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3345 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3346 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3349 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, conv
.d
);
3350 ok(SUCCEEDED(hr
), "Failed to set fog start, hr %#x.\n", hr
);
3351 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, conv
.d
);
3352 ok(SUCCEEDED(hr
), "Failed to set fog end, hr %#x.\n", hr
);
3354 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3356 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 1.0f
, 0);
3357 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3359 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vertexmode
);
3360 ok(SUCCEEDED(hr
), "Failed to set fogvertexmode, hr %#x.\n", hr
);
3361 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tablemode
);
3362 ok(SUCCEEDED(hr
), "Failed to set fogtablemode, hr %#x.\n", hr
);
3364 hr
= IDirect3DDevice7_BeginScene(device
);
3365 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3366 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad
, 4, 0);
3367 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3368 hr
= IDirect3DDevice7_EndScene(device
);
3369 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3371 color
= get_surface_color(rt
, 310, 240);
3372 ok(compare_color(color
, tests
[i
].color_left
, 1),
3373 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_left
, color
, i
);
3374 color
= get_surface_color(rt
, 330, 240);
3375 ok(compare_color(color
, tests
[i
].color_right
, 1),
3376 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_right
, color
, i
);
3379 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3380 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3382 IDirectDrawSurface7_Release(rt
);
3383 IDirect3DDevice7_Release(device
);
3384 DestroyWindow(window
);
3387 static void test_lighting_interface_versions(void)
3389 IDirect3DDevice7
*device
;
3390 IDirectDrawSurface7
*rt
;
3397 D3DMATERIAL7 material
;
3398 static D3DVERTEX quad
[] =
3400 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3401 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3402 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3403 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
3406 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
3409 struct vec3 position
;
3411 DWORD diffuse
, specular
;
3415 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3416 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3417 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3418 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3421 static D3DLVERTEX lquad
[] =
3423 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3424 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3425 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3426 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
3429 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
3432 struct vec3 position
;
3433 DWORD diffuse
, specular
;
3434 struct vec2 texcoord
;
3438 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3439 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3440 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3441 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
3444 static D3DTLVERTEX tlquad
[] =
3446 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3447 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3448 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3449 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
3456 DWORD d3drs_lighting
, d3drs_specular
;
3462 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
3463 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
3466 * Note that the specular result is 0x00000000 when lighting is on even if the
3467 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
3471 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x00ffffff},
3472 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
3473 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3474 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3475 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x00ffffff},
3476 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
3477 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
3478 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3481 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x00ff0000},
3482 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
3483 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3484 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3485 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x00ff8080},
3486 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
3487 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3488 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3491 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
3492 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x0000ff00},
3493 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3494 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3495 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
3496 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x0000ff00},
3497 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3498 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3501 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
3502 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x0000ff00},
3503 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
3504 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3505 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
3506 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x0000ff00},
3507 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
3508 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
3511 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
3512 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
3513 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3514 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
3515 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
3516 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
3517 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3518 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
3521 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3522 0, 0, 640, 480, 0, 0, 0, 0);
3524 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3526 skip("Failed to create a 3D device, skipping test.\n");
3527 DestroyWindow(window
);
3531 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3532 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3534 memset(&material
, 0, sizeof(material
));
3535 U2(U3(material
).emissive
).g
= 1.0f
;
3536 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
3537 ok(SUCCEEDED(hr
), "Failed set material, hr %#x.\n", hr
);
3538 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
3539 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
3541 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
3542 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
3543 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs
);
3544 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
3545 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
3546 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
3548 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3550 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
3551 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3553 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
3554 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
3555 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
3556 tests
[i
].d3drs_specular
);
3557 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
3559 hr
= IDirect3DDevice7_BeginScene(device
);
3560 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3561 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
3562 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
3563 hr
= IDirect3DDevice7_EndScene(device
);
3564 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3566 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
3567 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
3568 ok(rs
== tests
[i
].d3drs_lighting
, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
3569 rs
, tests
[i
].d3drs_lighting
);
3571 color
= get_surface_color(rt
, 320, 240);
3572 ok(compare_color(color
, tests
[i
].color
, 1),
3573 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
3574 color
, tests
[i
].color
, i
);
3577 IDirectDrawSurface7_Release(rt
);
3578 ref
= IDirect3DDevice7_Release(device
);
3579 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
3580 DestroyWindow(window
);
3586 IDirectDraw7
*ddraw
;
3589 } activateapp_testdata
;
3591 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3593 if (message
== WM_ACTIVATEAPP
)
3595 if (activateapp_testdata
.ddraw
)
3598 activateapp_testdata
.received
= FALSE
;
3599 hr
= IDirectDraw7_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3600 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3601 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3602 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3604 activateapp_testdata
.received
= TRUE
;
3607 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3610 static void test_coop_level_activateapp(void)
3612 IDirectDraw7
*ddraw
;
3616 DDSURFACEDESC2 ddsd
;
3617 IDirectDrawSurface7
*surface
;
3619 ddraw
= create_ddraw();
3620 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3622 wc
.lpfnWndProc
= activateapp_test_proc
;
3623 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3624 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3626 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3627 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3629 /* Exclusive with window already active. */
3630 SetActiveWindow(window
);
3631 activateapp_testdata
.received
= FALSE
;
3632 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3633 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3634 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3635 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3636 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3638 /* Exclusive with window not active. */
3639 SetActiveWindow(NULL
);
3640 activateapp_testdata
.received
= FALSE
;
3641 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3642 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3643 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3644 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3645 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3647 /* Normal with window not active, then exclusive with the same window. */
3648 SetActiveWindow(NULL
);
3649 activateapp_testdata
.received
= FALSE
;
3650 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3651 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3652 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3653 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3654 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3655 /* Except in the first SetCooperativeLevel call, Windows XP randomly does not send
3656 * WM_ACTIVATEAPP. Windows 7 sends the message reliably. Mark the XP behavior broken. */
3657 ok(activateapp_testdata
.received
|| broken(!activateapp_testdata
.received
),
3658 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3659 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3660 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3662 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3663 SetActiveWindow(NULL
);
3664 activateapp_testdata
.received
= FALSE
;
3665 activateapp_testdata
.ddraw
= ddraw
;
3666 activateapp_testdata
.window
= window
;
3667 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3668 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3669 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3670 ok(activateapp_testdata
.received
|| broken(!activateapp_testdata
.received
),
3671 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3672 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3673 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3675 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3676 * succeeding. Another switch to exclusive and back to normal is needed to release the
3677 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3678 * WM_ACTIVATEAPP messages. */
3679 activateapp_testdata
.ddraw
= NULL
;
3680 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3681 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3682 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3683 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3685 /* Setting DDSCL_NORMAL with recursive invocation. */
3686 SetActiveWindow(NULL
);
3687 activateapp_testdata
.received
= FALSE
;
3688 activateapp_testdata
.ddraw
= ddraw
;
3689 activateapp_testdata
.window
= window
;
3690 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3691 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3692 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3693 ok(activateapp_testdata
.received
|| broken(!activateapp_testdata
.received
),
3694 "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3696 /* DDraw is in exlusive mode now. */
3697 memset(&ddsd
, 0, sizeof(ddsd
));
3698 ddsd
.dwSize
= sizeof(ddsd
);
3699 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
3700 ddsd
.dwBackBufferCount
= 1;
3701 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
3702 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3703 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3704 IDirectDrawSurface7_Release(surface
);
3706 /* Recover again, just to be sure. */
3707 activateapp_testdata
.ddraw
= NULL
;
3708 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3709 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3710 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3711 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3713 DestroyWindow(window
);
3714 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3715 IDirectDraw7_Release(ddraw
);
3718 static void test_texturemanage(void)
3720 IDirectDraw7
*ddraw
;
3722 DDSURFACEDESC2 ddsd
;
3723 IDirectDrawSurface7
*surface
;
3725 DDCAPS hal_caps
, hel_caps
;
3726 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
3729 DWORD caps_in
, caps2_in
;
3731 DWORD caps_out
, caps2_out
;
3735 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3737 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3739 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3741 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3743 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
3744 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
3745 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
3746 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
3747 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
3748 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
3749 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
3750 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
3752 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3754 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3756 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3758 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3760 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3762 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
3764 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
3765 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
3766 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
3767 DDSCAPS_SYSTEMMEMORY
, 0},
3770 ddraw
= create_ddraw();
3771 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3772 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3773 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3775 memset(&hal_caps
, 0, sizeof(hal_caps
));
3776 hal_caps
.dwSize
= sizeof(hal_caps
);
3777 memset(&hel_caps
, 0, sizeof(hel_caps
));
3778 hel_caps
.dwSize
= sizeof(hel_caps
);
3779 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
3780 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
3781 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
3783 skip("Managed textures not supported, skipping managed texture test.\n");
3784 IDirectDraw7_Release(ddraw
);
3788 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
3790 memset(&ddsd
, 0, sizeof(ddsd
));
3791 ddsd
.dwSize
= sizeof(ddsd
);
3792 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
3793 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
3794 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
3798 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3799 ok(hr
== tests
[i
].hr
, "Got unexpected, hr %#x, case %u.\n", hr
, i
);
3803 memset(&ddsd
, 0, sizeof(ddsd
));
3804 ddsd
.dwSize
= sizeof(ddsd
);
3805 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
3806 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3808 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
3809 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
3810 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
3811 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
3812 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
3813 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
3815 IDirectDrawSurface7_Release(surface
);
3818 IDirectDraw7_Release(ddraw
);
3821 #define SUPPORT_DXT1 0x01
3822 #define SUPPORT_DXT2 0x02
3823 #define SUPPORT_DXT3 0x04
3824 #define SUPPORT_DXT4 0x08
3825 #define SUPPORT_DXT5 0x10
3826 #define SUPPORT_YUY2 0x20
3827 #define SUPPORT_UYVY 0x40
3829 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
3831 DWORD
*supported_fmts
= ctx
;
3833 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
3834 return DDENUMRET_OK
;
3836 switch (fmt
->dwFourCC
)
3838 case MAKEFOURCC('D','X','T','1'):
3839 *supported_fmts
|= SUPPORT_DXT1
;
3841 case MAKEFOURCC('D','X','T','2'):
3842 *supported_fmts
|= SUPPORT_DXT2
;
3844 case MAKEFOURCC('D','X','T','3'):
3845 *supported_fmts
|= SUPPORT_DXT3
;
3847 case MAKEFOURCC('D','X','T','4'):
3848 *supported_fmts
|= SUPPORT_DXT4
;
3850 case MAKEFOURCC('D','X','T','5'):
3851 *supported_fmts
|= SUPPORT_DXT5
;
3853 case MAKEFOURCC('Y','U','Y','2'):
3854 *supported_fmts
|= SUPPORT_YUY2
;
3856 case MAKEFOURCC('U','Y','V','Y'):
3857 *supported_fmts
|= SUPPORT_UYVY
;
3863 return DDENUMRET_OK
;
3866 static void test_block_formats_creation(void)
3868 HRESULT hr
, expect_hr
;
3869 unsigned int i
, j
, w
, h
;
3871 IDirectDraw7
*ddraw
;
3873 IDirect3DDevice7
*device
;
3874 IDirectDrawSurface7
*surface
;
3875 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
3876 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
3877 DDSURFACEDESC2 ddsd
;
3885 unsigned int block_width
;
3886 unsigned int block_height
;
3887 BOOL create_size_checked
, overlay
;
3891 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, TRUE
, FALSE
},
3892 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, TRUE
, FALSE
},
3893 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, TRUE
, FALSE
},
3894 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, TRUE
, FALSE
},
3895 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, TRUE
, FALSE
},
3896 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, FALSE
, TRUE
},
3897 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, FALSE
, TRUE
},
3907 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
3908 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
3910 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
3911 * Other hw / drivers successfully create those surfaces. Ignore them, this
3912 * suggests that no game uses this, otherwise Nvidia would support it. */
3914 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
3915 "videomemory texture", FALSE
3918 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
3919 "videomemory overlay", TRUE
3922 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
3923 "systemmemory texture", FALSE
3926 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
3927 "managed texture", FALSE
3931 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3932 0, 0, 640, 480, 0, 0, 0, 0);
3934 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3936 skip("Failed to create a 3D device, skipping test.\n");
3937 DestroyWindow(window
);
3941 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
3942 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3943 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
3944 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
3945 IDirect3D7_Release(d3d
);
3947 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
,
3949 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
3951 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
3952 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
3953 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3954 num_fourcc_codes
* sizeof(*fourcc_codes
));
3957 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
3958 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
3959 for (i
= 0; i
< num_fourcc_codes
; i
++)
3961 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
3963 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
3964 supported_overlay_fmts
|= formats
[j
].support_flag
;
3967 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
3969 memset(&hal_caps
, 0, sizeof(hal_caps
));
3970 hal_caps
.dwSize
= sizeof(hal_caps
);
3971 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
3972 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
3974 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
3976 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
3980 if (formats
[i
].overlay
!= types
[j
].overlay
3981 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
3984 if (formats
[i
].overlay
)
3985 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
3987 support
= supported_fmts
& formats
[i
].support_flag
;
3989 for (w
= 1; w
<= 8; w
++)
3991 for (h
= 1; h
<= 8; h
++)
3993 BOOL block_aligned
= TRUE
;
3996 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
3997 block_aligned
= FALSE
;
3999 memset(&ddsd
, 0, sizeof(ddsd
));
4000 ddsd
.dwSize
= sizeof(ddsd
);
4001 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4002 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
4003 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
4004 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
4005 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
4006 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
4010 /* TODO: Handle power of two limitations. I cannot test the pow2
4011 * behavior on windows because I have no hardware that doesn't at
4012 * least support np2_conditional. There's probably no HW that
4013 * supports DXTN textures but no conditional np2 textures. */
4014 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
4015 expect_hr
= DDERR_INVALIDPARAMS
;
4016 else if (formats
[i
].create_size_checked
&& !block_aligned
)
4018 expect_hr
= DDERR_INVALIDPARAMS
;
4019 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
4025 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4027 todo_wine
ok(hr
== expect_hr
,
4028 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4029 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4032 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4033 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4036 IDirectDrawSurface7_Release(surface
);
4043 IDirectDraw7_Release(ddraw
);
4044 IDirect3DDevice7_Release(device
);
4045 DestroyWindow(window
);
4048 struct format_support_check
4050 const DDPIXELFORMAT
*format
;
4054 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4056 struct format_support_check
*format
= ctx
;
4058 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
4060 format
->supported
= TRUE
;
4061 return DDENUMRET_CANCEL
;
4064 return DDENUMRET_OK
;
4067 static void test_unsupported_formats(void)
4070 BOOL expect_success
;
4072 IDirectDraw7
*ddraw
;
4074 IDirect3DDevice7
*device
;
4075 IDirectDrawSurface7
*surface
;
4076 DDSURFACEDESC2 ddsd
;
4078 DWORD expected_caps
;
4089 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
4090 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
4096 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4097 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
4101 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
4103 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4104 0, 0, 640, 480, 0, 0, 0, 0);
4106 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4108 skip("Failed to create a 3D device, skipping test.\n");
4109 DestroyWindow(window
);
4113 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
4114 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4115 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
4116 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4117 IDirect3D7_Release(d3d
);
4119 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4121 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
4122 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
4123 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4125 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
4127 memset(&ddsd
, 0, sizeof(ddsd
));
4128 ddsd
.dwSize
= sizeof(ddsd
);
4129 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4130 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
4133 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
4135 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
4136 expect_success
= FALSE
;
4138 expect_success
= TRUE
;
4140 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4141 ok(SUCCEEDED(hr
) == expect_success
,
4142 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
4143 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
4147 memset(&ddsd
, 0, sizeof(ddsd
));
4148 ddsd
.dwSize
= sizeof(ddsd
);
4149 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
4150 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4152 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
4153 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4154 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
4155 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4156 else if (check
.supported
)
4157 expected_caps
= DDSCAPS_VIDEOMEMORY
;
4159 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
4161 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
4162 "Expected capability %#x, format %s, input cap %#x.\n",
4163 expected_caps
, formats
[i
].name
, caps
[j
]);
4165 IDirectDrawSurface7_Release(surface
);
4169 IDirectDraw7_Release(ddraw
);
4170 IDirect3DDevice7_Release(device
);
4171 DestroyWindow(window
);
4174 static void test_rt_caps(void)
4176 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
4177 PALETTEENTRY palette_entries
[256];
4178 IDirectDrawPalette
*palette
;
4179 IDirectDraw7
*ddraw
;
4180 BOOL hal_ok
= FALSE
;
4181 DDPIXELFORMAT z_fmt
;
4188 static const DDPIXELFORMAT p8_fmt
=
4190 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
4191 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
4196 const DDPIXELFORMAT
*pf
;
4199 HRESULT create_device_hr
;
4200 HRESULT set_rt_hr
, alternative_set_rt_hr
;
4206 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4207 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4214 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4215 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4222 DDSCAPS_OFFSCREENPLAIN
,
4223 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4230 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4231 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4232 D3DERR_SURFACENOTINVIDMEM
,
4233 DDERR_INVALIDPARAMS
,
4238 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4239 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4246 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
4247 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4255 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4263 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4270 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4271 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4272 D3DERR_SURFACENOTINVIDMEM
,
4273 DDERR_INVALIDPARAMS
,
4278 DDSCAPS_SYSTEMMEMORY
,
4279 DDSCAPS_SYSTEMMEMORY
,
4287 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4294 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4296 DDERR_NOPALETTEATTACHED
,
4302 DDSCAPS_OFFSCREENPLAIN
,
4303 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
4310 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4311 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
4312 DDERR_NOPALETTEATTACHED
,
4318 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4319 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4326 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
4327 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4329 DDERR_INVALIDPIXELFORMAT
,
4330 DDERR_INVALIDPIXELFORMAT
,
4334 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4335 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4337 DDERR_INVALIDPIXELFORMAT
,
4338 DDERR_INVALIDPIXELFORMAT
,
4343 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
4350 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4351 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
4353 DDERR_INVALIDPARAMS
,
4354 DDERR_INVALIDPIXELFORMAT
,
4358 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4359 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
4366 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4367 0, 0, 640, 480, 0, 0, 0, 0);
4368 ddraw
= create_ddraw();
4369 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4370 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4371 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4373 if (FAILED(hr
= IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
4375 skip("D3D interface is not available, skipping test.\n");
4379 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
4380 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
4382 devtype
= &IID_IDirect3DTnLHalDevice
;
4384 memset(&z_fmt
, 0, sizeof(z_fmt
));
4385 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
4386 if (FAILED(hr
) || !z_fmt
.dwSize
)
4388 skip("No depth buffer formats available, skipping test.\n");
4389 IDirect3D7_Release(d3d
);
4393 memset(palette_entries
, 0, sizeof(palette_entries
));
4394 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
4395 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4397 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4399 IDirectDrawSurface7
*surface
, *rt
, *expected_rt
, *tmp
;
4400 DDSURFACEDESC2 surface_desc
;
4401 IDirect3DDevice7
*device
;
4403 memset(&surface_desc
, 0, sizeof(surface_desc
));
4404 surface_desc
.dwSize
= sizeof(surface_desc
);
4405 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4406 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4407 if (test_data
[i
].pf
)
4409 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4410 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
4412 surface_desc
.dwWidth
= 640;
4413 surface_desc
.dwHeight
= 480;
4414 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4415 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4416 i
, test_data
[i
].caps_in
, hr
);
4418 memset(&surface_desc
, 0, sizeof(surface_desc
));
4419 surface_desc
.dwSize
= sizeof(surface_desc
);
4420 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
4421 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4422 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
4423 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4424 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4426 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
4427 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
4428 i
, hr
, test_data
[i
].create_device_hr
);
4431 if (hr
== DDERR_NOPALETTEATTACHED
)
4433 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
4434 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
4435 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
4436 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
4437 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4439 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4441 IDirectDrawSurface7_Release(surface
);
4443 memset(&surface_desc
, 0, sizeof(surface_desc
));
4444 surface_desc
.dwSize
= sizeof(surface_desc
);
4445 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4446 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4447 surface_desc
.dwWidth
= 640;
4448 surface_desc
.dwHeight
= 480;
4449 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4450 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
4452 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
4453 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
4456 memset(&surface_desc
, 0, sizeof(surface_desc
));
4457 surface_desc
.dwSize
= sizeof(surface_desc
);
4458 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4459 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4460 if (test_data
[i
].pf
)
4462 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
4463 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
4465 surface_desc
.dwWidth
= 640;
4466 surface_desc
.dwHeight
= 480;
4467 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
4468 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
4469 i
, test_data
[i
].caps_in
, hr
);
4471 hr
= IDirect3DDevice7_SetRenderTarget(device
, rt
, 0);
4472 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
4473 "Test %u: Got unexpected hr %#x, expected %#x.\n",
4474 i
, hr
, test_data
[i
].set_rt_hr
);
4475 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
4478 expected_rt
= surface
;
4480 hr
= IDirect3DDevice7_GetRenderTarget(device
, &tmp
);
4481 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
4482 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
4484 IDirectDrawSurface7_Release(tmp
);
4485 IDirectDrawSurface7_Release(rt
);
4486 refcount
= IDirect3DDevice7_Release(device
);
4487 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
4488 refcount
= IDirectDrawSurface7_Release(surface
);
4489 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
4492 IDirectDrawPalette_Release(palette
);
4493 IDirect3D7_Release(d3d
);
4496 refcount
= IDirectDraw7_Release(ddraw
);
4497 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4498 DestroyWindow(window
);
4501 static void test_primary_caps(void)
4503 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4504 IDirectDrawSurface7
*surface
;
4505 DDSURFACEDESC2 surface_desc
;
4506 IDirectDraw7
*ddraw
;
4516 DWORD back_buffer_count
;
4524 DDSCAPS_PRIMARYSURFACE
,
4527 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
4531 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
4538 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
4545 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
4552 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
4559 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
4566 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4573 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4580 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4582 DDERR_NOEXCLUSIVEMODE
,
4586 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4587 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4593 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4594 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
4597 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
4600 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4601 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
4607 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
4608 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
4615 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4616 0, 0, 640, 480, 0, 0, 0, 0);
4617 ddraw
= create_ddraw();
4618 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4620 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4622 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
4623 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4625 memset(&surface_desc
, 0, sizeof(surface_desc
));
4626 surface_desc
.dwSize
= sizeof(surface_desc
);
4627 surface_desc
.dwFlags
= DDSD_CAPS
;
4628 if (test_data
[i
].back_buffer_count
!= ~0u)
4629 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4630 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
4631 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
4632 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4633 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
4637 memset(&surface_desc
, 0, sizeof(surface_desc
));
4638 surface_desc
.dwSize
= sizeof(surface_desc
);
4639 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
4640 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
4641 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
4642 "Test %u: Got unexpected caps %#x, expected %#x.\n",
4643 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
4645 IDirectDrawSurface7_Release(surface
);
4648 refcount
= IDirectDraw7_Release(ddraw
);
4649 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4650 DestroyWindow(window
);
4653 static void test_surface_lock(void)
4655 IDirectDraw7
*ddraw
;
4656 IDirect3D7
*d3d
= NULL
;
4657 IDirectDrawSurface7
*surface
;
4658 IDirect3DDevice7
*device
;
4662 DDSURFACEDESC2 ddsd
;
4664 DDPIXELFORMAT z_fmt
;
4665 BOOL hal_ok
= FALSE
;
4666 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
4667 D3DDEVICEDESC7 device_desc
;
4668 BOOL cubemap_supported
;
4678 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
4680 "videomemory offscreenplain"
4683 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4685 "systemmemory offscreenplain"
4688 DDSCAPS_PRIMARYSURFACE
,
4693 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4695 "videomemory texture"
4698 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4700 "opaque videomemory texture"
4703 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4705 "systemmemory texture"
4709 DDSCAPS2_TEXTUREMANAGE
,
4714 DDSCAPS2_D3DTEXTUREMANAGE
,
4719 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
4720 "opaque managed texture"
4724 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
4725 "opaque managed texture"
4728 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4738 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
4739 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
4743 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
4744 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
4745 "opaque videomemory cube"
4748 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_SYSTEMMEMORY
,
4749 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
4753 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
4754 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
4758 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
4759 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
4763 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
4764 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
4765 "opaque managed cube"
4768 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
4769 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
4770 "opaque managed cube"
4774 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4775 0, 0, 640, 480, 0, 0, 0, 0);
4776 ddraw
= create_ddraw();
4777 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4778 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4779 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4781 if (FAILED(hr
= IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
4783 skip("D3D interface is not available, skipping test.\n");
4787 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
4788 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
4790 devtype
= &IID_IDirect3DTnLHalDevice
;
4792 memset(&z_fmt
, 0, sizeof(z_fmt
));
4793 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
4794 if (FAILED(hr
) || !z_fmt
.dwSize
)
4796 skip("No depth buffer formats available, skipping test.\n");
4800 memset(&ddsd
, 0, sizeof(ddsd
));
4801 ddsd
.dwSize
= sizeof(ddsd
);
4802 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4805 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4806 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4807 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4809 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
4810 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x.\n", hr
);
4811 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
4812 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4813 cubemap_supported
= !!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
);
4814 IDirect3DDevice7_Release(device
);
4816 IDirectDrawSurface7_Release(surface
);
4818 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4820 if (!cubemap_supported
&& tests
[i
].caps2
& DDSCAPS2_CUBEMAP
)
4823 memset(&ddsd
, 0, sizeof(ddsd
));
4824 ddsd
.dwSize
= sizeof(ddsd
);
4825 ddsd
.dwFlags
= DDSD_CAPS
;
4826 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4828 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4832 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4834 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
4835 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
4837 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4838 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
4840 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4841 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4843 memset(&ddsd
, 0, sizeof(ddsd
));
4844 ddsd
.dwSize
= sizeof(ddsd
);
4845 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4846 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4849 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
4850 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4853 IDirectDrawSurface7_Release(surface
);
4858 IDirect3D7_Release(d3d
);
4859 refcount
= IDirectDraw7_Release(ddraw
);
4860 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4861 DestroyWindow(window
);
4864 static void test_surface_discard(void)
4866 IDirect3DDevice7
*device
;
4868 IDirectDraw7
*ddraw
;
4871 DDSURFACEDESC2 ddsd
;
4872 IDirectDrawSurface7
*surface
, *target
;
4881 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
4882 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
4883 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
4884 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
4885 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
4886 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
4887 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
4888 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
4892 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4893 0, 0, 640, 480, 0, 0, 0, 0);
4895 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4897 skip("Failed to create a 3D device, skipping test.\n");
4898 DestroyWindow(window
);
4901 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
4902 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4903 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
4904 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4905 hr
= IDirect3DDevice7_GetRenderTarget(device
, &target
);
4906 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4908 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4912 memset(&ddsd
, 0, sizeof(ddsd
));
4913 ddsd
.dwSize
= sizeof(ddsd
);
4914 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4915 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4916 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
4919 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4920 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
4922 memset(&ddsd
, 0, sizeof(ddsd
));
4923 ddsd
.dwSize
= sizeof(ddsd
);
4924 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
4925 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4926 addr
= ddsd
.lpSurface
;
4927 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
4928 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4930 memset(&ddsd
, 0, sizeof(ddsd
));
4931 ddsd
.dwSize
= sizeof(ddsd
);
4932 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
4933 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4934 discarded
= ddsd
.lpSurface
!= addr
;
4935 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
4936 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4938 hr
= IDirectDrawSurface7_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4939 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4941 memset(&ddsd
, 0, sizeof(ddsd
));
4942 ddsd
.dwSize
= sizeof(ddsd
);
4943 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
4944 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4945 discarded
|= ddsd
.lpSurface
!= addr
;
4946 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
4947 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4949 IDirectDrawSurface7_Release(surface
);
4951 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4952 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
4953 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4956 IDirectDrawSurface7_Release(target
);
4957 IDirectDraw7_Release(ddraw
);
4958 IDirect3D7_Release(d3d
);
4959 IDirect3DDevice7_Release(device
);
4960 DestroyWindow(window
);
4963 static void test_flip(void)
4965 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4966 IDirectDrawSurface7
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4967 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, 0};
4968 DDSURFACEDESC2 surface_desc
;
4969 BOOL sysmem_primary
;
4970 IDirectDraw7
*ddraw
;
4977 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4978 0, 0, 640, 480, 0, 0, 0, 0);
4979 ddraw
= create_ddraw();
4980 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4982 hr
= set_display_mode(ddraw
, 640, 480);
4983 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4984 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4985 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4987 memset(&surface_desc
, 0, sizeof(surface_desc
));
4988 surface_desc
.dwSize
= sizeof(surface_desc
);
4989 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4990 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4991 surface_desc
.dwBackBufferCount
= 3;
4992 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
4993 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4995 memset(&surface_desc
, 0, sizeof(surface_desc
));
4996 surface_desc
.dwSize
= sizeof(surface_desc
);
4997 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &surface_desc
);
4998 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4999 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
5000 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5001 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5002 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
5004 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
5005 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5006 memset(&surface_desc
, 0, sizeof(surface_desc
));
5007 surface_desc
.dwSize
= sizeof(surface_desc
);
5008 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer1
, &surface_desc
);
5009 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5010 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
5011 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
5012 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5014 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
5015 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5016 memset(&surface_desc
, 0, sizeof(surface_desc
));
5017 surface_desc
.dwSize
= sizeof(surface_desc
);
5018 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer2
, &surface_desc
);
5019 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5020 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
5021 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5022 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5024 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
5025 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5026 memset(&surface_desc
, 0, sizeof(surface_desc
));
5027 surface_desc
.dwSize
= sizeof(surface_desc
);
5028 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer3
, &surface_desc
);
5029 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5030 ok(!surface_desc
.dwBackBufferCount
, "Got unexpected back buffer count %u.\n", surface_desc
.dwBackBufferCount
);
5031 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5032 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5034 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
5035 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5036 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
5037 IDirectDrawSurface7_Release(surface
);
5039 memset(&surface_desc
, 0, sizeof(surface_desc
));
5040 surface_desc
.dwSize
= sizeof(surface_desc
);
5041 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5042 surface_desc
.ddsCaps
.dwCaps
= 0;
5043 surface_desc
.dwWidth
= 640;
5044 surface_desc
.dwHeight
= 480;
5045 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5046 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5047 hr
= IDirectDrawSurface7_Flip(primary
, surface
, DDFLIP_WAIT
);
5048 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5049 IDirectDrawSurface7_Release(surface
);
5051 hr
= IDirectDrawSurface7_Flip(primary
, primary
, DDFLIP_WAIT
);
5052 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5053 hr
= IDirectDrawSurface7_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
5054 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5055 hr
= IDirectDrawSurface7_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
5056 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5057 hr
= IDirectDrawSurface7_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
5058 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
5060 memset(&fx
, 0, sizeof(fx
));
5061 fx
.dwSize
= sizeof(fx
);
5062 U5(fx
).dwFillColor
= 0xffff0000;
5063 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5064 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5065 U5(fx
).dwFillColor
= 0xff00ff00;
5066 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5067 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5068 U5(fx
).dwFillColor
= 0xff0000ff;
5069 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5070 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5072 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
5073 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5074 color
= get_surface_color(backbuffer1
, 320, 240);
5075 /* The testbot seems to just copy the contents of one surface to all the
5076 * others, instead of properly flipping. */
5077 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5078 "Got unexpected color 0x%08x.\n", color
);
5079 color
= get_surface_color(backbuffer2
, 320, 240);
5080 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
5081 U5(fx
).dwFillColor
= 0xffff0000;
5082 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5083 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5085 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
5086 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5087 color
= get_surface_color(backbuffer1
, 320, 240);
5088 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5089 "Got unexpected color 0x%08x.\n", color
);
5090 color
= get_surface_color(backbuffer2
, 320, 240);
5091 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5092 U5(fx
).dwFillColor
= 0xff00ff00;
5093 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5094 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5096 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
5097 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5098 color
= get_surface_color(backbuffer1
, 320, 240);
5099 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5100 "Got unexpected color 0x%08x.\n", color
);
5101 color
= get_surface_color(backbuffer2
, 320, 240);
5102 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
5103 U5(fx
).dwFillColor
= 0xff0000ff;
5104 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5105 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5107 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
5108 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5109 color
= get_surface_color(backbuffer2
, 320, 240);
5110 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
5111 "Got unexpected color 0x%08x.\n", color
);
5112 color
= get_surface_color(backbuffer3
, 320, 240);
5113 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
5114 U5(fx
).dwFillColor
= 0xffff0000;
5115 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5116 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5118 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
5119 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5120 color
= get_surface_color(backbuffer1
, 320, 240);
5121 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5122 color
= get_surface_color(backbuffer3
, 320, 240);
5123 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
5124 "Got unexpected color 0x%08x.\n", color
);
5125 U5(fx
).dwFillColor
= 0xff00ff00;
5126 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
5127 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
5129 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
5130 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
5131 color
= get_surface_color(backbuffer1
, 320, 240);
5132 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
5133 "Got unexpected color 0x%08x.\n", color
);
5134 color
= get_surface_color(backbuffer2
, 320, 240);
5135 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
5137 IDirectDrawSurface7_Release(backbuffer3
);
5138 IDirectDrawSurface7_Release(backbuffer2
);
5139 IDirectDrawSurface7_Release(backbuffer1
);
5140 IDirectDrawSurface7_Release(primary
);
5141 refcount
= IDirectDraw7_Release(ddraw
);
5142 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5143 DestroyWindow(window
);
5146 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
5148 memset(ddsd
, 0, sizeof(*ddsd
));
5149 ddsd
->dwSize
= sizeof(*ddsd
);
5152 static void test_set_surface_desc(void)
5154 IDirectDraw7
*ddraw
;
5157 DDSURFACEDESC2 ddsd
;
5158 IDirectDrawSurface7
*surface
;
5168 invalid_caps_tests
[] =
5170 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
5171 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
5172 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
5173 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
5174 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
5177 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5178 0, 0, 640, 480, 0, 0, 0, 0);
5179 ddraw
= create_ddraw();
5180 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5181 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5182 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5185 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5188 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5189 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5190 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5191 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5192 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5193 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5194 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5196 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5197 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5200 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5201 ddsd
.lpSurface
= data
;
5202 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5203 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5205 /* Redundantly setting the same lpSurface is not an error. */
5206 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5207 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5209 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5210 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5211 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5212 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
5214 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
5215 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5216 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
5217 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
5218 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5219 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5222 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5223 ddsd
.lpSurface
= data
;
5224 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 1);
5225 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
5227 ddsd
.lpSurface
= NULL
;
5228 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5229 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
5231 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, NULL
, 0);
5232 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
5234 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5235 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5236 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5237 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5238 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
5240 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
5241 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5242 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
5244 ddsd
.dwFlags
= DDSD_CAPS
;
5245 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5246 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5248 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
5249 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
5250 ddsd
.lpSurface
= data
;
5251 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5252 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5253 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5254 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5255 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
5256 ddsd
.ddsCaps
.dwCaps
= 0;
5257 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
5258 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5259 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5261 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5262 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5263 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
5264 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
5265 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
5267 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
5269 ddsd
.dwFlags
= DDSD_HEIGHT
;
5271 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5272 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
5274 ddsd
.lpSurface
= data
;
5275 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
5276 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5277 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5280 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5281 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
5284 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5285 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
5286 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5287 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5289 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
5291 ddsd
.dwFlags
= DDSD_PITCH
;
5292 U1(ddsd
).lPitch
= 8 * 4;
5293 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5294 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
5296 ddsd
.dwFlags
= DDSD_WIDTH
;
5298 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5299 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
5301 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
5302 ddsd
.lpSurface
= data
;
5303 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5304 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
5306 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
5307 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5308 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
5310 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5311 U1(ddsd
).lPitch
= 16 * 4;
5313 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5314 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5317 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5318 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5319 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
5320 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
5321 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
5323 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
5325 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
5326 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5327 U1(ddsd
).lPitch
= 4 * 4;
5328 ddsd
.lpSurface
= data
;
5329 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5330 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5332 U1(ddsd
).lPitch
= 4;
5333 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5334 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
5336 U1(ddsd
).lPitch
= 16 * 4 + 1;
5337 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5338 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5340 U1(ddsd
).lPitch
= 16 * 4 + 3;
5341 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5342 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
5344 U1(ddsd
).lPitch
= -4;
5345 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5346 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
5348 U1(ddsd
).lPitch
= 16 * 4;
5349 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5350 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5353 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5354 U1(ddsd
).lPitch
= 0;
5356 ddsd
.lpSurface
= data
;
5357 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5358 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
5360 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
5361 U1(ddsd
).lPitch
= 16 * 4;
5363 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5364 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
5366 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
5367 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
5368 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5369 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5370 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5371 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5372 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5373 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5374 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5375 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
5377 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
5378 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5379 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5381 /* Can't set color keys. */
5383 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
5384 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
5385 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
5386 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5387 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5389 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
5390 ddsd
.lpSurface
= data
;
5391 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5392 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
5394 IDirectDrawSurface7_Release(surface
);
5396 /* SetSurfaceDesc needs systemmemory surfaces.
5398 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
5399 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
5402 ddsd
.dwFlags
= DDSD_CAPS
;
5403 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
5404 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
5405 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5407 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5410 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5411 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5412 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5413 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5414 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5415 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5418 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5419 ok(SUCCEEDED(hr
) || hr
== DDERR_NODIRECTDRAWHW
, "Failed to create surface, hr %#x.\n", hr
);
5422 skip("Cannot create a %s surface, skipping vidmem SetSurfaceDesc test.\n",
5423 invalid_caps_tests
[i
].name
);
5428 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5429 ddsd
.lpSurface
= data
;
5430 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5431 if (invalid_caps_tests
[i
].supported
)
5433 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5437 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5438 invalid_caps_tests
[i
].name
, hr
);
5440 /* Check priority of error conditions. */
5441 ddsd
.dwFlags
= DDSD_WIDTH
;
5442 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5443 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
5444 invalid_caps_tests
[i
].name
, hr
);
5447 IDirectDrawSurface7_Release(surface
);
5451 ref
= IDirectDraw7_Release(ddraw
);
5452 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5453 DestroyWindow(window
);
5456 static void test_user_memory_getdc(void)
5458 IDirectDraw7
*ddraw
;
5461 DDSURFACEDESC2 ddsd
;
5462 IDirectDrawSurface7
*surface
;
5468 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5469 0, 0, 640, 480, 0, 0, 0, 0);
5470 ddraw
= create_ddraw();
5471 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5472 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5473 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5476 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
5479 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5480 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5481 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5482 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5483 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5484 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5485 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5486 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5487 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5489 memset(data
, 0xaa, sizeof(data
));
5491 ddsd
.dwFlags
= DDSD_LPSURFACE
;
5492 ddsd
.lpSurface
= data
;
5493 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5494 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5496 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
5497 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5498 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
5499 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
5500 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
5501 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5503 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
5504 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
5506 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
5507 ddsd
.lpSurface
= data
;
5510 U1(ddsd
).lPitch
= sizeof(*data
);
5511 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
5512 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
5514 memset(data
, 0xaa, sizeof(data
));
5515 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
5516 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
5517 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
5518 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
5519 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
5520 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
5522 for (y
= 0; y
< 4; y
++)
5524 for (x
= 0; x
< 4; x
++)
5526 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
5527 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
5530 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
5534 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
5536 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
5538 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
5540 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
5543 IDirectDrawSurface7_Release(surface
);
5544 ref
= IDirectDraw7_Release(ddraw
);
5545 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5546 DestroyWindow(window
);
5549 static void test_sysmem_overlay(void)
5551 IDirectDraw7
*ddraw
;
5554 DDSURFACEDESC2 ddsd
;
5555 IDirectDrawSurface7
*surface
;
5558 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5559 0, 0, 640, 480, 0, 0, 0, 0);
5560 ddraw
= create_ddraw();
5561 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5562 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5563 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5566 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
5569 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
5570 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
5571 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5572 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
5573 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5574 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5575 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5576 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5577 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
5579 ref
= IDirectDraw7_Release(ddraw
);
5580 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
5581 DestroyWindow(window
);
5584 static void test_primary_palette(void)
5586 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, 0};
5587 IDirectDrawSurface7
*primary
, *backbuffer
;
5588 PALETTEENTRY palette_entries
[256];
5589 IDirectDrawPalette
*palette
, *tmp
;
5590 DDSURFACEDESC2 surface_desc
;
5591 IDirectDraw7
*ddraw
;
5597 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5598 0, 0, 640, 480, 0, 0, 0, 0);
5599 ddraw
= create_ddraw();
5600 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5601 if (FAILED(hr
= IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
5603 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
5604 IDirectDraw7_Release(ddraw
);
5605 DestroyWindow(window
);
5608 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5609 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5610 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5612 memset(&surface_desc
, 0, sizeof(surface_desc
));
5613 surface_desc
.dwSize
= sizeof(surface_desc
);
5614 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5615 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5616 surface_desc
.dwBackBufferCount
= 1;
5617 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5618 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5619 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
5620 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5622 memset(palette_entries
, 0, sizeof(palette_entries
));
5623 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
5624 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5625 refcount
= get_refcount((IUnknown
*)palette
);
5626 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5628 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5629 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5630 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5632 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
5633 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5635 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
5636 * and is generally somewhat broken with respect to 8 bpp / palette
5638 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
)))
5640 win_skip("Broken palette handling detected, skipping tests.\n");
5641 IDirectDrawPalette_Release(tmp
);
5642 IDirectDrawPalette_Release(palette
);
5643 /* The Windows 8 testbot keeps extra references to the primary and
5644 * backbuffer while in 8 bpp mode. */
5645 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
5646 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
5650 refcount
= get_refcount((IUnknown
*)palette
);
5651 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5653 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5654 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5655 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
5656 "Got unexpected palette caps %#x.\n", palette_caps
);
5658 hr
= IDirectDrawSurface7_SetPalette(primary
, NULL
);
5659 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5660 refcount
= get_refcount((IUnknown
*)palette
);
5661 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5663 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
5664 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
5665 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
5667 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
5668 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5669 refcount
= get_refcount((IUnknown
*)palette
);
5670 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5672 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
5673 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5674 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
5675 IDirectDrawPalette_Release(tmp
);
5676 hr
= IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
);
5677 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5679 refcount
= IDirectDrawPalette_Release(palette
);
5680 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5681 refcount
= IDirectDrawPalette_Release(palette
);
5682 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5684 /* Note that this only seems to work when the palette is attached to the
5685 * primary surface. When attached to a regular surface, attempting to get
5686 * the palette here will cause an access violation. */
5687 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
5688 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5691 refcount
= IDirectDrawSurface7_Release(backbuffer
);
5692 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5693 refcount
= IDirectDrawSurface7_Release(primary
);
5694 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5695 refcount
= IDirectDraw7_Release(ddraw
);
5696 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5697 DestroyWindow(window
);
5700 static HRESULT WINAPI
surface_counter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
5702 UINT
*surface_count
= context
;
5705 IDirectDrawSurface_Release(surface
);
5707 return DDENUMRET_OK
;
5710 static void test_surface_attachment(void)
5712 IDirectDrawSurface7
*surface1
, *surface2
, *surface3
, *surface4
;
5713 IDirectDrawSurface
*surface1v1
, *surface2v1
;
5714 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, 0};
5715 DDSURFACEDESC2 surface_desc
;
5716 IDirectDraw7
*ddraw
;
5722 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5723 0, 0, 640, 480, 0, 0, 0, 0);
5724 ddraw
= create_ddraw();
5725 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5726 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5727 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5729 memset(&surface_desc
, 0, sizeof(surface_desc
));
5730 surface_desc
.dwSize
= sizeof(surface_desc
);
5731 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
5732 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5733 U2(surface_desc
).dwMipMapCount
= 3;
5734 surface_desc
.dwWidth
= 128;
5735 surface_desc
.dwHeight
= 128;
5736 if (FAILED(hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
)))
5738 skip("Failed to create a texture, skipping tests.\n");
5739 IDirectDraw7_Release(ddraw
);
5740 DestroyWindow(window
);
5744 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
5745 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5746 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
5747 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
5748 hr
= IDirectDrawSurface7_GetAttachedSurface(surface3
, &caps
, &surface4
);
5749 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5752 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
5753 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5755 IDirectDrawSurface7_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
5756 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
5758 IDirectDrawSurface7_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
5759 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
5761 memset(&surface_desc
, 0, sizeof(surface_desc
));
5762 surface_desc
.dwSize
= sizeof(surface_desc
);
5763 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5764 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5765 surface_desc
.dwWidth
= 16;
5766 surface_desc
.dwHeight
= 16;
5767 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5768 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5770 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
5771 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5772 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
5773 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5774 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
5775 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5776 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
5777 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5778 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
5779 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5780 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
5781 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5783 IDirectDrawSurface7_Release(surface4
);
5785 memset(&surface_desc
, 0, sizeof(surface_desc
));
5786 surface_desc
.dwSize
= sizeof(surface_desc
);
5787 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5788 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
5789 surface_desc
.dwWidth
= 16;
5790 surface_desc
.dwHeight
= 16;
5791 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5792 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5794 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
5795 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5796 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
5797 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5798 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
5799 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5800 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
5801 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5802 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
5803 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5804 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
5805 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5807 IDirectDrawSurface7_Release(surface4
);
5808 IDirectDrawSurface7_Release(surface3
);
5809 IDirectDrawSurface7_Release(surface2
);
5810 IDirectDrawSurface7_Release(surface1
);
5812 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5813 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5815 /* Try a single primary and two offscreen plain surfaces. */
5816 memset(&surface_desc
, 0, sizeof(surface_desc
));
5817 surface_desc
.dwSize
= sizeof(surface_desc
);
5818 surface_desc
.dwFlags
= DDSD_CAPS
;
5819 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
5820 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5821 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5823 memset(&surface_desc
, 0, sizeof(surface_desc
));
5824 surface_desc
.dwSize
= sizeof(surface_desc
);
5825 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5826 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5827 surface_desc
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
5828 surface_desc
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
5829 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5830 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5832 memset(&surface_desc
, 0, sizeof(surface_desc
));
5833 surface_desc
.dwSize
= sizeof(surface_desc
);
5834 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5835 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5836 surface_desc
.dwWidth
= GetSystemMetrics(SM_CXSCREEN
);
5837 surface_desc
.dwHeight
= GetSystemMetrics(SM_CYSCREEN
);
5838 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5839 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5841 /* This one has a different size. */
5842 memset(&surface_desc
, 0, sizeof(surface_desc
));
5843 surface_desc
.dwSize
= sizeof(surface_desc
);
5844 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5845 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5846 surface_desc
.dwWidth
= 128;
5847 surface_desc
.dwHeight
= 128;
5848 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
5849 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5851 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
5852 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5853 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
5854 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5855 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
5856 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5857 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
5858 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5859 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
5860 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5862 IDirectDrawSurface7_Release(surface4
);
5863 IDirectDrawSurface7_Release(surface3
);
5864 IDirectDrawSurface7_Release(surface2
);
5865 IDirectDrawSurface7_Release(surface1
);
5867 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
5868 memset(&surface_desc
, 0, sizeof(surface_desc
));
5869 surface_desc
.dwSize
= sizeof(surface_desc
);
5870 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5871 surface_desc
.dwWidth
= 64;
5872 surface_desc
.dwHeight
= 64;
5873 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5874 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
5875 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
5876 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
5877 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
5878 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
5879 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
5880 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
5881 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5882 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
5883 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5885 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
5886 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
5887 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
5888 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
5889 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
5890 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5892 hr
= IDirectDrawSurface7_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
5893 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
5894 hr
= IDirectDrawSurface7_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
5895 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
5897 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
5898 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5899 refcount
= get_refcount((IUnknown
*)surface2
);
5900 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5901 refcount
= get_refcount((IUnknown
*)surface2v1
);
5902 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5903 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
5904 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
5905 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
5906 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
5907 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
5908 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
5910 /* Attaching while already attached to other surface. */
5911 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
5912 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5913 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface3
, 0, surface2
);
5914 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5915 IDirectDrawSurface7_Release(surface3
);
5917 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
5918 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5919 refcount
= get_refcount((IUnknown
*)surface2
);
5920 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5921 refcount
= get_refcount((IUnknown
*)surface2v1
);
5922 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
5924 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
5925 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
5926 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5927 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
5928 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
5929 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
5930 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
5931 refcount
= IDirectDrawSurface7_Release(surface2
);
5932 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5933 refcount
= IDirectDrawSurface7_Release(surface1
);
5934 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5936 /* Automatic detachment on release. */
5937 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
5938 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
5939 refcount
= get_refcount((IUnknown
*)surface2v1
);
5940 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
5941 refcount
= IDirectDrawSurface_Release(surface1v1
);
5942 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5943 refcount
= IDirectDrawSurface_Release(surface2v1
);
5944 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5945 refcount
= IDirectDraw7_Release(ddraw
);
5946 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5947 DestroyWindow(window
);
5950 static void test_private_data(void)
5952 IDirectDraw7
*ddraw
;
5953 IDirectDrawSurface7
*surface
, *surface2
;
5954 DDSURFACEDESC2 surface_desc
;
5955 ULONG refcount
, refcount2
, refcount3
;
5957 DWORD size
= sizeof(ptr
);
5960 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
5961 DWORD data
[] = {1, 2, 3, 4};
5963 static const GUID ddraw_private_data_test_guid
=
5968 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
5970 static const GUID ddraw_private_data_test_guid2
=
5975 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5978 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5979 0, 0, 640, 480, 0, 0, 0, 0);
5980 ddraw
= create_ddraw();
5981 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5982 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5983 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5985 reset_ddsd(&surface_desc
);
5986 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
5987 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
5988 surface_desc
.dwHeight
= 4;
5989 surface_desc
.dwWidth
= 4;
5990 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5991 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5993 /* NULL pointers are not valid, but don't cause a crash. */
5994 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
5995 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
5996 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
5997 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
5998 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
5999 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
6000 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6002 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6003 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6004 0, DDSPD_IUNKNOWNPOINTER
);
6005 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6006 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6007 5, DDSPD_IUNKNOWNPOINTER
);
6008 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6009 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6010 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
6011 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6013 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6014 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6015 * erases the old content and returns an error. This behavior has
6016 * been fixed in d3d8 and d3d9. Unless an application is found
6017 * that depends on this we don't care about this behavior. */
6018 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6019 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6020 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6021 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6022 0, DDSPD_IUNKNOWNPOINTER
);
6023 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6025 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6026 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
6027 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
6028 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
6030 refcount
= get_refcount((IUnknown
*)ddraw
);
6031 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6032 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6033 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6034 refcount2
= get_refcount((IUnknown
*)ddraw
);
6035 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
6037 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
6038 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
6039 refcount2
= get_refcount((IUnknown
*)ddraw
);
6040 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
6042 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6043 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6044 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6045 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
6046 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
6047 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6048 refcount2
= get_refcount((IUnknown
*)ddraw
);
6049 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
6051 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6052 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6053 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6054 size
= 2 * sizeof(ptr
);
6055 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6056 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
6057 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
6058 refcount2
= get_refcount(ptr
);
6059 /* Object is NOT addref'ed by the getter. */
6060 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
6061 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
6063 ptr
= (IUnknown
*)0xdeadbeef;
6065 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
6066 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
6067 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
6068 size
= 2 * sizeof(ptr
);
6069 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
6070 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6071 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
6073 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6074 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
6075 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
6076 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
6077 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
6078 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6080 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
6081 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6082 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
6083 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
6084 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
6085 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6087 refcount3
= IDirectDrawSurface7_Release(surface
);
6088 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
6090 /* Destroying the surface frees the reference held on the private data. It also frees
6091 * the reference the surface is holding on its creating object. */
6092 refcount2
= get_refcount((IUnknown
*)ddraw
);
6093 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
6095 memset(&hal_caps
, 0, sizeof(hal_caps
));
6096 hal_caps
.dwSize
= sizeof(hal_caps
);
6097 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
6098 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6099 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6101 reset_ddsd(&surface_desc
);
6102 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
6103 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6104 surface_desc
.dwHeight
= 4;
6105 surface_desc
.dwWidth
= 4;
6106 U2(surface_desc
).dwMipMapCount
= 2;
6107 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6108 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6109 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
6110 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6112 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
6113 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6114 hr
= IDirectDrawSurface7_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
6115 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6117 IDirectDrawSurface7_Release(surface2
);
6118 IDirectDrawSurface7_Release(surface
);
6121 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
6123 refcount
= IDirectDraw7_Release(ddraw
);
6124 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6125 DestroyWindow(window
);
6128 static void test_pixel_format(void)
6130 HWND window
, window2
= NULL
;
6131 HDC hdc
, hdc2
= NULL
;
6133 int format
, test_format
;
6134 PIXELFORMATDESCRIPTOR pfd
;
6135 IDirectDraw7
*ddraw
= NULL
;
6136 IDirectDrawClipper
*clipper
= NULL
;
6137 DDSURFACEDESC2 ddsd
;
6138 IDirectDrawSurface7
*primary
= NULL
;
6142 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
6143 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6146 skip("Failed to create window\n");
6150 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
6151 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
6153 hdc
= GetDC(window
);
6156 skip("Failed to get DC\n");
6161 hdc2
= GetDC(window2
);
6163 gl
= LoadLibraryA("opengl32.dll");
6164 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6166 format
= GetPixelFormat(hdc
);
6167 ok(format
== 0, "new window has pixel format %d\n", format
);
6169 ZeroMemory(&pfd
, sizeof(pfd
));
6170 pfd
.nSize
= sizeof(pfd
);
6172 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
6173 pfd
.iPixelType
= PFD_TYPE_RGBA
;
6174 pfd
.iLayerType
= PFD_MAIN_PLANE
;
6175 format
= ChoosePixelFormat(hdc
, &pfd
);
6178 skip("no pixel format available\n");
6182 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
6184 skip("failed to set pixel format\n");
6188 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
6190 skip("failed to set pixel format on second window\n");
6193 ReleaseDC(window2
, hdc2
);
6198 ddraw
= create_ddraw();
6199 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6201 test_format
= GetPixelFormat(hdc
);
6202 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6204 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6207 skip("Failed to set cooperative level, hr %#x.\n", hr
);
6211 test_format
= GetPixelFormat(hdc
);
6212 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6216 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
6217 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
6218 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
6219 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
6221 test_format
= GetPixelFormat(hdc
);
6222 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6224 test_format
= GetPixelFormat(hdc2
);
6225 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6228 memset(&ddsd
, 0, sizeof(ddsd
));
6229 ddsd
.dwSize
= sizeof(ddsd
);
6230 ddsd
.dwFlags
= DDSD_CAPS
;
6231 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6233 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
6234 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
6236 test_format
= GetPixelFormat(hdc
);
6237 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6241 test_format
= GetPixelFormat(hdc2
);
6242 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6247 hr
= IDirectDrawSurface7_SetClipper(primary
, clipper
);
6248 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
6250 test_format
= GetPixelFormat(hdc
);
6251 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6253 test_format
= GetPixelFormat(hdc2
);
6254 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6257 memset(&fx
, 0, sizeof(fx
));
6258 fx
.dwSize
= sizeof(fx
);
6259 hr
= IDirectDrawSurface7_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6260 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
6262 test_format
= GetPixelFormat(hdc
);
6263 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
6267 test_format
= GetPixelFormat(hdc2
);
6268 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
6272 if (primary
) IDirectDrawSurface7_Release(primary
);
6273 if (clipper
) IDirectDrawClipper_Release(clipper
);
6274 if (ddraw
) IDirectDraw7_Release(ddraw
);
6275 if (gl
) FreeLibrary(gl
);
6276 if (hdc
) ReleaseDC(window
, hdc
);
6277 if (hdc2
) ReleaseDC(window2
, hdc2
);
6278 if (window
) DestroyWindow(window
);
6279 if (window2
) DestroyWindow(window2
);
6282 static void test_create_surface_pitch(void)
6284 IDirectDrawSurface7
*surface
;
6285 DDSURFACEDESC2 surface_desc
;
6286 IDirectDraw7
*ddraw
;
6304 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
6306 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
6308 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
6310 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
6312 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
6314 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
6316 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
6318 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
6320 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
6322 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
6324 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
6326 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
6329 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
;
6331 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6332 0, 0, 640, 480, 0, 0, 0, 0);
6333 ddraw
= create_ddraw();
6334 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6335 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6336 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6338 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
6340 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
6342 memset(&surface_desc
, 0, sizeof(surface_desc
));
6343 surface_desc
.dwSize
= sizeof(surface_desc
);
6344 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
6345 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
6346 surface_desc
.dwWidth
= 63;
6347 surface_desc
.dwHeight
= 63;
6348 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
6349 surface_desc
.lpSurface
= mem
;
6350 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6351 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6352 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6353 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6354 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6355 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6356 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6357 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
6358 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
6362 memset(&surface_desc
, 0, sizeof(surface_desc
));
6363 surface_desc
.dwSize
= sizeof(surface_desc
);
6364 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
6365 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
6366 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
6367 "Test %u: Got unexpected flags %#x, expected %#x.\n",
6368 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
6369 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out
,
6370 "Test %u: Got unexpected pitch %u, expected %u.\n",
6371 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out
);
6373 IDirectDrawSurface7_Release(surface
);
6376 HeapFree(GetProcessHeap(), 0, mem
);
6377 refcount
= IDirectDraw7_Release(ddraw
);
6378 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6379 DestroyWindow(window
);
6382 static void test_mipmap_lock(void)
6384 IDirectDrawSurface7
*surface
, *surface2
;
6385 DDSURFACEDESC2 surface_desc
;
6386 IDirectDraw7
*ddraw
;
6390 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
6393 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6394 0, 0, 640, 480, 0, 0, 0, 0);
6395 ddraw
= create_ddraw();
6396 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6397 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6398 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6400 memset(&hal_caps
, 0, sizeof(hal_caps
));
6401 hal_caps
.dwSize
= sizeof(hal_caps
);
6402 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
6403 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6404 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6406 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
6407 IDirectDraw7_Release(ddraw
);
6408 DestroyWindow(window
);
6412 memset(&surface_desc
, 0, sizeof(surface_desc
));
6413 surface_desc
.dwSize
= sizeof(surface_desc
);
6414 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6415 surface_desc
.dwWidth
= 4;
6416 surface_desc
.dwHeight
= 4;
6417 U2(surface_desc
).dwMipMapCount
= 2;
6418 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
6419 | DDSCAPS_SYSTEMMEMORY
;
6420 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6421 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6422 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
6423 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6425 memset(&surface_desc
, 0, sizeof(surface_desc
));
6426 surface_desc
.dwSize
= sizeof(surface_desc
);
6427 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6428 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6429 memset(&surface_desc
, 0, sizeof(surface_desc
));
6430 surface_desc
.dwSize
= sizeof(surface_desc
);
6431 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
6432 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6433 IDirectDrawSurface7_Unlock(surface2
, NULL
);
6434 IDirectDrawSurface7_Unlock(surface
, NULL
);
6436 IDirectDrawSurface7_Release(surface2
);
6437 IDirectDrawSurface7_Release(surface
);
6438 refcount
= IDirectDraw7_Release(ddraw
);
6439 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6440 DestroyWindow(window
);
6443 static void test_palette_complex(void)
6445 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
6446 DDSURFACEDESC2 surface_desc
;
6447 IDirectDraw7
*ddraw
;
6448 IDirectDrawPalette
*palette
, *palette2
;
6452 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, 0};
6454 PALETTEENTRY palette_entries
[256];
6457 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6458 0, 0, 640, 480, 0, 0, 0, 0);
6459 ddraw
= create_ddraw();
6460 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6461 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6462 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6464 memset(&hal_caps
, 0, sizeof(hal_caps
));
6465 hal_caps
.dwSize
= sizeof(hal_caps
);
6466 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
6467 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6468 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
6470 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
6471 IDirectDraw7_Release(ddraw
);
6472 DestroyWindow(window
);
6476 memset(&surface_desc
, 0, sizeof(surface_desc
));
6477 surface_desc
.dwSize
= sizeof(surface_desc
);
6478 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6479 surface_desc
.dwWidth
= 128;
6480 surface_desc
.dwHeight
= 128;
6481 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6482 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6483 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6484 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
6485 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6486 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6488 memset(palette_entries
, 0, sizeof(palette_entries
));
6489 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6490 palette_entries
, &palette
, NULL
);
6491 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6493 palette2
= (void *)0xdeadbeef;
6494 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
6495 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6496 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
6497 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
6498 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6499 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
6500 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6501 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
6502 IDirectDrawPalette_Release(palette2
);
6505 IDirectDrawSurface7_AddRef(mipmap
);
6506 for (i
= 0; i
< 7; ++i
)
6508 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6509 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
6510 palette2
= (void *)0xdeadbeef;
6511 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
6512 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6513 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6515 hr
= IDirectDrawSurface7_SetPalette(tmp
, palette
);
6516 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6518 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
6519 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
6520 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
6522 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
6523 * ddraw versions. Combined with the test results above this means no
6524 * palette is available. So depending on the driver either GetDC fails
6525 * or the DIB color table contains random data. */
6527 IDirectDrawSurface7_Release(mipmap
);
6531 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
6532 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6533 IDirectDrawSurface7_Release(mipmap
);
6534 refcount
= IDirectDrawSurface7_Release(surface
);
6535 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6537 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
6538 memset(&surface_desc
, 0, sizeof(surface_desc
));
6539 surface_desc
.dwSize
= sizeof(surface_desc
);
6540 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6541 surface_desc
.dwWidth
= 128;
6542 surface_desc
.dwHeight
= 128;
6543 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6544 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6545 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6546 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6547 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6548 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6549 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6550 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6551 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6553 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
6554 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6555 hr
= IDirectDrawSurface7_SetPalette(mipmap
, palette
);
6556 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x.\n", hr
);
6558 IDirectDrawSurface7_Release(mipmap
);
6559 refcount
= IDirectDrawSurface7_Release(surface
);
6560 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6561 refcount
= IDirectDrawPalette_Release(palette
);
6562 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6564 refcount
= IDirectDraw7_Release(ddraw
);
6565 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6566 DestroyWindow(window
);
6569 static void test_p8_rgb_blit(void)
6571 IDirectDrawSurface7
*src
, *dst
;
6572 DDSURFACEDESC2 surface_desc
;
6573 IDirectDraw7
*ddraw
;
6574 IDirectDrawPalette
*palette
;
6578 PALETTEENTRY palette_entries
[256];
6580 static const BYTE src_data
[] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
6581 static const D3DCOLOR expected
[] =
6583 0x00000000, 0x00010101, 0x00020202, 0x00030303,
6584 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
6588 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6589 0, 0, 640, 480, 0, 0, 0, 0);
6590 ddraw
= create_ddraw();
6591 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6592 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6593 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6595 memset(palette_entries
, 0, sizeof(palette_entries
));
6596 palette_entries
[0].peRed
= 0xff;
6597 palette_entries
[1].peGreen
= 0xff;
6598 palette_entries
[2].peBlue
= 0xff;
6599 palette_entries
[3].peFlags
= 0xff;
6600 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6601 palette_entries
, &palette
, NULL
);
6602 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6604 memset(&surface_desc
, 0, sizeof(surface_desc
));
6605 surface_desc
.dwSize
= sizeof(surface_desc
);
6606 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6607 surface_desc
.dwWidth
= 8;
6608 surface_desc
.dwHeight
= 1;
6609 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6610 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6611 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6612 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
6613 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
6614 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6616 memset(&surface_desc
, 0, sizeof(surface_desc
));
6617 surface_desc
.dwSize
= sizeof(surface_desc
);
6618 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6619 surface_desc
.dwWidth
= 8;
6620 surface_desc
.dwHeight
= 1;
6621 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6622 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6623 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6624 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6625 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6626 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6627 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6628 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6629 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
6630 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6632 memset(&surface_desc
, 0, sizeof(surface_desc
));
6633 surface_desc
.dwSize
= sizeof(surface_desc
);
6634 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
6635 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
6636 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
6637 hr
= IDirectDrawSurface7_Unlock(src
, NULL
);
6638 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
6640 hr
= IDirectDrawSurface7_SetPalette(src
, palette
);
6641 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6642 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
6643 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
6644 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
6645 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
6646 "Failed to blit, hr %#x.\n", hr
);
6650 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
6652 color
= get_surface_color(dst
, x
, 0);
6653 todo_wine
ok(compare_color(color
, expected
[x
], 0),
6654 "Pixel %u: Got color %#x, expected %#x.\n",
6655 x
, color
, expected
[x
]);
6659 IDirectDrawSurface7_Release(src
);
6660 IDirectDrawSurface7_Release(dst
);
6661 IDirectDrawPalette_Release(palette
);
6663 refcount
= IDirectDraw7_Release(ddraw
);
6664 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6665 DestroyWindow(window
);
6668 static void test_material(void)
6670 static const D3DCOLORVALUE null_color
;
6671 IDirect3DDevice7
*device
;
6672 D3DMATERIAL7 material
;
6677 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6678 0, 0, 640, 480, 0, 0, 0, 0);
6679 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
6681 skip("Failed to create a 3D device, skipping test.\n");
6682 DestroyWindow(window
);
6686 hr
= IDirect3DDevice7_GetMaterial(device
, &material
);
6687 ok(SUCCEEDED(hr
), "Failed to get material, hr %#x.\n", hr
);
6688 ok(!memcmp(&U(material
).diffuse
, &null_color
, sizeof(null_color
)),
6689 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
6690 U1(U(material
).diffuse
).r
, U2(U(material
).diffuse
).g
,
6691 U3(U(material
).diffuse
).b
, U3(U(material
).diffuse
).a
);
6692 ok(!memcmp(&U1(material
).ambient
, &null_color
, sizeof(null_color
)),
6693 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
6694 U1(U1(material
).ambient
).r
, U2(U1(material
).ambient
).g
,
6695 U3(U1(material
).ambient
).b
, U3(U1(material
).ambient
).a
);
6696 ok(!memcmp(&U2(material
).specular
, &null_color
, sizeof(null_color
)),
6697 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
6698 U1(U2(material
).specular
).r
, U2(U2(material
).specular
).g
,
6699 U3(U2(material
).specular
).b
, U3(U2(material
).specular
).a
);
6700 ok(!memcmp(&U3(material
).emissive
, &null_color
, sizeof(null_color
)),
6701 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
6702 U1(U3(material
).emissive
).r
, U2(U3(material
).emissive
).g
,
6703 U3(U3(material
).emissive
).b
, U3(U3(material
).emissive
).a
);
6704 ok(U4(material
).power
== 0.0f
, "Got unexpected power %.8e.\n", U4(material
).power
);
6706 refcount
= IDirect3DDevice7_Release(device
);
6707 ok(!refcount
, "Device has %u references left.\n", refcount
);
6708 DestroyWindow(window
);
6711 static void test_palette_gdi(void)
6713 IDirectDrawSurface7
*surface
, *primary
;
6714 DDSURFACEDESC2 surface_desc
;
6715 IDirectDraw7
*ddraw
;
6716 IDirectDrawPalette
*palette
, *palette2
;
6720 PALETTEENTRY palette_entries
[256];
6723 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
6724 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
6725 * not the point of this test. */
6726 static const RGBQUAD expected1
[] =
6728 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6729 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
6731 static const RGBQUAD expected2
[] =
6733 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6734 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
6736 static const RGBQUAD expected3
[] =
6738 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
6739 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
6741 HPALETTE ddraw_palette_handle
;
6742 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
6743 RGBQUAD rgbquad
[255];
6744 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
6746 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6747 0, 0, 640, 480, 0, 0, 0, 0);
6748 ddraw
= create_ddraw();
6749 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6750 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6751 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6753 memset(&surface_desc
, 0, sizeof(surface_desc
));
6754 surface_desc
.dwSize
= sizeof(surface_desc
);
6755 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6756 surface_desc
.dwWidth
= 16;
6757 surface_desc
.dwHeight
= 16;
6758 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6759 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6760 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6761 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
6762 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6763 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6765 /* Avoid colors from the Windows default palette. */
6766 memset(palette_entries
, 0, sizeof(palette_entries
));
6767 palette_entries
[1].peRed
= 0x01;
6768 palette_entries
[2].peGreen
= 0x02;
6769 palette_entries
[3].peBlue
= 0x03;
6770 palette_entries
[4].peRed
= 0x13;
6771 palette_entries
[4].peGreen
= 0x14;
6772 palette_entries
[4].peBlue
= 0x15;
6773 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6774 palette_entries
, &palette
, NULL
);
6775 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6777 /* If there is no palette assigned and the display mode is not 8 bpp, some
6778 * drivers refuse to create a DC while others allow it. If a DC is created,
6779 * the DIB color table is uninitialized and contains random colors. No error
6780 * is generated when trying to read pixels and random garbage is returned.
6782 * The most likely explanation is that if the driver creates a DC, it (or
6783 * the higher-level runtime) uses GetSystemPaletteEntries to find the
6784 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
6785 * contains uninitialized garbage. See comments below for the P8 case. */
6787 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
6788 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6789 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6790 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6791 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
6792 todo_wine
ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
6793 "Got unexpected palette %p, expected %p.\n",
6794 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
6795 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
6797 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6798 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6799 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
6801 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
6802 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6803 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6804 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
6806 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6808 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6809 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6810 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6813 /* Update the palette while the DC is in use. This does not modify the DC. */
6814 palette_entries
[4].peRed
= 0x23;
6815 palette_entries
[4].peGreen
= 0x24;
6816 palette_entries
[4].peBlue
= 0x25;
6817 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
6818 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
6820 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
6821 ok(i
== 1, "Expected count 1, got %u.\n", i
);
6822 todo_wine
ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
6823 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6824 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
6825 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
6827 /* Neither does re-setting the palette. */
6828 hr
= IDirectDrawSurface7_SetPalette(surface
, NULL
);
6829 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6830 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
6831 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6833 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
6834 ok(i
== 1, "Expected count 1, got %u.\n", i
);
6835 todo_wine
ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
6836 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6837 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
6838 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
6840 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6841 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6843 /* Refresh the DC. This updates the palette. */
6844 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6845 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6846 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6847 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6848 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
6850 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
6851 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6852 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6853 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
6855 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6857 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6858 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6859 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6861 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6862 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6864 refcount
= IDirectDrawSurface7_Release(surface
);
6865 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6867 if (FAILED(hr
= IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6869 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6870 IDirectDrawPalette_Release(palette
);
6871 IDirectDraw7_Release(ddraw
);
6872 DestroyWindow(window
);
6875 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
6876 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
6877 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6879 memset(&surface_desc
, 0, sizeof(surface_desc
));
6880 surface_desc
.dwSize
= sizeof(surface_desc
);
6881 surface_desc
.dwFlags
= DDSD_CAPS
;
6882 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6883 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6884 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6886 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6887 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6888 hr
= IDirectDrawSurface7_GetDC(primary
, &dc
);
6889 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6890 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
6891 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
6892 todo_wine
ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
6893 "Got unexpected palette %p, expected %p.\n",
6894 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
6895 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
6897 /* The primary uses the system palette. In exclusive mode, the system palette matches
6898 * the ddraw palette attached to the primary, so the result is what you would expect
6899 * from a regular surface. Tests for the interaction between the ddraw palette and
6900 * the system palette are not included pending an application that depends on this.
6901 * The relation between those causes problems on Windows Vista and newer for games
6902 * like Age of Empires or Starcraft. Don't emulate it without a real need. */
6903 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6904 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6905 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
6907 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
6908 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6909 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6910 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
6912 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6914 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6915 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6916 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6918 hr
= IDirectDrawSurface7_ReleaseDC(primary
, dc
);
6919 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6921 memset(&surface_desc
, 0, sizeof(surface_desc
));
6922 surface_desc
.dwSize
= sizeof(surface_desc
);
6923 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6924 surface_desc
.dwWidth
= 16;
6925 surface_desc
.dwHeight
= 16;
6926 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6927 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6928 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6930 /* Here the offscreen surface appears to use the primary's palette,
6931 * but in all likelyhood it is actually the system palette. */
6932 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6933 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6934 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6935 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6936 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
6938 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
6939 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6940 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6941 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
6943 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6945 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6946 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6947 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6949 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6950 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6952 /* On real hardware a change to the primary surface's palette applies immediately,
6953 * even on device contexts from offscreen surfaces that do not have their own
6954 * palette. On the testbot VMs this is not the case. Don't test this until we
6955 * know of an application that depends on this. */
6957 memset(palette_entries
, 0, sizeof(palette_entries
));
6958 palette_entries
[1].peBlue
= 0x40;
6959 palette_entries
[2].peRed
= 0x40;
6960 palette_entries
[3].peGreen
= 0x40;
6961 palette_entries
[4].peRed
= 0x12;
6962 palette_entries
[4].peGreen
= 0x34;
6963 palette_entries
[4].peBlue
= 0x56;
6964 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6965 palette_entries
, &palette2
, NULL
);
6966 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6967 hr
= IDirectDrawSurface7_SetPalette(surface
, palette2
);
6968 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6970 /* A palette assigned to the offscreen surface overrides the primary / system
6972 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6973 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6974 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6975 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6976 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
6978 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
6979 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6980 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6981 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
6983 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6985 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6986 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6987 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6989 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6990 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6992 refcount
= IDirectDrawSurface7_Release(surface
);
6993 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6995 /* The Windows 8 testbot keeps extra references to the primary and
6996 * backbuffer while in 8 bpp mode. */
6997 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
6998 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7000 refcount
= IDirectDrawSurface7_Release(primary
);
7001 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7002 refcount
= IDirectDrawPalette_Release(palette2
);
7003 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7004 refcount
= IDirectDrawPalette_Release(palette
);
7005 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7006 refcount
= IDirectDraw7_Release(ddraw
);
7007 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7008 DestroyWindow(window
);
7013 HMODULE module
= GetModuleHandleA("ddraw.dll");
7014 IDirectDraw7
*ddraw
;
7016 if (!(pDirectDrawCreateEx
= (void *)GetProcAddress(module
, "DirectDrawCreateEx")))
7018 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
7022 if (!(ddraw
= create_ddraw()))
7024 skip("Failed to create a ddraw object, skipping tests.\n");
7027 IDirectDraw7_Release(ddraw
);
7029 test_process_vertices();
7030 test_coop_level_create_device_window();
7032 test_coop_level_d3d_state();
7033 test_surface_interface_mismatch();
7034 test_coop_level_threaded();
7036 test_texture_load_ckey();
7044 test_window_style();
7045 test_redundant_mode_set();
7046 test_coop_level_mode_set();
7047 test_coop_level_mode_set_multi();
7049 test_coop_level_surf_create();
7051 test_coop_level_multi_window();
7052 test_draw_strided();
7053 test_clear_rect_count();
7054 test_coop_level_versions();
7056 test_lighting_interface_versions();
7057 test_coop_level_activateapp();
7058 test_texturemanage();
7059 test_block_formats_creation();
7060 test_unsupported_formats();
7062 test_primary_caps();
7063 test_surface_lock();
7064 test_surface_discard();
7066 test_set_surface_desc();
7067 test_user_memory_getdc();
7068 test_sysmem_overlay();
7069 test_primary_palette();
7070 test_surface_attachment();
7071 test_private_data();
7072 test_pixel_format();
7073 test_create_surface_pitch();
7075 test_palette_complex();