2 * Copyright 2006, 2012-2014 Stefan Dösinger for CodeWeavers
3 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
26 static HRESULT (WINAPI
*pDirectDrawCreateEx
)(GUID
*guid
, void **ddraw
, REFIID iid
, IUnknown
*outer_unknown
);
27 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
28 static DEVMODEW registry_mode
;
45 struct create_window_thread_param
48 HANDLE window_created
;
49 HANDLE destroy_window
;
53 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
63 if (abs(x
- y
) > ulps
)
69 static BOOL
compare_vec3(struct vec3
*vec
, float x
, float y
, float z
, unsigned int ulps
)
71 return compare_float(vec
->x
, x
, ulps
)
72 && compare_float(vec
->y
, y
, ulps
)
73 && compare_float(vec
->z
, z
, ulps
);
76 static BOOL
compare_vec4(struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
78 return compare_float(vec
->x
, x
, ulps
)
79 && compare_float(vec
->y
, y
, ulps
)
80 && compare_float(vec
->z
, z
, ulps
)
81 && compare_float(vec
->w
, w
, ulps
);
84 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
86 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
88 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
90 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
92 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
96 static ULONG
get_refcount(IUnknown
*iface
)
98 IUnknown_AddRef(iface
);
99 return IUnknown_Release(iface
);
102 static DWORD WINAPI
create_window_thread_proc(void *param
)
104 struct create_window_thread_param
*p
= param
;
108 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
109 0, 0, 640, 480, 0, 0, 0, 0);
110 ret
= SetEvent(p
->window_created
);
111 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
117 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
118 DispatchMessageA(&msg
);
119 res
= WaitForSingleObject(p
->destroy_window
, 100);
120 if (res
== WAIT_OBJECT_0
)
122 if (res
!= WAIT_TIMEOUT
)
124 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
129 DestroyWindow(p
->window
);
134 static void create_window_thread(struct create_window_thread_param
*p
)
138 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
139 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
140 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
141 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
142 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
143 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
144 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
145 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
148 static void destroy_window_thread(struct create_window_thread_param
*p
)
150 SetEvent(p
->destroy_window
);
151 WaitForSingleObject(p
->thread
, INFINITE
);
152 CloseHandle(p
->destroy_window
);
153 CloseHandle(p
->window_created
);
154 CloseHandle(p
->thread
);
157 static IDirectDrawSurface7
*get_depth_stencil(IDirect3DDevice7
*device
)
159 IDirectDrawSurface7
*rt
, *ret
;
160 DDSCAPS2 caps
= {DDSCAPS_ZBUFFER
, 0, 0, {0}};
163 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
164 ok(SUCCEEDED(hr
), "Failed to get the render target, hr %#x.\n", hr
);
165 hr
= IDirectDrawSurface7_GetAttachedSurface(rt
, &caps
, &ret
);
166 ok(SUCCEEDED(hr
) || hr
== DDERR_NOTFOUND
, "Failed to get the z buffer, hr %#x.\n", hr
);
167 IDirectDrawSurface7_Release(rt
);
171 static HRESULT
set_display_mode(IDirectDraw7
*ddraw
, DWORD width
, DWORD height
)
173 if (SUCCEEDED(IDirectDraw7_SetDisplayMode(ddraw
, width
, height
, 32, 0, 0)))
175 return IDirectDraw7_SetDisplayMode(ddraw
, width
, height
, 24, 0, 0);
178 static D3DCOLOR
get_surface_color(IDirectDrawSurface7
*surface
, UINT x
, UINT y
)
180 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
181 DDSURFACEDESC2 surface_desc
;
185 memset(&surface_desc
, 0, sizeof(surface_desc
));
186 surface_desc
.dwSize
= sizeof(surface_desc
);
188 hr
= IDirectDrawSurface7_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
, NULL
);
189 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
193 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
195 hr
= IDirectDrawSurface7_Unlock(surface
, &rect
);
196 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
201 static HRESULT CALLBACK
enum_z_fmt(DDPIXELFORMAT
*format
, void *ctx
)
203 DDPIXELFORMAT
*z_fmt
= ctx
;
205 if (U1(*format
).dwZBufferBitDepth
> U1(*z_fmt
).dwZBufferBitDepth
)
211 static IDirectDraw7
*create_ddraw(void)
215 if (FAILED(pDirectDrawCreateEx(NULL
, (void **)&ddraw
, &IID_IDirectDraw7
, NULL
)))
221 static HRESULT WINAPI
enum_devtype_cb(char *desc_str
, char *name
, D3DDEVICEDESC7
*desc
, void *ctx
)
224 if (IsEqualGUID(&desc
->deviceGUID
, &IID_IDirect3DTnLHalDevice
))
227 return DDENUMRET_CANCEL
;
232 static IDirect3DDevice7
*create_device(HWND window
, DWORD coop_level
)
234 IDirectDrawSurface7
*surface
, *ds
;
235 IDirect3DDevice7
*device
= NULL
;
236 DDSURFACEDESC2 surface_desc
;
242 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
244 if (!(ddraw
= create_ddraw()))
247 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, coop_level
);
248 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
250 memset(&surface_desc
, 0, sizeof(surface_desc
));
251 surface_desc
.dwSize
= sizeof(surface_desc
);
252 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
253 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
254 surface_desc
.dwWidth
= 640;
255 surface_desc
.dwHeight
= 480;
257 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
258 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
260 if (coop_level
& DDSCL_NORMAL
)
262 IDirectDrawClipper
*clipper
;
264 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
265 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
266 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
267 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
268 hr
= IDirectDrawSurface7_SetClipper(surface
, clipper
);
269 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
270 IDirectDrawClipper_Release(clipper
);
273 hr
= IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d7
);
274 IDirectDraw7_Release(ddraw
);
277 IDirectDrawSurface7_Release(surface
);
281 hr
= IDirect3D7_EnumDevices(d3d7
, enum_devtype_cb
, &hal_ok
);
282 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
283 if (hal_ok
) devtype
= &IID_IDirect3DTnLHalDevice
;
285 memset(&z_fmt
, 0, sizeof(z_fmt
));
286 hr
= IDirect3D7_EnumZBufferFormats(d3d7
, devtype
, enum_z_fmt
, &z_fmt
);
287 if (FAILED(hr
) || !z_fmt
.dwSize
)
289 IDirect3D7_Release(d3d7
);
290 IDirectDrawSurface7_Release(surface
);
294 memset(&surface_desc
, 0, sizeof(surface_desc
));
295 surface_desc
.dwSize
= sizeof(surface_desc
);
296 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
297 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
298 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
299 surface_desc
.dwWidth
= 640;
300 surface_desc
.dwHeight
= 480;
301 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
302 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
305 IDirect3D7_Release(d3d7
);
306 IDirectDrawSurface7_Release(surface
);
310 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
311 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
312 IDirectDrawSurface7_Release(ds
);
315 IDirect3D7_Release(d3d7
);
316 IDirectDrawSurface7_Release(surface
);
320 hr
= IDirect3D7_CreateDevice(d3d7
, devtype
, surface
, &device
);
321 IDirect3D7_Release(d3d7
);
322 IDirectDrawSurface7_Release(surface
);
333 WPARAM expect_wparam
;
336 static const struct message
*expect_messages
;
338 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
340 if (expect_messages
&& message
== expect_messages
->message
)
342 if (expect_messages
->check_wparam
)
343 ok (wparam
== expect_messages
->expect_wparam
,
344 "Got unexpected wparam %lx for message %x, expected %lx.\n",
345 wparam
, message
, expect_messages
->expect_wparam
);
350 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
353 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
354 * interface. This prevents subsequent SetCooperativeLevel() calls on a
355 * different window from failing with DDERR_HWNDALREADYSET. */
356 static void fix_wndproc(HWND window
, LONG_PTR proc
)
361 if (!(ddraw
= create_ddraw()))
364 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
365 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
366 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
367 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
368 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
370 IDirectDraw7_Release(ddraw
);
373 static void test_process_vertices(void)
375 IDirect3DVertexBuffer7
*src_vb
, *dst_vb1
, *dst_vb2
;
376 D3DVERTEXBUFFERDESC vb_desc
;
377 IDirect3DDevice7
*device
;
378 struct vec4
*dst_data
;
379 struct vec3
*dst_data2
;
380 struct vec3
*src_data
;
386 static D3DMATRIX world
=
388 0.0f
, 1.0f
, 0.0f
, 0.0f
,
389 1.0f
, 0.0f
, 0.0f
, 0.0f
,
390 0.0f
, 0.0f
, 0.0f
, 1.0f
,
391 0.0f
, 1.0f
, 1.0f
, 1.0f
,
393 static D3DMATRIX view
=
395 2.0f
, 0.0f
, 0.0f
, 0.0f
,
396 0.0f
, -1.0f
, 0.0f
, 0.0f
,
397 0.0f
, 0.0f
, 1.0f
, 0.0f
,
398 0.0f
, 0.0f
, 0.0f
, 3.0f
,
400 static D3DMATRIX proj
=
402 1.0f
, 0.0f
, 0.0f
, 1.0f
,
403 0.0f
, 1.0f
, 1.0f
, 0.0f
,
404 0.0f
, 1.0f
, 1.0f
, 0.0f
,
405 1.0f
, 0.0f
, 0.0f
, 1.0f
,
408 window
= CreateWindowA("static", "d3d7_test", WS_OVERLAPPEDWINDOW
,
409 0, 0, 640, 480, 0, 0, 0, 0);
410 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
412 skip("Failed to create a 3D device, skipping test.\n");
413 DestroyWindow(window
);
417 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d7
);
418 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
420 memset(&vb_desc
, 0, sizeof(vb_desc
));
421 vb_desc
.dwSize
= sizeof(vb_desc
);
422 vb_desc
.dwFVF
= D3DFVF_XYZ
;
423 vb_desc
.dwNumVertices
= 4;
424 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &src_vb
, 0);
425 ok(SUCCEEDED(hr
), "Failed to create source vertex buffer, hr %#x.\n", hr
);
427 hr
= IDirect3DVertexBuffer7_Lock(src_vb
, 0, (void **)&src_data
, NULL
);
428 ok(SUCCEEDED(hr
), "Failed to lock source vertex buffer, hr %#x.\n", hr
);
429 src_data
[0].x
= 0.0f
;
430 src_data
[0].y
= 0.0f
;
431 src_data
[0].z
= 0.0f
;
432 src_data
[1].x
= 1.0f
;
433 src_data
[1].y
= 1.0f
;
434 src_data
[1].z
= 1.0f
;
435 src_data
[2].x
= -1.0f
;
436 src_data
[2].y
= -1.0f
;
437 src_data
[2].z
= 0.5f
;
438 src_data
[3].x
= 0.5f
;
439 src_data
[3].y
= -0.5f
;
440 src_data
[3].z
= 0.25f
;
441 hr
= IDirect3DVertexBuffer7_Unlock(src_vb
);
442 ok(SUCCEEDED(hr
), "Failed to unlock source vertex buffer, hr %#x.\n", hr
);
444 memset(&vb_desc
, 0, sizeof(vb_desc
));
445 vb_desc
.dwSize
= sizeof(vb_desc
);
446 vb_desc
.dwFVF
= D3DFVF_XYZRHW
;
447 vb_desc
.dwNumVertices
= 4;
448 /* MSDN says that the last parameter must be 0 - check that. */
449 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &dst_vb1
, 4);
450 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
452 memset(&vb_desc
, 0, sizeof(vb_desc
));
453 vb_desc
.dwSize
= sizeof(vb_desc
);
454 vb_desc
.dwFVF
= D3DFVF_XYZ
;
455 vb_desc
.dwNumVertices
= 5;
456 /* MSDN says that the last parameter must be 0 - check that. */
457 hr
= IDirect3D7_CreateVertexBuffer(d3d7
, &vb_desc
, &dst_vb2
, 12345678);
458 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
460 memset(&vp
, 0, sizeof(vp
));
467 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
468 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
470 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
471 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
472 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb2
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
473 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
475 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
476 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
477 ok(compare_vec4(&dst_data
[0], +1.280e+2f
, +1.280e+2f
, +0.000e+0f
, +1.000e+0f
, 4096),
478 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
479 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
480 ok(compare_vec4(&dst_data
[1], +1.920e+2f
, +6.400e+1f
, +1.000e+0f
, +1.000e+0f
, 4096),
481 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
482 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
483 ok(compare_vec4(&dst_data
[2], +6.400e+1f
, +1.920e+2f
, +5.000e-1f
, +1.000e+0f
, 4096),
484 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
485 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
486 ok(compare_vec4(&dst_data
[3], +1.600e+2f
, +1.600e+2f
, +2.500e-1f
, +1.000e+0f
, 4096),
487 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
488 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
489 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
490 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
492 hr
= IDirect3DVertexBuffer7_Lock(dst_vb2
, 0, (void **)&dst_data2
, NULL
);
493 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
494 /* Small thing without much practical meaning, but I stumbled upon it,
495 * so let's check for it: If the output vertex buffer has no RHW value,
496 * the RHW value of the last vertex is written into the next vertex. */
497 ok(compare_vec3(&dst_data2
[4], +1.000e+0f
, +0.000e+0f
, +0.000e+0f
, 4096),
498 "Got unexpected vertex 4 {%.8e, %.8e, %.8e}.\n",
499 dst_data2
[4].x
, dst_data2
[4].y
, dst_data2
[4].z
);
500 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb2
);
501 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
503 /* Try a more complicated viewport, same vertices. */
504 memset(&vp
, 0, sizeof(vp
));
511 hr
= IDirect3DDevice7_SetViewport(device
, &vp
);
512 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
514 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
515 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
517 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
518 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
519 ok(compare_vec4(&dst_data
[0], +1.330e+2f
, +7.000e+1f
, -2.000e+0f
, +1.000e+0f
, 4096),
520 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
521 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
522 ok(compare_vec4(&dst_data
[1], +2.560e+2f
, +5.000e+0f
, +4.000e+0f
, +1.000e+0f
, 4096),
523 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
524 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
525 ok(compare_vec4(&dst_data
[2], +1.000e+1f
, +1.350e+2f
, +1.000e+0f
, +1.000e+0f
, 4096),
526 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
527 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
528 ok(compare_vec4(&dst_data
[3], +1.945e+2f
, +1.025e+2f
, -5.000e-1f
, +1.000e+0f
, 4096),
529 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
530 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
531 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
532 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
534 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &world
);
535 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
536 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &view
);
537 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
538 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &proj
);
539 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
541 hr
= IDirect3DVertexBuffer7_ProcessVertices(dst_vb1
, D3DVOP_TRANSFORM
, 0, 4, src_vb
, 0, device
, 0);
542 ok(SUCCEEDED(hr
), "Failed to process vertices, hr %#x.\n", hr
);
544 hr
= IDirect3DVertexBuffer7_Lock(dst_vb1
, 0, (void **)&dst_data
, NULL
);
545 ok(SUCCEEDED(hr
), "Failed to lock destination vertex buffer, hr %#x.\n", hr
);
546 ok(compare_vec4(&dst_data
[0], +2.560e+2f
, +7.000e+1f
, -2.000e+0f
, +3.333e-1f
, 4096),
547 "Got unexpected vertex 0 {%.8e, %.8e, %.8e, %.8e}.\n",
548 dst_data
[0].x
, dst_data
[0].y
, dst_data
[0].z
, dst_data
[0].w
);
549 ok(compare_vec4(&dst_data
[1], +2.560e+2f
, +7.813e+1f
, -2.750e+0f
, +1.250e-1f
, 4096),
550 "Got unexpected vertex 1 {%.8e, %.8e, %.8e, %.8e}.\n",
551 dst_data
[1].x
, dst_data
[1].y
, dst_data
[1].z
, dst_data
[1].w
);
552 ok(compare_vec4(&dst_data
[2], +2.560e+2f
, +4.400e+1f
, +4.000e-1f
, +4.000e-1f
, 4096),
553 "Got unexpected vertex 2 {%.8e, %.8e, %.8e, %.8e}.\n",
554 dst_data
[2].x
, dst_data
[2].y
, dst_data
[2].z
, dst_data
[2].w
);
555 ok(compare_vec4(&dst_data
[3], +2.560e+2f
, +8.182e+1f
, -3.091e+0f
, +3.636e-1f
, 4096),
556 "Got unexpected vertex 3 {%.8e, %.8e, %.8e, %.8e}.\n",
557 dst_data
[3].x
, dst_data
[3].y
, dst_data
[3].z
, dst_data
[3].w
);
558 hr
= IDirect3DVertexBuffer7_Unlock(dst_vb1
);
559 ok(SUCCEEDED(hr
), "Failed to unlock destination vertex buffer, hr %#x.\n", hr
);
561 IDirect3DVertexBuffer7_Release(dst_vb2
);
562 IDirect3DVertexBuffer7_Release(dst_vb1
);
563 IDirect3DVertexBuffer7_Release(src_vb
);
564 IDirect3D7_Release(d3d7
);
565 IDirect3DDevice7_Release(device
);
566 DestroyWindow(window
);
569 static void test_coop_level_create_device_window(void)
571 HWND focus_window
, device_window
;
575 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
576 0, 0, 640, 480, 0, 0, 0, 0);
577 ddraw
= create_ddraw();
578 ok(!!ddraw
, "Failed to create a ddraw object.\n");
580 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
581 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
582 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
583 ok(!device_window
, "Unexpected device window found.\n");
584 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
585 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
586 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
587 ok(!device_window
, "Unexpected device window found.\n");
588 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
589 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
590 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
591 ok(!device_window
, "Unexpected device window found.\n");
592 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
593 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
594 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
595 ok(!device_window
, "Unexpected device window found.\n");
596 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
597 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
598 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
599 ok(!device_window
, "Unexpected device window found.\n");
601 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
602 if (broken(hr
== DDERR_INVALIDPARAMS
))
604 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
605 IDirectDraw7_Release(ddraw
);
606 DestroyWindow(focus_window
);
610 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
611 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
612 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
613 ok(!device_window
, "Unexpected device window found.\n");
614 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
615 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
616 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
617 ok(!device_window
, "Unexpected device window found.\n");
619 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
620 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
621 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
622 ok(!device_window
, "Unexpected device window found.\n");
623 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
624 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
625 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
626 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
627 ok(!!device_window
, "Device window not found.\n");
629 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
630 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
631 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
632 ok(!device_window
, "Unexpected device window found.\n");
633 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
634 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
635 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
636 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
637 ok(!!device_window
, "Device window not found.\n");
639 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
640 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
641 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
642 ok(!device_window
, "Unexpected device window found.\n");
643 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
644 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
645 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
646 ok(!device_window
, "Unexpected device window found.\n");
647 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
648 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
649 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
650 ok(!device_window
, "Unexpected device window found.\n");
651 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
652 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
653 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
654 ok(!!device_window
, "Device window not found.\n");
656 IDirectDraw7_Release(ddraw
);
657 DestroyWindow(focus_window
);
660 static void test_clipper_blt(void)
662 IDirectDrawSurface7
*src_surface
, *dst_surface
;
663 RECT client_rect
, src_rect
;
664 IDirectDrawClipper
*clipper
;
665 DDSURFACEDESC2 surface_desc
;
666 unsigned int i
, j
, x
, y
;
678 static const DWORD src_data
[] =
680 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
681 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
682 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
684 static const D3DCOLOR expected1
[] =
686 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
687 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
688 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
689 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
691 /* Nvidia on Windows seems to have an off-by-one error
692 * when processing source rectangles. Our left = 1 and
693 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
694 * read as well, but only for the edge pixels on the
695 * output image. The bug happens on the y axis as well,
696 * but we only read one row there, and all source rows
697 * contain the same data. This bug is not dependent on
698 * the presence of a clipper. */
699 static const D3DCOLOR expected1_broken
[] =
701 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
702 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
703 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
704 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
706 static const D3DCOLOR expected2
[] =
708 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
709 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
710 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
711 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
714 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
715 10, 10, 640, 480, 0, 0, 0, 0);
716 ShowWindow(window
, SW_SHOW
);
717 ddraw
= create_ddraw();
718 ok(!!ddraw
, "Failed to create a ddraw object.\n");
720 ret
= GetClientRect(window
, &client_rect
);
721 ok(ret
, "Failed to get client rect.\n");
722 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
723 ok(ret
, "Failed to map client rect.\n");
725 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
726 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
728 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
729 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
730 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
731 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
732 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
733 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
734 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
735 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
736 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
737 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
738 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
739 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
740 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
741 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
742 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
743 "Got unexpected bounding rect {%d, %d, %d, %d}, expected {%d, %d, %d, %d}.\n",
744 rgn_data
->rdh
.rcBound
.left
, rgn_data
->rdh
.rcBound
.top
,
745 rgn_data
->rdh
.rcBound
.right
, rgn_data
->rdh
.rcBound
.bottom
,
746 client_rect
.left
, client_rect
.top
, client_rect
.right
, client_rect
.bottom
);
747 HeapFree(GetProcessHeap(), 0, rgn_data
);
749 r1
= CreateRectRgn(0, 0, 320, 240);
750 ok(!!r1
, "Failed to create region.\n");
751 r2
= CreateRectRgn(320, 240, 640, 480);
752 ok(!!r2
, "Failed to create region.\n");
753 CombineRgn(r1
, r1
, r2
, RGN_OR
);
754 ret
= GetRegionData(r1
, 0, NULL
);
755 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
756 ret
= GetRegionData(r1
, ret
, rgn_data
);
757 ok(!!ret
, "Failed to get region data.\n");
762 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
763 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
764 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
765 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
766 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
767 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
769 HeapFree(GetProcessHeap(), 0, rgn_data
);
771 memset(&surface_desc
, 0, sizeof(surface_desc
));
772 surface_desc
.dwSize
= sizeof(surface_desc
);
773 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
774 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
775 surface_desc
.dwWidth
= 640;
776 surface_desc
.dwHeight
= 480;
777 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
778 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
779 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
780 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
781 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
782 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
784 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
785 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
786 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
787 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
789 memset(&fx
, 0, sizeof(fx
));
790 fx
.dwSize
= sizeof(fx
);
791 hr
= IDirectDrawSurface7_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
792 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
793 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
794 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
796 hr
= IDirectDrawSurface7_Lock(src_surface
, NULL
, &surface_desc
, 0, NULL
);
797 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
798 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
799 ptr
= surface_desc
.lpSurface
;
800 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
801 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
802 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
803 hr
= IDirectDrawSurface7_Unlock(src_surface
, NULL
);
804 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
806 hr
= IDirectDrawSurface7_SetClipper(dst_surface
, clipper
);
807 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
809 SetRect(&src_rect
, 1, 1, 5, 2);
810 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
811 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
812 for (i
= 0; i
< 4; ++i
)
814 for (j
= 0; j
< 4; ++j
)
816 x
= 80 * ((2 * j
) + 1);
817 y
= 60 * ((2 * i
) + 1);
818 color
= get_surface_color(dst_surface
, x
, y
);
819 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
820 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
821 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
825 U5(fx
).dwFillColor
= 0xff0000ff;
826 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
827 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
828 for (i
= 0; i
< 4; ++i
)
830 for (j
= 0; j
< 4; ++j
)
832 x
= 80 * ((2 * j
) + 1);
833 y
= 60 * ((2 * i
) + 1);
834 color
= get_surface_color(dst_surface
, x
, y
);
835 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
836 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
840 hr
= IDirectDrawSurface7_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
841 ok(hr
== DDERR_BLTFASTCANTCLIP
, "Got unexpected hr %#x.\n", hr
);
843 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
844 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
845 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
846 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
847 DestroyWindow(window
);
848 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
849 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
850 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
851 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
852 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
853 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
854 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
855 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
856 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
857 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
858 hr
= IDirectDrawSurface7_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
859 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
861 IDirectDrawSurface7_Release(dst_surface
);
862 IDirectDrawSurface7_Release(src_surface
);
863 refcount
= IDirectDrawClipper_Release(clipper
);
864 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
865 IDirectDraw7_Release(ddraw
);
868 static void test_coop_level_d3d_state(void)
870 IDirectDrawSurface7
*rt
, *surface
;
871 IDirect3DDevice7
*device
;
879 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
880 0, 0, 640, 480, 0, 0, 0, 0);
881 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
883 skip("Failed to create a 3D device, skipping test.\n");
884 DestroyWindow(window
);
888 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
889 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
890 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
891 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
892 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
893 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
894 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
895 ok(!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
896 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
897 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
898 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
899 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
900 color
= get_surface_color(rt
, 320, 240);
901 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
903 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
904 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
905 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
906 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
907 IDirect3D7_Release(d3d
);
908 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
909 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
910 hr
= IDirectDrawSurface7_IsLost(rt
);
911 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
912 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
913 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
914 IDirectDraw7_Release(ddraw
);
916 hr
= IDirect3DDevice7_GetRenderTarget(device
, &surface
);
917 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
918 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
919 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ZENABLE
, &value
);
920 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
921 ok(!!value
, "Got unexpected z-enable state %#x.\n", value
);
922 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, &value
);
923 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
924 ok(!!value
, "Got unexpected alpha blend enable state %#x.\n", value
);
925 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 0.0f
, 0);
926 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
927 color
= get_surface_color(rt
, 320, 240);
928 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
930 IDirectDrawSurface7_Release(surface
);
931 IDirectDrawSurface7_Release(rt
);
932 IDirect3DDevice7_Release(device
);
933 DestroyWindow(window
);
936 static void test_surface_interface_mismatch(void)
938 IDirectDraw7
*ddraw
= NULL
;
939 IDirect3D7
*d3d
= NULL
;
940 IDirectDrawSurface7
*surface
= NULL
, *ds
;
941 IDirectDrawSurface3
*surface3
= NULL
;
942 IDirect3DDevice7
*device
= NULL
;
943 DDSURFACEDESC2 surface_desc
;
950 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
951 0, 0, 640, 480, 0, 0, 0, 0);
952 ddraw
= create_ddraw();
953 ok(!!ddraw
, "Failed to create a ddraw object.\n");
954 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
955 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
957 memset(&surface_desc
, 0, sizeof(surface_desc
));
958 surface_desc
.dwSize
= sizeof(surface_desc
);
959 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
960 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
961 surface_desc
.dwWidth
= 640;
962 surface_desc
.dwHeight
= 480;
964 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
965 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
967 hr
= IDirectDrawSurface7_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
968 ok(SUCCEEDED(hr
), "Failed to QI IDirectDrawSurface3, hr %#x.\n", hr
);
970 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
972 skip("D3D interface is not available, skipping test.\n");
976 memset(&z_fmt
, 0, sizeof(z_fmt
));
977 hr
= IDirect3D7_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
978 if (FAILED(hr
) || !z_fmt
.dwSize
)
980 skip("No depth buffer formats available, skipping test.\n");
984 memset(&surface_desc
, 0, sizeof(surface_desc
));
985 surface_desc
.dwSize
= sizeof(surface_desc
);
986 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
987 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
988 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
989 surface_desc
.dwWidth
= 640;
990 surface_desc
.dwHeight
= 480;
991 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
992 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
996 /* Using a different surface interface version still works */
997 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
998 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
999 refcount
= IDirectDrawSurface7_Release(ds
);
1000 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1005 hr
= IDirect3D7_CreateDevice(d3d
, &IID_IDirect3DHALDevice
, (IDirectDrawSurface7
*)surface3
, &device
);
1006 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1010 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffff0000, 0.0f
, 0);
1011 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1012 color
= get_surface_color(surface
, 320, 240);
1013 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1016 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1017 if (surface
) IDirectDrawSurface7_Release(surface
);
1018 if (device
) IDirect3DDevice7_Release(device
);
1019 if (d3d
) IDirect3D7_Release(d3d
);
1020 if (ddraw
) IDirectDraw7_Release(ddraw
);
1021 DestroyWindow(window
);
1024 static void test_coop_level_threaded(void)
1026 struct create_window_thread_param p
;
1027 IDirectDraw7
*ddraw
;
1030 ddraw
= create_ddraw();
1031 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1032 create_window_thread(&p
);
1034 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1035 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1037 IDirectDraw7_Release(ddraw
);
1038 destroy_window_thread(&p
);
1041 static void test_depth_blit(void)
1043 IDirect3DDevice7
*device
;
1051 { -1.0, 1.0, 0.50f
, 0xff00ff00},
1052 { 1.0, 1.0, 0.50f
, 0xff00ff00},
1053 { -1.0, -1.0, 0.50f
, 0xff00ff00},
1054 { 1.0, -1.0, 0.50f
, 0xff00ff00},
1056 static const D3DCOLOR expected_colors
[4][4] =
1058 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1059 {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
1060 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1061 {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1063 DDSURFACEDESC2 ddsd_new
, ddsd_existing
;
1065 IDirectDrawSurface7
*ds1
, *ds2
, *ds3
, *rt
;
1066 RECT src_rect
, dst_rect
;
1071 IDirectDraw7
*ddraw
;
1075 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1076 0, 0, 640, 480, 0, 0, 0, 0);
1077 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1079 skip("Failed to create a 3D device, skipping test.\n");
1080 DestroyWindow(window
);
1084 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1085 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
1086 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1087 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
1088 IDirect3D7_Release(d3d
);
1090 ds1
= get_depth_stencil(device
);
1092 memset(&ddsd_new
, 0, sizeof(ddsd_new
));
1093 ddsd_new
.dwSize
= sizeof(ddsd_new
);
1094 memset(&ddsd_existing
, 0, sizeof(ddsd_existing
));
1095 ddsd_existing
.dwSize
= sizeof(ddsd_existing
);
1096 hr
= IDirectDrawSurface7_GetSurfaceDesc(ds1
, &ddsd_existing
);
1097 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
1098 ddsd_new
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
1099 ddsd_new
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1100 ddsd_new
.dwWidth
= ddsd_existing
.dwWidth
;
1101 ddsd_new
.dwHeight
= ddsd_existing
.dwHeight
;
1102 U4(ddsd_new
).ddpfPixelFormat
= U4(ddsd_existing
).ddpfPixelFormat
;
1103 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd_new
, &ds2
, NULL
);
1104 ok(SUCCEEDED(hr
), "Failed to create a z buffer, hr %#x.\n", hr
);
1105 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd_new
, &ds3
, NULL
);
1106 ok(SUCCEEDED(hr
), "Failed to create a z buffer, hr %#x.\n", hr
);
1107 IDirectDraw7_Release(ddraw
);
1109 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_TRUE
);
1110 ok(SUCCEEDED(hr
), "Failed to enable z testing, hr %#x.\n", hr
);
1111 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZFUNC
, D3DCMP_LESSEQUAL
);
1112 ok(SUCCEEDED(hr
), "Failed to set the z function, hr %#x.\n", hr
);
1113 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
1114 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
1116 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
1117 ok(SUCCEEDED(hr
), "Failed to clear the z buffer, hr %#x.\n", hr
);
1120 SetRect(&src_rect
, 0, 0, 320, 240);
1121 SetRect(&dst_rect
, 0, 0, 320, 240);
1122 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1123 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1124 /* Different locations. */
1125 SetRect(&src_rect
, 0, 0, 320, 240);
1126 SetRect(&dst_rect
, 320, 240, 640, 480);
1127 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1128 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1130 SetRect(&src_rect
, 0, 0, 320, 240);
1131 SetRect(&dst_rect
, 0, 0, 640, 480);
1132 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1133 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1135 SetRect(&src_rect
, 0, 480, 640, 0);
1136 SetRect(&dst_rect
, 0, 0, 640, 480);
1137 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1138 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1139 SetRect(&src_rect
, 0, 0, 640, 480);
1140 SetRect(&dst_rect
, 0, 480, 640, 0);
1141 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1142 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
1143 /* Full, explicit. */
1144 SetRect(&src_rect
, 0, 0, 640, 480);
1145 SetRect(&dst_rect
, 0, 0, 640, 480);
1146 hr
= IDirectDrawSurface7_Blt(ds2
, &dst_rect
, ds1
, &src_rect
, DDBLT_WAIT
, NULL
);
1147 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1148 /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
1150 /* Depth blit inside a BeginScene / EndScene pair */
1151 hr
= IDirect3DDevice7_BeginScene(device
);
1152 ok(SUCCEEDED(hr
), "Failed to start scene, hr %#x.\n", hr
);
1153 /* From the current depth stencil */
1154 hr
= IDirectDrawSurface7_Blt(ds2
, NULL
, ds1
, NULL
, DDBLT_WAIT
, NULL
);
1155 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1156 /* To the current depth stencil */
1157 hr
= IDirectDrawSurface7_Blt(ds1
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1158 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1159 /* Between unbound surfaces */
1160 hr
= IDirectDrawSurface7_Blt(ds3
, NULL
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1161 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1162 hr
= IDirect3DDevice7_EndScene(device
);
1163 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1165 /* Avoid changing the depth stencil, it doesn't work properly on Windows.
1166 * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
1167 * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
1168 * a reliable result(z = 0.0) */
1169 memset(&fx
, 0, sizeof(fx
));
1170 fx
.dwSize
= sizeof(fx
);
1171 hr
= IDirectDrawSurface7_Blt(ds2
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
1172 ok(SUCCEEDED(hr
), "Failed to clear the source z buffer, hr %#x.\n", hr
);
1174 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
, 0xffff0000, 1.0f
, 0);
1175 ok(SUCCEEDED(hr
), "Failed to clear the color and z buffers, hr %#x.\n", hr
);
1176 SetRect(&dst_rect
, 0, 0, 320, 240);
1177 hr
= IDirectDrawSurface7_Blt(ds1
, &dst_rect
, ds2
, NULL
, DDBLT_WAIT
, NULL
);
1178 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1179 IDirectDrawSurface7_Release(ds3
);
1180 IDirectDrawSurface7_Release(ds2
);
1181 IDirectDrawSurface7_Release(ds1
);
1183 hr
= IDirect3DDevice7_BeginScene(device
);
1184 ok(SUCCEEDED(hr
), "Failed to start scene, hr %#x.\n", hr
);
1185 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
1187 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1188 hr
= IDirect3DDevice7_EndScene(device
);
1189 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1191 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1192 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1193 for (i
= 0; i
< 4; ++i
)
1195 for (j
= 0; j
< 4; ++j
)
1197 unsigned int x
= 80 * ((2 * j
) + 1);
1198 unsigned int y
= 60 * ((2 * i
) + 1);
1199 color
= get_surface_color(rt
, x
, y
);
1200 ok(compare_color(color
, expected_colors
[i
][j
], 1),
1201 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors
[i
][j
], x
, y
, color
);
1205 IDirectDrawSurface7_Release(rt
);
1206 IDirect3DDevice7_Release(device
);
1207 DestroyWindow(window
);
1210 static void test_texture_load_ckey(void)
1213 IDirect3DDevice7
*device
;
1214 IDirectDraw7
*ddraw
;
1215 IDirectDrawSurface7
*src
;
1216 IDirectDrawSurface7
*dst
;
1217 DDSURFACEDESC2 ddsd
;
1222 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1223 0, 0, 640, 480, 0, 0, 0, 0);
1224 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1226 skip("Failed to create a 3D device, skipping test.\n");
1227 DestroyWindow(window
);
1231 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1232 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
1233 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1234 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
1235 IDirect3D7_Release(d3d
);
1237 memset(&ddsd
, 0, sizeof(ddsd
));
1238 ddsd
.dwSize
= sizeof(ddsd
);
1239 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1240 ddsd
.dwHeight
= 128;
1242 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
;
1243 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &src
, NULL
);
1244 ok(SUCCEEDED(hr
), "Failed to create source texture, hr %#x.\n", hr
);
1245 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1246 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &dst
, NULL
);
1247 ok(SUCCEEDED(hr
), "Failed to create destination texture, hr %#x.\n", hr
);
1249 /* No surface has a color key */
1250 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1251 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1252 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0xdeadbeef;
1253 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1254 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1255 ok(ckey
.dwColorSpaceLowValue
== 0xdeadbeef, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1256 ok(ckey
.dwColorSpaceHighValue
== 0xdeadbeef, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1258 /* Source surface has a color key */
1259 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x0000ff00;
1260 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1261 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1262 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1263 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1264 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1265 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1266 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1267 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1269 /* Both surfaces have a color key: Dest ckey is overwritten */
1270 ckey
.dwColorSpaceLowValue
= ckey
.dwColorSpaceHighValue
= 0x000000ff;
1271 hr
= IDirectDrawSurface7_SetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1272 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1273 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1274 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1275 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1276 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1277 ok(ckey
.dwColorSpaceLowValue
== 0x0000ff00, "dwColorSpaceLowValue is %#x.\n", ckey
.dwColorSpaceLowValue
);
1278 ok(ckey
.dwColorSpaceHighValue
== 0x0000ff00, "dwColorSpaceHighValue is %#x.\n", ckey
.dwColorSpaceHighValue
);
1280 /* Only the destination has a color key: It is deleted. This behavior differs from
1281 * IDirect3DTexture(2)::Load */
1282 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, NULL
);
1283 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1284 hr
= IDirectDrawSurface7_GetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
1285 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1286 hr
= IDirect3DDevice7_Load(device
, dst
, NULL
, src
, NULL
, 0);
1287 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
1288 hr
= IDirectDrawSurface7_GetColorKey(dst
, DDCKEY_SRCBLT
, &ckey
);
1289 todo_wine
ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1291 IDirectDrawSurface7_Release(dst
);
1292 IDirectDrawSurface7_Release(src
);
1293 IDirectDraw7_Release(ddraw
);
1294 IDirect3DDevice7_Release(device
);
1295 DestroyWindow(window
);
1298 static void test_zenable(void)
1302 struct vec4 position
;
1307 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1308 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xff00ff00},
1309 {{640.0f
, 480.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1310 {{640.0f
, 0.0f
, 1.5f
, 1.0f
}, 0xff00ff00},
1312 IDirect3DDevice7
*device
;
1313 IDirectDrawSurface7
*rt
;
1320 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1321 0, 0, 640, 480, 0, 0, 0, 0);
1322 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1324 skip("Failed to create a 3D device, skipping test.\n");
1325 DestroyWindow(window
);
1329 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1330 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
1332 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 0.0f
, 0);
1333 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1334 hr
= IDirect3DDevice7_BeginScene(device
);
1335 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1336 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, tquad
, 4, 0);
1337 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1338 hr
= IDirect3DDevice7_EndScene(device
);
1339 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1341 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1342 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1343 for (i
= 0; i
< 4; ++i
)
1345 for (j
= 0; j
< 4; ++j
)
1347 x
= 80 * ((2 * j
) + 1);
1348 y
= 60 * ((2 * i
) + 1);
1349 color
= get_surface_color(rt
, x
, y
);
1350 ok(compare_color(color
, 0x0000ff00, 1),
1351 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1354 IDirectDrawSurface7_Release(rt
);
1356 IDirect3DDevice7_Release(device
);
1357 DestroyWindow(window
);
1360 static void test_ck_rgba(void)
1364 struct vec4 position
;
1365 struct vec2 texcoord
;
1369 {{ 0.0f
, 480.0f
, 0.25f
, 1.0f
}, {0.0f
, 0.0f
}},
1370 {{ 0.0f
, 0.0f
, 0.25f
, 1.0f
}, {0.0f
, 1.0f
}},
1371 {{640.0f
, 480.0f
, 0.25f
, 1.0f
}, {1.0f
, 0.0f
}},
1372 {{640.0f
, 0.0f
, 0.25f
, 1.0f
}, {1.0f
, 1.0f
}},
1373 {{ 0.0f
, 480.0f
, 0.75f
, 1.0f
}, {0.0f
, 0.0f
}},
1374 {{ 0.0f
, 0.0f
, 0.75f
, 1.0f
}, {0.0f
, 1.0f
}},
1375 {{640.0f
, 480.0f
, 0.75f
, 1.0f
}, {1.0f
, 0.0f
}},
1376 {{640.0f
, 0.0f
, 0.75f
, 1.0f
}, {1.0f
, 1.0f
}},
1380 D3DCOLOR fill_color
;
1383 D3DCOLOR result1
, result1_broken
;
1384 D3DCOLOR result2
, result2_broken
;
1388 /* r200 on Windows doesn't check the alpha component when applying the color
1389 * key, so the key matches on every texel. */
1390 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1391 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x000000ff, 0x000000ff},
1392 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1393 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1394 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00, 0x000000ff},
1395 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00, 0x000000ff},
1396 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00, 0x00807f00},
1397 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
1400 IDirectDrawSurface7
*texture
;
1401 DDSURFACEDESC2 surface_desc
;
1402 IDirect3DDevice7
*device
;
1403 IDirectDrawSurface7
*rt
;
1404 IDirectDraw7
*ddraw
;
1412 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1413 0, 0, 640, 480, 0, 0, 0, 0);
1414 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1416 skip("Failed to create a 3D device, skipping test.\n");
1417 DestroyWindow(window
);
1421 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1422 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1423 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1424 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1425 IDirect3D7_Release(d3d
);
1427 memset(&surface_desc
, 0, sizeof(surface_desc
));
1428 surface_desc
.dwSize
= sizeof(surface_desc
);
1429 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1430 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1431 surface_desc
.dwWidth
= 256;
1432 surface_desc
.dwHeight
= 256;
1433 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1434 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1435 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1436 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1437 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1438 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1439 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1440 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1441 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1442 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
1443 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1445 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture
);
1446 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1447 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1448 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1449 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1450 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1452 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1453 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1455 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1457 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1458 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1459 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1460 ok(SUCCEEDED(hr
), "Failed to enable alpha blending, hr %#x.\n", hr
);
1462 memset(&fx
, 0, sizeof(fx
));
1463 fx
.dwSize
= sizeof(fx
);
1464 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1465 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1466 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1468 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffff0000, 1.0f
, 0);
1469 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1470 hr
= IDirect3DDevice7_BeginScene(device
);
1471 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1472 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1473 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1474 hr
= IDirect3DDevice7_EndScene(device
);
1475 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1477 color
= get_surface_color(rt
, 320, 240);
1478 ok(compare_color(color
, tests
[i
].result1
, 1) || compare_color(color
, tests
[i
].result1_broken
, 1),
1479 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1480 tests
[i
].result1
, i
, color
);
1482 U5(fx
).dwFillColor
= 0xff0000ff;
1483 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1484 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1486 hr
= IDirect3DDevice7_BeginScene(device
);
1487 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1488 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[4], 4, 0);
1489 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1490 hr
= IDirect3DDevice7_EndScene(device
);
1491 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1493 /* This tests that fragments that are masked out by the color key are
1494 * discarded, instead of just fully transparent. */
1495 color
= get_surface_color(rt
, 320, 240);
1496 ok(compare_color(color
, tests
[i
].result2
, 1) || compare_color(color
, tests
[i
].result2_broken
, 1),
1497 "Expected color 0x%08x for test %u, got 0x%08x.\n",
1498 tests
[i
].result2
, i
, color
);
1501 IDirectDrawSurface7_Release(rt
);
1502 IDirectDrawSurface7_Release(texture
);
1503 IDirectDraw7_Release(ddraw
);
1504 IDirect3DDevice7_Release(device
);
1505 DestroyWindow(window
);
1508 static void test_ck_default(void)
1512 struct vec4 position
;
1513 struct vec2 texcoord
;
1517 {{ 0.0f
, 480.0f
, 0.0f
, 1.0f
}, {0.0f
, 0.0f
}},
1518 {{ 0.0f
, 0.0f
, 0.0f
, 1.0f
}, {0.0f
, 1.0f
}},
1519 {{640.0f
, 480.0f
, 0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
1520 {{640.0f
, 0.0f
, 0.0f
, 1.0f
}, {1.0f
, 1.0f
}},
1522 IDirectDrawSurface7
*surface
, *rt
;
1523 DDSURFACEDESC2 surface_desc
;
1524 IDirect3DDevice7
*device
;
1525 IDirectDraw7
*ddraw
;
1533 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1534 0, 0, 640, 480, 0, 0, 0, 0);
1536 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1538 skip("Failed to create a 3D device, skipping test.\n");
1539 DestroyWindow(window
);
1543 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1544 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1545 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1546 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1547 IDirect3D7_Release(d3d
);
1549 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
1550 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1552 memset(&surface_desc
, 0, sizeof(surface_desc
));
1553 surface_desc
.dwSize
= sizeof(surface_desc
);
1554 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1555 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1556 surface_desc
.dwWidth
= 256;
1557 surface_desc
.dwHeight
= 256;
1558 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
1559 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1560 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
1561 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1562 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1563 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1564 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1565 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1566 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1567 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1568 hr
= IDirect3DDevice7_SetTexture(device
, 0, surface
);
1569 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
1571 memset(&fx
, 0, sizeof(fx
));
1572 fx
.dwSize
= sizeof(fx
);
1573 U5(fx
).dwFillColor
= 0x000000ff;
1574 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1575 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1577 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1578 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1579 hr
= IDirect3DDevice7_BeginScene(device
);
1580 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1581 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1582 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1583 ok(!value
, "Got unexpected color keying state %#x.\n", value
);
1584 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1585 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1586 hr
= IDirect3DDevice7_EndScene(device
);
1587 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1588 color
= get_surface_color(rt
, 320, 240);
1589 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1591 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff00ff00, 1.0f
, 0);
1592 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1593 hr
= IDirect3DDevice7_BeginScene(device
);
1594 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1595 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1596 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
1597 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZRHW
| D3DFVF_TEX1
, &tquad
[0], 4, 0);
1598 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
1599 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, &value
);
1600 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1601 ok(!!value
, "Got unexpected color keying state %#x.\n", value
);
1602 hr
= IDirect3DDevice7_EndScene(device
);
1603 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1604 color
= get_surface_color(rt
, 320, 240);
1605 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1607 IDirectDrawSurface7_Release(surface
);
1608 IDirectDrawSurface7_Release(rt
);
1609 IDirect3DDevice7_Release(device
);
1610 IDirectDraw7_Release(ddraw
);
1611 DestroyWindow(window
);
1614 static void test_ck_complex(void)
1616 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
1617 D3DDEVICEDESC7 device_desc
;
1618 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
1619 DDSURFACEDESC2 surface_desc
;
1620 IDirect3DDevice7
*device
;
1621 DDCOLORKEY color_key
;
1622 IDirectDraw7
*ddraw
;
1629 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1630 0, 0, 640, 480, 0, 0, 0, 0);
1631 if (!(device
= create_device(window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1633 skip("Failed to create a 3D device, skipping test.\n");
1634 DestroyWindow(window
);
1637 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
1638 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
1639 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
1640 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1641 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
1642 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
1643 IDirect3D7_Release(d3d
);
1645 memset(&surface_desc
, 0, sizeof(surface_desc
));
1646 surface_desc
.dwSize
= sizeof(surface_desc
);
1647 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1648 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1649 surface_desc
.dwWidth
= 128;
1650 surface_desc
.dwHeight
= 128;
1651 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1652 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1654 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1655 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1656 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1657 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1658 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1659 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1660 memset(&color_key
, 0, sizeof(color_key
));
1661 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1662 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1663 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1664 color_key
.dwColorSpaceLowValue
);
1665 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1666 color_key
.dwColorSpaceHighValue
);
1669 IDirectDrawSurface_AddRef(mipmap
);
1670 for (i
= 0; i
< 7; ++i
)
1672 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1673 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1674 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1675 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1677 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1678 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1679 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1680 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1682 IDirectDrawSurface_Release(mipmap
);
1686 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1687 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1688 IDirectDrawSurface_Release(mipmap
);
1689 refcount
= IDirectDrawSurface7_Release(surface
);
1690 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1692 memset(&surface_desc
, 0, sizeof(surface_desc
));
1693 surface_desc
.dwSize
= sizeof(surface_desc
);
1694 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1695 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1696 U5(surface_desc
).dwBackBufferCount
= 1;
1697 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1698 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1700 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1701 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1702 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1703 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1704 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1705 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1706 memset(&color_key
, 0, sizeof(color_key
));
1707 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1708 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1709 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1710 color_key
.dwColorSpaceLowValue
);
1711 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1712 color_key
.dwColorSpaceHighValue
);
1714 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &tmp
);
1715 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1717 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1718 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1719 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1720 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1721 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1722 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1723 memset(&color_key
, 0, sizeof(color_key
));
1724 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1725 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1726 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1727 color_key
.dwColorSpaceLowValue
);
1728 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1729 color_key
.dwColorSpaceHighValue
);
1731 IDirectDrawSurface_Release(tmp
);
1733 refcount
= IDirectDrawSurface7_Release(surface
);
1734 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1736 if (!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
1738 skip("Device does not support cubemaps.\n");
1741 memset(&surface_desc
, 0, sizeof(surface_desc
));
1742 surface_desc
.dwSize
= sizeof(surface_desc
);
1743 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1744 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1745 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
;
1746 surface_desc
.dwWidth
= 128;
1747 surface_desc
.dwHeight
= 128;
1748 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1749 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1751 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1752 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1753 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1754 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1755 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1756 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1758 caps
.dwCaps2
= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
1759 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
1760 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1762 hr
= IDirectDrawSurface7_GetColorKey(mipmap
, DDCKEY_SRCBLT
, &color_key
);
1763 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1764 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1765 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1766 hr
= IDirectDrawSurface7_SetColorKey(mipmap
, DDCKEY_SRCBLT
, &color_key
);
1767 todo_wine
ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1769 color_key
.dwColorSpaceLowValue
= 0;
1770 color_key
.dwColorSpaceHighValue
= 0;
1771 hr
= IDirectDrawSurface7_GetColorKey(mipmap
, DDCKEY_SRCBLT
, &color_key
);
1772 todo_wine
ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1773 todo_wine
ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x.\n",
1774 color_key
.dwColorSpaceLowValue
);
1775 todo_wine
ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x.\n",
1776 color_key
.dwColorSpaceHighValue
);
1778 IDirectDrawSurface_AddRef(mipmap
);
1779 for (i
= 0; i
< 7; ++i
)
1781 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1782 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1783 hr
= IDirectDrawSurface7_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1784 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1786 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1787 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1788 hr
= IDirectDrawSurface7_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1789 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1791 IDirectDrawSurface_Release(mipmap
);
1795 IDirectDrawSurface7_Release(mipmap
);
1797 refcount
= IDirectDrawSurface7_Release(surface
);
1798 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1801 IDirectDraw7_Release(ddraw
);
1802 refcount
= IDirect3DDevice7_Release(device
);
1803 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1804 DestroyWindow(window
);
1810 REFIID refcount_iid
;
1814 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1815 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1817 ULONG refcount
, expected_refcount
;
1818 IUnknown
*iface1
, *iface2
;
1822 for (i
= 0; i
< entry_count
; ++i
)
1824 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1825 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1828 for (j
= 0; j
< entry_count
; ++j
)
1830 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1831 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1834 expected_refcount
= 0;
1835 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1836 ++expected_refcount
;
1837 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1838 ++expected_refcount
;
1839 refcount
= IUnknown_Release(iface2
);
1840 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1841 refcount
, test_name
, i
, j
, expected_refcount
);
1845 expected_refcount
= 0;
1846 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1847 ++expected_refcount
;
1848 refcount
= IUnknown_Release(iface1
);
1849 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1850 refcount
, test_name
, i
, expected_refcount
);
1855 static void test_surface_qi(void)
1857 static const struct qi_test tests
[] =
1859 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
1860 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
1861 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1862 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1863 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1864 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1865 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1866 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1867 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1868 {&IID_IDirect3DDevice7
, NULL
, E_NOINTERFACE
},
1869 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
1870 {&IID_IDirect3DDevice2
, NULL
, E_NOINTERFACE
},
1871 {&IID_IDirect3DDevice
, NULL
, E_NOINTERFACE
},
1872 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
1873 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
1874 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
1875 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
1876 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
1877 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
1878 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
1879 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
1880 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
1881 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
1882 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
1883 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
1884 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
1885 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
1886 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
1887 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
1888 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
1889 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
1890 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
1891 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
1892 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
1893 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
1894 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
1895 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
1896 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
1897 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
1898 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
1899 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
1900 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1903 IDirectDrawSurface7
*surface
;
1904 DDSURFACEDESC2 surface_desc
;
1905 IDirect3DDevice7
*device
;
1906 IDirectDraw7
*ddraw
;
1910 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1911 0, 0, 640, 480, 0, 0, 0, 0);
1912 /* Try to create a D3D device to see if the ddraw implementation supports
1913 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1914 * doesn't support e.g. the IDirect3DTexture interfaces. */
1915 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1917 skip("Failed to create a 3D device, skipping test.\n");
1918 DestroyWindow(window
);
1921 IDirect3DDevice_Release(device
);
1922 ddraw
= create_ddraw();
1923 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1924 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
1925 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1927 memset(&surface_desc
, 0, sizeof(surface_desc
));
1928 surface_desc
.dwSize
= sizeof(surface_desc
);
1929 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1930 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1931 surface_desc
.dwWidth
= 512;
1932 surface_desc
.dwHeight
= 512;
1933 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1934 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1936 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface7
, tests
, sizeof(tests
) / sizeof(*tests
));
1938 IDirectDrawSurface7_Release(surface
);
1939 IDirectDraw7_Release(ddraw
);
1940 DestroyWindow(window
);
1943 static void test_device_qi(void)
1945 static const struct qi_test tests
[] =
1947 {&IID_IDirect3DTexture2
, NULL
, E_NOINTERFACE
},
1948 {&IID_IDirect3DTexture
, NULL
, E_NOINTERFACE
},
1949 {&IID_IDirectDrawGammaControl
, NULL
, E_NOINTERFACE
},
1950 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1951 {&IID_IDirectDrawSurface7
, NULL
, E_NOINTERFACE
},
1952 {&IID_IDirectDrawSurface4
, NULL
, E_NOINTERFACE
},
1953 {&IID_IDirectDrawSurface3
, NULL
, E_NOINTERFACE
},
1954 {&IID_IDirectDrawSurface2
, NULL
, E_NOINTERFACE
},
1955 {&IID_IDirectDrawSurface
, NULL
, E_NOINTERFACE
},
1956 {&IID_IDirect3DDevice7
, &IID_IDirect3DDevice7
, S_OK
},
1957 {&IID_IDirect3DDevice3
, NULL
, E_NOINTERFACE
},
1958 {&IID_IDirect3DDevice2
, NULL
, E_NOINTERFACE
},
1959 {&IID_IDirect3DDevice
, NULL
, E_NOINTERFACE
},
1960 {&IID_IDirect3DRampDevice
, NULL
, E_NOINTERFACE
},
1961 {&IID_IDirect3DRGBDevice
, NULL
, E_NOINTERFACE
},
1962 {&IID_IDirect3DHALDevice
, NULL
, E_NOINTERFACE
},
1963 {&IID_IDirect3DMMXDevice
, NULL
, E_NOINTERFACE
},
1964 {&IID_IDirect3DRefDevice
, NULL
, E_NOINTERFACE
},
1965 {&IID_IDirect3DTnLHalDevice
, NULL
, E_NOINTERFACE
},
1966 {&IID_IDirect3DNullDevice
, NULL
, E_NOINTERFACE
},
1967 {&IID_IDirect3D7
, NULL
, E_NOINTERFACE
},
1968 {&IID_IDirect3D3
, NULL
, E_NOINTERFACE
},
1969 {&IID_IDirect3D2
, NULL
, E_NOINTERFACE
},
1970 {&IID_IDirect3D
, NULL
, E_NOINTERFACE
},
1971 {&IID_IDirectDraw7
, NULL
, E_NOINTERFACE
},
1972 {&IID_IDirectDraw4
, NULL
, E_NOINTERFACE
},
1973 {&IID_IDirectDraw3
, NULL
, E_NOINTERFACE
},
1974 {&IID_IDirectDraw2
, NULL
, E_NOINTERFACE
},
1975 {&IID_IDirectDraw
, NULL
, E_NOINTERFACE
},
1976 {&IID_IDirect3DLight
, NULL
, E_NOINTERFACE
},
1977 {&IID_IDirect3DMaterial
, NULL
, E_NOINTERFACE
},
1978 {&IID_IDirect3DMaterial2
, NULL
, E_NOINTERFACE
},
1979 {&IID_IDirect3DMaterial3
, NULL
, E_NOINTERFACE
},
1980 {&IID_IDirect3DExecuteBuffer
, NULL
, E_NOINTERFACE
},
1981 {&IID_IDirect3DViewport
, NULL
, E_NOINTERFACE
},
1982 {&IID_IDirect3DViewport2
, NULL
, E_NOINTERFACE
},
1983 {&IID_IDirect3DViewport3
, NULL
, E_NOINTERFACE
},
1984 {&IID_IDirect3DVertexBuffer
, NULL
, E_NOINTERFACE
},
1985 {&IID_IDirect3DVertexBuffer7
, NULL
, E_NOINTERFACE
},
1986 {&IID_IDirectDrawPalette
, NULL
, E_NOINTERFACE
},
1987 {&IID_IDirectDrawClipper
, NULL
, E_NOINTERFACE
},
1988 {&IID_IUnknown
, &IID_IDirect3DDevice7
, S_OK
},
1991 IDirect3DDevice7
*device
;
1994 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1995 0, 0, 640, 480, 0, 0, 0, 0);
1996 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
1998 skip("Failed to create a 3D device, skipping test.\n");
1999 DestroyWindow(window
);
2003 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirect3DDevice7
, tests
, sizeof(tests
) / sizeof(*tests
));
2005 IDirect3DDevice7_Release(device
);
2006 DestroyWindow(window
);
2009 static void test_wndproc(void)
2011 LONG_PTR proc
, ddraw_proc
;
2012 IDirectDraw7
*ddraw
;
2018 static struct message messages
[] =
2020 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2021 {WM_MOVE
, FALSE
, 0},
2022 {WM_SIZE
, FALSE
, 0},
2023 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2024 {WM_ACTIVATE
, FALSE
, 0},
2025 {WM_SETFOCUS
, FALSE
, 0},
2029 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2030 ddraw
= create_ddraw();
2031 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2033 wc
.lpfnWndProc
= test_proc
;
2034 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2035 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2037 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2038 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2040 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2041 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2042 (LONG_PTR
)test_proc
, proc
);
2043 expect_messages
= messages
;
2044 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2045 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2046 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2047 expect_messages
= NULL
;
2048 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2049 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2050 (LONG_PTR
)test_proc
, proc
);
2051 ref
= IDirectDraw7_Release(ddraw
);
2052 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2053 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2054 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2055 (LONG_PTR
)test_proc
, proc
);
2057 /* DDSCL_NORMAL doesn't. */
2058 ddraw
= create_ddraw();
2059 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2060 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2061 (LONG_PTR
)test_proc
, proc
);
2062 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2063 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2064 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2065 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2066 (LONG_PTR
)test_proc
, proc
);
2067 ref
= IDirectDraw7_Release(ddraw
);
2068 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2069 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2070 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2071 (LONG_PTR
)test_proc
, proc
);
2073 /* The original window proc is only restored by ddraw if the current
2074 * window proc matches the one ddraw set. This also affects switching
2075 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2076 ddraw
= create_ddraw();
2077 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2078 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2079 (LONG_PTR
)test_proc
, proc
);
2080 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2081 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2082 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2083 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2084 (LONG_PTR
)test_proc
, proc
);
2086 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2087 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2088 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2089 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2090 (LONG_PTR
)test_proc
, proc
);
2091 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2092 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2093 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2094 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2095 (LONG_PTR
)test_proc
, proc
);
2096 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2097 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2098 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2099 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2100 (LONG_PTR
)DefWindowProcA
, proc
);
2101 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2102 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2103 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2104 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2105 (LONG_PTR
)DefWindowProcA
, proc
);
2106 ref
= IDirectDraw7_Release(ddraw
);
2107 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2108 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2109 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2110 (LONG_PTR
)test_proc
, proc
);
2112 ddraw
= create_ddraw();
2113 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2114 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2115 (LONG_PTR
)test_proc
, proc
);
2116 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2117 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2118 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2119 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2120 (LONG_PTR
)test_proc
, proc
);
2121 ref
= IDirectDraw7_Release(ddraw
);
2122 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2123 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2124 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2125 (LONG_PTR
)DefWindowProcA
, proc
);
2127 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2128 expect_messages
= NULL
;
2129 DestroyWindow(window
);
2130 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2133 static void test_window_style(void)
2135 LONG style
, exstyle
, tmp
, expected_style
;
2136 RECT fullscreen_rect
, r
;
2137 IDirectDraw7
*ddraw
;
2143 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2144 0, 0, 100, 100, 0, 0, 0, 0);
2145 ddraw
= create_ddraw();
2146 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2148 style
= GetWindowLongA(window
, GWL_STYLE
);
2149 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2150 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2152 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2153 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2155 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2156 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2157 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2158 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2160 GetWindowRect(window
, &r
);
2161 ok(EqualRect(&r
, &fullscreen_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2162 fullscreen_rect
.left
, fullscreen_rect
.top
, fullscreen_rect
.right
, fullscreen_rect
.bottom
,
2163 r
.left
, r
.top
, r
.right
, r
.bottom
);
2164 GetClientRect(window
, &r
);
2165 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2167 ret
= SetForegroundWindow(GetDesktopWindow());
2168 ok(ret
, "Failed to set foreground window.\n");
2170 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2171 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2172 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2173 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2175 ret
= SetForegroundWindow(window
);
2176 ok(ret
, "Failed to set foreground window.\n");
2177 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2178 * the next tests expect this. */
2179 ShowWindow(window
, SW_HIDE
);
2181 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2182 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2184 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2185 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2186 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2187 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2189 ShowWindow(window
, SW_SHOW
);
2190 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2191 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2193 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2194 expected_style
= style
| WS_VISIBLE
;
2195 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2196 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2197 expected_style
= exstyle
| WS_EX_TOPMOST
;
2198 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2200 ret
= SetForegroundWindow(GetDesktopWindow());
2201 ok(ret
, "Failed to set foreground window.\n");
2202 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2203 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2204 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2205 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2206 expected_style
= exstyle
| WS_EX_TOPMOST
;
2207 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2209 ref
= IDirectDraw7_Release(ddraw
);
2210 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2212 DestroyWindow(window
);
2215 static void test_redundant_mode_set(void)
2217 DDSURFACEDESC2 surface_desc
= {0};
2218 IDirectDraw7
*ddraw
;
2224 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2225 0, 0, 100, 100, 0, 0, 0, 0);
2226 ddraw
= create_ddraw();
2227 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2228 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2229 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2231 surface_desc
.dwSize
= sizeof(surface_desc
);
2232 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &surface_desc
);
2233 ok(SUCCEEDED(hr
), "GetDipslayMode failed, hr %#x.\n", hr
);
2235 hr
= IDirectDraw7_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2236 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2237 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2239 GetWindowRect(window
, &r
);
2242 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2243 GetWindowRect(window
, &s
);
2244 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2245 r
.left
, r
.top
, r
.right
, r
.bottom
,
2246 s
.left
, s
.top
, s
.right
, s
.bottom
);
2248 hr
= IDirectDraw7_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2249 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
, 0, 0);
2250 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2252 GetWindowRect(window
, &s
);
2253 ok(EqualRect(&r
, &s
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2254 r
.left
, r
.top
, r
.right
, r
.bottom
,
2255 s
.left
, s
.top
, s
.right
, s
.bottom
);
2257 ref
= IDirectDraw7_Release(ddraw
);
2258 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2260 DestroyWindow(window
);
2263 static SIZE screen_size
, screen_size2
;
2265 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2267 if (message
== WM_SIZE
)
2269 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2270 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2273 return test_proc(hwnd
, message
, wparam
, lparam
);
2276 static LRESULT CALLBACK
mode_set_proc2(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2278 if (message
== WM_SIZE
)
2280 screen_size2
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2281 screen_size2
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2284 return test_proc(hwnd
, message
, wparam
, lparam
);
2287 struct test_coop_level_mode_set_enum_param
2289 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2292 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC2
*surface_desc
, void *context
)
2294 struct test_coop_level_mode_set_enum_param
*param
= context
;
2296 if (U1(U4(*surface_desc
).ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2297 return DDENUMRET_OK
;
2298 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2299 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2300 return DDENUMRET_OK
;
2302 if (!param
->ddraw_width
)
2304 param
->ddraw_width
= surface_desc
->dwWidth
;
2305 param
->ddraw_height
= surface_desc
->dwHeight
;
2306 return DDENUMRET_OK
;
2308 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2309 return DDENUMRET_OK
;
2311 param
->user32_width
= surface_desc
->dwWidth
;
2312 param
->user32_height
= surface_desc
->dwHeight
;
2313 return DDENUMRET_CANCEL
;
2316 static void test_coop_level_mode_set(void)
2318 IDirectDrawSurface7
*primary
;
2319 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2320 IDirectDraw7
*ddraw
;
2321 DDSURFACEDESC2 ddsd
;
2323 HWND window
, window2
;
2327 struct test_coop_level_mode_set_enum_param param
;
2332 static const struct message exclusive_messages
[] =
2334 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2335 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2336 {WM_SIZE
, FALSE
, 0},
2337 {WM_DISPLAYCHANGE
, FALSE
, 0},
2340 static const struct message exclusive_focus_loss_messages
[] =
2342 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2343 {WM_DISPLAYCHANGE
, FALSE
, 0},
2344 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2345 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2346 * SW_MINIMIZED, causing a recursive window activation that does not
2347 * produce the same result in Wine yet. Ignore the difference for now.
2348 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2349 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2350 {WM_MOVE
, FALSE
, 0},
2351 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2352 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2355 static const struct message exclusive_focus_restore_messages
[] =
2357 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2358 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2359 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2360 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2361 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2362 /* Native redundantly sets the window size here. */
2363 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2364 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2365 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2366 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2369 static const struct message sc_restore_messages
[] =
2371 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2372 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2373 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2374 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2377 static const struct message sc_minimize_messages
[] =
2379 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2380 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2381 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2382 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2385 static const struct message sc_maximize_messages
[] =
2387 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2388 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2389 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2390 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2394 static const struct message normal_messages
[] =
2396 {WM_DISPLAYCHANGE
, FALSE
, 0},
2400 ddraw
= create_ddraw();
2401 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2403 memset(¶m
, 0, sizeof(param
));
2404 hr
= IDirectDraw7_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2405 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2406 ref
= IDirectDraw7_Release(ddraw
);
2407 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2409 if (!param
.user32_height
)
2411 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2415 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2416 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2417 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2419 memset(&devmode
, 0, sizeof(devmode
));
2420 devmode
.dmSize
= sizeof(devmode
);
2421 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2422 devmode
.dmPelsWidth
= param
.user32_width
;
2423 devmode
.dmPelsHeight
= param
.user32_height
;
2424 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2425 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2427 ddraw
= create_ddraw();
2428 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2430 wc
.lpfnWndProc
= mode_set_proc
;
2431 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2432 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2433 wc
.lpfnWndProc
= mode_set_proc2
;
2434 wc
.lpszClassName
= "ddraw_test_wndproc_wc2";
2435 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2437 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2438 0, 0, 100, 100, 0, 0, 0, 0);
2439 window2
= CreateWindowA("ddraw_test_wndproc_wc2", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2440 0, 0, 100, 100, 0, 0, 0, 0);
2442 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2443 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2445 GetWindowRect(window
, &r
);
2446 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2447 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2448 r
.left
, r
.top
, r
.right
, r
.bottom
);
2450 memset(&ddsd
, 0, sizeof(ddsd
));
2451 ddsd
.dwSize
= sizeof(ddsd
);
2452 ddsd
.dwFlags
= DDSD_CAPS
;
2453 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2455 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2456 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2457 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2458 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2459 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2460 param
.user32_width
, ddsd
.dwWidth
);
2461 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2462 param
.user32_height
, ddsd
.dwHeight
);
2464 GetWindowRect(window
, &r
);
2465 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2466 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2467 r
.left
, r
.top
, r
.right
, r
.bottom
);
2469 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2470 expect_messages
= exclusive_messages
;
2474 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2475 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2477 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2478 expect_messages
= NULL
;
2479 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2480 "Expected screen size %ux%u, got %ux%u.\n",
2481 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2483 GetWindowRect(window
, &r
);
2484 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2485 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2486 r
.left
, r
.top
, r
.right
, r
.bottom
);
2488 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2489 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2490 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2491 param
.user32_width
, ddsd
.dwWidth
);
2492 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2493 param
.user32_height
, ddsd
.dwHeight
);
2494 IDirectDrawSurface7_Release(primary
);
2496 memset(&ddsd
, 0, sizeof(ddsd
));
2497 ddsd
.dwSize
= sizeof(ddsd
);
2498 ddsd
.dwFlags
= DDSD_CAPS
;
2499 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2501 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2502 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2503 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2504 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2505 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2506 param
.ddraw_width
, ddsd
.dwWidth
);
2507 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2508 param
.ddraw_height
, ddsd
.dwHeight
);
2510 GetWindowRect(window
, &r
);
2511 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2512 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2513 r
.left
, r
.top
, r
.right
, r
.bottom
);
2515 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2516 expect_messages
= exclusive_messages
;
2520 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2521 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2523 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2524 expect_messages
= NULL
;
2525 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2526 "Expected screen size %ux%u, got %ux%u.\n",
2527 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2529 GetWindowRect(window
, &r
);
2530 ok(EqualRect(&r
, &user32_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2531 user32_rect
.left
, user32_rect
.top
, user32_rect
.right
, user32_rect
.bottom
,
2532 r
.left
, r
.top
, r
.right
, r
.bottom
);
2534 expect_messages
= exclusive_focus_loss_messages
;
2535 ret
= SetForegroundWindow(GetDesktopWindow());
2536 ok(ret
, "Failed to set foreground window.\n");
2537 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2538 memset(&devmode
, 0, sizeof(devmode
));
2539 devmode
.dmSize
= sizeof(devmode
);
2540 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2541 ok(ret
, "Failed to get display mode.\n");
2542 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2543 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2544 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2546 expect_messages
= exclusive_focus_restore_messages
;
2547 ShowWindow(window
, SW_RESTORE
);
2548 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2550 GetWindowRect(window
, &r
);
2551 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2552 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
2553 r
.left
, r
.top
, r
.right
, r
.bottom
);
2554 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2555 ok(ret
, "Failed to get display mode.\n");
2556 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2557 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2558 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2560 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2561 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2562 /* Normally the primary should be restored here. Unfortunately this causes the
2563 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2564 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2565 * the point of the GetSurfaceDesc call. */
2567 expect_messages
= sc_minimize_messages
;
2568 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2569 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2570 expect_messages
= NULL
;
2572 expect_messages
= sc_restore_messages
;
2573 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2574 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2575 expect_messages
= NULL
;
2577 expect_messages
= sc_maximize_messages
;
2578 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2579 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2580 expect_messages
= NULL
;
2582 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2583 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2585 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2586 expect_messages
= exclusive_messages
;
2590 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2591 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2593 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2594 expect_messages
= NULL
;
2595 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2596 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2597 "Expected screen size %ux%u, got %ux%u.\n",
2598 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2600 GetWindowRect(window
, &r
);
2601 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2602 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2603 r
.left
, r
.top
, r
.right
, r
.bottom
);
2605 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2606 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2607 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2608 param
.ddraw_width
, ddsd
.dwWidth
);
2609 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2610 param
.ddraw_height
, ddsd
.dwHeight
);
2611 IDirectDrawSurface7_Release(primary
);
2614 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2615 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2617 memset(&ddsd
, 0, sizeof(ddsd
));
2618 ddsd
.dwSize
= sizeof(ddsd
);
2619 ddsd
.dwFlags
= DDSD_CAPS
;
2620 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2622 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2623 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2624 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2625 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2626 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2627 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2628 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2629 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2631 GetWindowRect(window
, &r
);
2632 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2633 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2634 r
.left
, r
.top
, r
.right
, r
.bottom
);
2636 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2637 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2639 GetWindowRect(window
, &r
);
2640 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2641 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2642 r
.left
, r
.top
, r
.right
, r
.bottom
);
2644 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2645 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2646 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2647 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2648 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2649 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2650 IDirectDrawSurface7_Release(primary
);
2652 memset(&ddsd
, 0, sizeof(ddsd
));
2653 ddsd
.dwSize
= sizeof(ddsd
);
2654 ddsd
.dwFlags
= DDSD_CAPS
;
2655 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2657 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2658 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2659 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2660 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2661 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2662 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2663 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2664 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2666 GetWindowRect(window
, &r
);
2667 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2668 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2669 r
.left
, r
.top
, r
.right
, r
.bottom
);
2671 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2672 expect_messages
= normal_messages
;
2676 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2677 devmode
.dmPelsWidth
= param
.user32_width
;
2678 devmode
.dmPelsHeight
= param
.user32_height
;
2679 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2680 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2682 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2683 expect_messages
= NULL
;
2684 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2686 GetWindowRect(window
, &r
);
2687 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2688 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2689 r
.left
, r
.top
, r
.right
, r
.bottom
);
2691 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2692 expect_messages
= normal_messages
;
2696 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2697 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2699 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2700 expect_messages
= NULL
;
2701 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2703 GetWindowRect(window
, &r
);
2704 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2705 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2706 r
.left
, r
.top
, r
.right
, r
.bottom
);
2708 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2709 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2710 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2711 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2712 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2713 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2714 IDirectDrawSurface7_Release(primary
);
2716 memset(&ddsd
, 0, sizeof(ddsd
));
2717 ddsd
.dwSize
= sizeof(ddsd
);
2718 ddsd
.dwFlags
= DDSD_CAPS
;
2719 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2721 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2722 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2723 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2724 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2725 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2726 param
.ddraw_width
, ddsd
.dwWidth
);
2727 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2728 param
.ddraw_height
, ddsd
.dwHeight
);
2730 GetWindowRect(window
, &r
);
2731 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2732 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2733 r
.left
, r
.top
, r
.right
, r
.bottom
);
2735 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2736 expect_messages
= normal_messages
;
2740 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2741 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2743 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2744 expect_messages
= NULL
;
2745 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2747 GetWindowRect(window
, &r
);
2748 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2749 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2750 r
.left
, r
.top
, r
.right
, r
.bottom
);
2752 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2753 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2754 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2755 param
.ddraw_width
, ddsd
.dwWidth
);
2756 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2757 param
.ddraw_height
, ddsd
.dwHeight
);
2758 IDirectDrawSurface7_Release(primary
);
2760 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2761 ok(ret
, "Failed to get display mode.\n");
2762 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2763 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2764 "Expected resolution %ux%u, got %ux%u.\n",
2765 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2766 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2767 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2768 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2770 memset(&ddsd
, 0, sizeof(ddsd
));
2771 ddsd
.dwSize
= sizeof(ddsd
);
2772 ddsd
.dwFlags
= DDSD_CAPS
;
2773 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2775 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2776 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2777 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2778 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2779 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2780 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2781 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2782 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2784 GetWindowRect(window
, &r
);
2785 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2786 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2787 r
.left
, r
.top
, r
.right
, r
.bottom
);
2789 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2790 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2791 * not DDSCL_FULLSCREEN. */
2792 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2793 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2795 GetWindowRect(window
, &r
);
2796 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2797 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2798 r
.left
, r
.top
, r
.right
, r
.bottom
);
2800 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2801 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2802 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2803 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2804 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2805 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2806 IDirectDrawSurface7_Release(primary
);
2808 memset(&ddsd
, 0, sizeof(ddsd
));
2809 ddsd
.dwSize
= sizeof(ddsd
);
2810 ddsd
.dwFlags
= DDSD_CAPS
;
2811 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2813 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2814 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2815 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2816 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2817 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2818 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2819 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2820 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2822 GetWindowRect(window
, &r
);
2823 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2824 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2825 r
.left
, r
.top
, r
.right
, r
.bottom
);
2827 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2828 expect_messages
= normal_messages
;
2832 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2833 devmode
.dmPelsWidth
= param
.user32_width
;
2834 devmode
.dmPelsHeight
= param
.user32_height
;
2835 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2836 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2838 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2839 expect_messages
= NULL
;
2840 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2842 GetWindowRect(window
, &r
);
2843 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2844 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2845 r
.left
, r
.top
, r
.right
, r
.bottom
);
2847 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2848 expect_messages
= normal_messages
;
2852 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2853 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2855 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2856 expect_messages
= NULL
;
2857 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2859 GetWindowRect(window
, &r
);
2860 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2861 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2862 r
.left
, r
.top
, r
.right
, r
.bottom
);
2864 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2865 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2866 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2867 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2868 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2869 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2870 IDirectDrawSurface7_Release(primary
);
2872 memset(&ddsd
, 0, sizeof(ddsd
));
2873 ddsd
.dwSize
= sizeof(ddsd
);
2874 ddsd
.dwFlags
= DDSD_CAPS
;
2875 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2877 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2878 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2879 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2880 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2881 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2882 param
.ddraw_width
, ddsd
.dwWidth
);
2883 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2884 param
.ddraw_height
, ddsd
.dwHeight
);
2886 GetWindowRect(window
, &r
);
2887 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2888 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2889 r
.left
, r
.top
, r
.right
, r
.bottom
);
2891 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2892 expect_messages
= normal_messages
;
2896 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
2897 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2899 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2900 expect_messages
= NULL
;
2901 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2903 GetWindowRect(window
, &r
);
2904 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2905 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2906 r
.left
, r
.top
, r
.right
, r
.bottom
);
2908 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2909 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2910 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2911 param
.ddraw_width
, ddsd
.dwWidth
);
2912 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2913 param
.ddraw_height
, ddsd
.dwHeight
);
2914 IDirectDrawSurface7_Release(primary
);
2916 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2917 ok(ret
, "Failed to get display mode.\n");
2918 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2919 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2920 "Expected resolution %ux%u, got %ux%u.\n",
2921 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2922 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2923 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2924 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2926 memset(&ddsd
, 0, sizeof(ddsd
));
2927 ddsd
.dwSize
= sizeof(ddsd
);
2928 ddsd
.dwFlags
= DDSD_CAPS
;
2929 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2931 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2932 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2933 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2934 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2935 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2936 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2937 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2938 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2939 IDirectDrawSurface7_Release(primary
);
2941 GetWindowRect(window
, &r
);
2942 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2943 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2944 r
.left
, r
.top
, r
.right
, r
.bottom
);
2946 /* Changing the coop level from EXCLUSIVE to NORMAL restores the screen resolution */
2947 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2948 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2949 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2950 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2952 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2953 expect_messages
= exclusive_messages
;
2957 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2958 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2960 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2961 expect_messages
= NULL
;
2962 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2963 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2964 "Expected screen size %ux%u, got %ux%u.\n",
2965 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2966 screen_size
.cx
, screen_size
.cy
);
2968 GetWindowRect(window
, &r
);
2969 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
2970 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
2971 r
.left
, r
.top
, r
.right
, r
.bottom
);
2973 memset(&ddsd
, 0, sizeof(ddsd
));
2974 ddsd
.dwSize
= sizeof(ddsd
);
2975 ddsd
.dwFlags
= DDSD_CAPS
;
2976 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2978 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2979 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2980 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
2981 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2982 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2983 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2984 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2985 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2986 IDirectDrawSurface7_Release(primary
);
2988 /* The screen restore is a property of DDSCL_EXCLUSIVE */
2989 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2990 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2991 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2992 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2994 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2995 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2997 memset(&ddsd
, 0, sizeof(ddsd
));
2998 ddsd
.dwSize
= sizeof(ddsd
);
2999 ddsd
.dwFlags
= DDSD_CAPS
;
3000 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3002 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3003 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3004 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3005 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3006 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
3007 param
.ddraw_width
, ddsd
.dwWidth
);
3008 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
3009 param
.ddraw_height
, ddsd
.dwHeight
);
3010 IDirectDrawSurface7_Release(primary
);
3012 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
3013 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
3015 /* If the window is changed at the same time, messages are sent to the new window. */
3016 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3017 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3018 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
3019 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3021 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
3022 expect_messages
= exclusive_messages
;
3025 screen_size2
.cx
= 0;
3026 screen_size2
.cy
= 0;
3028 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3029 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3031 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
3032 expect_messages
= NULL
;
3033 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n",
3034 screen_size
.cx
, screen_size
.cy
);
3035 ok(screen_size2
.cx
== registry_mode
.dmPelsWidth
&& screen_size2
.cy
== registry_mode
.dmPelsHeight
,
3036 "Expected screen size 2 %ux%u, got %ux%u.\n",
3037 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size2
.cx
, screen_size2
.cy
);
3039 GetWindowRect(window
, &r
);
3040 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3041 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3042 r
.left
, r
.top
, r
.right
, r
.bottom
);
3043 GetWindowRect(window2
, &r
);
3044 ok(EqualRect(&r
, ®istry_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3045 registry_rect
.left
, registry_rect
.top
, registry_rect
.right
, registry_rect
.bottom
,
3046 r
.left
, r
.top
, r
.right
, r
.bottom
);
3048 memset(&ddsd
, 0, sizeof(ddsd
));
3049 ddsd
.dwSize
= sizeof(ddsd
);
3050 ddsd
.dwFlags
= DDSD_CAPS
;
3051 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3053 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
3054 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
3055 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &ddsd
);
3056 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3057 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
3058 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
3059 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
3060 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
3061 IDirectDrawSurface7_Release(primary
);
3063 ref
= IDirectDraw7_Release(ddraw
);
3064 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3066 GetWindowRect(window
, &r
);
3067 ok(EqualRect(&r
, &ddraw_rect
), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3068 ddraw_rect
.left
, ddraw_rect
.top
, ddraw_rect
.right
, ddraw_rect
.bottom
,
3069 r
.left
, r
.top
, r
.right
, r
.bottom
);
3071 expect_messages
= NULL
;
3072 DestroyWindow(window
);
3073 DestroyWindow(window2
);
3074 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3075 UnregisterClassA("ddraw_test_wndproc_wc2", GetModuleHandleA(NULL
));
3078 static void test_coop_level_mode_set_multi(void)
3080 IDirectDraw7
*ddraw1
, *ddraw2
;
3086 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3087 0, 0, 100, 100, 0, 0, 0, 0);
3088 ddraw1
= create_ddraw();
3089 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
3091 /* With just a single ddraw object, the display mode is restored on
3093 hr
= set_display_mode(ddraw1
, 800, 600);
3094 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3095 w
= GetSystemMetrics(SM_CXSCREEN
);
3096 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3097 h
= GetSystemMetrics(SM_CYSCREEN
);
3098 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3100 ref
= IDirectDraw7_Release(ddraw1
);
3101 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3102 w
= GetSystemMetrics(SM_CXSCREEN
);
3103 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3104 h
= GetSystemMetrics(SM_CYSCREEN
);
3105 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3107 /* When there are multiple ddraw objects, the display mode is restored to
3108 * the initial mode, before the first SetDisplayMode() call. */
3109 ddraw1
= create_ddraw();
3110 hr
= set_display_mode(ddraw1
, 800, 600);
3111 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3112 w
= GetSystemMetrics(SM_CXSCREEN
);
3113 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3114 h
= GetSystemMetrics(SM_CYSCREEN
);
3115 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3117 ddraw2
= create_ddraw();
3118 hr
= set_display_mode(ddraw2
, 640, 480);
3119 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3120 w
= GetSystemMetrics(SM_CXSCREEN
);
3121 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3122 h
= GetSystemMetrics(SM_CYSCREEN
);
3123 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3125 ref
= IDirectDraw7_Release(ddraw2
);
3126 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3127 w
= GetSystemMetrics(SM_CXSCREEN
);
3128 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3129 h
= GetSystemMetrics(SM_CYSCREEN
);
3130 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3132 ref
= IDirectDraw7_Release(ddraw1
);
3133 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3134 w
= GetSystemMetrics(SM_CXSCREEN
);
3135 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3136 h
= GetSystemMetrics(SM_CYSCREEN
);
3137 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3139 /* Regardless of release ordering. */
3140 ddraw1
= create_ddraw();
3141 hr
= set_display_mode(ddraw1
, 800, 600);
3142 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3143 w
= GetSystemMetrics(SM_CXSCREEN
);
3144 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3145 h
= GetSystemMetrics(SM_CYSCREEN
);
3146 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3148 ddraw2
= create_ddraw();
3149 hr
= set_display_mode(ddraw2
, 640, 480);
3150 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3151 w
= GetSystemMetrics(SM_CXSCREEN
);
3152 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3153 h
= GetSystemMetrics(SM_CYSCREEN
);
3154 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3156 ref
= IDirectDraw7_Release(ddraw1
);
3157 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3158 w
= GetSystemMetrics(SM_CXSCREEN
);
3159 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3160 h
= GetSystemMetrics(SM_CYSCREEN
);
3161 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3163 ref
= IDirectDraw7_Release(ddraw2
);
3164 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3165 w
= GetSystemMetrics(SM_CXSCREEN
);
3166 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3167 h
= GetSystemMetrics(SM_CYSCREEN
);
3168 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3170 /* But only for ddraw objects that called SetDisplayMode(). */
3171 ddraw1
= create_ddraw();
3172 ddraw2
= create_ddraw();
3173 hr
= set_display_mode(ddraw2
, 640, 480);
3174 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3175 w
= GetSystemMetrics(SM_CXSCREEN
);
3176 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3177 h
= GetSystemMetrics(SM_CYSCREEN
);
3178 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3180 ref
= IDirectDraw7_Release(ddraw1
);
3181 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3182 w
= GetSystemMetrics(SM_CXSCREEN
);
3183 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3184 h
= GetSystemMetrics(SM_CYSCREEN
);
3185 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3187 ref
= IDirectDraw7_Release(ddraw2
);
3188 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3189 w
= GetSystemMetrics(SM_CXSCREEN
);
3190 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3191 h
= GetSystemMetrics(SM_CYSCREEN
);
3192 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3194 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3195 * restoring the display mode. */
3196 ddraw1
= create_ddraw();
3197 hr
= set_display_mode(ddraw1
, 800, 600);
3198 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3199 w
= GetSystemMetrics(SM_CXSCREEN
);
3200 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3201 h
= GetSystemMetrics(SM_CYSCREEN
);
3202 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3204 ddraw2
= create_ddraw();
3205 hr
= set_display_mode(ddraw2
, 640, 480);
3206 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3207 w
= GetSystemMetrics(SM_CXSCREEN
);
3208 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3209 h
= GetSystemMetrics(SM_CYSCREEN
);
3210 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3212 hr
= IDirectDraw7_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3213 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3215 ref
= IDirectDraw7_Release(ddraw1
);
3216 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3217 w
= GetSystemMetrics(SM_CXSCREEN
);
3218 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3219 h
= GetSystemMetrics(SM_CYSCREEN
);
3220 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3222 ref
= IDirectDraw7_Release(ddraw2
);
3223 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3224 w
= GetSystemMetrics(SM_CXSCREEN
);
3225 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3226 h
= GetSystemMetrics(SM_CYSCREEN
);
3227 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3229 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3230 ddraw1
= create_ddraw();
3231 hr
= set_display_mode(ddraw1
, 800, 600);
3232 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3233 w
= GetSystemMetrics(SM_CXSCREEN
);
3234 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3235 h
= GetSystemMetrics(SM_CYSCREEN
);
3236 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3238 hr
= IDirectDraw7_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3239 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3241 ddraw2
= create_ddraw();
3242 hr
= set_display_mode(ddraw2
, 640, 480);
3243 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3245 ref
= IDirectDraw7_Release(ddraw1
);
3246 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3247 w
= GetSystemMetrics(SM_CXSCREEN
);
3248 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3249 h
= GetSystemMetrics(SM_CYSCREEN
);
3250 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3252 ref
= IDirectDraw7_Release(ddraw2
);
3253 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3254 w
= GetSystemMetrics(SM_CXSCREEN
);
3255 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3256 h
= GetSystemMetrics(SM_CYSCREEN
);
3257 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3259 DestroyWindow(window
);
3262 static void test_initialize(void)
3264 IDirectDraw7
*ddraw
;
3267 ddraw
= create_ddraw();
3268 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3270 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3271 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3272 IDirectDraw7_Release(ddraw
);
3275 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw7
, (void **)&ddraw
);
3276 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw7 instance, hr %#x.\n", hr
);
3277 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3278 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3279 hr
= IDirectDraw7_Initialize(ddraw
, NULL
);
3280 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3281 IDirectDraw7_Release(ddraw
);
3285 static void test_coop_level_surf_create(void)
3287 IDirectDrawSurface7
*surface
;
3288 IDirectDraw7
*ddraw
;
3289 DDSURFACEDESC2 ddsd
;
3292 ddraw
= create_ddraw();
3293 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3295 memset(&ddsd
, 0, sizeof(ddsd
));
3296 ddsd
.dwSize
= sizeof(ddsd
);
3297 ddsd
.dwFlags
= DDSD_CAPS
;
3298 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3299 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3300 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3302 IDirectDraw7_Release(ddraw
);
3305 static void test_vb_discard(void)
3307 static const struct vec4 quad
[] =
3309 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
3310 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
3311 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
3312 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
3315 IDirect3DDevice7
*device
;
3317 IDirect3DVertexBuffer7
*buffer
;
3320 D3DVERTEXBUFFERDESC desc
;
3322 static const unsigned int vbsize
= 16;
3325 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3326 0, 0, 640, 480, 0, 0, 0, 0);
3328 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3330 skip("Failed to create a 3D device, skipping test.\n");
3331 DestroyWindow(window
);
3335 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
3336 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
3338 memset(&desc
, 0, sizeof(desc
));
3339 desc
.dwSize
= sizeof(desc
);
3340 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
3341 desc
.dwFVF
= D3DFVF_XYZRHW
;
3342 desc
.dwNumVertices
= vbsize
;
3343 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
3344 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
3346 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3347 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3348 memcpy(data
, quad
, sizeof(quad
));
3349 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3350 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3352 hr
= IDirect3DDevice7_BeginScene(device
);
3353 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3354 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
3355 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3356 hr
= IDirect3DDevice7_EndScene(device
);
3357 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3359 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3360 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3361 memset(data
, 0xaa, sizeof(struct vec4
) * vbsize
);
3362 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3363 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3365 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, (void **)&data
, NULL
);
3366 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
3367 for (i
= 0; i
< sizeof(struct vec4
) * vbsize
; i
++)
3369 if (data
[i
] != 0xaa)
3371 ok(FALSE
, "Vertex buffer data byte %u is 0x%02x, expected 0xaa\n", i
, data
[i
]);
3375 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
3376 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
3378 IDirect3DVertexBuffer7_Release(buffer
);
3379 IDirect3D7_Release(d3d
);
3380 IDirect3DDevice7_Release(device
);
3381 DestroyWindow(window
);
3384 static void test_coop_level_multi_window(void)
3386 HWND window1
, window2
;
3387 IDirectDraw7
*ddraw
;
3390 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3391 0, 0, 640, 480, 0, 0, 0, 0);
3392 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3393 0, 0, 640, 480, 0, 0, 0, 0);
3394 ddraw
= create_ddraw();
3395 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3397 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3398 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3399 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3400 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3401 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3402 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3404 IDirectDraw7_Release(ddraw
);
3405 DestroyWindow(window2
);
3406 DestroyWindow(window1
);
3409 static void test_draw_strided(void)
3411 static struct vec3 position
[] =
3418 static DWORD diffuse
[] =
3420 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00,
3422 static WORD indices
[] =
3427 IDirectDrawSurface7
*rt
;
3428 IDirect3DDevice7
*device
;
3432 D3DDRAWPRIMITIVESTRIDEDDATA strided
;
3434 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3435 0, 0, 640, 480, 0, 0, 0, 0);
3437 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3439 skip("Failed to create a 3D device, skipping test.\n");
3440 DestroyWindow(window
);
3444 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3445 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3447 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3448 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3449 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 1.0f
, 0);
3450 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3451 hr
= IDirect3DDevice7_BeginScene(device
);
3452 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3454 memset(&strided
, 0x55, sizeof(strided
));
3455 strided
.position
.lpvData
= position
;
3456 strided
.position
.dwStride
= sizeof(*position
);
3457 strided
.diffuse
.lpvData
= diffuse
;
3458 strided
.diffuse
.dwStride
= sizeof(*diffuse
);
3459 hr
= IDirect3DDevice7_DrawIndexedPrimitiveStrided(device
, D3DPT_TRIANGLELIST
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
,
3460 &strided
, 4, indices
, 6, 0);
3461 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3463 hr
= IDirect3DDevice7_EndScene(device
);
3464 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3466 color
= get_surface_color(rt
, 320, 240);
3467 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
3469 IDirectDrawSurface7_Release(rt
);
3470 IDirect3DDevice7_Release(device
);
3471 DestroyWindow(window
);
3474 static void test_lighting(void)
3476 static D3DMATRIX mat
=
3478 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3479 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3480 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3481 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3485 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3486 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3487 1.0f
, 0.0f
, 1.0f
, 0.0f
,
3488 0.0f
, 0.0f
, 0.5f
, 1.0f
,
3492 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3493 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3494 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
3495 10.f
, 10.0f
, 10.0f
, 1.0f
,
3499 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3500 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3501 0.0f
, 0.0f
, 1.0f
, -1.0f
,
3502 10.f
, 10.0f
, 10.0f
, 0.0f
,
3506 struct vec3 position
;
3511 {{-1.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3512 {{-1.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3513 {{ 0.0f
, 0.0f
, 0.1f
}, 0xffff0000},
3514 {{ 0.0f
, -1.0f
, 0.1f
}, 0xffff0000},
3518 {{-1.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3519 {{-1.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3520 {{ 0.0f
, 1.0f
, 0.1f
}, 0xff00ff00},
3521 {{ 0.0f
, 0.0f
, 0.1f
}, 0xff00ff00},
3525 struct vec3 position
;
3531 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3532 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3533 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3534 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
3538 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3539 {{0.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3540 {{1.0f
, 1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3541 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xffffff00},
3545 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3546 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3547 {{ 1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3548 {{ 1.0f
, -1.0f
, 0.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3552 {{-10.0f
, -11.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3553 {{-10.0f
, -9.0f
, 11.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3554 {{-10.0f
, -9.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3555 {{-10.0f
, -11.0f
, 9.0f
}, {-1.0f
, 0.0f
, 0.0f
}, 0xff0000ff},
3559 {{-11.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3560 {{-11.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3561 {{ -9.0f
, -9.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3562 {{ -9.0f
, -11.0f
, -10.0f
}, {0.0f
, 0.0f
, -1.0f
}, 0xff0000ff},
3564 static WORD indices
[] = {0, 1, 2, 2, 3, 0};
3567 D3DMATRIX
*world_matrix
;
3570 const char *message
;
3574 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
3575 {&mat_singular
, nquad
, 0x000000ff, "Lit quad with singular world matrix"},
3576 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
3577 {&mat_nonaffine
, translatedquad
, 0x00000000, "Lit quad with non-affine matrix"},
3581 IDirect3DDevice7
*device
;
3582 IDirectDrawSurface7
*rt
;
3584 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
3585 DWORD nfvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_NORMAL
;
3590 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3591 0, 0, 640, 480, 0, 0, 0, 0);
3592 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3594 skip("Failed to create a 3D device, skipping test.\n");
3595 DestroyWindow(window
);
3599 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3600 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3602 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3603 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3605 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3606 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3607 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3608 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
3609 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3610 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
3611 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3612 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3613 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3614 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
3615 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3616 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3617 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_STENCILENABLE
, FALSE
);
3618 ok(SUCCEEDED(hr
), "Failed to disable stencil buffering, hr %#x.\n", hr
);
3619 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
3620 ok(SUCCEEDED(hr
), "Failed to disable culling, hr %#x.\n", hr
);
3622 hr
= IDirect3DDevice7_BeginScene(device
);
3623 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3625 /* No lights are defined... That means, lit vertices should be entirely black. */
3626 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3627 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3628 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, unlitquad
, 4,
3630 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3632 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3633 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3634 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, litquad
, 4,
3636 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3638 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
3639 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
3640 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, unlitnquad
, 4,
3642 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3644 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, TRUE
);
3645 ok(SUCCEEDED(hr
), "Failed to enable lighting, hr %#x.\n", hr
);
3646 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, litnquad
, 4,
3648 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3650 hr
= IDirect3DDevice7_EndScene(device
);
3651 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3653 color
= get_surface_color(rt
, 160, 360);
3654 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x, expected 0x00ff0000.\n", color
);
3655 color
= get_surface_color(rt
, 160, 120);
3656 ok(color
== 0x00000000, "Lit quad without normals has color 0x%08x, expected 0x00000000.\n", color
);
3657 color
= get_surface_color(rt
, 480, 360);
3658 ok(color
== 0x000000ff, "Unlit quad with normals has color 0x%08x, expected 0x000000ff.\n", color
);
3659 color
= get_surface_color(rt
, 480, 120);
3660 ok(color
== 0x00000000, "Lit quad with normals has color 0x%08x, expected 0x00000000.\n", color
);
3662 hr
= IDirect3DDevice7_LightEnable(device
, 0, TRUE
);
3663 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
3665 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3667 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, tests
[i
].world_matrix
);
3668 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3670 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3671 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
3673 hr
= IDirect3DDevice7_BeginScene(device
);
3674 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3676 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, nfvf
, tests
[i
].quad
,
3678 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3680 hr
= IDirect3DDevice7_EndScene(device
);
3681 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3683 color
= get_surface_color(rt
, 320, 240);
3684 ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
3687 IDirectDrawSurface7_Release(rt
);
3689 refcount
= IDirect3DDevice7_Release(device
);
3690 ok(!refcount
, "Device has %u references left.\n", refcount
);
3691 DestroyWindow(window
);
3694 static void test_specular_lighting(void)
3696 static const unsigned int vertices_side
= 5;
3697 const unsigned int indices_count
= (vertices_side
- 1) * (vertices_side
- 1) * 2 * 3;
3698 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_NORMAL
;
3699 static D3DMATRIX mat
=
3701 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3702 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3703 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3704 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3706 static D3DLIGHT7 directional
=
3708 D3DLIGHT_DIRECTIONAL
,
3709 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3710 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3711 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3712 {{0.0f
}, {0.0f
}, {0.0f
}},
3713 {{0.0f
}, {0.0f
}, {1.0f
}},
3718 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3719 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3720 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3721 {{0.0f
}, {0.0f
}, {0.0f
}},
3722 {{0.0f
}, {0.0f
}, {0.0f
}},
3730 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3731 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3732 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3733 {{0.0f
}, {0.0f
}, {0.0f
}},
3734 {{0.0f
}, {0.0f
}, {1.0f
}},
3738 M_PI
/ 12.0f
, M_PI
/ 3.0f
3740 /* The chosen range value makes the test fail when using a manhattan
3741 * distance metric vs the correct euclidean distance. */
3745 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3746 {{1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}},
3747 {{0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
3748 {{0.0f
}, {0.0f
}, {0.0f
}},
3749 {{0.0f
}, {0.0f
}, {0.0f
}},
3754 static const struct expected_color
3759 expected_directional
[] =
3761 {160, 120, 0x00ffffff},
3762 {320, 120, 0x00ffffff},
3763 {480, 120, 0x00ffffff},
3764 {160, 240, 0x00ffffff},
3765 {320, 240, 0x00ffffff},
3766 {480, 240, 0x00ffffff},
3767 {160, 360, 0x00ffffff},
3768 {320, 360, 0x00ffffff},
3769 {480, 360, 0x00ffffff},
3771 expected_directional_local
[] =
3773 {160, 120, 0x003c3c3c},
3774 {320, 120, 0x00717171},
3775 {480, 120, 0x003c3c3c},
3776 {160, 240, 0x00717171},
3777 {320, 240, 0x00ffffff},
3778 {480, 240, 0x00717171},
3779 {160, 360, 0x003c3c3c},
3780 {320, 360, 0x00717171},
3781 {480, 360, 0x003c3c3c},
3785 {160, 120, 0x00282828},
3786 {320, 120, 0x005a5a5a},
3787 {480, 120, 0x00282828},
3788 {160, 240, 0x005a5a5a},
3789 {320, 240, 0x00ffffff},
3790 {480, 240, 0x005a5a5a},
3791 {160, 360, 0x00282828},
3792 {320, 360, 0x005a5a5a},
3793 {480, 360, 0x00282828},
3795 expected_point_local
[] =
3797 {160, 120, 0x00000000},
3798 {320, 120, 0x00070707},
3799 {480, 120, 0x00000000},
3800 {160, 240, 0x00070707},
3801 {320, 240, 0x00ffffff},
3802 {480, 240, 0x00070707},
3803 {160, 360, 0x00000000},
3804 {320, 360, 0x00070707},
3805 {480, 360, 0x00000000},
3809 {160, 120, 0x00000000},
3810 {320, 120, 0x00141414},
3811 {480, 120, 0x00000000},
3812 {160, 240, 0x00141414},
3813 {320, 240, 0x00ffffff},
3814 {480, 240, 0x00141414},
3815 {160, 360, 0x00000000},
3816 {320, 360, 0x00141414},
3817 {480, 360, 0x00000000},
3819 expected_spot_local
[] =
3821 {160, 120, 0x00000000},
3822 {320, 120, 0x00020202},
3823 {480, 120, 0x00000000},
3824 {160, 240, 0x00020202},
3825 {320, 240, 0x00ffffff},
3826 {480, 240, 0x00020202},
3827 {160, 360, 0x00000000},
3828 {320, 360, 0x00020202},
3829 {480, 360, 0x00000000},
3831 expected_point_range
[] =
3833 {160, 120, 0x00000000},
3834 {320, 120, 0x005a5a5a},
3835 {480, 120, 0x00000000},
3836 {160, 240, 0x005a5a5a},
3837 {320, 240, 0x00ffffff},
3838 {480, 240, 0x005a5a5a},
3839 {160, 360, 0x00000000},
3840 {320, 360, 0x005a5a5a},
3841 {480, 360, 0x00000000},
3847 const struct expected_color
*expected
;
3848 unsigned int expected_count
;
3852 {&directional
, FALSE
, expected_directional
,
3853 sizeof(expected_directional
) / sizeof(expected_directional
[0])},
3854 {&directional
, TRUE
, expected_directional_local
,
3855 sizeof(expected_directional_local
) / sizeof(expected_directional_local
[0])},
3856 {&point
, FALSE
, expected_point
,
3857 sizeof(expected_point
) / sizeof(expected_point
[0])},
3858 {&point
, TRUE
, expected_point_local
,
3859 sizeof(expected_point_local
) / sizeof(expected_point_local
[0])},
3860 {&spot
, FALSE
, expected_spot
,
3861 sizeof(expected_spot
) / sizeof(expected_spot
[0])},
3862 {&spot
, TRUE
, expected_spot_local
,
3863 sizeof(expected_spot_local
) / sizeof(expected_spot_local
[0])},
3864 {&point_range
, FALSE
, expected_point_range
,
3865 sizeof(expected_point_range
) / sizeof(expected_point_range
[0])},
3867 IDirect3DDevice7
*device
;
3868 IDirectDrawSurface7
*rt
;
3869 D3DMATERIAL7 material
;
3874 unsigned int i
, j
, x
, y
;
3877 struct vec3 position
;
3882 quad
= HeapAlloc(GetProcessHeap(), 0, vertices_side
* vertices_side
* sizeof(*quad
));
3883 indices
= HeapAlloc(GetProcessHeap(), 0, indices_count
* sizeof(*indices
));
3884 for (i
= 0, y
= 0; y
< vertices_side
; ++y
)
3886 for (x
= 0; x
< vertices_side
; ++x
)
3888 quad
[i
].position
.x
= x
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
3889 quad
[i
].position
.y
= y
* 2.0f
/ (vertices_side
- 1) - 1.0f
;
3890 quad
[i
].position
.z
= 1.0f
;
3891 quad
[i
].normal
.x
= 0.0f
;
3892 quad
[i
].normal
.y
= 0.0f
;
3893 quad
[i
++].normal
.z
= -1.0f
;
3896 for (i
= 0, y
= 0; y
< (vertices_side
- 1); ++y
)
3898 for (x
= 0; x
< (vertices_side
- 1); ++x
)
3900 indices
[i
++] = y
* vertices_side
+ x
+ 1;
3901 indices
[i
++] = y
* vertices_side
+ x
;
3902 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
3903 indices
[i
++] = y
* vertices_side
+ x
+ 1;
3904 indices
[i
++] = (y
+ 1) * vertices_side
+ x
;
3905 indices
[i
++] = (y
+ 1) * vertices_side
+ x
+ 1;
3909 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3910 0, 0, 640, 480, 0, 0, 0, 0);
3911 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
3913 skip("Failed to create a 3D device, skipping test.\n");
3914 DestroyWindow(window
);
3918 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
3919 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3921 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_WORLD
, &mat
);
3922 ok(SUCCEEDED(hr
), "Failed to set world transform, hr %#x.\n", hr
);
3923 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_VIEW
, &mat
);
3924 ok(SUCCEEDED(hr
), "Failed to set view transform, hr %#x.\n", hr
);
3925 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &mat
);
3926 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
3927 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
3928 ok(SUCCEEDED(hr
), "Failed to disable clipping, hr %#x.\n", hr
);
3929 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
3930 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
3931 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
3932 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
3934 memset(&material
, 0, sizeof(material
));
3935 U1(U2(material
).specular
).r
= 1.0f
;
3936 U2(U2(material
).specular
).g
= 1.0f
;
3937 U3(U2(material
).specular
).b
= 1.0f
;
3938 U4(U2(material
).specular
).a
= 1.0f
;
3939 U4(material
).power
= 30.0f
;
3940 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
3941 ok(SUCCEEDED(hr
), "Failed to set material, hr %#x.\n", hr
);
3943 hr
= IDirect3DDevice7_LightEnable(device
, 0, TRUE
);
3944 ok(SUCCEEDED(hr
), "Failed to enable light 0, hr %#x.\n", hr
);
3945 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, TRUE
);
3946 ok(SUCCEEDED(hr
), "Failed to enable specular lighting, hr %#x.\n", hr
);
3948 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
3950 hr
= IDirect3DDevice7_SetLight(device
, 0, tests
[i
].light
);
3951 ok(SUCCEEDED(hr
), "Failed to set light parameters, hr %#x.\n", hr
);
3953 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LOCALVIEWER
, tests
[i
].local_viewer
);
3954 ok(SUCCEEDED(hr
), "Failed to set local viewer state, hr %#x.\n", hr
);
3956 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0, 0);
3957 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
3959 hr
= IDirect3DDevice7_BeginScene(device
);
3960 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
3962 hr
= IDirect3DDevice7_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, fvf
, quad
,
3963 vertices_side
* vertices_side
, indices
, indices_count
, 0);
3964 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
3966 hr
= IDirect3DDevice7_EndScene(device
);
3967 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
3969 for (j
= 0; j
< tests
[i
].expected_count
; ++j
)
3971 color
= get_surface_color(rt
, tests
[i
].expected
[j
].x
, tests
[i
].expected
[j
].y
);
3972 ok(compare_color(color
, tests
[i
].expected
[j
].color
, 1),
3973 "Expected color 0x%08x at location (%u, %u), got 0x%08x, case %u.\n",
3974 tests
[i
].expected
[j
].color
, tests
[i
].expected
[j
].x
,
3975 tests
[i
].expected
[j
].y
, color
, i
);
3979 IDirectDrawSurface7_Release(rt
);
3981 refcount
= IDirect3DDevice7_Release(device
);
3982 ok(!refcount
, "Device has %u references left.\n", refcount
);
3983 DestroyWindow(window
);
3984 HeapFree(GetProcessHeap(), 0, indices
);
3985 HeapFree(GetProcessHeap(), 0, quad
);
3988 static void test_clear_rect_count(void)
3990 IDirectDrawSurface7
*rt
;
3991 IDirect3DDevice7
*device
;
3995 D3DRECT rect
= {{0}, {0}, {640}, {480}};
3997 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3998 0, 0, 640, 480, 0, 0, 0, 0);
3999 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4001 skip("Failed to create a 3D device, skipping test.\n");
4002 DestroyWindow(window
);
4006 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4007 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4009 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
4010 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4011 hr
= IDirect3DDevice7_Clear(device
, 0, &rect
, D3DCLEAR_TARGET
, 0x00ff0000, 1.0f
, 0);
4012 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4014 color
= get_surface_color(rt
, 320, 240);
4015 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x00ff0000, 1)),
4016 "Clear with count = 0, rect != NULL has color %#08x.\n", color
);
4018 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00ffffff, 1.0f
, 0);
4019 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4020 hr
= IDirect3DDevice7_Clear(device
, 1, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
4021 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4023 color
= get_surface_color(rt
, 320, 240);
4024 ok(compare_color(color
, 0x0000ff00, 1),
4025 "Clear with count = 1, rect = NULL has color %#08x.\n", color
);
4027 IDirectDrawSurface7_Release(rt
);
4028 IDirect3DDevice7_Release(device
);
4029 DestroyWindow(window
);
4032 static BOOL
test_mode_restored(IDirectDraw7
*ddraw
, HWND window
)
4034 DDSURFACEDESC2 ddsd1
, ddsd2
;
4037 memset(&ddsd1
, 0, sizeof(ddsd1
));
4038 ddsd1
.dwSize
= sizeof(ddsd1
);
4039 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd1
);
4040 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4042 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4043 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4044 hr
= set_display_mode(ddraw
, 640, 480);
4045 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
4046 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4047 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4049 memset(&ddsd2
, 0, sizeof(ddsd2
));
4050 ddsd2
.dwSize
= sizeof(ddsd2
);
4051 hr
= IDirectDraw7_GetDisplayMode(ddraw
, &ddsd2
);
4052 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
4053 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
4054 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
4056 return ddsd1
.dwWidth
== ddsd2
.dwWidth
&& ddsd1
.dwHeight
== ddsd2
.dwHeight
;
4059 static void test_coop_level_versions(void)
4065 IDirectDrawSurface
*surface
;
4066 IDirectDraw7
*ddraw7
;
4069 window
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
4070 0, 0, 640, 480, 0, 0, 0, 0);
4072 ddraw7
= create_ddraw();
4073 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4074 /* Newly created ddraw objects restore the mode on ddraw2+::SetCooperativeLevel(NORMAL) */
4075 restored
= test_mode_restored(ddraw7
, window
);
4076 ok(restored
, "Display mode not restored in new ddraw object\n");
4078 /* A failing ddraw1::SetCooperativeLevel call does not have an effect */
4079 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4080 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4082 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4083 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4084 restored
= test_mode_restored(ddraw7
, window
);
4085 ok(restored
, "Display mode not restored after bad ddraw1::SetCooperativeLevel call\n");
4087 /* A successful one does */
4088 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4089 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4090 restored
= test_mode_restored(ddraw7
, window
);
4091 ok(!restored
, "Display mode restored after good ddraw1::SetCooperativeLevel call\n");
4093 IDirectDraw_Release(ddraw
);
4094 IDirectDraw7_Release(ddraw7
);
4096 ddraw7
= create_ddraw();
4097 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4098 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4099 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4101 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_SETFOCUSWINDOW
);
4102 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4103 restored
= test_mode_restored(ddraw7
, window
);
4104 ok(!restored
, "Display mode restored after ddraw1::SetCooperativeLevel(SETFOCUSWINDOW) call\n");
4106 IDirectDraw_Release(ddraw
);
4107 IDirectDraw7_Release(ddraw7
);
4109 /* A failing call does not restore the ddraw2+ behavior */
4110 ddraw7
= create_ddraw();
4111 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4112 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4113 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4115 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4116 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4117 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4118 ok(FAILED(hr
), "SetCooperativeLevel returned %#x, expected failure.\n", hr
);
4119 restored
= test_mode_restored(ddraw7
, window
);
4120 ok(!restored
, "Display mode restored after good-bad ddraw1::SetCooperativeLevel() call sequence\n");
4122 IDirectDraw_Release(ddraw
);
4123 IDirectDraw7_Release(ddraw7
);
4125 /* Neither does a sequence of successful calls with the new interface */
4126 ddraw7
= create_ddraw();
4127 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4128 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4129 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4131 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4132 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4133 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
4134 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4135 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
4136 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4138 restored
= test_mode_restored(ddraw7
, window
);
4139 ok(!restored
, "Display mode restored after ddraw1-ddraw7 SetCooperativeLevel() call sequence\n");
4140 IDirectDraw_Release(ddraw
);
4141 IDirectDraw7_Release(ddraw7
);
4143 /* ddraw1::CreateSurface does not triger the ddraw1 behavior */
4144 ddraw7
= create_ddraw();
4145 ok(!!ddraw7
, "Failed to create a ddraw object.\n");
4146 hr
= IDirectDraw7_QueryInterface(ddraw7
, &IID_IDirectDraw
, (void **)&ddraw
);
4147 ok(SUCCEEDED(hr
), "QueryInterface failed, hr %#x.\n", hr
);
4149 hr
= IDirectDraw7_SetCooperativeLevel(ddraw7
, window
, DDSCL_NORMAL
);
4150 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
4152 memset(&ddsd
, 0, sizeof(ddsd
));
4153 ddsd
.dwSize
= sizeof(ddsd
);
4154 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4155 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4156 ddsd
.dwWidth
= ddsd
.dwHeight
= 8;
4157 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4158 ok(SUCCEEDED(hr
), "CreateSurface failed, hr %#x.\n", hr
);
4159 IDirectDrawSurface_Release(surface
);
4160 restored
= test_mode_restored(ddraw7
, window
);
4161 ok(restored
, "Display mode not restored after ddraw1::CreateSurface() call\n");
4163 IDirectDraw_Release(ddraw
);
4164 IDirectDraw7_Release(ddraw7
);
4165 DestroyWindow(window
);
4168 static void test_fog_special(void)
4172 struct vec3 position
;
4177 {{ -1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
4178 {{ 1.0f
, 1.0f
, 1.0f
}, 0xff00ff00},
4179 {{ -1.0f
, -1.0f
, 0.0f
}, 0xff00ff00},
4180 {{ 1.0f
, -1.0f
, 1.0f
}, 0xff00ff00},
4184 DWORD vertexmode
, tablemode
;
4185 D3DCOLOR color_left
, color_right
;
4189 {D3DFOG_LINEAR
, D3DFOG_NONE
, 0x00ff0000, 0x00ff0000},
4190 {D3DFOG_NONE
, D3DFOG_LINEAR
, 0x0000ff00, 0x00ff0000},
4201 IDirect3DDevice7
*device
;
4202 IDirectDrawSurface7
*rt
;
4204 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4205 0, 0, 640, 480, 0, 0, 0, 0);
4207 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4209 skip("Failed to create a 3D device, skipping test.\n");
4210 DestroyWindow(window
);
4214 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4215 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4217 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
4218 ok(SUCCEEDED(hr
), "Failed to enable fog, hr %#x.\n", hr
);
4219 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0xffff0000);
4220 ok(SUCCEEDED(hr
), "Failed to set fog color, hr %#x.\n", hr
);
4221 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
4222 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4223 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4224 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
4227 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, conv
.d
);
4228 ok(SUCCEEDED(hr
), "Failed to set fog start, hr %#x.\n", hr
);
4229 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, conv
.d
);
4230 ok(SUCCEEDED(hr
), "Failed to set fog end, hr %#x.\n", hr
);
4232 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4234 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 1.0f
, 0);
4235 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
4237 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vertexmode
);
4238 ok(SUCCEEDED(hr
), "Failed to set fogvertexmode, hr %#x.\n", hr
);
4239 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tablemode
);
4240 ok(SUCCEEDED(hr
), "Failed to set fogtablemode, hr %#x.\n", hr
);
4242 hr
= IDirect3DDevice7_BeginScene(device
);
4243 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4244 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
, quad
, 4, 0);
4245 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4246 hr
= IDirect3DDevice7_EndScene(device
);
4247 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4249 color
= get_surface_color(rt
, 310, 240);
4250 ok(compare_color(color
, tests
[i
].color_left
, 1),
4251 "Expected left color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_left
, color
, i
);
4252 color
= get_surface_color(rt
, 330, 240);
4253 ok(compare_color(color
, tests
[i
].color_right
, 1),
4254 "Expected right color 0x%08x, got 0x%08x, case %u.\n", tests
[i
].color_right
, color
, i
);
4257 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
4258 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
4260 IDirectDrawSurface7_Release(rt
);
4261 IDirect3DDevice7_Release(device
);
4262 DestroyWindow(window
);
4265 static void test_lighting_interface_versions(void)
4267 IDirect3DDevice7
*device
;
4268 IDirectDrawSurface7
*rt
;
4275 D3DMATERIAL7 material
;
4276 static D3DVERTEX quad
[] =
4278 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4279 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4280 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4281 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
4284 #define FVF_COLORVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
4287 struct vec3 position
;
4289 DWORD diffuse
, specular
;
4293 {{-1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4294 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4295 {{-1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4296 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 0.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4299 static D3DLVERTEX lquad
[] =
4301 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4302 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4303 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4304 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}, {0xff808080}},
4307 #define FVF_LVERTEX2 (D3DFVF_LVERTEX & ~D3DFVF_RESERVED1)
4310 struct vec3 position
;
4311 DWORD diffuse
, specular
;
4312 struct vec2 texcoord
;
4316 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4317 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4318 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4319 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff808080},
4322 static D3DTLVERTEX tlquad
[] =
4324 {{ 0.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4325 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4326 {{ 640.0f
}, { 480.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4327 {{ 640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xff0000ff}, {0xff808080}},
4334 DWORD d3drs_lighting
, d3drs_specular
;
4340 /* Lighting is enabled when D3DFVF_XYZ is used and D3DRENDERSTATE_LIGHTING is
4341 * enabled. D3DDP_DONOTLIGHT is ignored. Lighting is also enabled when normals
4344 * Note that the specular result is 0x00000000 when lighting is on even if the
4345 * input vertex has specular color because D3DRENDERSTATE_COLORVERTEX is not
4349 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, 0, 0x00ffffff},
4350 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, 0, 0x0000ff00},
4351 { D3DFVF_VERTEX
, quad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4352 { D3DFVF_VERTEX
, quad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4353 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, 0, 0x00ffffff},
4354 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, 0, 0x0000ff00},
4355 { D3DFVF_VERTEX
, quad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ffffff},
4356 { D3DFVF_VERTEX
, quad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4359 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4360 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4361 { FVF_COLORVERTEX
, quad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4362 { FVF_COLORVERTEX
, quad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4363 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4364 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4365 { FVF_COLORVERTEX
, quad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4366 { FVF_COLORVERTEX
, quad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4369 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, 0, 0x00ff0000},
4370 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, 0, 0x0000ff00},
4371 { D3DFVF_LVERTEX
, lquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4372 { D3DFVF_LVERTEX
, lquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4373 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, 0, 0x00ff8080},
4374 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, 0, 0x0000ff00},
4375 { D3DFVF_LVERTEX
, lquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4376 { D3DFVF_LVERTEX
, lquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4379 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, 0, 0x00ff0000},
4380 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, 0, 0x0000ff00},
4381 { FVF_LVERTEX2
, lquad2
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x00ff0000},
4382 { FVF_LVERTEX2
, lquad2
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4383 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, 0, 0x00ff8080},
4384 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, 0, 0x0000ff00},
4385 { FVF_LVERTEX2
, lquad2
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x00ff8080},
4386 { FVF_LVERTEX2
, lquad2
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x0000ff00},
4389 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, 0, 0x000000ff},
4390 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, 0, 0x000000ff},
4391 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4392 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, FALSE
, D3DDP_DONOTLIGHT
, 0x000000ff},
4393 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, 0, 0x008080ff},
4394 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, 0, 0x008080ff},
4395 { D3DFVF_TLVERTEX
, tlquad
, FALSE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4396 { D3DFVF_TLVERTEX
, tlquad
, TRUE
, TRUE
, D3DDP_DONOTLIGHT
, 0x008080ff},
4399 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4400 0, 0, 640, 480, 0, 0, 0, 0);
4402 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4404 skip("Failed to create a 3D device, skipping test.\n");
4405 DestroyWindow(window
);
4409 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
4410 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4412 memset(&material
, 0, sizeof(material
));
4413 U2(U3(material
).emissive
).g
= 1.0f
;
4414 hr
= IDirect3DDevice7_SetMaterial(device
, &material
);
4415 ok(SUCCEEDED(hr
), "Failed set material, hr %#x.\n", hr
);
4416 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
4417 ok(SUCCEEDED(hr
), "Failed to disable z test, hr %#x.\n", hr
);
4419 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
4420 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
4421 ok(rs
== TRUE
, "Initial D3DRENDERSTATE_LIGHTING is %#x, expected TRUE.\n", rs
);
4422 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
, &rs
);
4423 ok(SUCCEEDED(hr
), "Failed to get specularenable render state, hr %#x.\n", hr
);
4424 ok(rs
== FALSE
, "Initial D3DRENDERSTATE_SPECULARENABLE is %#x, expected FALSE.\n", rs
);
4426 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4428 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xff202020, 0.0f
, 0);
4429 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
4431 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, tests
[i
].d3drs_lighting
);
4432 ok(SUCCEEDED(hr
), "Failed to set lighting render state, hr %#x.\n", hr
);
4433 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SPECULARENABLE
,
4434 tests
[i
].d3drs_specular
);
4435 ok(SUCCEEDED(hr
), "Failed to set specularenable render state, hr %#x.\n", hr
);
4437 hr
= IDirect3DDevice7_BeginScene(device
);
4438 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
4439 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
4440 tests
[i
].vertextype
, tests
[i
].data
, 4, tests
[i
].draw_flags
| D3DDP_WAIT
);
4441 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
4442 hr
= IDirect3DDevice7_EndScene(device
);
4443 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
4445 hr
= IDirect3DDevice7_GetRenderState(device
, D3DRENDERSTATE_LIGHTING
, &rs
);
4446 ok(SUCCEEDED(hr
), "Failed to get lighting render state, hr %#x.\n", hr
);
4447 ok(rs
== tests
[i
].d3drs_lighting
, "D3DRENDERSTATE_LIGHTING is %#x, expected %#x.\n",
4448 rs
, tests
[i
].d3drs_lighting
);
4450 color
= get_surface_color(rt
, 320, 240);
4451 ok(compare_color(color
, tests
[i
].color
, 1),
4452 "Got unexpected color 0x%08x, expected 0x%08x, test %u.\n",
4453 color
, tests
[i
].color
, i
);
4456 IDirectDrawSurface7_Release(rt
);
4457 ref
= IDirect3DDevice7_Release(device
);
4458 ok(ref
== 0, "Device not properly released, refcount %u.\n", ref
);
4459 DestroyWindow(window
);
4465 IDirectDraw7
*ddraw
;
4468 } activateapp_testdata
;
4470 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
4472 if (message
== WM_ACTIVATEAPP
)
4474 if (activateapp_testdata
.ddraw
)
4477 activateapp_testdata
.received
= FALSE
;
4478 hr
= IDirectDraw7_SetCooperativeLevel(activateapp_testdata
.ddraw
,
4479 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
4480 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
4481 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
4483 activateapp_testdata
.received
= TRUE
;
4486 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
4489 static void test_coop_level_activateapp(void)
4491 IDirectDraw7
*ddraw
;
4495 DDSURFACEDESC2 ddsd
;
4496 IDirectDrawSurface7
*surface
;
4498 ddraw
= create_ddraw();
4499 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4501 wc
.lpfnWndProc
= activateapp_test_proc
;
4502 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
4503 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
4505 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
4506 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
4508 /* Exclusive with window already active. */
4509 SetForegroundWindow(window
);
4510 activateapp_testdata
.received
= FALSE
;
4511 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4512 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4513 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
4514 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4515 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4517 /* Exclusive with window not active. */
4518 SetForegroundWindow(GetDesktopWindow());
4519 activateapp_testdata
.received
= FALSE
;
4520 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4521 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4522 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4523 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4524 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4526 /* Normal with window not active, then exclusive with the same window. */
4527 SetForegroundWindow(GetDesktopWindow());
4528 activateapp_testdata
.received
= FALSE
;
4529 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4530 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4531 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
4532 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4533 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4534 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4535 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4536 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4538 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
4539 SetForegroundWindow(GetDesktopWindow());
4540 activateapp_testdata
.received
= FALSE
;
4541 activateapp_testdata
.ddraw
= ddraw
;
4542 activateapp_testdata
.window
= window
;
4543 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
4544 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4545 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4546 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4547 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4548 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4550 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
4551 * succeeding. Another switch to exclusive and back to normal is needed to release the
4552 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
4553 * WM_ACTIVATEAPP messages. */
4554 activateapp_testdata
.ddraw
= NULL
;
4555 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4556 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4557 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4558 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4560 /* Setting DDSCL_NORMAL with recursive invocation. */
4561 SetForegroundWindow(GetDesktopWindow());
4562 activateapp_testdata
.received
= FALSE
;
4563 activateapp_testdata
.ddraw
= ddraw
;
4564 activateapp_testdata
.window
= window
;
4565 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
4566 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4567 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4568 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
4570 /* DDraw is in exlusive mode now. */
4571 memset(&ddsd
, 0, sizeof(ddsd
));
4572 ddsd
.dwSize
= sizeof(ddsd
);
4573 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4574 U5(ddsd
).dwBackBufferCount
= 1;
4575 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4576 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4577 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4578 IDirectDrawSurface7_Release(surface
);
4580 /* Recover again, just to be sure. */
4581 activateapp_testdata
.ddraw
= NULL
;
4582 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4583 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4584 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4585 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4587 DestroyWindow(window
);
4588 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
4589 IDirectDraw7_Release(ddraw
);
4592 static void test_texturemanage(void)
4594 IDirectDraw7
*ddraw
;
4596 DDSURFACEDESC2 ddsd
;
4597 IDirectDrawSurface7
*surface
;
4599 DDCAPS hal_caps
, hel_caps
;
4600 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
4603 DWORD caps_in
, caps2_in
;
4605 DWORD caps_out
, caps2_out
;
4609 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4611 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4613 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4615 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4617 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, DD_OK
,
4618 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
},
4619 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, DD_OK
,
4620 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
},
4621 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4622 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_LOCALVIDMEM
, 0},
4623 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0, DD_OK
,
4624 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0},
4626 {0, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4628 {0, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4630 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4632 {DDSCAPS_SYSTEMMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4634 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_TEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4636 {DDSCAPS_VIDEOMEMORY
, DDSCAPS2_D3DTEXTUREMANAGE
, DDERR_INVALIDCAPS
,
4638 {DDSCAPS_VIDEOMEMORY
, 0, DD_OK
,
4639 DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
, 0},
4640 {DDSCAPS_SYSTEMMEMORY
, 0, DD_OK
,
4641 DDSCAPS_SYSTEMMEMORY
, 0},
4644 ddraw
= create_ddraw();
4645 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4646 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
4647 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4649 memset(&hal_caps
, 0, sizeof(hal_caps
));
4650 hal_caps
.dwSize
= sizeof(hal_caps
);
4651 memset(&hel_caps
, 0, sizeof(hel_caps
));
4652 hel_caps
.dwSize
= sizeof(hel_caps
);
4653 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, &hel_caps
);
4654 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4655 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
4657 skip("Managed textures not supported, skipping managed texture test.\n");
4658 IDirectDraw7_Release(ddraw
);
4662 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4664 memset(&ddsd
, 0, sizeof(ddsd
));
4665 ddsd
.dwSize
= sizeof(ddsd
);
4666 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4667 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps_in
;
4668 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2_in
;
4672 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4673 if (tests
[i
].hr
== DD_OK
&& is_ddraw64
&& (tests
[i
].caps_in
& DDSCAPS_TEXTURE
))
4674 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
4676 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, tests
[i
].hr
);
4680 memset(&ddsd
, 0, sizeof(ddsd
));
4681 ddsd
.dwSize
= sizeof(ddsd
);
4682 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
4683 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
4685 ok(ddsd
.ddsCaps
.dwCaps
== tests
[i
].caps_out
,
4686 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4687 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps_out
, ddsd
.ddsCaps
.dwCaps
, i
);
4688 ok(ddsd
.ddsCaps
.dwCaps2
== tests
[i
].caps2_out
,
4689 "Input caps %#x, %#x, expected output caps %#x, got %#x, case %u.\n",
4690 tests
[i
].caps_in
, tests
[i
].caps2_in
, tests
[i
].caps2_out
, ddsd
.ddsCaps
.dwCaps2
, i
);
4692 IDirectDrawSurface7_Release(surface
);
4695 IDirectDraw7_Release(ddraw
);
4698 #define SUPPORT_DXT1 0x01
4699 #define SUPPORT_DXT2 0x02
4700 #define SUPPORT_DXT3 0x04
4701 #define SUPPORT_DXT4 0x08
4702 #define SUPPORT_DXT5 0x10
4703 #define SUPPORT_YUY2 0x20
4704 #define SUPPORT_UYVY 0x40
4706 static HRESULT WINAPI
test_block_formats_creation_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
4708 DWORD
*supported_fmts
= ctx
;
4710 if (!(fmt
->dwFlags
& DDPF_FOURCC
))
4711 return DDENUMRET_OK
;
4713 switch (fmt
->dwFourCC
)
4715 case MAKEFOURCC('D','X','T','1'):
4716 *supported_fmts
|= SUPPORT_DXT1
;
4718 case MAKEFOURCC('D','X','T','2'):
4719 *supported_fmts
|= SUPPORT_DXT2
;
4721 case MAKEFOURCC('D','X','T','3'):
4722 *supported_fmts
|= SUPPORT_DXT3
;
4724 case MAKEFOURCC('D','X','T','4'):
4725 *supported_fmts
|= SUPPORT_DXT4
;
4727 case MAKEFOURCC('D','X','T','5'):
4728 *supported_fmts
|= SUPPORT_DXT5
;
4730 case MAKEFOURCC('Y','U','Y','2'):
4731 *supported_fmts
|= SUPPORT_YUY2
;
4733 case MAKEFOURCC('U','Y','V','Y'):
4734 *supported_fmts
|= SUPPORT_UYVY
;
4740 return DDENUMRET_OK
;
4743 static void test_block_formats_creation(void)
4745 HRESULT hr
, expect_hr
;
4746 unsigned int i
, j
, w
, h
;
4748 IDirectDraw7
*ddraw
;
4750 IDirect3DDevice7
*device
;
4751 IDirectDrawSurface7
*surface
;
4752 DWORD supported_fmts
= 0, supported_overlay_fmts
= 0;
4753 DWORD num_fourcc_codes
= 0, *fourcc_codes
;
4754 DDSURFACEDESC2 ddsd
;
4763 unsigned int block_width
;
4764 unsigned int block_height
;
4765 unsigned int block_size
;
4766 BOOL create_size_checked
, overlay
;
4770 {MAKEFOURCC('D','X','T','1'), "D3DFMT_DXT1", SUPPORT_DXT1
, 4, 4, 8, TRUE
, FALSE
},
4771 {MAKEFOURCC('D','X','T','2'), "D3DFMT_DXT2", SUPPORT_DXT2
, 4, 4, 16, TRUE
, FALSE
},
4772 {MAKEFOURCC('D','X','T','3'), "D3DFMT_DXT3", SUPPORT_DXT3
, 4, 4, 16, TRUE
, FALSE
},
4773 {MAKEFOURCC('D','X','T','4'), "D3DFMT_DXT4", SUPPORT_DXT4
, 4, 4, 16, TRUE
, FALSE
},
4774 {MAKEFOURCC('D','X','T','5'), "D3DFMT_DXT5", SUPPORT_DXT5
, 4, 4, 16, TRUE
, FALSE
},
4775 {MAKEFOURCC('Y','U','Y','2'), "D3DFMT_YUY2", SUPPORT_YUY2
, 2, 1, 4, FALSE
, TRUE
},
4776 {MAKEFOURCC('U','Y','V','Y'), "D3DFMT_UYVY", SUPPORT_UYVY
, 2, 1, 4, FALSE
, TRUE
},
4786 /* DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY fails to create any fourcc
4787 * surface with DDERR_INVALIDPIXELFORMAT. Don't care about it for now.
4789 * Nvidia returns E_FAIL on DXTN DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY.
4790 * Other hw / drivers successfully create those surfaces. Ignore them, this
4791 * suggests that no game uses this, otherwise Nvidia would support it. */
4793 DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
, 0,
4794 "videomemory texture", FALSE
4797 DDSCAPS_VIDEOMEMORY
| DDSCAPS_OVERLAY
, 0,
4798 "videomemory overlay", TRUE
4801 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
, 0,
4802 "systemmemory texture", FALSE
4805 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
4806 "managed texture", FALSE
4818 enum size_type size_type
;
4824 {DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DD_OK
},
4825 {DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
4826 {DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DD_OK
},
4827 {DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DD_OK
},
4828 {DDSD_LPSURFACE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4829 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4830 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
4831 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DD_OK
},
4832 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 1, DD_OK
},
4833 {DDSD_LPSURFACE
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, -1, DDERR_INVALIDPARAMS
},
4834 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_ZERO
, 0, DDERR_INVALIDPARAMS
},
4835 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_PITCH
, 0, DDERR_INVALIDPARAMS
},
4836 {DDSD_LPSURFACE
| DDSD_PITCH
, SIZE_TYPE_SIZE
, 0, DDERR_INVALIDPARAMS
},
4837 {DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, SIZE_TYPE_SIZE
, 0, DDERR_INVALIDPARAMS
},
4840 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4841 0, 0, 640, 480, 0, 0, 0, 0);
4843 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
4845 skip("Failed to create a 3D device, skipping test.\n");
4846 DestroyWindow(window
);
4850 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
4851 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
4852 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
4853 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
4854 IDirect3D7_Release(d3d
);
4856 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
,
4858 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
4860 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
4861 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4862 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
4863 num_fourcc_codes
* sizeof(*fourcc_codes
));
4866 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
4867 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
4868 for (i
= 0; i
< num_fourcc_codes
; i
++)
4870 for (j
= 0; j
< sizeof(formats
) / sizeof(*formats
); j
++)
4872 if (fourcc_codes
[i
] == formats
[j
].fourcc
)
4873 supported_overlay_fmts
|= formats
[j
].support_flag
;
4876 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
4878 memset(&hal_caps
, 0, sizeof(hal_caps
));
4879 hal_caps
.dwSize
= sizeof(hal_caps
);
4880 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
4881 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
4883 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 2 * 2 * 16 + 1);
4885 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
4887 for (j
= 0; j
< sizeof(types
) / sizeof(*types
); j
++)
4891 if (formats
[i
].overlay
!= types
[j
].overlay
4892 || (types
[j
].overlay
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
)))
4895 if (formats
[i
].overlay
)
4896 support
= supported_overlay_fmts
& formats
[i
].support_flag
;
4898 support
= supported_fmts
& formats
[i
].support_flag
;
4900 for (w
= 1; w
<= 8; w
++)
4902 for (h
= 1; h
<= 8; h
++)
4904 BOOL block_aligned
= TRUE
;
4907 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
4908 block_aligned
= FALSE
;
4910 memset(&ddsd
, 0, sizeof(ddsd
));
4911 ddsd
.dwSize
= sizeof(ddsd
);
4912 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
4913 ddsd
.ddsCaps
.dwCaps
= types
[j
].caps
;
4914 ddsd
.ddsCaps
.dwCaps2
= types
[j
].caps2
;
4915 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
4916 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
4917 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
4921 /* TODO: Handle power of two limitations. I cannot test the pow2
4922 * behavior on windows because I have no hardware that doesn't at
4923 * least support np2_conditional. There's probably no HW that
4924 * supports DXTN textures but no conditional np2 textures. */
4925 if (!support
&& !(types
[j
].caps
& DDSCAPS_SYSTEMMEMORY
))
4926 expect_hr
= DDERR_INVALIDPARAMS
;
4927 else if (formats
[i
].create_size_checked
&& !block_aligned
)
4929 expect_hr
= DDERR_INVALIDPARAMS
;
4930 if (!(types
[j
].caps
& DDSCAPS_TEXTURE
))
4936 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4938 todo_wine
ok(hr
== expect_hr
,
4939 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4940 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4943 "Got unexpected hr %#x for format %s, resource type %s, size %ux%u, expected %#x.\n",
4944 hr
, formats
[i
].name
, types
[j
].name
, w
, h
, expect_hr
);
4947 IDirectDrawSurface7_Release(surface
);
4952 if (formats
[i
].overlay
)
4955 for (j
= 0; j
< sizeof(user_mem_tests
) / sizeof(*user_mem_tests
); ++j
)
4957 memset(&ddsd
, 0, sizeof(ddsd
));
4958 ddsd
.dwSize
= sizeof(ddsd
);
4959 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| user_mem_tests
[j
].flags
;
4960 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
;
4962 switch (user_mem_tests
[j
].size_type
)
4964 case SIZE_TYPE_ZERO
:
4965 U1(ddsd
).dwLinearSize
= 0;
4968 case SIZE_TYPE_PITCH
:
4969 U1(ddsd
).dwLinearSize
= 2 * formats
[i
].block_size
;
4972 case SIZE_TYPE_SIZE
:
4973 U1(ddsd
).dwLinearSize
= 2 * 2 * formats
[i
].block_size
;
4976 U1(ddsd
).dwLinearSize
+= user_mem_tests
[j
].rel_size
;
4978 ddsd
.lpSurface
= mem
;
4979 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
4980 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
4981 U4(ddsd
).ddpfPixelFormat
.dwFourCC
= formats
[i
].fourcc
;
4985 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4986 ok(hr
== user_mem_tests
[j
].hr
, "Test %u: Got unexpected hr %#x, format %s.\n", j
, hr
, formats
[i
].name
);
4991 memset(&ddsd
, 0, sizeof(ddsd
));
4992 ddsd
.dwSize
= sizeof(ddsd
);
4993 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
4994 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", j
, hr
);
4995 ok(ddsd
.dwFlags
== (DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_LINEARSIZE
),
4996 "Test %u: Got unexpected flags %#x.\n", j
, ddsd
.dwFlags
);
4997 if (user_mem_tests
[j
].flags
& DDSD_LPSURFACE
)
4998 ok(U1(ddsd
).dwLinearSize
== ~0u, "Test %u: Got unexpected linear size %#x.\n",
4999 j
, U1(ddsd
).dwLinearSize
);
5001 ok(U1(ddsd
).dwLinearSize
== 2 * 2 * formats
[i
].block_size
,
5002 "Test %u: Got unexpected linear size %#x, expected %#x.\n",
5003 j
, U1(ddsd
).dwLinearSize
, 2 * 2 * formats
[i
].block_size
);
5004 IDirectDrawSurface7_Release(surface
);
5008 HeapFree(GetProcessHeap(), 0, mem
);
5010 IDirectDraw7_Release(ddraw
);
5011 IDirect3DDevice7_Release(device
);
5012 DestroyWindow(window
);
5015 struct format_support_check
5017 const DDPIXELFORMAT
*format
;
5021 static HRESULT WINAPI
test_unsupported_formats_cb(DDPIXELFORMAT
*fmt
, void *ctx
)
5023 struct format_support_check
*format
= ctx
;
5025 if (!memcmp(format
->format
, fmt
, sizeof(*fmt
)))
5027 format
->supported
= TRUE
;
5028 return DDENUMRET_CANCEL
;
5031 return DDENUMRET_OK
;
5034 static void test_unsupported_formats(void)
5037 BOOL expect_success
;
5039 IDirectDraw7
*ddraw
;
5041 IDirect3DDevice7
*device
;
5042 IDirectDrawSurface7
*surface
;
5043 DDSURFACEDESC2 ddsd
;
5045 DWORD expected_caps
;
5056 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
5057 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
5063 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5064 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
5068 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
5070 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5071 0, 0, 640, 480, 0, 0, 0, 0);
5073 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5075 skip("Failed to create a 3D device, skipping test.\n");
5076 DestroyWindow(window
);
5080 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
5081 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5082 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **) &ddraw
);
5083 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5084 IDirect3D7_Release(d3d
);
5086 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
5088 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
5089 hr
= IDirect3DDevice7_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
5090 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
5092 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
5094 memset(&ddsd
, 0, sizeof(ddsd
));
5095 ddsd
.dwSize
= sizeof(ddsd
);
5096 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5097 U4(ddsd
).ddpfPixelFormat
= formats
[i
].fmt
;
5100 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
5102 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
5103 expect_success
= FALSE
;
5105 expect_success
= TRUE
;
5107 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5108 ok(SUCCEEDED(hr
) == expect_success
,
5109 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
5110 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
5114 memset(&ddsd
, 0, sizeof(ddsd
));
5115 ddsd
.dwSize
= sizeof(ddsd
);
5116 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
5117 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5119 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
5120 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5121 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
5122 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5123 else if (check
.supported
)
5124 expected_caps
= DDSCAPS_VIDEOMEMORY
;
5126 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
5128 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
5129 "Expected capability %#x, format %s, input cap %#x.\n",
5130 expected_caps
, formats
[i
].name
, caps
[j
]);
5132 IDirectDrawSurface7_Release(surface
);
5136 IDirectDraw7_Release(ddraw
);
5137 IDirect3DDevice7_Release(device
);
5138 DestroyWindow(window
);
5141 static void test_rt_caps(void)
5143 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
5144 PALETTEENTRY palette_entries
[256];
5145 IDirectDrawPalette
*palette
;
5146 IDirectDraw7
*ddraw
;
5147 BOOL hal_ok
= FALSE
;
5148 DDPIXELFORMAT z_fmt
;
5155 static const DDPIXELFORMAT p8_fmt
=
5157 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
5158 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
5163 const DDPIXELFORMAT
*pf
;
5166 HRESULT create_device_hr
;
5167 HRESULT set_rt_hr
, alternative_set_rt_hr
;
5173 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5174 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5181 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5182 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5189 DDSCAPS_OFFSCREENPLAIN
,
5190 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5197 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5198 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5199 D3DERR_SURFACENOTINVIDMEM
,
5200 DDERR_INVALIDPARAMS
,
5205 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5206 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5213 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
5214 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5222 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5230 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5237 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5238 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5239 D3DERR_SURFACENOTINVIDMEM
,
5240 DDERR_INVALIDPARAMS
,
5245 DDSCAPS_SYSTEMMEMORY
,
5246 DDSCAPS_SYSTEMMEMORY
,
5254 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5261 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5263 DDERR_NOPALETTEATTACHED
,
5269 DDSCAPS_OFFSCREENPLAIN
,
5270 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
5277 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5278 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
5279 DDERR_NOPALETTEATTACHED
,
5285 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5286 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5293 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
5294 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5296 DDERR_INVALIDPIXELFORMAT
,
5297 DDERR_INVALIDPIXELFORMAT
,
5301 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5302 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5304 DDERR_INVALIDPIXELFORMAT
,
5305 DDERR_INVALIDPIXELFORMAT
,
5310 DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
5317 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5318 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
5320 DDERR_INVALIDPARAMS
,
5321 DDERR_INVALIDPIXELFORMAT
,
5325 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5326 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
5333 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5334 0, 0, 640, 480, 0, 0, 0, 0);
5335 ddraw
= create_ddraw();
5336 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5337 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5338 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5340 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
5342 skip("D3D interface is not available, skipping test.\n");
5346 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
5347 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
5349 devtype
= &IID_IDirect3DTnLHalDevice
;
5351 memset(&z_fmt
, 0, sizeof(z_fmt
));
5352 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
5353 if (FAILED(hr
) || !z_fmt
.dwSize
)
5355 skip("No depth buffer formats available, skipping test.\n");
5356 IDirect3D7_Release(d3d
);
5360 memset(palette_entries
, 0, sizeof(palette_entries
));
5361 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
5362 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5364 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5366 IDirectDrawSurface7
*surface
, *rt
, *expected_rt
, *tmp
;
5367 DDSURFACEDESC2 surface_desc
;
5368 IDirect3DDevice7
*device
;
5370 memset(&surface_desc
, 0, sizeof(surface_desc
));
5371 surface_desc
.dwSize
= sizeof(surface_desc
);
5372 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5373 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5374 if (test_data
[i
].pf
)
5376 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5377 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5379 surface_desc
.dwWidth
= 640;
5380 surface_desc
.dwHeight
= 480;
5381 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5382 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5383 i
, test_data
[i
].caps_in
, hr
);
5385 memset(&surface_desc
, 0, sizeof(surface_desc
));
5386 surface_desc
.dwSize
= sizeof(surface_desc
);
5387 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
5388 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5389 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
5390 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5391 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5393 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5394 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
5395 i
, hr
, test_data
[i
].create_device_hr
);
5398 if (hr
== DDERR_NOPALETTEATTACHED
)
5400 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
5401 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
5402 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5403 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
5404 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5406 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5408 IDirectDrawSurface7_Release(surface
);
5410 memset(&surface_desc
, 0, sizeof(surface_desc
));
5411 surface_desc
.dwSize
= sizeof(surface_desc
);
5412 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5413 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5414 surface_desc
.dwWidth
= 640;
5415 surface_desc
.dwHeight
= 480;
5416 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5417 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface, hr %#x.\n", i
, hr
);
5419 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5420 ok(SUCCEEDED(hr
), "Test %u: Failed to create device, hr %#x.\n", i
, hr
);
5423 memset(&surface_desc
, 0, sizeof(surface_desc
));
5424 surface_desc
.dwSize
= sizeof(surface_desc
);
5425 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5426 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5427 if (test_data
[i
].pf
)
5429 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
5430 U4(surface_desc
).ddpfPixelFormat
= *test_data
[i
].pf
;
5432 surface_desc
.dwWidth
= 640;
5433 surface_desc
.dwHeight
= 480;
5434 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &rt
, NULL
);
5435 ok(SUCCEEDED(hr
), "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
5436 i
, test_data
[i
].caps_in
, hr
);
5438 hr
= IDirect3DDevice7_SetRenderTarget(device
, rt
, 0);
5439 ok(hr
== test_data
[i
].set_rt_hr
|| broken(hr
== test_data
[i
].alternative_set_rt_hr
),
5440 "Test %u: Got unexpected hr %#x, expected %#x.\n",
5441 i
, hr
, test_data
[i
].set_rt_hr
);
5442 if (SUCCEEDED(hr
) || hr
== DDERR_INVALIDPIXELFORMAT
)
5445 expected_rt
= surface
;
5447 hr
= IDirect3DDevice7_GetRenderTarget(device
, &tmp
);
5448 ok(SUCCEEDED(hr
), "Test %u: Failed to get render target, hr %#x.\n", i
, hr
);
5449 ok(tmp
== expected_rt
, "Test %u: Got unexpected rt %p.\n", i
, tmp
);
5451 IDirectDrawSurface7_Release(tmp
);
5452 IDirectDrawSurface7_Release(rt
);
5453 refcount
= IDirect3DDevice7_Release(device
);
5454 ok(refcount
== 0, "Test %u: The device was not properly freed, refcount %u.\n", i
, refcount
);
5455 refcount
= IDirectDrawSurface7_Release(surface
);
5456 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
5459 IDirectDrawPalette_Release(palette
);
5460 IDirect3D7_Release(d3d
);
5463 refcount
= IDirectDraw7_Release(ddraw
);
5464 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5465 DestroyWindow(window
);
5468 static void test_primary_caps(void)
5470 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5471 IDirectDrawSurface7
*surface
;
5472 DDSURFACEDESC2 surface_desc
;
5473 IDirectDraw7
*ddraw
;
5483 DWORD back_buffer_count
;
5491 DDSCAPS_PRIMARYSURFACE
,
5494 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
5498 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
5505 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
5512 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
5519 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
5526 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
5533 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5540 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5547 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5549 DDERR_NOEXCLUSIVEMODE
,
5553 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5554 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5560 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5561 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
5564 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
5567 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5568 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
5574 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
5575 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
5582 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5583 0, 0, 640, 480, 0, 0, 0, 0);
5584 ddraw
= create_ddraw();
5585 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5587 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5589 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
5590 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5592 memset(&surface_desc
, 0, sizeof(surface_desc
));
5593 surface_desc
.dwSize
= sizeof(surface_desc
);
5594 surface_desc
.dwFlags
= DDSD_CAPS
;
5595 if (test_data
[i
].back_buffer_count
!= ~0u)
5596 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
5597 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
5598 U5(surface_desc
).dwBackBufferCount
= test_data
[i
].back_buffer_count
;
5599 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5600 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5604 memset(&surface_desc
, 0, sizeof(surface_desc
));
5605 surface_desc
.dwSize
= sizeof(surface_desc
);
5606 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
5607 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5608 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
5609 "Test %u: Got unexpected caps %#x, expected %#x.\n",
5610 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
5612 IDirectDrawSurface7_Release(surface
);
5615 refcount
= IDirectDraw7_Release(ddraw
);
5616 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5617 DestroyWindow(window
);
5620 static void test_surface_lock(void)
5622 IDirectDraw7
*ddraw
;
5623 IDirect3D7
*d3d
= NULL
;
5624 IDirectDrawSurface7
*surface
;
5625 IDirect3DDevice7
*device
;
5629 DDSURFACEDESC2 ddsd
;
5631 DDPIXELFORMAT z_fmt
;
5632 BOOL hal_ok
= FALSE
;
5633 const GUID
*devtype
= &IID_IDirect3DHALDevice
;
5634 D3DDEVICEDESC7 device_desc
;
5635 BOOL cubemap_supported
;
5645 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
5647 "videomemory offscreenplain"
5650 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
5652 "systemmemory offscreenplain"
5655 DDSCAPS_PRIMARYSURFACE
,
5660 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5662 "videomemory texture"
5665 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
5667 "opaque videomemory texture"
5670 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
5672 "systemmemory texture"
5676 DDSCAPS2_TEXTUREMANAGE
,
5681 DDSCAPS2_D3DTEXTUREMANAGE
,
5686 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5687 "opaque managed texture"
5691 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_OPAQUE
,
5692 "opaque managed texture"
5695 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
5705 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
5706 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5710 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_VIDEOMEMORY
,
5711 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5712 "opaque videomemory cube"
5715 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_SYSTEMMEMORY
,
5716 DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5720 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5721 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5725 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5726 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
,
5730 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5731 DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5732 "opaque managed cube"
5735 DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
,
5736 DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_CUBEMAP
| DDSCAPS2_CUBEMAP_ALLFACES
| DDSCAPS2_OPAQUE
,
5737 "opaque managed cube"
5741 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5742 0, 0, 640, 480, 0, 0, 0, 0);
5743 ddraw
= create_ddraw();
5744 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5745 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5746 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5748 if (FAILED(IDirectDraw7_QueryInterface(ddraw
, &IID_IDirect3D7
, (void **)&d3d
)))
5750 skip("D3D interface is not available, skipping test.\n");
5754 hr
= IDirect3D7_EnumDevices(d3d
, enum_devtype_cb
, &hal_ok
);
5755 ok(SUCCEEDED(hr
), "Failed to enumerate devices, hr %#x.\n", hr
);
5757 devtype
= &IID_IDirect3DTnLHalDevice
;
5759 memset(&z_fmt
, 0, sizeof(z_fmt
));
5760 hr
= IDirect3D7_EnumZBufferFormats(d3d
, devtype
, enum_z_fmt
, &z_fmt
);
5761 if (FAILED(hr
) || !z_fmt
.dwSize
)
5763 skip("No depth buffer formats available, skipping test.\n");
5767 memset(&ddsd
, 0, sizeof(ddsd
));
5768 ddsd
.dwSize
= sizeof(ddsd
);
5769 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5772 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
5773 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5774 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5776 hr
= IDirect3D7_CreateDevice(d3d
, devtype
, surface
, &device
);
5777 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x.\n", hr
);
5778 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
5779 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5780 cubemap_supported
= !!(device_desc
.dpcTriCaps
.dwTextureCaps
& D3DPTEXTURECAPS_CUBEMAP
);
5781 IDirect3DDevice7_Release(device
);
5783 IDirectDrawSurface7_Release(surface
);
5785 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5787 if (!cubemap_supported
&& tests
[i
].caps2
& DDSCAPS2_CUBEMAP
)
5790 memset(&ddsd
, 0, sizeof(ddsd
));
5791 ddsd
.dwSize
= sizeof(ddsd
);
5792 ddsd
.dwFlags
= DDSD_CAPS
;
5793 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
5795 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
5799 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
5801 ddsd
.dwFlags
|= DDSD_PIXELFORMAT
;
5802 U4(ddsd
).ddpfPixelFormat
= z_fmt
;
5804 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5805 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5807 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5808 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5810 memset(&ddsd
, 0, sizeof(ddsd
));
5811 ddsd
.dwSize
= sizeof(ddsd
);
5812 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
5813 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5816 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5817 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
5820 IDirectDrawSurface7_Release(surface
);
5825 IDirect3D7_Release(d3d
);
5826 refcount
= IDirectDraw7_Release(ddraw
);
5827 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
5828 DestroyWindow(window
);
5831 static void test_surface_discard(void)
5833 IDirect3DDevice7
*device
;
5835 IDirectDraw7
*ddraw
;
5838 DDSURFACEDESC2 ddsd
;
5839 IDirectDrawSurface7
*surface
, *target
;
5848 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5849 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5850 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, TRUE
},
5851 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
},
5852 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
},
5853 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5854 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
},
5855 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
| DDSCAPS2_HINTDYNAMIC
, FALSE
},
5859 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5860 0, 0, 640, 480, 0, 0, 0, 0);
5862 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
5864 skip("Failed to create a 3D device, skipping test.\n");
5865 DestroyWindow(window
);
5868 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
5869 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
5870 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
5871 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
5872 hr
= IDirect3DDevice7_GetRenderTarget(device
, &target
);
5873 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5875 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
5879 memset(&ddsd
, 0, sizeof(ddsd
));
5880 ddsd
.dwSize
= sizeof(ddsd
);
5881 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
5882 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5883 ddsd
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
5886 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
5887 ok(SUCCEEDED(hr
), "Failed to create offscreen surface, hr %#x, case %u.\n", hr
, i
);
5889 memset(&ddsd
, 0, sizeof(ddsd
));
5890 ddsd
.dwSize
= sizeof(ddsd
);
5891 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
5892 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5893 addr
= ddsd
.lpSurface
;
5894 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5895 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5897 memset(&ddsd
, 0, sizeof(ddsd
));
5898 ddsd
.dwSize
= sizeof(ddsd
);
5899 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5900 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5901 discarded
= ddsd
.lpSurface
!= addr
;
5902 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5903 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5905 hr
= IDirectDrawSurface7_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
5906 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
5908 memset(&ddsd
, 0, sizeof(ddsd
));
5909 ddsd
.dwSize
= sizeof(ddsd
);
5910 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
, NULL
);
5911 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5912 discarded
|= ddsd
.lpSurface
!= addr
;
5913 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
5914 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5916 IDirectDrawSurface7_Release(surface
);
5918 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
5919 * AMD r500, evergreen). Windows XP, at least on AMD r200, does not. */
5920 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
5923 IDirectDrawSurface7_Release(target
);
5924 IDirectDraw7_Release(ddraw
);
5925 IDirect3D7_Release(d3d
);
5926 IDirect3DDevice7_Release(device
);
5927 DestroyWindow(window
);
5930 static void test_flip(void)
5932 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
5933 IDirectDrawSurface7
*primary
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
5934 DDSCAPS2 caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
5935 DDSURFACEDESC2 surface_desc
;
5936 BOOL sysmem_primary
;
5937 IDirectDraw7
*ddraw
;
5944 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5945 0, 0, 640, 480, 0, 0, 0, 0);
5946 ddraw
= create_ddraw();
5947 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5949 hr
= set_display_mode(ddraw
, 640, 480);
5950 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
5951 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
5952 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5954 memset(&surface_desc
, 0, sizeof(surface_desc
));
5955 surface_desc
.dwSize
= sizeof(surface_desc
);
5956 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
5957 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
5958 U5(surface_desc
).dwBackBufferCount
= 3;
5959 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
5960 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5962 memset(&surface_desc
, 0, sizeof(surface_desc
));
5963 surface_desc
.dwSize
= sizeof(surface_desc
);
5964 hr
= IDirectDrawSurface7_GetSurfaceDesc(primary
, &surface_desc
);
5965 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5966 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
)
5967 == (DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5968 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5969 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
5971 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &caps
, &backbuffer1
);
5972 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5973 memset(&surface_desc
, 0, sizeof(surface_desc
));
5974 surface_desc
.dwSize
= sizeof(surface_desc
);
5975 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer1
, &surface_desc
);
5976 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5977 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
5978 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
| DDSCAPS_BACKBUFFER
),
5979 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5981 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
5982 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5983 memset(&surface_desc
, 0, sizeof(surface_desc
));
5984 surface_desc
.dwSize
= sizeof(surface_desc
);
5985 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer2
, &surface_desc
);
5986 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5987 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
5988 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5989 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
5991 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
5992 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
5993 memset(&surface_desc
, 0, sizeof(surface_desc
));
5994 surface_desc
.dwSize
= sizeof(surface_desc
);
5995 hr
= IDirectDrawSurface7_GetSurfaceDesc(backbuffer3
, &surface_desc
);
5996 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5997 ok(!U5(surface_desc
).dwBackBufferCount
, "Got unexpected back buffer count %u.\n", U5(surface_desc
).dwBackBufferCount
);
5998 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == (DDSCAPS_FLIP
| DDSCAPS_COMPLEX
),
5999 "Got unexpected caps %#x.\n", surface_desc
.ddsCaps
.dwCaps
);
6001 hr
= IDirectDrawSurface7_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
6002 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6003 ok(surface
== primary
, "Got unexpected surface %p, expected %p.\n", surface
, primary
);
6004 IDirectDrawSurface7_Release(surface
);
6006 memset(&surface_desc
, 0, sizeof(surface_desc
));
6007 surface_desc
.dwSize
= sizeof(surface_desc
);
6008 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6009 surface_desc
.ddsCaps
.dwCaps
= 0;
6010 surface_desc
.dwWidth
= 640;
6011 surface_desc
.dwHeight
= 480;
6012 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6013 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6014 hr
= IDirectDrawSurface7_Flip(primary
, surface
, DDFLIP_WAIT
);
6015 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6016 IDirectDrawSurface7_Release(surface
);
6018 hr
= IDirectDrawSurface7_Flip(primary
, primary
, DDFLIP_WAIT
);
6019 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6020 hr
= IDirectDrawSurface7_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
6021 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6022 hr
= IDirectDrawSurface7_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
6023 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6024 hr
= IDirectDrawSurface7_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
6025 ok(hr
== DDERR_NOTFLIPPABLE
, "Got unexpected hr %#x.\n", hr
);
6027 memset(&fx
, 0, sizeof(fx
));
6028 fx
.dwSize
= sizeof(fx
);
6029 U5(fx
).dwFillColor
= 0xffff0000;
6030 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6031 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6032 U5(fx
).dwFillColor
= 0xff00ff00;
6033 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6034 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6035 U5(fx
).dwFillColor
= 0xff0000ff;
6036 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6037 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6039 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
6040 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6041 color
= get_surface_color(backbuffer1
, 320, 240);
6042 /* The testbot seems to just copy the contents of one surface to all the
6043 * others, instead of properly flipping. */
6044 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6045 "Got unexpected color 0x%08x.\n", color
);
6046 color
= get_surface_color(backbuffer2
, 320, 240);
6047 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6048 U5(fx
).dwFillColor
= 0xffff0000;
6049 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6050 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6052 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
6053 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6054 color
= get_surface_color(backbuffer1
, 320, 240);
6055 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6056 "Got unexpected color 0x%08x.\n", color
);
6057 color
= get_surface_color(backbuffer2
, 320, 240);
6058 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6059 U5(fx
).dwFillColor
= 0xff00ff00;
6060 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6061 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6063 hr
= IDirectDrawSurface7_Flip(primary
, NULL
, DDFLIP_WAIT
);
6064 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6065 color
= get_surface_color(backbuffer1
, 320, 240);
6066 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6067 "Got unexpected color 0x%08x.\n", color
);
6068 color
= get_surface_color(backbuffer2
, 320, 240);
6069 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6070 U5(fx
).dwFillColor
= 0xff0000ff;
6071 hr
= IDirectDrawSurface7_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6072 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6074 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer1
, DDFLIP_WAIT
);
6075 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6076 color
= get_surface_color(backbuffer2
, 320, 240);
6077 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
6078 "Got unexpected color 0x%08x.\n", color
);
6079 color
= get_surface_color(backbuffer3
, 320, 240);
6080 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
6081 U5(fx
).dwFillColor
= 0xffff0000;
6082 hr
= IDirectDrawSurface7_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6083 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6085 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer2
, DDFLIP_WAIT
);
6086 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6087 color
= get_surface_color(backbuffer1
, 320, 240);
6088 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
6089 color
= get_surface_color(backbuffer3
, 320, 240);
6090 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
6091 "Got unexpected color 0x%08x.\n", color
);
6092 U5(fx
).dwFillColor
= 0xff00ff00;
6093 hr
= IDirectDrawSurface7_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6094 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
6096 hr
= IDirectDrawSurface7_Flip(primary
, backbuffer3
, DDFLIP_WAIT
);
6097 ok(SUCCEEDED(hr
), "Failed to flip, hr %#x.\n", hr
);
6098 color
= get_surface_color(backbuffer1
, 320, 240);
6099 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
6100 "Got unexpected color 0x%08x.\n", color
);
6101 color
= get_surface_color(backbuffer2
, 320, 240);
6102 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
6104 IDirectDrawSurface7_Release(backbuffer3
);
6105 IDirectDrawSurface7_Release(backbuffer2
);
6106 IDirectDrawSurface7_Release(backbuffer1
);
6107 IDirectDrawSurface7_Release(primary
);
6108 refcount
= IDirectDraw7_Release(ddraw
);
6109 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
6110 DestroyWindow(window
);
6113 static void reset_ddsd(DDSURFACEDESC2
*ddsd
)
6115 memset(ddsd
, 0, sizeof(*ddsd
));
6116 ddsd
->dwSize
= sizeof(*ddsd
);
6119 static void test_set_surface_desc(void)
6121 IDirectDraw7
*ddraw
;
6124 DDSURFACEDESC2 ddsd
;
6125 IDirectDrawSurface7
*surface
;
6135 invalid_caps_tests
[] =
6137 {DDSCAPS_VIDEOMEMORY
, 0, FALSE
, "videomemory plain"},
6138 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, TRUE
, "systemmemory texture"},
6139 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, FALSE
, "managed texture"},
6140 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, FALSE
, "managed texture"},
6141 {DDSCAPS_PRIMARYSURFACE
| DDSCAPS_SYSTEMMEMORY
, 0, FALSE
, "systemmemory primary"},
6144 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6145 0, 0, 640, 480, 0, 0, 0, 0);
6146 ddraw
= create_ddraw();
6147 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6148 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6149 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6152 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6155 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6156 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6157 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6158 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6159 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6160 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6161 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6163 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6164 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6167 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6168 ddsd
.lpSurface
= data
;
6169 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6170 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6172 /* Redundantly setting the same lpSurface is not an error. */
6173 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6174 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6176 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6177 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6178 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6179 ok(ddsd
.lpSurface
== NULL
, "lpSurface is %p, expected NULL.\n", ddsd
.lpSurface
);
6181 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &ddsd
, 0, NULL
);
6182 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6183 ok(!(ddsd
.dwFlags
& DDSD_LPSURFACE
), "DDSD_LPSURFACE is set.\n");
6184 ok(ddsd
.lpSurface
== data
, "lpSurface is %p, expected %p.\n", data
, data
);
6185 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
6186 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6189 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6190 ddsd
.lpSurface
= data
;
6191 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 1);
6192 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with flags=1 returned %#x.\n", hr
);
6194 ddsd
.lpSurface
= NULL
;
6195 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6196 ok(hr
== DDERR_INVALIDPARAMS
, "Setting lpSurface=NULL returned %#x.\n", hr
);
6198 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, NULL
, 0);
6199 ok(hr
== DDERR_INVALIDPARAMS
, "SetSurfaceDesc with NULL desc returned %#x.\n", hr
);
6201 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6202 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6203 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6204 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6205 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6207 /* Setting the caps is an error. This also means the original description cannot be reapplied. */
6208 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6209 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the original desc returned %#x.\n", hr
);
6211 ddsd
.dwFlags
= DDSD_CAPS
;
6212 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6213 ok(hr
== DDERR_INVALIDPARAMS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6215 /* dwCaps = 0 is allowed, but ignored. Caps2 can be anything and is ignored too. */
6216 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_LPSURFACE
;
6217 ddsd
.lpSurface
= data
;
6218 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6219 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6220 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6221 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6222 ok(hr
== DDERR_INVALIDCAPS
, "Setting DDSD_CAPS returned %#x.\n", hr
);
6223 ddsd
.ddsCaps
.dwCaps
= 0;
6224 ddsd
.ddsCaps
.dwCaps2
= 0xdeadbeef;
6225 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6226 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6228 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6229 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6230 ok(ddsd
.ddsCaps
.dwCaps
== (DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
),
6231 "Got unexpected caps %#x.\n", ddsd
.ddsCaps
.dwCaps
);
6232 ok(ddsd
.ddsCaps
.dwCaps2
== 0, "Got unexpected caps2 %#x.\n", 0);
6234 /* Setting the height is allowed, but it cannot be set to 0, and only if LPSURFACE is set too. */
6236 ddsd
.dwFlags
= DDSD_HEIGHT
;
6238 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6239 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height without lpSurface returned %#x.\n", hr
);
6241 ddsd
.lpSurface
= data
;
6242 ddsd
.dwFlags
= DDSD_HEIGHT
| DDSD_LPSURFACE
;
6243 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6244 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6247 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6248 ok(hr
== DDERR_INVALIDPARAMS
, "Setting height=0 returned %#x.\n", hr
);
6251 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6252 ok(SUCCEEDED(hr
), "GetSurfaceDesc failed, hr %#x.\n", hr
);
6253 ok(ddsd
.dwWidth
== 8, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6254 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6256 /* Pitch and width can be set, but only together, and only with LPSURFACE. They must not be 0. */
6258 ddsd
.dwFlags
= DDSD_PITCH
;
6259 U1(ddsd
).lPitch
= 8 * 4;
6260 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6261 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch without lpSurface or width returned %#x.\n", hr
);
6263 ddsd
.dwFlags
= DDSD_WIDTH
;
6265 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6266 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width without lpSurface or pitch returned %#x.\n", hr
);
6268 ddsd
.dwFlags
= DDSD_PITCH
| DDSD_LPSURFACE
;
6269 ddsd
.lpSurface
= data
;
6270 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6271 ok(hr
== DDERR_INVALIDPARAMS
, "Setting pitch and lpSurface without width returned %#x.\n", hr
);
6273 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_LPSURFACE
;
6274 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6275 ok(hr
== DDERR_INVALIDPARAMS
, "Setting width and lpSurface without pitch returned %#x.\n", hr
);
6277 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6278 U1(ddsd
).lPitch
= 16 * 4;
6280 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6281 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6284 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &ddsd
);
6285 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6286 ok(ddsd
.dwWidth
== 16, "SetSurfaceDesc: Expected width 8, got %u.\n", ddsd
.dwWidth
);
6287 ok(ddsd
.dwHeight
== 16, "SetSurfaceDesc: Expected height 16, got %u.\n", ddsd
.dwHeight
);
6288 ok(U1(ddsd
).lPitch
== 16 * 4, "SetSurfaceDesc: Expected pitch 64, got %u.\n", U1(ddsd
).lPitch
);
6290 /* The pitch must be 32 bit aligned and > 0, but is not verified for sanity otherwise.
6292 * VMware rejects those calls, but all real drivers accept it. Mark the VMware behavior broken. */
6293 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6294 U1(ddsd
).lPitch
= 4 * 4;
6295 ddsd
.lpSurface
= data
;
6296 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6297 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6299 U1(ddsd
).lPitch
= 4;
6300 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6301 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_INVALIDPARAMS
), "Failed to set surface desc, hr %#x.\n", hr
);
6303 U1(ddsd
).lPitch
= 16 * 4 + 1;
6304 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6305 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6307 U1(ddsd
).lPitch
= 16 * 4 + 3;
6308 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6309 ok(hr
== DDERR_INVALIDPARAMS
, "Setting misaligned pitch returned %#x.\n", hr
);
6311 U1(ddsd
).lPitch
= -4;
6312 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6313 ok(hr
== DDERR_INVALIDPARAMS
, "Setting negative pitch returned %#x.\n", hr
);
6315 U1(ddsd
).lPitch
= 16 * 4;
6316 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6317 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6320 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6321 U1(ddsd
).lPitch
= 0;
6323 ddsd
.lpSurface
= data
;
6324 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6325 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero pitch returned %#x.\n", hr
);
6327 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_PITCH
| DDSD_LPSURFACE
;
6328 U1(ddsd
).lPitch
= 16 * 4;
6330 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6331 ok(hr
== DDERR_INVALIDPARAMS
, "Setting zero width returned %#x.\n", hr
);
6333 /* Setting the pixelformat without LPSURFACE is an error, but with LPSURFACE it works. */
6334 ddsd
.dwFlags
= DDSD_PIXELFORMAT
;
6335 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6336 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6337 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6338 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6339 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6340 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6341 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6342 ok(hr
== DDERR_INVALIDPARAMS
, "Setting the pixel format returned %#x.\n", hr
);
6344 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_LPSURFACE
;
6345 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6346 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6348 /* Can't set color keys. */
6350 ddsd
.dwFlags
= DDSD_CKSRCBLT
;
6351 ddsd
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00ff0000;
6352 ddsd
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00ff0000;
6353 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6354 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6356 ddsd
.dwFlags
= DDSD_CKSRCBLT
| DDSD_LPSURFACE
;
6357 ddsd
.lpSurface
= data
;
6358 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6359 ok(hr
== DDERR_INVALIDPARAMS
, "Setting ddckCKSrcBlt returned %#x.\n", hr
);
6361 IDirectDrawSurface7_Release(surface
);
6363 /* SetSurfaceDesc needs systemmemory surfaces.
6365 * As a sidenote, fourcc surfaces aren't allowed in sysmem, thus testing DDSD_LINEARSIZE is moot. */
6366 for (i
= 0; i
< sizeof(invalid_caps_tests
) / sizeof(*invalid_caps_tests
); i
++)
6369 ddsd
.dwFlags
= DDSD_CAPS
;
6370 ddsd
.ddsCaps
.dwCaps
= invalid_caps_tests
[i
].caps
;
6371 ddsd
.ddsCaps
.dwCaps2
= invalid_caps_tests
[i
].caps2
;
6372 if (!(invalid_caps_tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
6374 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6377 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6378 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6379 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6380 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6381 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6382 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6385 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6386 if (is_ddraw64
&& (invalid_caps_tests
[i
].caps
& DDSCAPS_TEXTURE
))
6387 todo_wine
ok(hr
== E_NOINTERFACE
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6389 ok(hr
== DD_OK
|| hr
== DDERR_NODIRECTDRAWHW
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
6394 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6395 ddsd
.lpSurface
= data
;
6396 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6397 if (invalid_caps_tests
[i
].supported
)
6399 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6403 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6404 invalid_caps_tests
[i
].name
, hr
);
6406 /* Check priority of error conditions. */
6407 ddsd
.dwFlags
= DDSD_WIDTH
;
6408 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6409 ok(hr
== DDERR_INVALIDSURFACETYPE
, "SetSurfaceDesc on a %s surface returned %#x.\n",
6410 invalid_caps_tests
[i
].name
, hr
);
6413 IDirectDrawSurface7_Release(surface
);
6416 ref
= IDirectDraw7_Release(ddraw
);
6417 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6418 DestroyWindow(window
);
6421 static void test_user_memory_getdc(void)
6423 IDirectDraw7
*ddraw
;
6426 DDSURFACEDESC2 ddsd
;
6427 IDirectDrawSurface7
*surface
;
6433 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6434 0, 0, 640, 480, 0, 0, 0, 0);
6435 ddraw
= create_ddraw();
6436 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6437 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6438 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6441 ddsd
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_PIXELFORMAT
;
6444 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6445 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6446 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6447 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6448 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6449 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6450 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6451 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6452 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6454 memset(data
, 0xaa, sizeof(data
));
6456 ddsd
.dwFlags
= DDSD_LPSURFACE
;
6457 ddsd
.lpSurface
= data
;
6458 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6459 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6461 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6462 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6463 BitBlt(dc
, 0, 0, 16, 8, NULL
, 0, 0, WHITENESS
);
6464 BitBlt(dc
, 0, 8, 16, 8, NULL
, 0, 0, BLACKNESS
);
6465 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6466 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6468 ok(data
[0][0] == 0xffffffff, "Expected color 0xffffffff, got %#x.\n", data
[0][0]);
6469 ok(data
[15][15] == 0x00000000, "Expected color 0x00000000, got %#x.\n", data
[15][15]);
6471 ddsd
.dwFlags
= DDSD_LPSURFACE
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PITCH
;
6472 ddsd
.lpSurface
= data
;
6475 U1(ddsd
).lPitch
= sizeof(*data
);
6476 hr
= IDirectDrawSurface7_SetSurfaceDesc(surface
, &ddsd
, 0);
6477 ok(SUCCEEDED(hr
), "Failed to set surface desc, hr %#x.\n", hr
);
6479 memset(data
, 0xaa, sizeof(data
));
6480 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
6481 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6482 BitBlt(dc
, 0, 0, 4, 8, NULL
, 0, 0, BLACKNESS
);
6483 BitBlt(dc
, 1, 1, 2, 2, NULL
, 0, 0, WHITENESS
);
6484 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
6485 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6487 for (y
= 0; y
< 4; y
++)
6489 for (x
= 0; x
< 4; x
++)
6491 if ((x
== 1 || x
== 2) && (y
== 1 || y
== 2))
6492 ok(data
[y
][x
] == 0xffffffff, "Expected color 0xffffffff on position %ux%u, got %#x.\n",
6495 ok(data
[y
][x
] == 0x00000000, "Expected color 0x00000000 on position %ux%u, got %#x.\n",
6499 ok(data
[0][5] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 5x0, got %#x.\n",
6501 ok(data
[7][3] == 0x00000000, "Expected color 0x00000000 on position 3x7, got %#x.\n",
6503 ok(data
[7][4] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 4x7, got %#x.\n",
6505 ok(data
[8][0] == 0xaaaaaaaa, "Expected color 0xaaaaaaaa on position 0x8, got %#x.\n",
6508 IDirectDrawSurface7_Release(surface
);
6509 ref
= IDirectDraw7_Release(ddraw
);
6510 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6511 DestroyWindow(window
);
6514 static void test_sysmem_overlay(void)
6516 IDirectDraw7
*ddraw
;
6519 DDSURFACEDESC2 ddsd
;
6520 IDirectDrawSurface7
*surface
;
6523 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6524 0, 0, 640, 480, 0, 0, 0, 0);
6525 ddraw
= create_ddraw();
6526 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6527 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6528 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6531 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
6534 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
6535 U4(ddsd
).ddpfPixelFormat
.dwSize
= sizeof(U4(ddsd
).ddpfPixelFormat
);
6536 U4(ddsd
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6537 U1(U4(ddsd
).ddpfPixelFormat
).dwRGBBitCount
= 32;
6538 U2(U4(ddsd
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6539 U3(U4(ddsd
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6540 U4(U4(ddsd
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6541 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6542 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
6544 ref
= IDirectDraw7_Release(ddraw
);
6545 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
6546 DestroyWindow(window
);
6549 static void test_primary_palette(void)
6551 DDSCAPS2 surface_caps
= {DDSCAPS_FLIP
, 0, 0, {0}};
6552 IDirectDrawSurface7
*primary
, *backbuffer
;
6553 PALETTEENTRY palette_entries
[256];
6554 IDirectDrawPalette
*palette
, *tmp
;
6555 DDSURFACEDESC2 surface_desc
;
6556 IDirectDraw7
*ddraw
;
6562 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6563 0, 0, 640, 480, 0, 0, 0, 0);
6564 ddraw
= create_ddraw();
6565 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6566 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
6568 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6569 IDirectDraw7_Release(ddraw
);
6570 DestroyWindow(window
);
6573 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6574 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6576 memset(&surface_desc
, 0, sizeof(surface_desc
));
6577 surface_desc
.dwSize
= sizeof(surface_desc
);
6578 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6579 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6580 U5(surface_desc
).dwBackBufferCount
= 1;
6581 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6582 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6583 hr
= IDirectDrawSurface7_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
6584 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
6586 memset(palette_entries
, 0, sizeof(palette_entries
));
6587 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
6588 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6589 refcount
= get_refcount((IUnknown
*)palette
);
6590 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6592 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6593 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6594 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6596 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6597 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6599 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
6600 * and is generally somewhat broken with respect to 8 bpp / palette
6602 if (SUCCEEDED(IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
)))
6604 win_skip("Broken palette handling detected, skipping tests.\n");
6605 IDirectDrawPalette_Release(tmp
);
6606 IDirectDrawPalette_Release(palette
);
6607 /* The Windows 8 testbot keeps extra references to the primary and
6608 * backbuffer while in 8 bpp mode. */
6609 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
6610 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6614 refcount
= get_refcount((IUnknown
*)palette
);
6615 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6617 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6618 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6619 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
6620 "Got unexpected palette caps %#x.\n", palette_caps
);
6622 hr
= IDirectDrawSurface7_SetPalette(primary
, NULL
);
6623 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6624 refcount
= get_refcount((IUnknown
*)palette
);
6625 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6627 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
6628 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
6629 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
6631 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
6632 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6633 refcount
= get_refcount((IUnknown
*)palette
);
6634 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6636 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
6637 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
6638 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
6639 IDirectDrawPalette_Release(tmp
);
6640 hr
= IDirectDrawSurface7_GetPalette(backbuffer
, &tmp
);
6641 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6643 refcount
= IDirectDrawPalette_Release(palette
);
6644 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6645 refcount
= IDirectDrawPalette_Release(palette
);
6646 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6648 /* Note that this only seems to work when the palette is attached to the
6649 * primary surface. When attached to a regular surface, attempting to get
6650 * the palette here will cause an access violation. */
6651 hr
= IDirectDrawSurface7_GetPalette(primary
, &tmp
);
6652 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
6655 refcount
= IDirectDrawSurface7_Release(backbuffer
);
6656 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6657 refcount
= IDirectDrawSurface7_Release(primary
);
6658 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6659 refcount
= IDirectDraw7_Release(ddraw
);
6660 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6661 DestroyWindow(window
);
6664 static HRESULT WINAPI
surface_counter(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
6666 UINT
*surface_count
= context
;
6669 IDirectDrawSurface_Release(surface
);
6671 return DDENUMRET_OK
;
6674 static void test_surface_attachment(void)
6676 IDirectDrawSurface7
*surface1
, *surface2
, *surface3
, *surface4
;
6677 IDirectDrawSurface
*surface1v1
, *surface2v1
;
6678 DDSCAPS2 caps
= {DDSCAPS_TEXTURE
, 0, 0, {0}};
6679 DDSURFACEDESC2 surface_desc
;
6680 IDirectDraw7
*ddraw
;
6686 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6687 0, 0, 640, 480, 0, 0, 0, 0);
6688 ddraw
= create_ddraw();
6689 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6690 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6691 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6693 memset(&surface_desc
, 0, sizeof(surface_desc
));
6694 surface_desc
.dwSize
= sizeof(surface_desc
);
6695 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
6696 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
6697 U2(surface_desc
).dwMipMapCount
= 3;
6698 surface_desc
.dwWidth
= 128;
6699 surface_desc
.dwHeight
= 128;
6700 if (FAILED(IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
)))
6702 skip("Failed to create a texture, skipping tests.\n");
6703 IDirectDraw7_Release(ddraw
);
6704 DestroyWindow(window
);
6708 hr
= IDirectDrawSurface7_GetAttachedSurface(surface1
, &caps
, &surface2
);
6709 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6710 hr
= IDirectDrawSurface7_GetAttachedSurface(surface2
, &caps
, &surface3
);
6711 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
6712 hr
= IDirectDrawSurface7_GetAttachedSurface(surface3
, &caps
, &surface4
);
6713 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
6716 IDirectDrawSurface7_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
6717 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6719 IDirectDrawSurface7_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
6720 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
6722 IDirectDrawSurface7_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
6723 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
6725 memset(&surface_desc
, 0, sizeof(surface_desc
));
6726 surface_desc
.dwSize
= sizeof(surface_desc
);
6727 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6728 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6729 surface_desc
.dwWidth
= 16;
6730 surface_desc
.dwHeight
= 16;
6731 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6732 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6734 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6735 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6736 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6737 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6738 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
6739 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6740 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
6741 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6742 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
6743 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6744 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
6745 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6747 IDirectDrawSurface7_Release(surface4
);
6749 memset(&surface_desc
, 0, sizeof(surface_desc
));
6750 surface_desc
.dwSize
= sizeof(surface_desc
);
6751 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6752 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
6753 surface_desc
.dwWidth
= 16;
6754 surface_desc
.dwHeight
= 16;
6755 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6756 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6758 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6759 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6760 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6761 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6762 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface4
);
6763 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6764 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface3
);
6765 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6766 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface4
);
6767 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6768 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface2
);
6769 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6771 IDirectDrawSurface7_Release(surface4
);
6772 IDirectDrawSurface7_Release(surface3
);
6773 IDirectDrawSurface7_Release(surface2
);
6774 IDirectDrawSurface7_Release(surface1
);
6776 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6777 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6779 /* Try a single primary and two offscreen plain surfaces. */
6780 memset(&surface_desc
, 0, sizeof(surface_desc
));
6781 surface_desc
.dwSize
= sizeof(surface_desc
);
6782 surface_desc
.dwFlags
= DDSD_CAPS
;
6783 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6784 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6785 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6787 memset(&surface_desc
, 0, sizeof(surface_desc
));
6788 surface_desc
.dwSize
= sizeof(surface_desc
);
6789 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6790 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6791 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6792 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6793 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6794 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6796 memset(&surface_desc
, 0, sizeof(surface_desc
));
6797 surface_desc
.dwSize
= sizeof(surface_desc
);
6798 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6799 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6800 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
6801 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
6802 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6803 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6805 /* This one has a different size. */
6806 memset(&surface_desc
, 0, sizeof(surface_desc
));
6807 surface_desc
.dwSize
= sizeof(surface_desc
);
6808 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6809 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6810 surface_desc
.dwWidth
= 128;
6811 surface_desc
.dwHeight
= 128;
6812 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
6813 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6815 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6816 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6817 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface1
);
6818 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6819 hr
= IDirectDrawSurface7_AddAttachedSurface(surface2
, surface3
);
6820 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6821 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface4
);
6822 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6823 hr
= IDirectDrawSurface7_AddAttachedSurface(surface4
, surface1
);
6824 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6826 IDirectDrawSurface7_Release(surface4
);
6827 IDirectDrawSurface7_Release(surface3
);
6828 IDirectDrawSurface7_Release(surface2
);
6829 IDirectDrawSurface7_Release(surface1
);
6831 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
6832 memset(&surface_desc
, 0, sizeof(surface_desc
));
6833 surface_desc
.dwSize
= sizeof(surface_desc
);
6834 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6835 surface_desc
.dwWidth
= 64;
6836 surface_desc
.dwHeight
= 64;
6837 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
6838 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
6839 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
6840 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 16;
6841 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0xf800;
6842 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6843 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x001f;
6844 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
6845 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6846 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
6847 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6849 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
6850 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
6851 U1(U4(surface_desc
).ddpfPixelFormat
).dwZBufferBitDepth
= 16;
6852 U3(U4(surface_desc
).ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
6853 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
6854 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6856 hr
= IDirectDrawSurface7_QueryInterface(surface1
, &IID_IDirectDrawSurface
, (void **)&surface1v1
);
6857 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
6858 hr
= IDirectDrawSurface7_QueryInterface(surface2
, &IID_IDirectDrawSurface
, (void **)&surface2v1
);
6859 ok(SUCCEEDED(hr
), "Failed to get interface, hr %#x.\n", hr
);
6861 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6862 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6863 refcount
= get_refcount((IUnknown
*)surface2
);
6864 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6865 refcount
= get_refcount((IUnknown
*)surface2v1
);
6866 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6867 hr
= IDirectDrawSurface7_AddAttachedSurface(surface1
, surface2
);
6868 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
6869 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6870 todo_wine
ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
6871 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
6872 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
6874 /* Attaching while already attached to other surface. */
6875 hr
= IDirectDrawSurface7_AddAttachedSurface(surface3
, surface2
);
6876 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6877 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface3
, 0, surface2
);
6878 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6879 IDirectDrawSurface7_Release(surface3
);
6881 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
6882 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6883 refcount
= get_refcount((IUnknown
*)surface2
);
6884 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6885 refcount
= get_refcount((IUnknown
*)surface2v1
);
6886 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
6888 /* DeleteAttachedSurface() when attaching via IDirectDrawSurface. */
6889 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6890 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6891 hr
= IDirectDrawSurface7_DeleteAttachedSurface(surface1
, 0, surface2
);
6892 ok(hr
== DDERR_SURFACENOTATTACHED
, "Got unexpected hr %#x.\n", hr
);
6893 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1v1
, 0, surface2v1
);
6894 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
6895 refcount
= IDirectDrawSurface7_Release(surface2
);
6896 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6897 refcount
= IDirectDrawSurface7_Release(surface1
);
6898 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6900 /* Automatic detachment on release. */
6901 hr
= IDirectDrawSurface_AddAttachedSurface(surface1v1
, surface2v1
);
6902 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
6903 refcount
= get_refcount((IUnknown
*)surface2v1
);
6904 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
6905 refcount
= IDirectDrawSurface_Release(surface1v1
);
6906 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6907 refcount
= IDirectDrawSurface_Release(surface2v1
);
6908 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6909 refcount
= IDirectDraw7_Release(ddraw
);
6910 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6911 DestroyWindow(window
);
6914 static void test_private_data(void)
6916 IDirectDraw7
*ddraw
;
6917 IDirectDrawSurface7
*surface
, *surface2
;
6918 DDSURFACEDESC2 surface_desc
;
6919 ULONG refcount
, refcount2
, refcount3
;
6921 DWORD size
= sizeof(ptr
);
6924 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
6925 DWORD data
[] = {1, 2, 3, 4};
6927 static const GUID ddraw_private_data_test_guid
=
6932 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
6934 static const GUID ddraw_private_data_test_guid2
=
6939 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
6942 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6943 0, 0, 640, 480, 0, 0, 0, 0);
6944 ddraw
= create_ddraw();
6945 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6946 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6947 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6949 reset_ddsd(&surface_desc
);
6950 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
6951 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_OFFSCREENPLAIN
;
6952 surface_desc
.dwHeight
= 4;
6953 surface_desc
.dwWidth
= 4;
6954 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6955 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6957 /* NULL pointers are not valid, but don't cause a crash. */
6958 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
,
6959 sizeof(IUnknown
*), DDSPD_IUNKNOWNPOINTER
);
6960 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6961 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 0, 0);
6962 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6963 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, 1, 0);
6964 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6966 /* DDSPD_IUNKNOWNPOINTER needs sizeof(IUnknown *) bytes of data. */
6967 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6968 0, DDSPD_IUNKNOWNPOINTER
);
6969 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6970 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6971 5, DDSPD_IUNKNOWNPOINTER
);
6972 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6973 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6974 sizeof(ddraw
) * 2, DDSPD_IUNKNOWNPOINTER
);
6975 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6977 /* Note that with a size != 0 and size != sizeof(IUnknown *) and
6978 * DDSPD_IUNKNOWNPOINTER set SetPrivateData in ddraw4 and ddraw7
6979 * erases the old content and returns an error. This behavior has
6980 * been fixed in d3d8 and d3d9. Unless an application is found
6981 * that depends on this we don't care about this behavior. */
6982 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6983 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6984 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6985 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6986 0, DDSPD_IUNKNOWNPOINTER
);
6987 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
6989 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
6990 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
6991 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
6992 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
6994 refcount
= get_refcount((IUnknown
*)ddraw
);
6995 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
6996 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
6997 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
6998 refcount2
= get_refcount((IUnknown
*)ddraw
);
6999 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7001 hr
= IDirectDrawSurface7_FreePrivateData(surface
, &ddraw_private_data_test_guid
);
7002 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
7003 refcount2
= get_refcount((IUnknown
*)ddraw
);
7004 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7006 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7007 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7008 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7009 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, surface
,
7010 sizeof(surface
), DDSPD_IUNKNOWNPOINTER
);
7011 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7012 refcount2
= get_refcount((IUnknown
*)ddraw
);
7013 ok(refcount2
== refcount
, "Got unexpected refcount %u.\n", refcount2
);
7015 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, ddraw
,
7016 sizeof(ddraw
), DDSPD_IUNKNOWNPOINTER
);
7017 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7018 size
= 2 * sizeof(ptr
);
7019 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7020 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
7021 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7022 refcount2
= get_refcount(ptr
);
7023 /* Object is NOT addref'ed by the getter. */
7024 ok(ptr
== (IUnknown
*)ddraw
, "Returned interface pointer is %p, expected %p.\n", ptr
, ddraw
);
7025 ok(refcount2
== refcount
+ 1, "Got unexpected refcount %u.\n", refcount2
);
7027 ptr
= (IUnknown
*)0xdeadbeef;
7029 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7030 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7031 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7032 size
= 2 * sizeof(ptr
);
7033 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, &size
);
7034 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7035 ok(size
== 2 * sizeof(ptr
), "Got unexpected size %u.\n", size
);
7037 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, &ptr
, &size
);
7038 ok(hr
== DDERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
7039 ok(size
== sizeof(ddraw
), "Got unexpected size %u.\n", size
);
7040 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7041 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, NULL
, NULL
);
7042 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7044 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid2
, &ptr
, &size
);
7045 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7046 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
7047 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
7048 hr
= IDirectDrawSurface7_GetPrivateData(surface
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7049 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7051 refcount3
= IDirectDrawSurface7_Release(surface
);
7052 ok(!refcount3
, "Got unexpected refcount %u.\n", refcount3
);
7054 /* Destroying the surface frees the reference held on the private data. It also frees
7055 * the reference the surface is holding on its creating object. */
7056 refcount2
= get_refcount((IUnknown
*)ddraw
);
7057 ok(refcount2
== refcount
- 1, "Got unexpected refcount %u.\n", refcount2
);
7059 memset(&hal_caps
, 0, sizeof(hal_caps
));
7060 hal_caps
.dwSize
= sizeof(hal_caps
);
7061 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7062 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7063 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) == (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7066 reset_ddsd(&surface_desc
);
7067 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_MIPMAPCOUNT
;
7068 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7069 surface_desc
.dwHeight
= 4;
7070 surface_desc
.dwWidth
= 4;
7071 U2(surface_desc
).dwMipMapCount
= 2;
7072 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7073 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7074 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
7075 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7077 hr
= IDirectDrawSurface7_SetPrivateData(surface
, &ddraw_private_data_test_guid
, data
, sizeof(data
), 0);
7078 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
7079 hr
= IDirectDrawSurface7_GetPrivateData(surface2
, &ddraw_private_data_test_guid
, NULL
, NULL
);
7080 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7082 IDirectDrawSurface7_Release(surface2
);
7083 IDirectDrawSurface7_Release(surface
);
7086 skip("Mipmapped textures not supported, skipping mipmap private data test.\n");
7088 refcount
= IDirectDraw7_Release(ddraw
);
7089 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7090 DestroyWindow(window
);
7093 static void test_pixel_format(void)
7095 HWND window
, window2
= NULL
;
7096 HDC hdc
, hdc2
= NULL
;
7098 int format
, test_format
;
7099 PIXELFORMATDESCRIPTOR pfd
;
7100 IDirectDraw7
*ddraw
= NULL
;
7101 IDirectDrawClipper
*clipper
= NULL
;
7102 DDSURFACEDESC2 ddsd
;
7103 IDirectDrawSurface7
*primary
= NULL
;
7107 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7108 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7111 skip("Failed to create window\n");
7115 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
7116 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
7118 hdc
= GetDC(window
);
7121 skip("Failed to get DC\n");
7126 hdc2
= GetDC(window2
);
7128 gl
= LoadLibraryA("opengl32.dll");
7129 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7131 format
= GetPixelFormat(hdc
);
7132 ok(format
== 0, "new window has pixel format %d\n", format
);
7134 ZeroMemory(&pfd
, sizeof(pfd
));
7135 pfd
.nSize
= sizeof(pfd
);
7137 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7138 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7139 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7140 format
= ChoosePixelFormat(hdc
, &pfd
);
7143 skip("no pixel format available\n");
7147 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7149 skip("failed to set pixel format\n");
7153 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7155 skip("failed to set pixel format on second window\n");
7158 ReleaseDC(window2
, hdc2
);
7163 ddraw
= create_ddraw();
7164 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7166 test_format
= GetPixelFormat(hdc
);
7167 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7169 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7172 skip("Failed to set cooperative level, hr %#x.\n", hr
);
7176 test_format
= GetPixelFormat(hdc
);
7177 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7181 hr
= IDirectDraw7_CreateClipper(ddraw
, 0, &clipper
, NULL
);
7182 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
7183 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
7184 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
7186 test_format
= GetPixelFormat(hdc
);
7187 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7189 test_format
= GetPixelFormat(hdc2
);
7190 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7193 memset(&ddsd
, 0, sizeof(ddsd
));
7194 ddsd
.dwSize
= sizeof(ddsd
);
7195 ddsd
.dwFlags
= DDSD_CAPS
;
7196 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7198 hr
= IDirectDraw7_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
7199 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
7201 test_format
= GetPixelFormat(hdc
);
7202 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7206 test_format
= GetPixelFormat(hdc2
);
7207 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7212 hr
= IDirectDrawSurface7_SetClipper(primary
, clipper
);
7213 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
7215 test_format
= GetPixelFormat(hdc
);
7216 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7218 test_format
= GetPixelFormat(hdc2
);
7219 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7222 memset(&fx
, 0, sizeof(fx
));
7223 fx
.dwSize
= sizeof(fx
);
7224 hr
= IDirectDrawSurface7_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7225 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
7227 test_format
= GetPixelFormat(hdc
);
7228 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7232 test_format
= GetPixelFormat(hdc2
);
7233 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7237 if (primary
) IDirectDrawSurface7_Release(primary
);
7238 if (clipper
) IDirectDrawClipper_Release(clipper
);
7239 if (ddraw
) IDirectDraw7_Release(ddraw
);
7240 if (gl
) FreeLibrary(gl
);
7241 if (hdc
) ReleaseDC(window
, hdc
);
7242 if (hdc2
) ReleaseDC(window2
, hdc2
);
7243 if (window
) DestroyWindow(window
);
7244 if (window2
) DestroyWindow(window2
);
7247 static void test_create_surface_pitch(void)
7249 IDirectDrawSurface7
*surface
;
7250 DDSURFACEDESC2 surface_desc
;
7251 IDirectDraw7
*ddraw
;
7270 {DDSCAPS_VIDEOMEMORY
, 0, 0, DD_OK
,
7271 DDSD_PITCH
, 0x100, 0x100},
7272 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
7273 DDSD_PITCH
, 0x100, 0x100},
7274 {DDSCAPS_VIDEOMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
7275 DDSD_PITCH
, 0x100, 0x100},
7276 {DDSCAPS_VIDEOMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
7278 {DDSCAPS_SYSTEMMEMORY
, 0, 0, DD_OK
,
7279 DDSD_PITCH
, 0x100, 0x0fc},
7280 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x104, DD_OK
,
7281 DDSD_PITCH
, 0x100, 0x0fc},
7282 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
, 0x0f8, DD_OK
,
7283 DDSD_PITCH
, 0x100, 0x0fc},
7284 {DDSCAPS_SYSTEMMEMORY
, DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
7285 DDSD_PITCH
, 0x100, 0x0fc},
7286 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
7288 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DD_OK
,
7289 DDSD_PITCH
, 0x100, 0x100},
7290 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fe, DDERR_INVALIDPARAMS
,
7292 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0fc, DD_OK
,
7293 DDSD_PITCH
, 0x0fc, 0x0fc},
7294 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
, 0x0f8, DDERR_INVALIDPARAMS
,
7296 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x100, DDERR_INVALIDPARAMS
,
7298 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_LINEARSIZE
, 0x3f00, DDERR_INVALIDPARAMS
,
7300 {DDSCAPS_SYSTEMMEMORY
, DDSD_LPSURFACE
| DDSD_PITCH
| DDSD_LINEARSIZE
, 0x100, DD_OK
,
7301 DDSD_PITCH
, 0x100, 0x100},
7303 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
7305 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7306 0, 0, 640, 480, 0, 0, 0, 0);
7307 ddraw
= create_ddraw();
7308 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7309 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7310 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7312 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
7314 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
7316 memset(&surface_desc
, 0, sizeof(surface_desc
));
7317 surface_desc
.dwSize
= sizeof(surface_desc
);
7318 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
7319 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| test_data
[i
].placement
;
7320 surface_desc
.dwWidth
= 63;
7321 surface_desc
.dwHeight
= 63;
7322 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
7323 surface_desc
.lpSurface
= mem
;
7324 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7325 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7326 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7327 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7328 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7329 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7330 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7331 ok(hr
== test_data
[i
].hr
|| (test_data
[i
].placement
== DDSCAPS_VIDEOMEMORY
&& hr
== DDERR_NODIRECTDRAWHW
),
7332 "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
7336 memset(&surface_desc
, 0, sizeof(surface_desc
));
7337 surface_desc
.dwSize
= sizeof(surface_desc
);
7338 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
7339 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
7340 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
7341 "Test %u: Got unexpected flags %#x, expected %#x.\n",
7342 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
7343 if (sizeof(void *) != sizeof(DWORD
) && test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
7344 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
7345 "Test %u: Got unexpected pitch %u, expected %u.\n",
7346 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
7348 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
7349 "Test %u: Got unexpected pitch %u, expected %u.\n",
7350 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
7351 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
7353 IDirectDrawSurface7_Release(surface
);
7356 HeapFree(GetProcessHeap(), 0, mem
);
7357 refcount
= IDirectDraw7_Release(ddraw
);
7358 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7359 DestroyWindow(window
);
7362 static void test_mipmap_lock(void)
7364 IDirectDrawSurface7
*surface
, *surface2
;
7365 DDSURFACEDESC2 surface_desc
;
7366 IDirectDraw7
*ddraw
;
7370 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7373 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7374 0, 0, 640, 480, 0, 0, 0, 0);
7375 ddraw
= create_ddraw();
7376 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7377 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7378 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7380 memset(&hal_caps
, 0, sizeof(hal_caps
));
7381 hal_caps
.dwSize
= sizeof(hal_caps
);
7382 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7383 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7384 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7387 skip("Mipmapped textures not supported, skipping mipmap lock test.\n");
7388 IDirectDraw7_Release(ddraw
);
7389 DestroyWindow(window
);
7393 memset(&surface_desc
, 0, sizeof(surface_desc
));
7394 surface_desc
.dwSize
= sizeof(surface_desc
);
7395 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
7396 surface_desc
.dwWidth
= 4;
7397 surface_desc
.dwHeight
= 4;
7398 U2(surface_desc
).dwMipMapCount
= 2;
7399 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
7400 | DDSCAPS_SYSTEMMEMORY
;
7401 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7402 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7403 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &surface2
);
7404 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7406 memset(&surface_desc
, 0, sizeof(surface_desc
));
7407 surface_desc
.dwSize
= sizeof(surface_desc
);
7408 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
7409 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7410 memset(&surface_desc
, 0, sizeof(surface_desc
));
7411 surface_desc
.dwSize
= sizeof(surface_desc
);
7412 hr
= IDirectDrawSurface7_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
7413 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7414 IDirectDrawSurface7_Unlock(surface2
, NULL
);
7415 IDirectDrawSurface7_Unlock(surface
, NULL
);
7417 IDirectDrawSurface7_Release(surface2
);
7418 IDirectDrawSurface7_Release(surface
);
7419 refcount
= IDirectDraw7_Release(ddraw
);
7420 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7421 DestroyWindow(window
);
7424 static void test_palette_complex(void)
7426 IDirectDrawSurface7
*surface
, *mipmap
, *tmp
;
7427 DDSURFACEDESC2 surface_desc
;
7428 IDirectDraw7
*ddraw
;
7429 IDirectDrawPalette
*palette
, *palette2
;
7433 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
7435 PALETTEENTRY palette_entries
[256];
7438 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7439 0, 0, 640, 480, 0, 0, 0, 0);
7440 ddraw
= create_ddraw();
7441 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7442 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7443 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7445 memset(&hal_caps
, 0, sizeof(hal_caps
));
7446 hal_caps
.dwSize
= sizeof(hal_caps
);
7447 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
7448 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7449 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)
7452 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
7453 IDirectDraw7_Release(ddraw
);
7454 DestroyWindow(window
);
7458 memset(&surface_desc
, 0, sizeof(surface_desc
));
7459 surface_desc
.dwSize
= sizeof(surface_desc
);
7460 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7461 surface_desc
.dwWidth
= 128;
7462 surface_desc
.dwHeight
= 128;
7463 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7464 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7465 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7466 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7467 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7468 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7470 memset(palette_entries
, 0, sizeof(palette_entries
));
7471 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7472 palette_entries
, &palette
, NULL
);
7473 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7475 palette2
= (void *)0xdeadbeef;
7476 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
7477 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
7478 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
7479 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7480 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7481 hr
= IDirectDrawSurface7_GetPalette(surface
, &palette2
);
7482 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
7483 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
7484 IDirectDrawPalette_Release(palette2
);
7487 IDirectDrawSurface7_AddRef(mipmap
);
7488 for (i
= 0; i
< 7; ++i
)
7490 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7491 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
7492 palette2
= (void *)0xdeadbeef;
7493 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
7494 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7495 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7497 hr
= IDirectDrawSurface7_SetPalette(tmp
, palette
);
7498 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7500 hr
= IDirectDrawSurface7_GetPalette(tmp
, &palette2
);
7501 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
7502 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
7504 /* Ddraw7 uses the palette of the mipmap for GetDC, just like previous
7505 * ddraw versions. Combined with the test results above this means no
7506 * palette is available. So depending on the driver either GetDC fails
7507 * or the DIB color table contains random data. */
7509 IDirectDrawSurface7_Release(mipmap
);
7513 hr
= IDirectDrawSurface7_GetAttachedSurface(mipmap
, &caps
, &tmp
);
7514 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
7515 IDirectDrawSurface7_Release(mipmap
);
7516 refcount
= IDirectDrawSurface7_Release(surface
);
7517 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7519 /* Test DDERR_INVALIDPIXELFORMAT vs DDERR_NOTONMIPMAPSUBLEVEL. */
7520 memset(&surface_desc
, 0, sizeof(surface_desc
));
7521 surface_desc
.dwSize
= sizeof(surface_desc
);
7522 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7523 surface_desc
.dwWidth
= 128;
7524 surface_desc
.dwHeight
= 128;
7525 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
7526 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7527 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7528 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7529 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7530 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7531 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7532 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7533 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7535 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
7536 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
7537 hr
= IDirectDrawSurface7_SetPalette(mipmap
, palette
);
7538 ok(hr
== DDERR_NOTONMIPMAPSUBLEVEL
, "Got unexpected hr %#x.\n", hr
);
7540 IDirectDrawSurface7_Release(mipmap
);
7541 refcount
= IDirectDrawSurface7_Release(surface
);
7542 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7543 refcount
= IDirectDrawPalette_Release(palette
);
7544 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7546 refcount
= IDirectDraw7_Release(ddraw
);
7547 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7548 DestroyWindow(window
);
7551 static void test_p8_rgb_blit(void)
7553 IDirectDrawSurface7
*src
, *dst
;
7554 DDSURFACEDESC2 surface_desc
;
7555 IDirectDraw7
*ddraw
;
7556 IDirectDrawPalette
*palette
;
7560 PALETTEENTRY palette_entries
[256];
7562 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
7563 static const D3DCOLOR expected
[] =
7565 0x00101010, 0x00010101, 0x00020202, 0x00030303,
7566 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
7570 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7571 0, 0, 640, 480, 0, 0, 0, 0);
7572 ddraw
= create_ddraw();
7573 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7574 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7575 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7577 memset(palette_entries
, 0, sizeof(palette_entries
));
7578 palette_entries
[1].peGreen
= 0xff;
7579 palette_entries
[2].peBlue
= 0xff;
7580 palette_entries
[3].peFlags
= 0xff;
7581 palette_entries
[4].peRed
= 0xff;
7582 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7583 palette_entries
, &palette
, NULL
);
7584 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7586 memset(&surface_desc
, 0, sizeof(surface_desc
));
7587 surface_desc
.dwSize
= sizeof(surface_desc
);
7588 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7589 surface_desc
.dwWidth
= 8;
7590 surface_desc
.dwHeight
= 1;
7591 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7592 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7593 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7594 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7595 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7596 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7598 memset(&surface_desc
, 0, sizeof(surface_desc
));
7599 surface_desc
.dwSize
= sizeof(surface_desc
);
7600 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7601 surface_desc
.dwWidth
= 8;
7602 surface_desc
.dwHeight
= 1;
7603 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7604 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7605 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
7606 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
7607 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7608 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7609 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7610 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
7611 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7612 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7614 memset(&surface_desc
, 0, sizeof(surface_desc
));
7615 surface_desc
.dwSize
= sizeof(surface_desc
);
7616 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &surface_desc
, 0, NULL
);
7617 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
7618 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
7619 hr
= IDirectDrawSurface7_Unlock(src
, NULL
);
7620 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
7622 hr
= IDirectDrawSurface7_SetPalette(src
, palette
);
7623 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7624 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7625 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
7626 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
7627 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
7628 "Failed to blit, hr %#x.\n", hr
);
7632 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
7634 color
= get_surface_color(dst
, x
, 0);
7635 todo_wine
ok(compare_color(color
, expected
[x
], 0),
7636 "Pixel %u: Got color %#x, expected %#x.\n",
7637 x
, color
, expected
[x
]);
7641 IDirectDrawSurface7_Release(src
);
7642 IDirectDrawSurface7_Release(dst
);
7643 IDirectDrawPalette_Release(palette
);
7645 refcount
= IDirectDraw7_Release(ddraw
);
7646 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7647 DestroyWindow(window
);
7650 static void test_material(void)
7652 static const D3DCOLORVALUE null_color
;
7653 IDirect3DDevice7
*device
;
7654 D3DMATERIAL7 material
;
7659 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7660 0, 0, 640, 480, 0, 0, 0, 0);
7661 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
7663 skip("Failed to create a 3D device, skipping test.\n");
7664 DestroyWindow(window
);
7668 hr
= IDirect3DDevice7_GetMaterial(device
, &material
);
7669 ok(SUCCEEDED(hr
), "Failed to get material, hr %#x.\n", hr
);
7670 ok(!memcmp(&U(material
).diffuse
, &null_color
, sizeof(null_color
)),
7671 "Got unexpected diffuse color {%.8e, %.8e, %.8e, %.8e}.\n",
7672 U1(U(material
).diffuse
).r
, U2(U(material
).diffuse
).g
,
7673 U3(U(material
).diffuse
).b
, U4(U(material
).diffuse
).a
);
7674 ok(!memcmp(&U1(material
).ambient
, &null_color
, sizeof(null_color
)),
7675 "Got unexpected ambient color {%.8e, %.8e, %.8e, %.8e}.\n",
7676 U1(U1(material
).ambient
).r
, U2(U1(material
).ambient
).g
,
7677 U3(U1(material
).ambient
).b
, U4(U1(material
).ambient
).a
);
7678 ok(!memcmp(&U2(material
).specular
, &null_color
, sizeof(null_color
)),
7679 "Got unexpected specular color {%.8e, %.8e, %.8e, %.8e}.\n",
7680 U1(U2(material
).specular
).r
, U2(U2(material
).specular
).g
,
7681 U3(U2(material
).specular
).b
, U4(U2(material
).specular
).a
);
7682 ok(!memcmp(&U3(material
).emissive
, &null_color
, sizeof(null_color
)),
7683 "Got unexpected emissive color {%.8e, %.8e, %.8e, %.8e}.\n",
7684 U1(U3(material
).emissive
).r
, U2(U3(material
).emissive
).g
,
7685 U3(U3(material
).emissive
).b
, U4(U3(material
).emissive
).a
);
7686 ok(U4(material
).power
== 0.0f
, "Got unexpected power %.8e.\n", U4(material
).power
);
7688 refcount
= IDirect3DDevice7_Release(device
);
7689 ok(!refcount
, "Device has %u references left.\n", refcount
);
7690 DestroyWindow(window
);
7693 static void test_palette_gdi(void)
7695 IDirectDrawSurface7
*surface
, *primary
;
7696 DDSURFACEDESC2 surface_desc
;
7697 IDirectDraw7
*ddraw
;
7698 IDirectDrawPalette
*palette
, *palette2
;
7702 PALETTEENTRY palette_entries
[256];
7705 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
7706 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
7707 * not the point of this test. */
7708 static const RGBQUAD expected1
[] =
7710 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7711 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
7713 static const RGBQUAD expected2
[] =
7715 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
7716 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
7718 static const RGBQUAD expected3
[] =
7720 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
7721 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
7723 HPALETTE ddraw_palette_handle
;
7724 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
7725 RGBQUAD rgbquad
[255];
7726 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
7728 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7729 0, 0, 640, 480, 0, 0, 0, 0);
7730 ddraw
= create_ddraw();
7731 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7732 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7733 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7735 memset(&surface_desc
, 0, sizeof(surface_desc
));
7736 surface_desc
.dwSize
= sizeof(surface_desc
);
7737 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7738 surface_desc
.dwWidth
= 16;
7739 surface_desc
.dwHeight
= 16;
7740 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7741 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
7742 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
7743 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 8;
7744 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7745 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7747 /* Avoid colors from the Windows default palette. */
7748 memset(palette_entries
, 0, sizeof(palette_entries
));
7749 palette_entries
[1].peRed
= 0x01;
7750 palette_entries
[2].peGreen
= 0x02;
7751 palette_entries
[3].peBlue
= 0x03;
7752 palette_entries
[4].peRed
= 0x13;
7753 palette_entries
[4].peGreen
= 0x14;
7754 palette_entries
[4].peBlue
= 0x15;
7755 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7756 palette_entries
, &palette
, NULL
);
7757 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7759 /* If there is no palette assigned and the display mode is not 8 bpp, some
7760 * drivers refuse to create a DC while others allow it. If a DC is created,
7761 * the DIB color table is uninitialized and contains random colors. No error
7762 * is generated when trying to read pixels and random garbage is returned.
7764 * The most likely explanation is that if the driver creates a DC, it (or
7765 * the higher-level runtime) uses GetSystemPaletteEntries to find the
7766 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
7767 * contains uninitialized garbage. See comments below for the P8 case. */
7769 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7770 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7771 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7772 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7773 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7774 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
7775 "Got unexpected palette %p, expected %p.\n",
7776 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7778 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7779 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7780 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
7782 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
7783 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7784 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7785 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
7787 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7789 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7790 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7791 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7794 /* Update the palette while the DC is in use. This does not modify the DC. */
7795 palette_entries
[4].peRed
= 0x23;
7796 palette_entries
[4].peGreen
= 0x24;
7797 palette_entries
[4].peBlue
= 0x25;
7798 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
7799 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
7801 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7802 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7803 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7804 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7805 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7806 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7808 /* Neither does re-setting the palette. */
7809 hr
= IDirectDrawSurface7_SetPalette(surface
, NULL
);
7810 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7811 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
7812 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7814 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
7815 ok(i
== 1, "Expected count 1, got %u.\n", i
);
7816 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
7817 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7818 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
7819 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
7821 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
7822 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7824 /* Refresh the DC. This updates the palette. */
7825 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7826 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7827 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7828 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7829 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7831 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7832 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7833 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7834 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7836 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7838 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7839 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7840 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7842 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
7843 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7845 refcount
= IDirectDrawSurface7_Release(surface
);
7846 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7848 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
7850 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
7851 IDirectDrawPalette_Release(palette
);
7852 IDirectDraw7_Release(ddraw
);
7853 DestroyWindow(window
);
7856 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
7857 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
7858 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7860 memset(&surface_desc
, 0, sizeof(surface_desc
));
7861 surface_desc
.dwSize
= sizeof(surface_desc
);
7862 surface_desc
.dwFlags
= DDSD_CAPS
;
7863 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
7864 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
7865 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7867 hr
= IDirectDrawSurface7_SetPalette(primary
, palette
);
7868 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7869 hr
= IDirectDrawSurface7_GetDC(primary
, &dc
);
7870 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7871 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
7872 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
7873 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
7874 "Got unexpected palette %p, expected %p.\n",
7875 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
7876 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
7878 /* The primary uses the system palette. In exclusive mode, the system palette matches
7879 * the ddraw palette attached to the primary, so the result is what you would expect
7880 * from a regular surface. Tests for the interaction between the ddraw palette and
7881 * the system palette are not included pending an application that depends on this.
7882 * The relation between those causes problems on Windows Vista and newer for games
7883 * like Age of Empires or StarcCaft. Don't emulate it without a real need. */
7884 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7885 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7886 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7888 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7889 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7890 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7891 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7893 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7895 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7896 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7897 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7899 hr
= IDirectDrawSurface7_ReleaseDC(primary
, dc
);
7900 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7902 memset(&surface_desc
, 0, sizeof(surface_desc
));
7903 surface_desc
.dwSize
= sizeof(surface_desc
);
7904 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
7905 surface_desc
.dwWidth
= 16;
7906 surface_desc
.dwHeight
= 16;
7907 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7908 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7909 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7911 /* Here the offscreen surface appears to use the primary's palette,
7912 * but in all likelihood it is actually the system palette. */
7913 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7914 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7915 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7916 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7917 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
7919 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
7920 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7921 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7922 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
7924 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7926 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7927 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7928 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7930 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
7931 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7933 /* On real hardware a change to the primary surface's palette applies immediately,
7934 * even on device contexts from offscreen surfaces that do not have their own
7935 * palette. On the testbot VMs this is not the case. Don't test this until we
7936 * know of an application that depends on this. */
7938 memset(palette_entries
, 0, sizeof(palette_entries
));
7939 palette_entries
[1].peBlue
= 0x40;
7940 palette_entries
[2].peRed
= 0x40;
7941 palette_entries
[3].peGreen
= 0x40;
7942 palette_entries
[4].peRed
= 0x12;
7943 palette_entries
[4].peGreen
= 0x34;
7944 palette_entries
[4].peBlue
= 0x56;
7945 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
7946 palette_entries
, &palette2
, NULL
);
7947 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
7948 hr
= IDirectDrawSurface7_SetPalette(surface
, palette2
);
7949 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
7951 /* A palette assigned to the offscreen surface overrides the primary / system
7953 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
7954 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
7955 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
7956 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
7957 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
7959 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
7960 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
7961 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
7962 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
7964 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
7966 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
7967 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
7968 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
7970 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
7971 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
7973 refcount
= IDirectDrawSurface7_Release(surface
);
7974 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7976 /* The Windows 8 testbot keeps extra references to the primary and
7977 * backbuffer while in 8 bpp mode. */
7978 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
7979 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
7981 refcount
= IDirectDrawSurface7_Release(primary
);
7982 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7983 refcount
= IDirectDrawPalette_Release(palette2
);
7984 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7985 refcount
= IDirectDrawPalette_Release(palette
);
7986 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7987 refcount
= IDirectDraw7_Release(ddraw
);
7988 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
7989 DestroyWindow(window
);
7992 static void test_palette_alpha(void)
7994 IDirectDrawSurface7
*surface
;
7995 DDSURFACEDESC2 surface_desc
;
7996 IDirectDraw7
*ddraw
;
7997 IDirectDrawPalette
*palette
;
8001 PALETTEENTRY palette_entries
[256];
8006 BOOL attach_allowed
;
8011 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
8012 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
8013 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
8016 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8017 0, 0, 640, 480, 0, 0, 0, 0);
8018 ddraw
= create_ddraw();
8019 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8020 if (FAILED(IDirectDraw7_SetDisplayMode(ddraw
, 640, 480, 8, 0, 0)))
8022 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
8023 IDirectDraw7_Release(ddraw
);
8024 DestroyWindow(window
);
8027 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8028 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8030 memset(palette_entries
, 0, sizeof(palette_entries
));
8031 palette_entries
[1].peFlags
= 0x42;
8032 palette_entries
[2].peFlags
= 0xff;
8033 palette_entries
[3].peFlags
= 0x80;
8034 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
8035 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8037 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8038 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8039 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8040 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8041 palette_entries
[0].peFlags
);
8042 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8043 palette_entries
[1].peFlags
);
8044 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8045 palette_entries
[2].peFlags
);
8046 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8047 palette_entries
[3].peFlags
);
8049 IDirectDrawPalette_Release(palette
);
8051 memset(palette_entries
, 0, sizeof(palette_entries
));
8052 palette_entries
[1].peFlags
= 0x42;
8053 palette_entries
[1].peRed
= 0xff;
8054 palette_entries
[2].peFlags
= 0xff;
8055 palette_entries
[3].peFlags
= 0x80;
8056 hr
= IDirectDraw7_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
8057 palette_entries
, &palette
, NULL
);
8058 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
8060 memset(palette_entries
, 0x66, sizeof(palette_entries
));
8061 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
8062 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
8063 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8064 palette_entries
[0].peFlags
);
8065 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
8066 palette_entries
[1].peFlags
);
8067 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
8068 palette_entries
[2].peFlags
);
8069 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
8070 palette_entries
[3].peFlags
);
8072 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8074 memset(&surface_desc
, 0, sizeof(surface_desc
));
8075 surface_desc
.dwSize
= sizeof(surface_desc
);
8076 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
8077 surface_desc
.dwWidth
= 128;
8078 surface_desc
.dwHeight
= 128;
8079 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8080 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8081 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8083 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8084 if (test_data
[i
].attach_allowed
)
8085 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
8087 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8095 hr
= IDirectDrawSurface7_GetDC(surface
, &dc
);
8096 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
8097 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
8098 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
8099 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
8100 rgbquad
.rgbRed
, test_data
[i
].name
);
8101 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
8102 rgbquad
.rgbGreen
, test_data
[i
].name
);
8103 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
8104 rgbquad
.rgbBlue
, test_data
[i
].name
);
8105 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
8106 rgbquad
.rgbReserved
, test_data
[i
].name
);
8107 hr
= IDirectDrawSurface7_ReleaseDC(surface
, dc
);
8108 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8110 IDirectDrawSurface7_Release(surface
);
8113 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
8114 memset(&surface_desc
, 0, sizeof(surface_desc
));
8115 surface_desc
.dwSize
= sizeof(surface_desc
);
8116 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8117 surface_desc
.dwWidth
= 128;
8118 surface_desc
.dwHeight
= 128;
8119 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8120 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
8121 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8122 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
8123 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8124 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8125 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8126 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8127 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8128 hr
= IDirectDrawSurface7_SetPalette(surface
, palette
);
8129 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
8130 IDirectDrawSurface7_Release(surface
);
8132 /* The Windows 8 testbot keeps extra references to the primary
8133 * while in 8 bpp mode. */
8134 hr
= IDirectDraw7_RestoreDisplayMode(ddraw
);
8135 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
8137 refcount
= IDirectDrawPalette_Release(palette
);
8138 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8139 refcount
= IDirectDraw7_Release(ddraw
);
8140 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8141 DestroyWindow(window
);
8144 static void test_vb_writeonly(void)
8146 IDirect3DDevice7
*device
;
8148 IDirect3DVertexBuffer7
*buffer
;
8151 D3DVERTEXBUFFERDESC desc
;
8153 static const struct vec4 quad
[] =
8155 { 0.0f
, 480.0f
, 0.0f
, 1.0f
},
8156 { 0.0f
, 0.0f
, 0.0f
, 1.0f
},
8157 {640.0f
, 480.0f
, 0.0f
, 1.0f
},
8158 {640.0f
, 0.0f
, 0.0f
, 1.0f
},
8161 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8162 0, 0, 640, 480, 0, 0, 0, 0);
8164 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8166 skip("Failed to create a 3D device, skipping test.\n");
8167 DestroyWindow(window
);
8171 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
8172 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
8174 memset(&desc
, 0, sizeof(desc
));
8175 desc
.dwSize
= sizeof(desc
);
8176 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
8177 desc
.dwFVF
= D3DFVF_XYZRHW
;
8178 desc
.dwNumVertices
= sizeof(quad
) / sizeof(*quad
);
8179 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &buffer
, 0);
8180 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
8182 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_DISCARDCONTENTS
, &ptr
, NULL
);
8183 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8184 memcpy(ptr
, quad
, sizeof(quad
));
8185 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8186 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8188 hr
= IDirect3DDevice7_BeginScene(device
);
8189 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8190 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, D3DPT_TRIANGLESTRIP
, buffer
, 0, 4, 0);
8191 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8192 hr
= IDirect3DDevice7_EndScene(device
);
8193 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8195 hr
= IDirect3DVertexBuffer7_Lock(buffer
, 0, &ptr
, NULL
);
8196 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8197 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8198 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8199 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8201 hr
= IDirect3DVertexBuffer7_Lock(buffer
, DDLOCK_READONLY
, &ptr
, NULL
);
8202 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
8203 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
8204 hr
= IDirect3DVertexBuffer7_Unlock(buffer
);
8205 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
8207 IDirect3DVertexBuffer7_Release(buffer
);
8208 IDirect3D7_Release(d3d
);
8209 IDirect3DDevice7_Release(device
);
8210 DestroyWindow(window
);
8213 static void test_lost_device(void)
8215 IDirectDrawSurface7
*surface
;
8216 DDSURFACEDESC2 surface_desc
;
8217 HWND window1
, window2
;
8218 IDirectDraw7
*ddraw
;
8223 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8224 0, 0, 640, 480, 0, 0, 0, 0);
8225 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8226 0, 0, 640, 480, 0, 0, 0, 0);
8227 ddraw
= create_ddraw();
8228 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8229 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8230 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8232 memset(&surface_desc
, 0, sizeof(surface_desc
));
8233 surface_desc
.dwSize
= sizeof(surface_desc
);
8234 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8235 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8236 U5(surface_desc
).dwBackBufferCount
= 1;
8237 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8238 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8240 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8241 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8242 hr
= IDirectDrawSurface7_IsLost(surface
);
8243 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8244 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8245 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8247 ret
= SetForegroundWindow(GetDesktopWindow());
8248 ok(ret
, "Failed to set foreground window.\n");
8249 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8250 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8251 hr
= IDirectDrawSurface7_IsLost(surface
);
8252 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8253 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8254 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8256 ret
= SetForegroundWindow(window1
);
8257 ok(ret
, "Failed to set foreground window.\n");
8258 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8259 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8260 hr
= IDirectDrawSurface7_IsLost(surface
);
8261 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8262 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8263 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8265 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
8266 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8267 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8268 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8269 hr
= IDirectDrawSurface7_IsLost(surface
);
8270 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8271 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8272 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8274 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8275 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8276 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8277 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8278 hr
= IDirectDrawSurface7_IsLost(surface
);
8279 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8280 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8281 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8283 /* Trying to restore the primary will crash, probably because flippable
8284 * surfaces can't exist in DDSCL_NORMAL. */
8285 IDirectDrawSurface7_Release(surface
);
8286 memset(&surface_desc
, 0, sizeof(surface_desc
));
8287 surface_desc
.dwSize
= sizeof(surface_desc
);
8288 surface_desc
.dwFlags
= DDSD_CAPS
;
8289 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8290 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8291 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8293 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8294 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8295 hr
= IDirectDrawSurface7_IsLost(surface
);
8296 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8298 ret
= SetForegroundWindow(GetDesktopWindow());
8299 ok(ret
, "Failed to set foreground window.\n");
8300 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8301 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8302 hr
= IDirectDrawSurface7_IsLost(surface
);
8303 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8305 ret
= SetForegroundWindow(window1
);
8306 ok(ret
, "Failed to set foreground window.\n");
8307 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8308 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8309 hr
= IDirectDrawSurface7_IsLost(surface
);
8310 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8312 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8313 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8314 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8315 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8316 hr
= IDirectDrawSurface7_IsLost(surface
);
8317 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8319 hr
= IDirectDraw7_RestoreAllSurfaces(ddraw
);
8320 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8321 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8322 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8323 hr
= IDirectDrawSurface7_IsLost(surface
);
8324 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8326 IDirectDrawSurface7_Release(surface
);
8327 memset(&surface_desc
, 0, sizeof(surface_desc
));
8328 surface_desc
.dwSize
= sizeof(surface_desc
);
8329 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
8330 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
8331 U5(surface_desc
).dwBackBufferCount
= 1;
8332 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8333 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8335 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8336 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8337 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8338 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8339 hr
= IDirectDrawSurface7_IsLost(surface
);
8340 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8341 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8342 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8344 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8345 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8346 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8347 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8348 hr
= IDirectDrawSurface7_IsLost(surface
);
8349 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8350 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8351 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8353 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
8354 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8355 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8356 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8357 hr
= IDirectDrawSurface7_IsLost(surface
);
8358 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8359 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8360 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8362 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
8363 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8364 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8365 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8366 hr
= IDirectDrawSurface7_IsLost(surface
);
8367 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8368 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8369 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8371 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
8372 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8373 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8374 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8375 hr
= IDirectDrawSurface7_IsLost(surface
);
8376 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8377 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8378 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
8380 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
8381 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8382 hr
= IDirectDraw7_TestCooperativeLevel(ddraw
);
8383 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
8384 hr
= IDirectDrawSurface7_IsLost(surface
);
8385 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8386 hr
= IDirectDrawSurface7_Flip(surface
, NULL
, DDFLIP_WAIT
);
8387 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
8389 IDirectDrawSurface7_Release(surface
);
8390 refcount
= IDirectDraw7_Release(ddraw
);
8391 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8392 DestroyWindow(window2
);
8393 DestroyWindow(window1
);
8396 static void test_resource_priority(void)
8398 IDirectDrawSurface7
*surface
, *mipmap
;
8399 DDSURFACEDESC2 surface_desc
;
8400 IDirectDraw7
*ddraw
;
8404 DDSCAPS2 caps
= {DDSCAPS_COMPLEX
, 0, 0, {0}};
8406 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_MIPMAP
;
8414 /* SetPriority on offscreenplain surfaces crashes on AMD GPUs on Win7. */
8419 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem texture", DDERR_INVALIDPARAMS
, FALSE
},
8420 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem texture", DDERR_INVALIDPARAMS
, FALSE
},
8421 {DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
, "managed texture", DD_OK
, FALSE
},
8422 {DDSCAPS_TEXTURE
, DDSCAPS2_D3DTEXTUREMANAGE
, "managed texture", DD_OK
, FALSE
},
8423 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0, "vidmem offscreenplain", DDERR_INVALIDOBJECT
, TRUE
},
8424 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0, "sysmem offscreenplain", DDERR_INVALIDOBJECT
, TRUE
},
8427 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8428 0, 0, 640, 480, 0, 0, 0, 0);
8429 ddraw
= create_ddraw();
8430 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8431 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8432 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8434 memset(&hal_caps
, 0, sizeof(hal_caps
));
8435 hal_caps
.dwSize
= sizeof(hal_caps
);
8436 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
8437 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8438 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
8439 || !(hal_caps
.ddsCaps
.dwCaps
& DDSCAPS2_TEXTUREMANAGE
))
8441 skip("Required surface types not supported, skipping test.\n");
8445 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
8447 memset(&surface_desc
, 0, sizeof(surface_desc
));
8448 surface_desc
.dwSize
= sizeof(surface_desc
);
8449 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
8450 surface_desc
.dwWidth
= 32;
8451 surface_desc
.dwHeight
= 32;
8452 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
8453 surface_desc
.ddsCaps
.dwCaps2
= test_data
[i
].caps2
;
8454 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8455 if (is_ddraw64
&& (test_data
[i
].caps
& DDSCAPS_TEXTURE
))
8457 todo_wine
ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8459 IDirectDrawSurface7_Release(surface
);
8462 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8464 /* Priority == NULL segfaults. */
8465 priority
= 0xdeadbeef;
8466 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8467 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8468 if (SUCCEEDED(test_data
[i
].hr
))
8469 ok(priority
== 0, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8471 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8473 if (!test_data
[i
].crash
)
8475 hr
= IDirectDrawSurface7_SetPriority(surface
, 1);
8476 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8477 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8478 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8479 if (SUCCEEDED(test_data
[i
].hr
))
8481 ok(priority
== 1, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8482 hr
= IDirectDrawSurface7_SetPriority(surface
, 2);
8483 ok(hr
== test_data
[i
].hr
, "Got unexpected hr %#x, type %s.\n", hr
, test_data
[i
].name
);
8486 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type %s.\n", priority
, test_data
[i
].name
);
8489 IDirectDrawSurface7_Release(surface
);
8495 memset(&surface_desc
, 0, sizeof(surface_desc
));
8496 surface_desc
.dwSize
= sizeof(surface_desc
);
8497 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
| DDSD_MIPMAPCOUNT
;
8498 surface_desc
.dwWidth
= 32;
8499 surface_desc
.dwHeight
= 32;
8500 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
8501 surface_desc
.ddsCaps
.dwCaps2
= DDSCAPS2_TEXTUREMANAGE
;
8502 U2(surface_desc
).dwMipMapCount
= 2;
8503 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8504 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8505 hr
= IDirectDrawSurface7_GetAttachedSurface(surface
, &caps
, &mipmap
);
8506 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
8508 priority
= 0xdeadbeef;
8509 hr
= IDirectDrawSurface7_GetPriority(mipmap
, &priority
);
8510 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type managed mipmap.\n", hr
);
8511 ok(priority
== 0xdeadbeef, "Got unexpected priority %u, type managed mipmap.\n", priority
);
8512 /* SetPriority on the mipmap surface crashes. */
8513 hr
= IDirectDrawSurface7_GetPriority(surface
, &priority
);
8514 ok(SUCCEEDED(hr
), "Failed to get priority, hr %#x.\n", hr
);
8515 ok(priority
== 0, "Got unexpected priority %u, type managed mipmap.\n", priority
);
8517 IDirectDrawSurface7_Release(mipmap
);
8518 refcount
= IDirectDrawSurface7_Release(surface
);
8519 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8522 refcount
= IDirectDraw7_Release(ddraw
);
8523 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8524 DestroyWindow(window
);
8527 static void test_surface_desc_lock(void)
8529 IDirectDrawSurface7
*surface
;
8530 DDSURFACEDESC2 surface_desc
;
8531 IDirectDraw7
*ddraw
;
8536 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8537 0, 0, 640, 480, 0, 0, 0, 0);
8538 ddraw
= create_ddraw();
8539 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8540 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8541 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8543 memset(&surface_desc
, 0, sizeof(surface_desc
));
8544 surface_desc
.dwSize
= sizeof(surface_desc
);
8545 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
8546 surface_desc
.dwWidth
= 16;
8547 surface_desc
.dwHeight
= 16;
8548 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8549 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8550 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8552 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8553 surface_desc
.dwSize
= sizeof(surface_desc
);
8554 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8555 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8556 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8558 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8559 surface_desc
.dwSize
= sizeof(surface_desc
);
8560 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
8561 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8562 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8563 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8564 surface_desc
.dwSize
= sizeof(surface_desc
);
8565 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8566 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8567 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8568 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
8569 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8571 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
8572 surface_desc
.dwSize
= sizeof(surface_desc
);
8573 hr
= IDirectDrawSurface7_GetSurfaceDesc(surface
, &surface_desc
);
8574 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
8575 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8577 IDirectDrawSurface7_Release(surface
);
8578 refcount
= IDirectDraw7_Release(ddraw
);
8579 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8580 DestroyWindow(window
);
8583 static void test_fog_interpolation(void)
8586 IDirect3DDevice7
*device
;
8587 IDirectDrawSurface7
*rt
;
8593 struct vec3 position
;
8599 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
8600 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000, 0xff000000},
8601 {{ 1.0f
, -1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
8602 {{ 1.0f
, 1.0f
, 1.0f
}, 0xffff0000, 0x00000000},
8612 D3DFOGMODE vfog
, tfog
;
8614 D3DCOLOR middle_color
;
8619 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, FALSE
},
8620 {D3DFOG_NONE
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, FALSE
},
8621 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_FLAT
, 0x00007f80, TRUE
},
8622 {D3DFOG_EXP
, D3DFOG_NONE
, D3DSHADE_GOURAUD
, 0x00007f80, TRUE
},
8623 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
8624 {D3DFOG_NONE
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
8625 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_FLAT
, 0x0000ea15, FALSE
},
8626 {D3DFOG_EXP
, D3DFOG_EXP
, D3DSHADE_GOURAUD
, 0x0000ea15, FALSE
},
8628 D3DDEVICEDESC7 caps
;
8630 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8631 0, 0, 640, 480, 0, 0, 0, 0);
8633 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8635 skip("Failed to create a 3D device, skipping test.\n");
8636 DestroyWindow(window
);
8640 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8641 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8642 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8643 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8644 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8645 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests\n");
8647 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8648 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8649 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
8650 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8651 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8652 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8653 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8654 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8656 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGDENSITY
, conv
.d
);
8657 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8659 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
8660 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8661 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TFACTOR
);
8662 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
8663 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x000000ff);
8664 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8666 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8668 if(!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
8671 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00808080, 0.0f
, 0);
8672 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8674 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shade
);
8675 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8676 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vfog
);
8677 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8678 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tfog
);
8679 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8680 hr
= IDirect3DDevice7_BeginScene(device
);
8681 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8682 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8683 D3DFVF_XYZ
| D3DFVF_DIFFUSE
| D3DFVF_SPECULAR
, quad
, 4, 0);
8684 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8685 hr
= IDirect3DDevice7_EndScene(device
);
8686 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8688 color
= get_surface_color(rt
, 0, 240);
8689 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8690 color
= get_surface_color(rt
, 320, 240);
8692 todo_wine
ok(compare_color(color
, tests
[i
].middle_color
, 2),
8693 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8695 ok(compare_color(color
, tests
[i
].middle_color
, 2),
8696 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8697 color
= get_surface_color(rt
, 639, 240);
8698 ok(compare_color(color
, 0x0000fd02, 2), "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8701 IDirectDrawSurface7_Release(rt
);
8702 refcount
= IDirect3DDevice7_Release(device
);
8703 ok(!refcount
, "Device has %u references left.\n", refcount
);
8704 DestroyWindow(window
);
8707 static void test_negative_fixedfunction_fog(void)
8710 IDirect3DDevice7
*device
;
8711 IDirectDrawSurface7
*rt
;
8717 struct vec3 position
;
8722 {{-1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
8723 {{-1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
8724 {{ 1.0f
, -1.0f
, -0.5f
}, 0xffff0000},
8725 {{ 1.0f
, 1.0f
, -0.5f
}, 0xffff0000},
8729 struct vec4 position
;
8734 {{ 0.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8735 {{640.0f
, 0.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8736 {{ 0.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8737 {{640.0f
, 480.0f
, -0.5f
, 1.0f
}, 0xffff0000},
8740 static D3DMATRIX zero
=
8742 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8743 0.0f
, 1.0f
, 0.0f
, 0.0f
,
8744 0.0f
, 0.0f
, 0.0f
, 0.0f
,
8745 0.0f
, 0.0f
, 0.0f
, 1.0f
8747 static D3DMATRIX identity
=
8749 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8750 0.0f
, 1.0f
, 0.0f
, 0.0f
,
8751 0.0f
, 0.0f
, 1.0f
, 0.0f
,
8752 0.0f
, 0.0f
, 0.0f
, 1.0f
8764 D3DFOGMODE vfog
, tfog
;
8765 DWORD color
, color_broken
, color_broken2
;
8769 /* Run the XYZRHW tests first. Depth clamping is broken after RHW draws on the testbot.
8771 * Geforce8+ GPUs on Windows abs() table fog, everything else does not. */
8772 {D3DFVF_XYZRHW
, tquad
, &identity
, { 0.0f
}, {1.0f
}, D3DFOG_NONE
, D3DFOG_LINEAR
,
8773 0x00ff0000, 0x00808000, 0x00808000},
8774 /* r200 GPUs and presumably all d3d8 and older HW clamp the fog
8775 * parameters to 0.0 and 1.0 in the table fog case. */
8776 {D3DFVF_XYZRHW
, tquad
, &identity
, {-1.0f
}, {0.0f
}, D3DFOG_NONE
, D3DFOG_LINEAR
,
8777 0x00808000, 0x00ff0000, 0x0000ff00},
8778 /* test_fog_interpolation shows that vertex fog evaluates the fog
8779 * equation in the vertex pipeline. Start = -1.0 && end = 0.0 shows
8780 * that the abs happens before the fog equation is evaluated.
8782 * Vertex fog abs() behavior is the same on all GPUs. */
8783 {D3DFVF_XYZ
, quad
, &zero
, { 0.0f
}, {1.0f
}, D3DFOG_LINEAR
, D3DFOG_NONE
,
8784 0x00808000, 0x00808000, 0x00808000},
8785 {D3DFVF_XYZ
, quad
, &zero
, {-1.0f
}, {0.0f
}, D3DFOG_LINEAR
, D3DFOG_NONE
,
8786 0x0000ff00, 0x0000ff00, 0x0000ff00},
8787 {D3DFVF_XYZ
, quad
, &zero
, { 0.0f
}, {1.0f
}, D3DFOG_EXP
, D3DFOG_NONE
,
8788 0x009b6400, 0x009b6400, 0x009b6400},
8790 D3DDEVICEDESC7 caps
;
8792 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8793 0, 0, 640, 480, 0, 0, 0, 0);
8795 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8797 skip("Failed to create a 3D device, skipping test.\n");
8798 DestroyWindow(window
);
8802 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8803 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8804 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8805 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8806 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8807 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping some fog tests.\n");
8809 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8810 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8811 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
8812 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8813 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8814 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8815 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8816 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8817 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
8818 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
8820 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
8822 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
) && tests
[i
].tfog
)
8825 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x000000ff, 0.0f
, 0);
8826 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8828 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, tests
[i
].matrix
);
8829 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
8830 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGSTART
, tests
[i
].start
.d
);
8831 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8832 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGEND
, tests
[i
].end
.d
);
8833 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8834 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGVERTEXMODE
, tests
[i
].vfog
);
8835 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8836 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, tests
[i
].tfog
);
8837 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8839 hr
= IDirect3DDevice7_BeginScene(device
);
8840 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8841 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8842 tests
[i
].pos_type
| D3DFVF_DIFFUSE
, tests
[i
].quad
, 4, 0);
8843 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8844 hr
= IDirect3DDevice7_EndScene(device
);
8845 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8847 color
= get_surface_color(rt
, 0, 240);
8848 ok(compare_color(color
, tests
[i
].color
, 2) || broken(compare_color(color
, tests
[i
].color_broken
, 2))
8849 || broken(compare_color(color
, tests
[i
].color_broken2
, 2)),
8850 "Got unexpected color 0x%08x, case %u.\n", color
, i
);
8853 IDirectDrawSurface7_Release(rt
);
8854 refcount
= IDirect3DDevice7_Release(device
);
8855 ok(!refcount
, "Device has %u references left.\n", refcount
);
8856 DestroyWindow(window
);
8859 static void test_table_fog_zw(void)
8862 IDirect3DDevice7
*device
;
8863 IDirectDrawSurface7
*rt
;
8869 struct vec4 position
;
8874 {{ 0.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8875 {{640.0f
, 0.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8876 {{ 0.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8877 {{640.0f
, 480.0f
, 0.0f
, 0.0f
}, 0xffff0000},
8879 static D3DMATRIX identity
=
8881 1.0f
, 0.0f
, 0.0f
, 0.0f
,
8882 0.0f
, 1.0f
, 0.0f
, 0.0f
,
8883 0.0f
, 0.0f
, 1.0f
, 0.0f
,
8884 0.0f
, 0.0f
, 0.0f
, 1.0f
8886 D3DDEVICEDESC7 caps
;
8890 D3DZBUFFERTYPE z_test
;
8895 {0.7f
, 0.0f
, D3DZB_TRUE
, 0x004cb200},
8896 {0.7f
, 0.0f
, D3DZB_FALSE
, 0x004cb200},
8897 {0.7f
, 0.3f
, D3DZB_TRUE
, 0x004cb200},
8898 {0.7f
, 0.3f
, D3DZB_FALSE
, 0x004cb200},
8899 {0.7f
, 3.0f
, D3DZB_TRUE
, 0x004cb200},
8900 {0.7f
, 3.0f
, D3DZB_FALSE
, 0x004cb200},
8901 {0.3f
, 0.0f
, D3DZB_TRUE
, 0x00b24c00},
8902 {0.3f
, 0.0f
, D3DZB_FALSE
, 0x00b24c00},
8906 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8907 0, 0, 640, 480, 0, 0, 0, 0);
8909 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
8911 skip("Failed to create a 3D device, skipping test.\n");
8912 DestroyWindow(window
);
8916 hr
= IDirect3DDevice7_GetCaps(device
, &caps
);
8917 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8918 if (!(caps
.dpcTriCaps
.dwRasterCaps
& D3DPRASTERCAPS_FOGTABLE
))
8920 skip("D3DPRASTERCAPS_FOGTABLE not supported, skipping POSITIONT table fog test.\n");
8923 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
8924 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8926 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
8927 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8928 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, TRUE
);
8929 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8930 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGCOLOR
, 0x0000ff00);
8931 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8932 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_CLIPPING
, FALSE
);
8933 ok(SUCCEEDED(hr
), "SetRenderState failed, hr %#x.\n", hr
);
8934 /* Work around an AMD Windows driver bug. Needs a proj matrix applied redundantly. */
8935 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_PROJECTION
, &identity
);
8936 ok(SUCCEEDED(hr
), "Failed to set projection transform, hr %#x.\n", hr
);
8937 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGTABLEMODE
, D3DFOG_LINEAR
);
8938 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8940 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
8942 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0x000000ff, 1.0f
, 0);
8943 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8945 quad
[0].position
.z
= tests
[i
].z
;
8946 quad
[1].position
.z
= tests
[i
].z
;
8947 quad
[2].position
.z
= tests
[i
].z
;
8948 quad
[3].position
.z
= tests
[i
].z
;
8949 quad
[0].position
.w
= tests
[i
].w
;
8950 quad
[1].position
.w
= tests
[i
].w
;
8951 quad
[2].position
.w
= tests
[i
].w
;
8952 quad
[3].position
.w
= tests
[i
].w
;
8953 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, tests
[i
].z_test
);
8954 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8956 hr
= IDirect3DDevice7_BeginScene(device
);
8957 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8958 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
8959 D3DFVF_XYZRHW
| D3DFVF_DIFFUSE
, quad
, 4, 0);
8960 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
8961 hr
= IDirect3DDevice7_EndScene(device
);
8962 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8964 color
= get_surface_color(rt
, 0, 240);
8965 ok(compare_color(color
, tests
[i
].color
, 2),
8966 "Got unexpected color 0x%08x, expected 0x%8x, case %u.\n", color
, tests
[i
].color
, i
);
8969 IDirectDrawSurface7_Release(rt
);
8971 refcount
= IDirect3DDevice7_Release(device
);
8972 ok(!refcount
, "Device has %u references left.\n", refcount
);
8973 DestroyWindow(window
);
8976 static void test_signed_formats(void)
8979 IDirect3DDevice7
*device
;
8981 IDirectDraw7
*ddraw
;
8982 IDirectDrawSurface7
*surface
, *rt
;
8983 DDSURFACEDESC2 surface_desc
;
8986 D3DCOLOR color
, expected_color
;
8989 struct vec3 position
;
8990 struct vec2 texcoord
;
8994 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
8995 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
8996 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
8997 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
8999 /* See test_signed_formats() in dlls/d3d9/tests/visual.c for an explanation
9000 * of these values. */
9001 static const USHORT content_v8u8
[4][4] =
9003 {0x0000, 0x7f7f, 0x8880, 0x0000},
9004 {0x0080, 0x8000, 0x7f00, 0x007f},
9005 {0x193b, 0xe8c8, 0x0808, 0xf8f8},
9006 {0x4444, 0xc0c0, 0xa066, 0x22e0},
9008 static const DWORD content_x8l8v8u8
[4][4] =
9010 {0x00000000, 0x00ff7f7f, 0x00008880, 0x00ff0000},
9011 {0x00000080, 0x00008000, 0x00007f00, 0x0000007f},
9012 {0x0041193b, 0x0051e8c8, 0x00040808, 0x00fff8f8},
9013 {0x00824444, 0x0000c0c0, 0x00c2a066, 0x009222e0},
9015 static const USHORT content_l6v5u5
[4][4] =
9017 {0x0000, 0xfdef, 0x0230, 0xfc00},
9018 {0x0010, 0x0200, 0x01e0, 0x000f},
9019 {0x4067, 0x53b9, 0x0421, 0xffff},
9020 {0x8108, 0x0318, 0xc28c, 0x909c},
9025 const void *content
;
9028 unsigned int slop
, slop_broken
;
9029 DDPIXELFORMAT format
;
9034 "D3DFMT_V8U8", content_v8u8
, sizeof(WORD
), FALSE
, 1, 0,
9036 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
, 0,
9037 {16}, {0x000000ff}, {0x0000ff00}, {0x00000000}, {0x00000000}
9041 "D3DFMT_X8L8V8U8", content_x8l8v8u8
, sizeof(DWORD
), TRUE
, 1, 0,
9043 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
9044 {32}, {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}
9048 "D3DFMT_L6V5U5", content_l6v5u5
, sizeof(WORD
), TRUE
, 4, 7,
9050 sizeof(DDPIXELFORMAT
), DDPF_BUMPDUDV
| DDPF_BUMPLUMINANCE
, 0,
9051 {16}, {0x0000001f}, {0x000003e0}, {0x0000fc00}, {0x00000000}
9055 /* No V16U16 or Q8W8V8U8 support in ddraw. */
9057 static const D3DCOLOR expected_colors
[4][4] =
9059 {0x00808080, 0x00fefeff, 0x00010780, 0x008080ff},
9060 {0x00018080, 0x00800180, 0x0080fe80, 0x00fe8080},
9061 {0x00ba98a0, 0x004767a8, 0x00888881, 0x007878ff},
9062 {0x00c3c3c0, 0x003f3f80, 0x00e51fe1, 0x005fa2c8},
9064 unsigned int i
, width
, x
, y
;
9065 D3DDEVICEDESC7 device_desc
;
9067 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9068 0, 0, 640, 480, 0, 0, 0, 0);
9070 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9072 skip("Failed to create a 3D device, skipping test.\n");
9073 DestroyWindow(window
);
9077 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
9078 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9079 if (!(device_desc
.dwTextureOpCaps
& D3DTEXOPCAPS_BLENDFACTORALPHA
))
9081 skip("D3DTOP_BLENDFACTORALPHA not supported, skipping bumpmap format tests.\n");
9085 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9086 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9087 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9088 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9089 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9090 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9092 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9093 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9095 /* dst = tex * 0.5 + 1.0 * (1.0 - 0.5) = tex * 0.5 + 0.5 */
9096 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x80ffffff);
9097 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
9098 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_BLENDFACTORALPHA
);
9099 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9100 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9101 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9102 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
9103 ok(SUCCEEDED(hr
), "Failed to set texture stage state, hr %#x.\n", hr
);
9105 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
9107 for (width
= 1; width
< 5; width
+= 3)
9109 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
9110 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
9112 memset(&surface_desc
, 0, sizeof(surface_desc
));
9113 surface_desc
.dwSize
= sizeof(surface_desc
);
9114 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
;
9115 surface_desc
.dwWidth
= width
;
9116 surface_desc
.dwHeight
= 4;
9117 U4(surface_desc
).ddpfPixelFormat
= formats
[i
].format
;
9118 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
9119 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9122 skip("%s textures not supported, skipping.\n", formats
[i
].name
);
9125 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9126 hr
= IDirect3DDevice7_SetTexture(device
, 0, surface
);
9127 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9129 memset(&surface_desc
, 0, sizeof(surface_desc
));
9130 surface_desc
.dwSize
= sizeof(surface_desc
);
9131 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
9132 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9133 for (y
= 0; y
< 4; y
++)
9135 memcpy((char *)surface_desc
.lpSurface
+ y
* U1(surface_desc
).lPitch
,
9136 (char *)formats
[i
].content
+ y
* 4 * formats
[i
].pixel_size
,
9137 width
* formats
[i
].pixel_size
);
9139 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9140 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, format %s.\n", hr
, formats
[i
].name
);
9142 hr
= IDirect3DDevice7_BeginScene(device
);
9143 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9144 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
,
9145 D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
9146 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9147 hr
= IDirect3DDevice7_EndScene(device
);
9148 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9150 for (y
= 0; y
< 4; y
++)
9152 for (x
= 0; x
< width
; x
++)
9154 expected_color
= expected_colors
[y
][x
];
9155 if (!formats
[i
].blue
)
9156 expected_color
|= 0x000000ff;
9158 color
= get_surface_color(rt
, 80 + 160 * x
, 60 + 120 * y
);
9159 ok(compare_color(color
, expected_color
, formats
[i
].slop
)
9160 || broken(compare_color(color
, expected_color
, formats
[i
].slop_broken
)),
9161 "Expected color 0x%08x, got 0x%08x, format %s, location %ux%u.\n",
9162 expected_color
, color
, formats
[i
].name
, x
, y
);
9166 IDirectDrawSurface7_Release(surface
);
9171 IDirectDrawSurface7_Release(rt
);
9172 IDirectDraw7_Release(ddraw
);
9173 IDirect3D7_Release(d3d
);
9176 refcount
= IDirect3DDevice7_Release(device
);
9177 ok(!refcount
, "Device has %u references left.\n", refcount
);
9178 DestroyWindow(window
);
9181 static void test_color_fill(void)
9184 IDirect3DDevice7
*device
;
9186 IDirectDraw7
*ddraw
;
9187 IDirectDrawSurface7
*surface
, *surface2
;
9188 DDSURFACEDESC2 surface_desc
;
9189 DDPIXELFORMAT z_fmt
;
9194 RECT rect
= {5, 5, 7, 7};
9196 DWORD supported_fmts
= 0, num_fourcc_codes
, *fourcc_codes
;
9201 HRESULT colorfill_hr
, depthfill_hr
;
9206 DDPIXELFORMAT format
;
9211 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9212 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9214 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9215 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9219 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9220 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
9222 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9223 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9227 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9228 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
9230 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9231 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9235 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9236 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
9238 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9239 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9243 DDSCAPS_TEXTURE
, DDSCAPS2_TEXTUREMANAGE
,
9244 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "managed texture RGB", 0xdeadbeef, TRUE
,
9246 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9247 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
9251 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
, 0,
9252 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
9253 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9256 DDSCAPS_ZBUFFER
| DDSCAPS_SYSTEMMEMORY
, 0,
9257 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "sysmem zbuffer", 0, FALSE
,
9258 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
9261 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
9262 * different afterwards. DX9+ GPUs set one of the two luminance values
9263 * in each block, but AMD and Nvidia GPUs disagree on which luminance
9264 * value they set. r200 (dx8) just sets the entire block to the clear
9266 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9267 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
9269 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9270 {0}, {0}, {0}, {0}, {0}
9274 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9275 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
9277 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9278 {0}, {0}, {0}, {0}, {0}
9282 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9283 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
9285 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
9286 {0}, {0}, {0}, {0}, {0}
9290 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
, 0,
9291 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
9293 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
9294 {0}, {0}, {0}, {0}, {0}
9298 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, 0,
9299 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
9301 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9302 {0}, {0}, {0}, {0}, {0}
9306 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, 0,
9307 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
9309 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
9310 {0}, {0}, {0}, {0}, {0}
9314 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
9315 * surface works, presumably because it is handled by the runtime instead of
9317 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, 0,
9318 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
9320 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9321 {8}, {0}, {0}, {0}, {0}
9325 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, 0,
9326 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
9328 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
9329 {8}, {0}, {0}, {0}, {0}
9341 {SRCCOPY
, "SRCCOPY", DD_OK
},
9342 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
9343 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
9344 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
9345 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
9346 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
9347 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
9348 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
9349 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
9350 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
9351 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
9352 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
9353 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
9354 {BLACKNESS
, "BLACKNESS", DD_OK
},
9355 {WHITENESS
, "WHITENESS", DD_OK
},
9356 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
9359 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9360 0, 0, 640, 480, 0, 0, 0, 0);
9362 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9364 skip("Failed to create a 3D device, skipping test.\n");
9365 DestroyWindow(window
);
9369 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9370 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
9371 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9372 ok(SUCCEEDED(hr
), "Failed to get ddraw interface, hr %#x.\n", hr
);
9374 memset(&z_fmt
, 0, sizeof(z_fmt
));
9375 IDirect3D7_EnumZBufferFormats(d3d
, &IID_IDirect3DHALDevice
, enum_z_fmt
, &z_fmt
);
9377 skip("No Z buffer formats supported, skipping Z buffer colorfill test.\n");
9379 IDirect3DDevice7_EnumTextureFormats(device
, test_block_formats_creation_cb
, &supported_fmts
);
9380 if (!(supported_fmts
& SUPPORT_DXT1
))
9381 skip("DXT1 textures not supported, skipping DXT1 colorfill test.\n");
9383 IDirect3D7_Release(d3d
);
9385 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
9386 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9387 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
9388 num_fourcc_codes
* sizeof(*fourcc_codes
));
9391 hr
= IDirectDraw7_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
9392 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
9393 for (i
= 0; i
< num_fourcc_codes
; i
++)
9395 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
9396 supported_fmts
|= SUPPORT_YUY2
;
9397 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
9398 supported_fmts
|= SUPPORT_UYVY
;
9400 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
9402 memset(&hal_caps
, 0, sizeof(hal_caps
));
9403 hal_caps
.dwSize
= sizeof(hal_caps
);
9404 hr
= IDirectDraw7_GetCaps(ddraw
, &hal_caps
, NULL
);
9405 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
9407 if (!(supported_fmts
& (SUPPORT_YUY2
| SUPPORT_UYVY
)) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9408 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
9410 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
9412 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
9413 memset(&fx
, 0, sizeof(fx
));
9414 fx
.dwSize
= sizeof(fx
);
9415 U5(fx
).dwFillColor
= 0xdeadbeef;
9417 memset(&surface_desc
, 0, sizeof(surface_desc
));
9418 surface_desc
.dwSize
= sizeof(surface_desc
);
9419 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9420 surface_desc
.dwWidth
= 64;
9421 surface_desc
.dwHeight
= 64;
9422 U4(surface_desc
).ddpfPixelFormat
= tests
[i
].format
;
9423 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
9424 surface_desc
.ddsCaps
.dwCaps2
= tests
[i
].caps2
;
9426 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('D','X','T','1') && !(supported_fmts
& SUPPORT_DXT1
))
9428 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !(supported_fmts
& SUPPORT_YUY2
))
9430 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !(supported_fmts
& SUPPORT_UYVY
))
9432 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
9435 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
9440 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9443 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9444 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9446 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9447 if (tests
[i
].format
.dwFourCC
)
9448 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9449 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9451 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9452 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9454 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9455 if (tests
[i
].format
.dwFourCC
)
9456 todo_wine
ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9457 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9459 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9460 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
9462 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9464 memset(&surface_desc
, 0, sizeof(surface_desc
));
9465 surface_desc
.dwSize
= sizeof(surface_desc
);
9466 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9467 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9468 color
= surface_desc
.lpSurface
;
9469 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
9470 *color
, tests
[i
].result
, tests
[i
].name
);
9471 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9472 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9475 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9476 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9477 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9478 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9479 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
9480 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
9482 U5(fx
).dwFillColor
= 0xdeadbeef;
9483 fx
.dwROP
= BLACKNESS
;
9484 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9485 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9486 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9487 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9488 U5(fx
).dwFillColor
, tests
[i
].name
);
9490 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9492 memset(&surface_desc
, 0, sizeof(surface_desc
));
9493 surface_desc
.dwSize
= sizeof(surface_desc
);
9494 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9495 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9496 color
= surface_desc
.lpSurface
;
9497 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
9498 *color
, tests
[i
].name
);
9499 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9500 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9503 fx
.dwROP
= WHITENESS
;
9504 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9505 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
9506 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
9507 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
9508 U5(fx
).dwFillColor
, tests
[i
].name
);
9510 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
9512 memset(&surface_desc
, 0, sizeof(surface_desc
));
9513 surface_desc
.dwSize
= sizeof(surface_desc
);
9514 hr
= IDirectDrawSurface7_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
9515 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9516 color
= surface_desc
.lpSurface
;
9517 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
9518 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
9519 *color
, tests
[i
].name
);
9520 hr
= IDirectDrawSurface7_Unlock(surface
, NULL
);
9521 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
9524 IDirectDrawSurface7_Release(surface
);
9527 memset(&fx
, 0, sizeof(fx
));
9528 fx
.dwSize
= sizeof(fx
);
9529 U5(fx
).dwFillColor
= 0xdeadbeef;
9530 fx
.dwROP
= WHITENESS
;
9532 memset(&surface_desc
, 0, sizeof(surface_desc
));
9533 surface_desc
.dwSize
= sizeof(surface_desc
);
9534 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9535 surface_desc
.dwWidth
= 64;
9536 surface_desc
.dwHeight
= 64;
9537 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9538 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
9539 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9540 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9541 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9542 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9543 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
9544 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9545 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9546 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9547 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9550 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
9551 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9552 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
9553 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9555 /* Unused source rectangle. */
9556 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9557 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9558 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9559 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9561 /* Unused source surface. */
9562 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9563 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9564 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9565 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9566 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9567 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9568 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9569 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9571 /* Inverted destination or source rectangle. */
9572 SetRect(&rect
, 5, 7, 7, 5);
9573 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9574 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9575 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9576 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9577 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9578 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9579 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9580 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9581 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9582 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9584 /* Negative rectangle. */
9585 SetRect(&rect
, -1, -1, 5, 5);
9586 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9587 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9588 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9589 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9590 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9591 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9592 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9593 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9594 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9595 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9597 /* Out of bounds rectangle. */
9598 SetRect(&rect
, 0, 0, 65, 65);
9599 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
9600 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9601 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9602 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9604 /* Combine multiple flags. */
9605 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9606 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9607 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9608 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9609 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9610 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9612 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
9614 fx
.dwROP
= rops
[i
].rop
;
9615 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
9616 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
9619 IDirectDrawSurface7_Release(surface2
);
9620 IDirectDrawSurface7_Release(surface
);
9625 memset(&surface_desc
, 0, sizeof(surface_desc
));
9626 surface_desc
.dwSize
= sizeof(surface_desc
);
9627 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9628 surface_desc
.dwWidth
= 64;
9629 surface_desc
.dwHeight
= 64;
9630 U4(surface_desc
).ddpfPixelFormat
= z_fmt
;
9631 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
9632 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
9633 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9634 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
9635 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9638 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
9639 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9641 /* Unused source rectangle. */
9642 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9643 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9645 /* Unused source surface. */
9646 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9647 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9648 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9649 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9651 /* Inverted destination or source rectangle. */
9652 SetRect(&rect
, 5, 7, 7, 5);
9653 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9654 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9655 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9656 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9657 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9658 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9659 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9660 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9662 /* Negative rectangle. */
9663 SetRect(&rect
, -1, -1, 5, 5);
9664 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9665 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9666 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9667 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9668 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9669 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9670 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9671 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9673 /* Out of bounds rectangle. */
9674 SetRect(&rect
, 0, 0, 65, 65);
9675 hr
= IDirectDrawSurface7_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9676 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
9678 /* Combine multiple flags. */
9679 hr
= IDirectDrawSurface7_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
9680 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
9682 IDirectDrawSurface7_Release(surface2
);
9683 IDirectDrawSurface7_Release(surface
);
9686 IDirectDraw7_Release(ddraw
);
9687 refcount
= IDirect3DDevice7_Release(device
);
9688 ok(!refcount
, "Device has %u references left.\n", refcount
);
9689 DestroyWindow(window
);
9692 static void test_texcoordindex(void)
9694 static D3DMATRIX mat
=
9696 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9697 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9698 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9699 0.0f
, 0.0f
, 0.0f
, 0.0f
,
9704 struct vec2 texcoord1
;
9705 struct vec2 texcoord2
;
9706 struct vec2 texcoord3
;
9710 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}, {0.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9711 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}, {0.0f
, 1.0f
}, {1.0f
, 0.0f
}},
9712 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9713 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 0.0f
}},
9715 static const DWORD fvf
= D3DFVF_XYZ
| D3DFVF_TEX3
;
9716 IDirect3DDevice7
*device
;
9718 IDirectDraw7
*ddraw
;
9719 IDirectDrawSurface7
*rt
;
9722 IDirectDrawSurface7
*texture1
, *texture2
;
9723 DDSURFACEDESC2 surface_desc
;
9728 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9729 0, 0, 640, 480, 0, 0, 0, 0);
9730 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9732 skip("Failed to create a 3D device, skipping test.\n");
9733 DestroyWindow(window
);
9737 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9738 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
9739 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9740 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
9741 IDirect3D7_Release(d3d
);
9743 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9744 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9746 memset(&surface_desc
, 0, sizeof(surface_desc
));
9747 surface_desc
.dwSize
= sizeof(surface_desc
);
9748 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
9749 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
9750 surface_desc
.dwWidth
= 2;
9751 surface_desc
.dwHeight
= 2;
9752 U4(surface_desc
).ddpfPixelFormat
.dwSize
= sizeof(U4(surface_desc
).ddpfPixelFormat
);
9753 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
9754 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
9755 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
9756 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
9757 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
9758 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
9759 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture1
, NULL
);
9760 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9761 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture2
, NULL
);
9762 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
9764 memset(&surface_desc
, 0, sizeof(surface_desc
));
9765 surface_desc
.dwSize
= sizeof(surface_desc
);
9766 hr
= IDirectDrawSurface7_Lock(texture1
, 0, &surface_desc
, 0, NULL
);
9767 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9768 ptr
= surface_desc
.lpSurface
;
9769 ptr
[0] = 0xff000000;
9770 ptr
[1] = 0xff00ff00;
9771 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9772 ptr
[0] = 0xff0000ff;
9773 ptr
[1] = 0xff00ffff;
9774 hr
= IDirectDrawSurface7_Unlock(texture1
, NULL
);
9775 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9777 memset(&surface_desc
, 0, sizeof(surface_desc
));
9778 surface_desc
.dwSize
= sizeof(surface_desc
);
9779 hr
= IDirectDrawSurface7_Lock(texture2
, 0, &surface_desc
, 0, NULL
);
9780 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
9781 ptr
= surface_desc
.lpSurface
;
9782 ptr
[0] = 0xff000000;
9783 ptr
[1] = 0xff0000ff;
9784 ptr
+= surface_desc
.lPitch
/ sizeof(*ptr
);
9785 ptr
[0] = 0xffff0000;
9786 ptr
[1] = 0xffff00ff;
9787 hr
= IDirectDrawSurface7_Unlock(texture2
, 0);
9788 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
9790 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture1
);
9791 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9792 hr
= IDirect3DDevice7_SetTexture(device
, 1, texture2
);
9793 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
9794 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9795 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9796 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_SELECTARG1
);
9797 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9798 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9799 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9800 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLOROP
, D3DTOP_ADD
);
9801 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9802 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
9803 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9804 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_COLORARG2
, D3DTA_CURRENT
);
9805 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
9806 hr
= IDirect3DDevice7_SetTextureStageState(device
, 2, D3DTSS_COLOROP
, D3DTOP_DISABLE
);
9807 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
9809 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_TEXCOORDINDEX
, 1);
9810 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9811 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 0);
9812 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9814 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, FALSE
);
9815 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9817 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9818 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9820 hr
= IDirect3DDevice7_BeginScene(device
);
9821 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9822 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9823 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9824 hr
= IDirect3DDevice7_EndScene(device
);
9825 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9827 color
= get_surface_color(rt
, 160, 120);
9828 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9829 color
= get_surface_color(rt
, 480, 120);
9830 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9831 color
= get_surface_color(rt
, 160, 360);
9832 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
9833 color
= get_surface_color(rt
, 480, 360);
9834 ok(compare_color(color
, 0x00ffffff, 2), "Got unexpected color 0x%08x.\n", color
);
9836 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_COUNT2
);
9837 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
9838 hr
= IDirect3DDevice7_SetTransform(device
, D3DTRANSFORMSTATE_TEXTURE1
, &mat
);
9839 ok(SUCCEEDED(hr
), "Failed to set transformation matrix, hr %#x.\n", hr
);
9841 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9842 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9844 hr
= IDirect3DDevice7_BeginScene(device
);
9845 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9846 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9847 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9848 hr
= IDirect3DDevice7_EndScene(device
);
9849 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9851 color
= get_surface_color(rt
, 160, 120);
9852 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9853 color
= get_surface_color(rt
, 480, 120);
9854 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9855 color
= get_surface_color(rt
, 160, 360);
9856 ok(compare_color(color
, 0x00000000, 2), "Got unexpected color 0x%08x.\n", color
);
9857 color
= get_surface_color(rt
, 480, 360);
9858 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9860 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXTURETRANSFORMFLAGS
, D3DTTFF_DISABLE
);
9861 ok(SUCCEEDED(hr
), "Failed to set texture transform flags, hr %#x.\n", hr
);
9862 hr
= IDirect3DDevice7_SetTextureStageState(device
, 1, D3DTSS_TEXCOORDINDEX
, 2);
9863 ok(SUCCEEDED(hr
), "Failed to set texcoord index, hr %#x.\n", hr
);
9865 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffff00, 1.0f
, 0);
9866 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
9868 hr
= IDirect3DDevice7_BeginScene(device
);
9869 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9870 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, fvf
, quad
, 4, 0);
9871 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
9872 hr
= IDirect3DDevice7_EndScene(device
);
9873 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9875 color
= get_surface_color(rt
, 160, 120);
9876 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
9877 color
= get_surface_color(rt
, 480, 120);
9878 ok(compare_color(color
, 0x0000ffff, 2), "Got unexpected color 0x%08x.\n", color
);
9879 color
= get_surface_color(rt
, 160, 360);
9880 ok(compare_color(color
, 0x00ff00ff, 2), "Got unexpected color 0x%08x.\n", color
);
9881 color
= get_surface_color(rt
, 480, 360);
9882 ok(compare_color(color
, 0x00ffff00, 2), "Got unexpected color 0x%08x.\n", color
);
9884 IDirectDrawSurface7_Release(texture1
);
9885 IDirectDrawSurface7_Release(texture2
);
9887 IDirectDrawSurface7_Release(rt
);
9888 IDirectDraw_Release(ddraw
);
9889 refcount
= IDirect3DDevice7_Release(device
);
9890 ok(!refcount
, "Device has %u references left.\n", refcount
);
9891 DestroyWindow(window
);
9894 static void test_colorkey_precision(void)
9899 struct vec2 texcoord
;
9903 {{-1.0f
, -1.0f
, 0.0f
}, {0.0f
, 1.0f
}},
9904 {{-1.0f
, 1.0f
, 0.0f
}, {0.0f
, 0.0f
}},
9905 {{ 1.0f
, -1.0f
, 0.0f
}, {1.0f
, 1.0f
}},
9906 {{ 1.0f
, 1.0f
, 0.0f
}, {1.0f
, 0.0f
}},
9908 IDirect3DDevice7
*device
;
9910 IDirectDraw7
*ddraw
;
9911 IDirectDrawSurface7
*rt
;
9914 IDirectDrawSurface7
*src
, *dst
, *texture
;
9915 DDSURFACEDESC2 surface_desc
, lock_desc
;
9921 DWORD data
[4] = {0}, color_mask
;
9922 D3DDEVICEDESC7 device_desc
;
9926 unsigned int max
, shift
, bpp
, clear
;
9933 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8",
9935 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9936 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
9941 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel",
9943 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9944 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9949 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel",
9951 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
9952 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
9957 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4",
9959 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
9960 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
9966 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9967 0, 0, 640, 480, 0, 0, 0, 0);
9968 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
9970 skip("Failed to create a 3D device, skipping test.\n");
9971 DestroyWindow(window
);
9975 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
9976 * (color key doesn't match although the values are equal), and a false
9977 * positive when the color key is 0 and the texture contains the value 1.
9978 * I don't want to mark this broken unconditionally since this would
9979 * essentially disable the test on Windows. Try to detect WARP (and I
9980 * guess mismatch other SW renderers) by its ability to texture from
9981 * system memory. Also on random occasions 254 == 255 and 255 != 255.*/
9982 hr
= IDirect3DDevice7_GetCaps(device
, &device_desc
);
9983 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
9984 warp
= !!(device_desc
.dwDevCaps
& D3DDEVCAPS_TEXTURESYSTEMMEMORY
);
9986 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
9987 ok(SUCCEEDED(hr
), "Failed to get Direct3D7 interface, hr %#x.\n", hr
);
9988 hr
= IDirect3D7_QueryInterface(d3d
, &IID_IDirectDraw7
, (void **)&ddraw
);
9989 ok(SUCCEEDED(hr
), "Failed to get DirectDraw7 interface, hr %#x.\n", hr
);
9990 IDirect3D7_Release(d3d
);
9991 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
9992 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
9994 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
9995 ok(SUCCEEDED(hr
), "Failed to disable lighting, hr %#x.\n", hr
);
9996 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
9997 ok(SUCCEEDED(hr
), "Failed to disable z-buffering, hr %#x.\n", hr
);
9998 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
9999 ok(SUCCEEDED(hr
), "Failed to enable color keying, hr %#x.\n", hr
);
10000 /* Multiply the texture read result with 0, that way the result color if the key doesn't
10001 * match is constant. In theory color keying works without reading the texture result
10002 * (meaning we could just op=arg1, arg1=tfactor), but the Geforce7 Windows driver begs
10004 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLOROP
, D3DTOP_MODULATE
);
10005 ok(SUCCEEDED(hr
), "Failed to set color op, hr %#x.\n", hr
);
10006 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG1
, D3DTA_TEXTURE
);
10007 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10008 hr
= IDirect3DDevice7_SetTextureStageState(device
, 0, D3DTSS_COLORARG2
, D3DTA_TFACTOR
);
10009 ok(SUCCEEDED(hr
), "Failed to set color arg, hr %#x.\n", hr
);
10010 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_TEXTUREFACTOR
, 0x00000000);
10011 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
10013 memset(&fx
, 0, sizeof(fx
));
10014 fx
.dwSize
= sizeof(fx
);
10015 memset(&lock_desc
, 0, sizeof(lock_desc
));
10016 lock_desc
.dwSize
= sizeof(lock_desc
);
10018 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
10020 memset(&surface_desc
, 0, sizeof(surface_desc
));
10021 surface_desc
.dwSize
= sizeof(surface_desc
);
10022 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
10023 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10024 surface_desc
.dwWidth
= 4;
10025 surface_desc
.dwHeight
= 1;
10026 U4(surface_desc
).ddpfPixelFormat
= tests
[t
].fmt
;
10027 /* Windows XP (at least with the r200 driver, other drivers untested) produces
10028 * garbage when doing color keyed texture->texture blits. */
10029 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
10030 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10031 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
10032 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10034 fx
.dwFillColor
= tests
[t
].clear
;
10035 /* On the w8 testbot (WARP driver) the blit result has different values in the
10037 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
10038 | U3(tests
[t
].fmt
).dwGBitMask
10039 | U4(tests
[t
].fmt
).dwBBitMask
;
10041 for (c
= 0; c
<= tests
[t
].max
; ++c
)
10043 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
10044 * texture after it has been set once... */
10045 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
10046 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10047 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10048 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10049 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
10050 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10051 hr
= IDirect3DDevice7_SetTexture(device
, 0, texture
);
10052 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
10054 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
10055 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
10057 hr
= IDirectDrawSurface7_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10058 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10059 switch (tests
[t
].bpp
)
10062 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10063 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10064 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10065 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
10069 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
10070 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
10071 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
10072 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
10075 hr
= IDirectDrawSurface7_Unlock(src
, 0);
10076 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10077 hr
= IDirectDrawSurface7_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
10078 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10080 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
10081 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
10082 hr
= IDirectDrawSurface7_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
10083 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10085 hr
= IDirectDrawSurface7_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
10086 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
10088 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
10089 hr
= IDirectDrawSurface7_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
10090 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
10091 switch (tests
[t
].bpp
)
10094 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10095 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10096 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10097 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10101 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
10102 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
10103 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
10104 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
10107 hr
= IDirectDrawSurface7_Unlock(dst
, 0);
10108 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
10112 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10113 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
10115 if (data
[3] == tests
[t
].clear
)
10117 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
10118 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
10119 * even when a different surface is used. The blit itself doesn't draw anything,
10120 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
10121 * never be masked out by the key.
10123 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
10124 * terrible on WARP. */
10125 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
10126 IDirectDrawSurface7_Release(texture
);
10127 IDirectDrawSurface7_Release(src
);
10128 IDirectDrawSurface7_Release(dst
);
10133 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10134 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
10136 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10137 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
10139 if (c
== tests
[t
].max
)
10140 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10141 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
10143 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
10144 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
10146 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x0000ff00, 1.0f
, 0);
10147 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
10149 hr
= IDirect3DDevice7_BeginScene(device
);
10150 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10151 hr
= IDirect3DDevice7_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, D3DFVF_XYZ
| D3DFVF_TEX1
, quad
, 4, 0);
10152 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10153 hr
= IDirect3DDevice7_EndScene(device
);
10154 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10156 color
= get_surface_color(rt
, 80, 240);
10158 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10159 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10160 color
, tests
[t
].name
, c
);
10162 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10163 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10164 color
, tests
[t
].name
, c
);
10166 color
= get_surface_color(rt
, 240, 240);
10167 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10168 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10169 color
, tests
[t
].name
, c
);
10171 color
= get_surface_color(rt
, 400, 240);
10172 if (c
== tests
[t
].max
)
10173 ok(compare_color(color
, 0x0000ff00, 1) || broken(warp
&& compare_color(color
, 0x00000000, 1)),
10174 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10175 color
, tests
[t
].name
, c
);
10177 ok(compare_color(color
, 0x00000000, 1) || broken(warp
&& compare_color(color
, 0x0000ff00, 1)),
10178 "Got unexpected color 0x%08x, format %s, c=%u.\n",
10179 color
, tests
[t
].name
, c
);
10181 IDirectDrawSurface7_Release(texture
);
10183 IDirectDrawSurface7_Release(src
);
10184 IDirectDrawSurface7_Release(dst
);
10188 IDirectDrawSurface7_Release(rt
);
10189 IDirectDraw7_Release(ddraw
);
10190 refcount
= IDirect3DDevice7_Release(device
);
10191 ok(!refcount
, "Device has %u references left.\n", refcount
);
10192 DestroyWindow(window
);
10195 static void test_range_colorkey(void)
10197 IDirectDraw7
*ddraw
;
10200 IDirectDrawSurface7
*surface
;
10201 DDSURFACEDESC2 surface_desc
;
10205 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10206 0, 0, 640, 480, 0, 0, 0, 0);
10207 ddraw
= create_ddraw();
10208 ok(!!ddraw
, "Failed to create a ddraw object.\n");
10209 hr
= IDirectDraw7_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
10210 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
10212 memset(&surface_desc
, 0, sizeof(surface_desc
));
10213 surface_desc
.dwSize
= sizeof(surface_desc
);
10214 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
10215 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
10216 surface_desc
.dwWidth
= 1;
10217 surface_desc
.dwHeight
= 1;
10218 U4(surface_desc
).ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
10219 U1(U4(surface_desc
).ddpfPixelFormat
).dwRGBBitCount
= 32;
10220 U2(U4(surface_desc
).ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
10221 U3(U4(surface_desc
).ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
10222 U4(U4(surface_desc
).ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
10223 U5(U4(surface_desc
).ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
10225 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
10226 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10227 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10228 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10229 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10231 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10232 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10233 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10234 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10236 /* Same for DDSCAPS_OFFSCREENPLAIN. */
10237 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
10238 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10239 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
10240 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10241 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10243 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
10244 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10245 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10246 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10248 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
10249 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
10250 hr
= IDirectDraw7_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
10251 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
10253 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
10254 ckey
.dwColorSpaceLowValue
= 0x00000000;
10255 ckey
.dwColorSpaceHighValue
= 0x00000001;
10256 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10257 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10259 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10260 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10261 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10262 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10264 ckey
.dwColorSpaceLowValue
= 0x00000001;
10265 ckey
.dwColorSpaceHighValue
= 0x00000000;
10266 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10267 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10269 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10270 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10271 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10272 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10274 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
10275 ckey
.dwColorSpaceLowValue
= 0x00000000;
10276 ckey
.dwColorSpaceHighValue
= 0x00000000;
10277 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10278 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
10280 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
10281 ckey
.dwColorSpaceLowValue
= 0x00000001;
10282 ckey
.dwColorSpaceHighValue
= 0x00000000;
10283 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10284 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10285 ckey
.dwColorSpaceLowValue
= 0x00000000;
10286 ckey
.dwColorSpaceHighValue
= 0x00000001;
10287 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10288 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10289 /* Range destination keys don't work either. */
10290 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
10291 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10293 /* Just to show it's not because of A, R, and G having equal values. */
10294 ckey
.dwColorSpaceLowValue
= 0x00000000;
10295 ckey
.dwColorSpaceHighValue
= 0x01010101;
10296 hr
= IDirectDrawSurface7_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
10297 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
10299 /* None of these operations modified the key. */
10300 hr
= IDirectDrawSurface7_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
10301 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
10302 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
10303 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
10305 IDirectDrawSurface7_Release(surface
),
10306 refcount
= IDirectDraw7_Release(ddraw
);
10307 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
10308 DestroyWindow(window
);
10311 static void test_shademode(void)
10313 IDirect3DVertexBuffer7
*vb_strip
, *vb_list
, *buffer
;
10314 IDirect3DDevice7
*device
;
10315 D3DVERTEXBUFFERDESC desc
;
10316 IDirectDrawSurface7
*rt
;
10317 DWORD color0
, color1
;
10324 static const struct
10326 struct vec3 position
;
10331 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10332 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10333 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10334 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10338 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
10339 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10340 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10342 {{ 1.0f
, -1.0f
, 0.0f
}, 0xff0000ff},
10343 {{-1.0f
, 1.0f
, 0.0f
}, 0xff00ff00},
10344 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffffffff},
10346 static const struct
10350 DWORD color0
, color1
;
10354 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x0000ff00},
10355 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10356 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10357 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
10358 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
10359 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
10362 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
10363 0, 0, 640, 480, 0, 0, 0, 0);
10365 if (!(device
= create_device(window
, DDSCL_NORMAL
)))
10367 skip("Failed to create a 3D device, skipping test.\n");
10368 DestroyWindow(window
);
10372 hr
= IDirect3DDevice7_GetDirect3D(device
, &d3d
);
10373 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
10374 hr
= IDirect3DDevice7_GetRenderTarget(device
, &rt
);
10375 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
10377 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_LIGHTING
, FALSE
);
10378 ok(hr
== D3D_OK
, "Failed to disable lighting, hr %#x.\n", hr
);
10379 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
10380 ok(SUCCEEDED(hr
), "Failed to disable fog, hr %#x.\n", hr
);
10382 memset(&desc
, 0, sizeof(desc
));
10383 desc
.dwSize
= sizeof(desc
);
10384 desc
.dwCaps
= D3DVBCAPS_WRITEONLY
;
10385 desc
.dwFVF
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
10386 desc
.dwNumVertices
= sizeof(quad_strip
) / sizeof(*quad_strip
);
10387 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &vb_strip
, 0);
10388 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10389 hr
= IDirect3DVertexBuffer7_Lock(vb_strip
, 0, &data
, NULL
);
10390 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10391 memcpy(data
, quad_strip
, sizeof(quad_strip
));
10392 hr
= IDirect3DVertexBuffer7_Unlock(vb_strip
);
10393 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10395 desc
.dwNumVertices
= sizeof(quad_list
) / sizeof(*quad_list
);
10396 hr
= IDirect3D7_CreateVertexBuffer(d3d
, &desc
, &vb_list
, 0);
10397 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
10398 hr
= IDirect3DVertexBuffer7_Lock(vb_list
, 0, &data
, NULL
);
10399 ok(hr
== D3D_OK
, "Failed to lock vertex buffer, hr %#x.\n", hr
);
10400 memcpy(data
, quad_list
, sizeof(quad_list
));
10401 hr
= IDirect3DVertexBuffer7_Unlock(vb_list
);
10402 ok(hr
== D3D_OK
, "Failed to unlock vertex buffer, hr %#x.\n", hr
);
10404 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
10405 * the color fixups we have to do for FLAT shading will be dependent on that. */
10407 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
10409 hr
= IDirect3DDevice7_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
10410 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
10412 hr
= IDirect3DDevice7_SetRenderState(device
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
10413 ok(hr
== D3D_OK
, "Failed to set shade mode, hr %#x.\n", hr
);
10415 hr
= IDirect3DDevice7_BeginScene(device
);
10416 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
10417 buffer
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? vb_strip
: vb_list
;
10418 count
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? 4 : 6;
10419 hr
= IDirect3DDevice7_DrawPrimitiveVB(device
, tests
[i
].primtype
, buffer
, 0, count
, 0);
10420 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
10421 hr
= IDirect3DDevice7_EndScene(device
);
10422 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
10424 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
10425 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
10427 /* For D3DSHADE_FLAT it should take the color of the first vertex of
10428 * each triangle. This requires EXT_provoking_vertex or similar
10429 * functionality being available. */
10430 /* PHONG should be the same as GOURAUD, since no hardware implements
10432 ok(color0
== tests
[i
].color0
, "Test %u shading has color0 %08x, expected %08x.\n",
10433 i
, color0
, tests
[i
].color0
);
10434 ok(color1
== tests
[i
].color1
, "Test %u shading has color1 %08x, expected %08x.\n",
10435 i
, color1
, tests
[i
].color1
);
10438 IDirect3DVertexBuffer7_Release(vb_strip
);
10439 IDirect3DVertexBuffer7_Release(vb_list
);
10440 IDirectDrawSurface7_Release(rt
);
10441 IDirect3D7_Release(d3d
);
10442 refcount
= IDirect3DDevice7_Release(device
);
10443 ok(!refcount
, "Device has %u references left.\n", refcount
);
10444 DestroyWindow(window
);
10449 HMODULE module
= GetModuleHandleA("ddraw.dll");
10450 IDirectDraw7
*ddraw
;
10451 DEVMODEW current_mode
;
10453 if (!(pDirectDrawCreateEx
= (void *)GetProcAddress(module
, "DirectDrawCreateEx")))
10455 win_skip("DirectDrawCreateEx not available, skipping tests.\n");
10459 if (!(ddraw
= create_ddraw()))
10461 skip("Failed to create a ddraw object, skipping tests.\n");
10464 IDirectDraw7_Release(ddraw
);
10466 memset(¤t_mode
, 0, sizeof(current_mode
));
10467 current_mode
.dmSize
= sizeof(current_mode
);
10468 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
10469 registry_mode
.dmSize
= sizeof(registry_mode
);
10470 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
10471 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
10472 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
10474 skip("Current mode does not match registry mode, skipping test.\n");
10478 test_process_vertices();
10479 test_coop_level_create_device_window();
10480 test_clipper_blt();
10481 test_coop_level_d3d_state();
10482 test_surface_interface_mismatch();
10483 test_coop_level_threaded();
10485 test_texture_load_ckey();
10493 test_window_style();
10494 test_redundant_mode_set();
10495 test_coop_level_mode_set();
10496 test_coop_level_mode_set_multi();
10498 test_coop_level_surf_create();
10500 test_coop_level_multi_window();
10501 test_draw_strided();
10503 test_specular_lighting();
10504 test_clear_rect_count();
10505 test_coop_level_versions();
10506 test_fog_special();
10507 test_lighting_interface_versions();
10508 test_coop_level_activateapp();
10509 test_texturemanage();
10510 test_block_formats_creation();
10511 test_unsupported_formats();
10513 test_primary_caps();
10514 test_surface_lock();
10515 test_surface_discard();
10517 test_set_surface_desc();
10518 test_user_memory_getdc();
10519 test_sysmem_overlay();
10520 test_primary_palette();
10521 test_surface_attachment();
10522 test_private_data();
10523 test_pixel_format();
10524 test_create_surface_pitch();
10525 test_mipmap_lock();
10526 test_palette_complex();
10527 test_p8_rgb_blit();
10529 test_palette_gdi();
10530 test_palette_alpha();
10531 test_vb_writeonly();
10532 test_lost_device();
10533 test_resource_priority();
10534 test_surface_desc_lock();
10535 test_fog_interpolation();
10536 test_negative_fixedfunction_fog();
10537 test_table_fog_zw();
10538 test_signed_formats();
10540 test_texcoordindex();
10541 test_colorkey_precision();
10542 test_range_colorkey();